io.deephaven.engine.table.impl.DataAccessHelpers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
package io.deephaven.engine.table.impl;
import io.deephaven.engine.liveness.LivenessScopeStack;
import io.deephaven.engine.table.DataColumn;
import io.deephaven.engine.table.Table;
import io.deephaven.util.SafeCloseable;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@Deprecated
public class DataAccessHelpers {
// -----------------------------------------------------------------------------------------------------------------
// DataColumns for fetching data by row position; generally much less efficient than ColumnSource
// TODO(deephaven-core#3920): Delete DataColumn
// -----------------------------------------------------------------------------------------------------------------
public static DataColumn>[] getColumns(Table table) {
final Table t = table.coalesce();
return t.getDefinition()
.getColumnStream()
.map(c -> getColumn(t, c.getName()))
.toArray(DataColumn[]::new);
}
public static DataColumn getColumn(Table table, final int columnIndex) {
return getColumn(table, table.getDefinition().getColumns().get(columnIndex).getName());
}
public static DataColumn getColumn(Table table, @NotNull final String columnName) {
return new IndexedDataColumn<>(columnName, table.coalesce());
}
// -----------------------------------------------------------------------------------------------------------------
// Convenience data fetching; highly inefficient
// -----------------------------------------------------------------------------------------------------------------
public static Object[] getRecord(Table table, long rowNo, String... columnNames) {
try (final SafeCloseable ignored = LivenessScopeStack.open()) {
final Table t = table.coalesce();
final long key = t.getRowSet().get(rowNo);
return (columnNames.length > 0
? Arrays.stream(columnNames).map(t::getColumnSource)
: t.getColumnSources().stream())
.map(columnSource -> columnSource.get(key))
.toArray(Object[]::new);
}
}
}