Skip to content

Commit

Permalink
Remove QueryTable#maybeTransformToPrimitive
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Jul 21, 2023
1 parent 74664f7 commit b3ab034
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2550,37 +2550,6 @@ private static void throwColumnConflictMessage(Set<String> left, Set<String> rig
throw new RuntimeException("Column name conflicts: " + IterableUtils.makeCommaSeparatedList(conflicts));
}

/**
* If we have a column source that is a complex type, but can be reinterpreted or transformed into a simpler type,
* do the transformation, otherwise return the original column source.
*
* @param columnSource the column source to possibly reinterpret
* @return the transformed column source, or the original column source if there is not a relevant transformation
*/
static ColumnSource<?> maybeTransformToPrimitive(final ColumnSource<?> columnSource) {
if (Instant.class.isAssignableFrom(columnSource.getType())) {
if (columnSource.allowsReinterpret(long.class)) {
return columnSource.reinterpret(long.class);
} else {
// noinspection unchecked
final ColumnSource<Instant> columnSourceAsInstant = (ColumnSource<Instant>) columnSource;
return new InstantAsLongColumnSource(columnSourceAsInstant);
}
}

if (Boolean.class.isAssignableFrom(columnSource.getType())) {
if (columnSource.allowsReinterpret(byte.class)) {
return columnSource.reinterpret(byte.class);
} else {
// noinspection unchecked
final ColumnSource<Boolean> columnSourceAsBoolean = (ColumnSource<Boolean>) columnSource;
return new BooleanAsByteColumnSource(columnSourceAsBoolean);
}
}

return columnSource;
}

@Override
public Table sort(Collection<SortColumn> columnsToSortBy) {
final UpdateGraph updateGraph = getUpdateGraph();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.deephaven.engine.rowset.*;
import io.deephaven.engine.rowset.RowSetFactory;
import io.deephaven.engine.table.*;
import io.deephaven.engine.table.impl.sources.ReinterpretUtils;
import io.deephaven.engine.table.iterators.ChunkedLongColumnIterator;
import io.deephaven.engine.table.iterators.LongColumnIterator;
import io.deephaven.util.datastructures.hash.HashMapK4V4;
Expand Down Expand Up @@ -52,8 +53,8 @@ public SortOperation(QueryTable parent, SortPair[] sortPairs) {

for (int ii = 0; ii < sortColumnNames.length; ++ii) {
// noinspection unchecked
sortColumns[ii] = (ColumnSource<Comparable<?>>) QueryTable
.maybeTransformToPrimitive(parent.getColumnSource(sortColumnNames[ii]));
sortColumns[ii] = (ColumnSource<Comparable<?>>) ReinterpretUtils
.maybeConvertToPrimitive(parent.getColumnSource(sortColumnNames[ii]));

Require.requirement(
Comparable.class.isAssignableFrom(sortColumns[ii].getType())
Expand Down Expand Up @@ -267,8 +268,8 @@ public Result<QueryTable> initialize(boolean usePrev, long beforeClock) {
// source
for (int ii = 0; ii < sortedColumnsToSortBy.length; ++ii) {
// noinspection unchecked
sortedColumnsToSortBy[ii] =
(ColumnSource<Comparable<?>>) QueryTable.maybeTransformToPrimitive(sortedColumnsToSortBy[ii]);
sortedColumnsToSortBy[ii] = (ColumnSource<Comparable<?>>) ReinterpretUtils
.maybeConvertToPrimitive(sortedColumnsToSortBy[ii]);
}

resultTable = new QueryTable(resultRowSet, resultMap);
Expand Down

0 comments on commit b3ab034

Please sign in to comment.