use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.
the class TestListBasedRecordSet method testEmptyCursor.
@Test
public void testEmptyCursor() {
ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(), ImmutableList.of(BIGINT, INTEGER));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, INTEGER));
RecordCursor cursor = recordSet.cursor();
assertFalse(cursor.advanceNextPosition());
}
use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.
the class TestListBasedRecordSet method testCursor.
@Test
public void testCursor() {
ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(Arrays.asList("1", null, "3"), Arrays.asList("ab", "c", null)), ImmutableList.of(BIGINT, VARCHAR));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, VARCHAR));
RecordCursor cursor = recordSet.cursor();
assertTrue(cursor.advanceNextPosition());
assertEquals(cursor.getType(0), BIGINT);
assertEquals(cursor.getType(1), VARCHAR);
assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(2));
assertEquals(cursor.getLong(0), 1L);
assertEquals(cursor.getSlice(1), Slices.utf8Slice("ab"));
assertTrue(cursor.advanceNextPosition());
assertTrue(cursor.isNull(0));
assertEquals(cursor.getSlice(1), Slices.utf8Slice("c"));
assertTrue(cursor.advanceNextPosition());
assertEquals(cursor.getLong(0), 3L);
assertTrue(cursor.isNull(1));
assertFalse(cursor.advanceNextPosition());
assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(0));
}
use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.
the class PrestoThriftTypeUtils method fromLongBasedColumn.
public static PrestoThriftBlock fromLongBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], long[], PrestoThriftBlock> result) {
if (positions == 0) {
return result.apply(null, null);
}
boolean[] nulls = null;
long[] longs = null;
RecordCursor cursor = recordSet.cursor();
for (int position = 0; position < positions; position++) {
checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
if (cursor.isNull(columnIndex)) {
if (nulls == null) {
nulls = new boolean[positions];
}
nulls[position] = true;
} else {
if (longs == null) {
longs = new long[positions];
}
longs[position] = cursor.getLong(columnIndex);
}
}
checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
return result.apply(nulls, longs);
}
use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.
the class PrestoThriftTypeUtils method fromIntBasedColumn.
public static PrestoThriftBlock fromIntBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], int[], PrestoThriftBlock> result) {
if (positions == 0) {
return result.apply(null, null);
}
boolean[] nulls = null;
int[] ints = null;
RecordCursor cursor = recordSet.cursor();
for (int position = 0; position < positions; position++) {
checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
if (cursor.isNull(columnIndex)) {
if (nulls == null) {
nulls = new boolean[positions];
}
nulls[position] = true;
} else {
if (ints == null) {
ints = new int[positions];
}
ints[position] = (int) cursor.getLong(columnIndex);
}
}
checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
return result.apply(nulls, ints);
}
use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.
the class TpchIndexedData method indexTable.
private static IndexedTable indexTable(RecordSet recordSet, final List<String> outputColumns, List<String> keyColumns) {
List<Integer> keyPositions = keyColumns.stream().map(columnName -> {
int position = outputColumns.indexOf(columnName);
checkState(position != -1);
return position;
}).collect(toImmutableList());
ImmutableListMultimap.Builder<MaterializedTuple, MaterializedTuple> indexedValuesBuilder = ImmutableListMultimap.builder();
List<Type> outputTypes = recordSet.getColumnTypes();
List<Type> keyTypes = extractPositionValues(outputTypes, keyPositions);
RecordCursor cursor = recordSet.cursor();
while (cursor.advanceNextPosition()) {
List<Object> values = extractValues(cursor, outputTypes);
List<Object> keyValues = extractPositionValues(values, keyPositions);
indexedValuesBuilder.put(new MaterializedTuple(keyValues), new MaterializedTuple(values));
}
return new IndexedTable(keyColumns, keyTypes, outputColumns, outputTypes, indexedValuesBuilder.build());
}
Aggregations