use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
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 com.facebook.presto.spi.RecordCursor in project presto by prestodb.
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 com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TableStatisticsRecorder method recordStatistics.
public TableStatisticsData recordStatistics(Table table, double scaleFactor) {
Session session = Session.getDefaultSession().withScale(scaleFactor).withParallelism(1).withNoSexism(false);
List<Column> columns = ImmutableList.copyOf(table.getColumns());
RecordCursor recordCursor = new TpcdsRecordSet(Results.constructResults(table, session), columns).cursor();
List<ColumnStatisticsRecorder> statisticsRecorders = createStatisticsRecorders(columns);
long rowCount = 0;
while (recordCursor.advanceNextPosition()) {
rowCount++;
for (int columnId = 0; columnId < columns.size(); columnId++) {
Comparable<?> value = getPrestoValue(recordCursor, columns, columnId);
statisticsRecorders.get(columnId).record(value);
}
}
Map<String, ColumnStatisticsData> columnSampleStatistics = IntStream.range(0, columns.size()).boxed().collect(toImmutableMap(i -> columns.get(i).getName(), i -> statisticsRecorders.get(i).getRecording()));
return new TableStatisticsData(rowCount, columnSampleStatistics);
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class PrestoThriftPageResult method totalRecords.
private static int totalRecords(RecordSet recordSet) {
RecordCursor cursor = recordSet.cursor();
int result = 0;
while (cursor.advanceNextPosition()) {
result++;
}
return result;
}
Aggregations