use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TestHiveFileFormats method testCursorProvider.
private void testCursorProvider(HiveRecordCursorProvider cursorProvider, FileSplit split, HiveStorageFormat storageFormat, List<TestColumn> testColumns, int rowCount) throws IOException {
Properties splitProperties = new Properties();
splitProperties.setProperty(FILE_INPUT_FORMAT, storageFormat.getInputFormat());
splitProperties.setProperty(SERIALIZATION_LIB, storageFormat.getSerDe());
splitProperties.setProperty("columns", Joiner.on(',').join(transform(filter(testColumns, not(TestColumn::isPartitionKey)), TestColumn::getName)));
splitProperties.setProperty("columns.types", Joiner.on(',').join(transform(filter(testColumns, not(TestColumn::isPartitionKey)), TestColumn::getType)));
List<HivePartitionKey> partitionKeys = testColumns.stream().filter(TestColumn::isPartitionKey).map(input -> new HivePartitionKey(input.getName(), HiveType.valueOf(input.getObjectInspector().getTypeName()), (String) input.getWriteValue())).collect(toList());
Optional<ConnectorPageSource> pageSource = HivePageSourceProvider.createHivePageSource(ImmutableSet.of(cursorProvider), ImmutableSet.of(), "test", new Configuration(), SESSION, split.getPath(), OptionalInt.empty(), split.getStart(), split.getLength(), splitProperties, TupleDomain.all(), getColumnHandles(testColumns), partitionKeys, DateTimeZone.getDefault(), TYPE_MANAGER, ImmutableMap.of());
RecordCursor cursor = ((RecordPageSource) pageSource.get()).getCursor();
checkCursor(cursor, testColumns, rowCount);
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TestExampleRecordSet method testCursorMixedOrder.
@Test
public void testCursorMixedOrder() throws Exception {
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());
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TestExampleRecordSet method testCursorSimple.
@Test
public void testCursorSimple() throws Exception {
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());
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class HivePageSourceProvider method createHivePageSource.
public static Optional<ConnectorPageSource> createHivePageSource(Set<HiveRecordCursorProvider> cursorProviders, Set<HivePageSourceFactory> pageSourceFactories, String clientId, Configuration configuration, ConnectorSession session, Path path, OptionalInt bucketNumber, long start, long length, Properties schema, TupleDomain<HiveColumnHandle> effectivePredicate, List<HiveColumnHandle> hiveColumns, List<HivePartitionKey> partitionKeys, DateTimeZone hiveStorageTimeZone, TypeManager typeManager, Map<Integer, HiveType> columnCoercions) {
List<ColumnMapping> columnMappings = ColumnMapping.buildColumnMappings(partitionKeys, hiveColumns, columnCoercions, path, bucketNumber);
List<ColumnMapping> regularColumnMappings = ColumnMapping.extractRegularColumnMappings(columnMappings);
for (HivePageSourceFactory pageSourceFactory : pageSourceFactories) {
Optional<? extends ConnectorPageSource> pageSource = pageSourceFactory.createPageSource(configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, true), effectivePredicate, hiveStorageTimeZone);
if (pageSource.isPresent()) {
return Optional.of(new HivePageSource(columnMappings, hiveStorageTimeZone, typeManager, pageSource.get()));
}
}
for (HiveRecordCursorProvider provider : cursorProviders) {
// GenericHiveRecordCursor will automatically do the coercion without HiveCoercionRecordCursor
boolean doCoercion = !(provider instanceof GenericHiveRecordCursorProvider);
Optional<RecordCursor> cursor = provider.createRecordCursor(clientId, configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, doCoercion), effectivePredicate, hiveStorageTimeZone, typeManager);
if (cursor.isPresent()) {
RecordCursor delegate = cursor.get();
// Need to wrap RcText and RcBinary into a wrapper, which will do the coercion for mismatch columns
if (doCoercion) {
delegate = new HiveCoercionRecordCursor(regularColumnMappings, typeManager, delegate);
}
HiveRecordCursor hiveRecordCursor = new HiveRecordCursor(columnMappings, hiveStorageTimeZone, typeManager, delegate);
List<Type> columnTypes = hiveColumns.stream().map(input -> typeManager.getType(input.getTypeSignature())).collect(toList());
return Optional.of(new RecordPageSource(columnTypes, hiveRecordCursor));
}
}
return Optional.empty();
}
use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.
the class TestLocalFileRecordSet method assertData.
private static void assertData(LocalFileTables localFileTables, LocalFileMetadata metadata) {
SchemaTableName tableName = getSchemaTableName();
List<LocalFileColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, new LocalFileTableHandle(tableName, OptionalInt.of(0), OptionalInt.of(-1))).values().stream().map(column -> (LocalFileColumnHandle) column).collect(Collectors.toList());
LocalFileRecordSet recordSet = new LocalFileRecordSet(localFileTables, new LocalFileSplit(address, tableName, TupleDomain.all()), columnHandles);
RecordCursor cursor = recordSet.cursor();
for (int i = 0; i < columnHandles.size(); i++) {
assertEquals(cursor.getType(i), columnHandles.get(i).getColumnType());
}
// test one row
assertTrue(cursor.advanceNextPosition());
assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
assertEquals(cursor.getSlice(3).toStringUtf8(), "POST");
assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/memory");
assertTrue(cursor.isNull(5));
assertTrue(cursor.isNull(6));
assertEquals(cursor.getLong(7), 200);
assertEquals(cursor.getLong(8), 0);
assertEquals(cursor.getLong(9), 1000);
assertEquals(cursor.getLong(10), 10);
assertTrue(cursor.isNull(11));
assertTrue(cursor.advanceNextPosition());
assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
assertEquals(cursor.getSlice(3).toStringUtf8(), "GET");
assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/service/presto/general");
assertEquals(cursor.getSlice(5).toStringUtf8(), "foo");
assertEquals(cursor.getSlice(6).toStringUtf8(), "ffffffff-ffff-ffff-ffff-ffffffffffff");
assertEquals(cursor.getLong(7), 200);
assertEquals(cursor.getLong(8), 0);
assertEquals(cursor.getLong(9), 37);
assertEquals(cursor.getLong(10), 1094);
assertEquals(cursor.getSlice(11).toStringUtf8(), "a7229d56-5cbd-4e23-81ff-312ba6be0f12");
}
Aggregations