Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.connect;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import io.deephaven.benchmark.util.Dates;
import io.deephaven.benchmark.util.Numbers;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.table.Table;
/**
* Create an in-memory table from either CSV or a Deephaven table. Provides some basic accessors for getting column
* values. No data typing is done on import of the data. Use typed methods like {@code getNumber()} to convert from
* whatever row value came from the import.
*
* Note: This class is not a general purpose class for reading CSV or Deephaven Table data. It fits specific cases used
* by the Benchmark framework.
*/
public class CachedResultTable implements ResultTable {
/**
* Create an in-memory table instance from basic CSV. Does not handle quotes and is mainly used for testing. Skips
* any lines that do not have the same items as the header and trims all row items. No attempt is made to determine
* data types.
*
* @param csv basic csv with a header and columns
* @param delim
* @return a cached result table instance
*/
static public ResultTable create(String csv, String delim) {
var importer = new CsvImporter(csv, delim);
int minRowColumnCount = importer.columns().size();
return new CachedResultTable(importer.columns(), importer.rows(minRowColumnCount));
}
/**
* Create an in-memory table instance from a Deephaven Engine Table. Whatever datatype is read from the Table is
* stored in this cache.
*
* @param table a Deephaven table (likely procured from a subscription)
* @return a cached result table
*/
static public ResultTable create(Table table) {
var importer = new EngineTableImporter(table);
return new CachedResultTable(importer.columns(), importer.rows());
}
final List columns;
final List> rows;
CachedResultTable(List columns, List> rows) {
this.columns = columns;
this.rows = rows;
}
public List getColumnNames() {
return getNonFormatColumns(columns);
}
public int getRowCount() {
return rows.size();
}
public Object getValue(int rowIndex, String columnName) {
if (rowIndex >= rows.size())
return null;
var value = rows.get(rowIndex).get(getColumnIndex(columnName));
var regex = columnName + "__.*_FORMAT";
var formatNames = columns.stream().filter(c -> c.matches(regex)).toList();
if (!formatNames.isEmpty()) {
var formatVal = rows.get(rowIndex).get(getColumnIndex(formatNames.get(0)));
var formatName = formatNames.get(0).replace(columnName + "__", "");
value = formatValue(value, formatName, formatVal.toString());
}
return value;
}
public List