Search in sources :

Example 1 with ColumnType

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;
}
Also used : ColumnType(tech.tablesaw.api.ColumnType) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 2 with ColumnType

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;
}
Also used : ColumnType(tech.tablesaw.api.ColumnType)

Example 3 with ColumnType

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;
}
Also used : ColumnType(tech.tablesaw.api.ColumnType) Column(tech.tablesaw.columns.Column) ArrayList(java.util.ArrayList) Objects(com.google.common.base.Objects)

Example 4 with ColumnType

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);
}
Also used : ColumnType(tech.tablesaw.api.ColumnType) ReadOptions(tech.tablesaw.io.ReadOptions) Reader(java.io.Reader) DataReader(tech.tablesaw.io.DataReader) FileReader(tech.tablesaw.io.FileReader)

Example 5 with ColumnType

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);
        }
    }
}
Also used : ColumnType(tech.tablesaw.api.ColumnType) DateColumn(tech.tablesaw.api.DateColumn) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeColumn(tech.tablesaw.api.DateTimeColumn)

Aggregations

ColumnType (tech.tablesaw.api.ColumnType)17 Table (tech.tablesaw.api.Table)7 ArrayList (java.util.ArrayList)6 Column (tech.tablesaw.columns.Column)6 List (java.util.List)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 Reader (java.io.Reader)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)2 DoubleColumn (tech.tablesaw.api.DoubleColumn)2 IntColumn (tech.tablesaw.api.IntColumn)2 LongColumn (tech.tablesaw.api.LongColumn)2 Row (tech.tablesaw.api.Row)2 Objects (com.google.common.base.Objects)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Streams (com.google.common.collect.Streams)1 AbstractParser (com.univocity.parsers.common.AbstractParser)1 ResultSetMetaData (java.sql.ResultSetMetaData)1