Skip to content

Commit

Permalink
fill
Browse files Browse the repository at this point in the history
  • Loading branch information
Baunsgaard committed Oct 21, 2024
1 parent 6e5172d commit 7077bd7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
46 changes: 37 additions & 9 deletions src/main/java/org/apache/sysds/runtime/io/FrameReaderTextCSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ protected final int readCSVFrameFromInputSplit(InputSplit split, InputFormat<Lon
final CellAssigner f;
if(naValues != null )
f = FrameReaderTextCSV::assignCellGeneric;
else
else if(isFill && dfillValue != 0)
f = FrameReaderTextCSV::assignCellNoFill;
else
f = FrameReaderTextCSV::assignCellNoNa;

// (int row, Array<?> dest, String val, int length, Set<String> naValues, boolean isFill,
// double dfillValue, String sfillValue, int col) ->{};
// create record reader
Expand Down Expand Up @@ -221,27 +224,52 @@ void assign(int row, Array<?> dest, String val, int length, Set<String> naValues
double dfillValue, String sfillValue, int col);
}

private static void assignCellNoFill(int row, Array<?> dest, String val, int length, Set<String> naValues, boolean isFill,
double dfillValue, String sfillValue, int col) {
if(length == 0){
dest.set(row, sfillValue);
} else {
final String part = IOUtilFunctions.trim(val, length);
if(part == null || part.isEmpty() ) {
dest.set(row, sfillValue);
}
else
dest.set(row, part);
}
}


private static void assignCellNoNa(int row, Array<?> dest, String val, int length, Set<String> naValues, boolean isFill,
double dfillValue, String sfillValue, int col) {
final String part = IOUtilFunctions.trim(val, length);
if(part == null || part.isEmpty() ) {
if(length == 0){
if(isFill && dfillValue != 0)
dest.set(row, sfillValue);
} else {
final String part = IOUtilFunctions.trim(val, length);
if(part == null || part.isEmpty() ) {
if(isFill && dfillValue != 0)
dest.set(row, sfillValue);
}
else
dest.set(row, part);
}
else
dest.set(row, part);
}

private static void assignCellGeneric(int row, Array<?> dest, String val, int length, Set<String> naValues, boolean isFill,
double dfillValue, String sfillValue, int col) {
final String part = IOUtilFunctions.trim(val, length);
if(part == null || part.isEmpty() || (naValues != null && naValues.contains(part))) {
if(length == 0) {
if(isFill && dfillValue != 0)
dest.set(row, sfillValue);
}
else
dest.set(row, part);
else {
final String part = IOUtilFunctions.trim(val, length);
if(part == null || part.isEmpty() || (naValues != null && naValues.contains(part))) {
if(isFill && dfillValue != 0)
dest.set(row, sfillValue);
}
else
dest.set(row, part);
}
}

// private static boolean assignCellNoNan(int row, Array<?>[] destA, String val, boolean emptyValuesFound, int col) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/apache/sysds/runtime/io/IOUtilFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,23 @@ private static int getToNoQuoteCharDelim(final String str, final int from, final

public static String trim(String str) {
final int len = str.length();
if(len == 0)
return str;
return trim(str, len);
}

/**
* Caller must have a string of at least 1 character length.
*
* @param str string to trim
* @param len length of string
* @return the trimmed string.
*/
public static String trim(String str, final int len) {
try{
if(len == 0)
return str;

// short the call to return input if not whitespace in ends.
else if(str.charAt(0) <= ' ' || str.charAt(len -1) <= ' ')
if(str.charAt(0) <= ' ' || str.charAt(len -1) <= ' ')
return str.trim();
else
return str;
Expand Down

0 comments on commit 7077bd7

Please sign in to comment.