@Override public boolean advanceNextPosition() { return delegate.advanceNextPosition(); }
@Override public boolean advanceNextPosition() { return delegate.advanceNextPosition(); }
@Override public boolean advanceNextPosition() { return delegate.advanceNextPosition(); }
@Override public boolean advanceNextPosition() { while (delegate.advanceNextPosition()) { if (fieldSetsEqual(delegate, fieldSets)) { return true; } } return false; }
private static int totalRecords(RecordSet recordSet) { RecordCursor cursor = recordSet.cursor(); int result = 0; while (cursor.advanceNextPosition()) { result++; } return result; } }
@Override public boolean advanceNextPosition() { for (int i = 0; i < columnMappings.size(); i++) { if (coercers[i] != null) { coercers[i].reset(); } } return delegate.advanceNextPosition(); }
@Override public boolean advanceNextPosition() { checkState(!closed); while (currentCursor == null || !currentCursor.advanceNextPosition()) { if (!iterator.hasNext()) { return false; } if (currentCursor != null) { currentCursor.close(); } currentCursor = iterator.next(); } return true; }
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); }
private static void assertRecordCursor(List<Type> types, Iterator<?>[] valuesByField, RecordCursor cursor) { while (cursor.advanceNextPosition()) { for (int field = 0; field < types.size(); field++) { assertTrue(valuesByField[field].hasNext()); Object expected = valuesByField[field].next(); Object actual = getActualCursorValue(cursor, types.get(field), field); assertEquals(actual, expected); } } }
@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()); }
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()); }
private List<Long> readTimeStampsFrom(RecordSet recordSet) { ImmutableList.Builder<Long> result = ImmutableList.builder(); try (RecordCursor cursor = recordSet.cursor()) { while (cursor.advanceNextPosition()) { for (int i = 0; i < recordSet.getColumnTypes().size(); i++) { cursor.isNull(i); } if (cursor.isNull(0)) { return result.build(); } assertTrue(recordSet.getColumnTypes().get(0) instanceof TimestampType); result.add(cursor.getLong(0)); } } return result.build(); }
@Test public void testGetRecordSet() { ConnectorTransactionHandle transaction = new JdbcTransactionHandle(); JdbcRecordSetProvider recordSetProvider = new JdbcRecordSetProvider(jdbcClient); RecordSet recordSet = recordSetProvider.getRecordSet(transaction, SESSION, split, ImmutableList.of(textColumn, textShortColumn, valueColumn)); assertNotNull(recordSet, "recordSet is null"); RecordCursor cursor = recordSet.cursor(); assertNotNull(cursor, "cursor is null"); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(2)); assertEquals(cursor.getSlice(0), cursor.getSlice(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("one", 1L) .put("two", 2L) .put("three", 3L) .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
@Test public void testCursorMixedOrder() { RecordSet recordSet = new JdbcRecordSet(jdbcClient, session, split, ImmutableList.of( columnHandles.get("value"), columnHandles.get("value"), columnHandles.get("text"))); try (RecordCursor cursor = recordSet.cursor()) { assertEquals(cursor.getType(0), BIGINT); assertEquals(cursor.getType(1), BIGINT); assertEquals(cursor.getType(2), VARCHAR); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { assertEquals(cursor.getLong(0), cursor.getLong(1)); data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("one", 1L) .put("two", 2L) .put("three", 3L) .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); } }
@Test public void testGetRecordSet() { ExampleRecordSetProvider recordSetProvider = new ExampleRecordSetProvider(new ExampleConnectorId("test")); RecordSet recordSet = recordSetProvider.getRecordSet(ExampleTransactionHandle.INSTANCE, SESSION, new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("test", "value", BIGINT, 1))); assertNotNull(recordSet, "recordSet is null"); RecordCursor cursor = recordSet.cursor(); assertNotNull(cursor, "cursor is null"); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
@Test public void testRecordSetProvider() throws Exception { for (SchemaTableName schemaTableName : metadata.listTables(SESSION, JMX_SCHEMA_NAME)) { RecordSet recordSet = getRecordSet(schemaTableName); try (RecordCursor cursor = recordSet.cursor()) { while (cursor.advanceNextPosition()) { for (int i = 0; i < recordSet.getColumnTypes().size(); i++) { cursor.isNull(i); } } } } }
@Test public void testCursorSimple() { RecordSet recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("test", "value", BIGINT, 1))); RecordCursor cursor = recordSet.cursor(); assertEquals(cursor.getType(0), createUnboundedVarcharType()); assertEquals(cursor.getType(1), BIGINT); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(1)); assertFalse(cursor.isNull(0)); assertFalse(cursor.isNull(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
@Test public void testCursorMixedOrder() { RecordSet recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "value", BIGINT, 1), new ExampleColumnHandle("test", "value", BIGINT, 1), new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0))); RecordCursor cursor = recordSet.cursor(); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { assertEquals(cursor.getLong(0), cursor.getLong(1)); data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
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); }
@Test public void test() { TypeManager typeManager = new TypeRegistry(); FunctionRegistry functionRegistry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); ArrayType arrayOfBigintType = new ArrayType(BIGINT); FieldSetFilteringRecordSet fieldSetFilteringRecordSet = new FieldSetFilteringRecordSet( functionRegistry, new InMemoryRecordSet( ImmutableList.of(BIGINT, BIGINT, TIMESTAMP_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE, arrayOfBigintType, arrayOfBigintType), ImmutableList.of( ImmutableList.of( 100L, 100L, // test same time in different time zone to make sure equal check was done properly packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)))), ImmutableList.of(ImmutableSet.of(0, 1), ImmutableSet.of(2, 3), ImmutableSet.of(4, 5))); RecordCursor recordCursor = fieldSetFilteringRecordSet.cursor(); assertTrue(recordCursor.advanceNextPosition()); } }