use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class ASTDataset method getColumnValue.
private IExpr getColumnValue(int rowPosition, int columnPosition) {
Column<?> column = fTable.column(columnPosition);
ColumnType t = column.type();
Object obj = fTable.get(rowPosition, columnPosition);
if (t.equals(ColumnType.BOOLEAN)) {
Boolean b = (Boolean) obj;
if (b) {
return S.True;
} else {
return S.False;
}
} else if (t.equals(ColumnType.SHORT)) {
short sValue = (Short) obj;
return F.ZZ(sValue);
} else if (t.equals(ColumnType.INTEGER)) {
int iValue = (Integer) obj;
return F.ZZ(iValue);
} else if (t.equals(ColumnType.LONG)) {
long lValue = (Long) obj;
return F.ZZ(lValue);
} else if (t.equals(ColumnType.FLOAT)) {
float fValue = (Float) obj;
return F.num(fValue);
} else if (t.equals(ColumnType.DOUBLE)) {
double dValue = (Double) obj;
return F.num(dValue);
} else if (t.equals(ColumnType.STRING)) {
return F.stringx((String) obj);
} else if (t.equals(ColumnType.EXPR)) {
return (IExpr) obj;
// } else if (t.equals(ColumnType.SKIP)) {
// ruleCache(cache, assoc, F.Rule(colName, F.Missing));
}
IExpr valueStr = F.stringx(obj.toString());
return valueStr;
}
use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class Summarizer method getAggregateFunctionMultimap.
private ArrayListMultimap<String, AggregateFunction<?, ?>> getAggregateFunctionMultimap() {
ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap = ArrayListMultimap.create();
for (String name : summarizedColumns) {
Column<?> column = temp.column(name);
ColumnType type = column.type();
for (AggregateFunction<?, ?> reduction : reductions) {
if (reduction.isCompatibleColumn(type)) {
reductionMultimap.put(name, reduction);
}
}
}
if (reductionMultimap.isEmpty()) {
throw new IllegalArgumentException("None of the aggregate functions provided apply to the summarized column type(s).");
}
return reductionMultimap;
}
use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class ArgumentList method createEmptyDestinationColumns.
/**
* @return an ordered list of new columns this analytic query will generate.
*/
List<Column<?>> createEmptyDestinationColumns(int rowCount) {
List<Column<?>> newColumns = new ArrayList<>();
for (String toColumn : newColumnNames) {
FunctionCall<? extends FunctionMetaData> functionCall = Stream.of(aggregateFunctions.get(toColumn), numberingFunctions.get(toColumn)).filter(java.util.Objects::nonNull).findFirst().get();
ColumnType type = functionCall.function.returnType();
Column<?> resultColumn = type.create(toColumn);
newColumns.add(resultColumn);
for (int i = 0; i < rowCount; i++) {
resultColumn.appendMissing();
}
}
return newColumns;
}
use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class CsvReader method getReaderAndColumnTypes.
/**
* Determines column types if not provided by the user Reads all input into memory unless File was
* provided
*/
private Pair<Reader, ReadOptions.ColumnTypeReadOptions> getReaderAndColumnTypes(Source source, CsvReadOptions options) throws IOException {
ReadOptions.ColumnTypeReadOptions columnTypeReadOptions = options.columnTypeReadOptions();
byte[] bytesCache = null;
boolean need2ParseFile = !columnTypeReadOptions.hasColumnTypeForAllColumns() && (!options.header() || !columnTypeReadOptions.hasColumnTypeForAllColumnsIfHavingColumnNames());
if (need2ParseFile) {
Reader reader = source.createReader(null);
if (source.file() == null) {
String s = CharStreams.toString(reader);
bytesCache = source.getCharset() != null ? s.getBytes(source.getCharset()) : s.getBytes();
// create a new reader since we just exhausted the existing one
reader = source.createReader(bytesCache);
}
ColumnType[] detectedColumnTypes = detectColumnTypes(reader, options);
// for only header present)
if (detectedColumnTypes.length > 0) {
columnTypeReadOptions = ReadOptions.ColumnTypeReadOptions.of(detectedColumnTypes);
}
}
return Pair.create(source.createReader(bytesCache), columnTypeReadOptions);
}
use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class CsvWriter method writeValues.
private void writeValues(Table table, CsvWriteOptions options, int r, String[] entries, int c) {
DateTimeFormatter dateFormatter = options.dateFormatter();
DateTimeFormatter dateTimeFormatter = options.dateTimeFormatter();
ColumnType columnType = table.column(c).type();
if (dateFormatter != null && columnType.equals(ColumnType.LOCAL_DATE)) {
DateColumn dc = (DateColumn) table.column(c);
entries[c] = options.dateFormatter().format(dc.get(r));
} else if (dateTimeFormatter != null && columnType.equals(ColumnType.LOCAL_DATE_TIME)) {
DateTimeColumn dc = (DateTimeColumn) table.column(c);
entries[c] = options.dateTimeFormatter().format(dc.get(r));
} else {
if (options.usePrintFormatters()) {
entries[c] = table.getString(r, c);
} else {
entries[c] = table.getUnformatted(r, c);
}
}
}
Aggregations