use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestCursorProcessorCompiler method testCompilerWithCSE.
@Test
public void testCompilerWithCSE() {
PageFunctionCompiler functionCompiler = new PageFunctionCompiler(METADATA, 0);
ExpressionCompiler expressionCompiler = new ExpressionCompiler(METADATA, functionCompiler);
RowExpression filter = new SpecialFormExpression(AND, BIGINT, ADD_X_Y_GREATER_THAN_2, ADD_X_Y_LESS_THAN_10);
List<? extends RowExpression> projections = createIfProjectionList(5);
Supplier<CursorProcessor> cseCursorProcessorSupplier = expressionCompiler.compileCursorProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), projections, "key", true);
Supplier<CursorProcessor> noCseSECursorProcessorSupplier = expressionCompiler.compileCursorProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), projections, "key", false);
Page input = createLongBlockPage(2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
List<Type> types = ImmutableList.of(BIGINT, BIGINT);
PageBuilder pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(toList()));
RecordSet recordSet = new PageRecordSet(types, input);
cseCursorProcessorSupplier.get().process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), recordSet.cursor(), pageBuilder);
Page pageFromCSE = pageBuilder.build();
pageBuilder.reset();
noCseSECursorProcessorSupplier.get().process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), recordSet.cursor(), pageBuilder);
Page pageFromNoCSE = pageBuilder.build();
checkPageEqual(pageFromCSE, pageFromNoCSE);
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestExampleRecordSetProvider method testGetRecordSet.
@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());
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestExampleRecordSet method testGetColumnTypes.
@Test
public void testGetColumnTypes() {
RecordSet recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of(new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("test", "value", BIGINT, 1)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(createUnboundedVarcharType(), BIGINT));
recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of(new ExampleColumnHandle("test", "value", BIGINT, 1), new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, createUnboundedVarcharType()));
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)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, BIGINT, createUnboundedVarcharType()));
recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of());
assertEquals(recordSet.getColumnTypes(), ImmutableList.of());
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class IndexSourceOperator method addSplit.
@Override
public Supplier<Optional<UpdatablePageSource>> addSplit(Split split) {
requireNonNull(split, "split is null");
checkState(source == null, "Index source split already set");
IndexSplit indexSplit = (IndexSplit) split.getConnectorSplit();
// Normalize the incoming RecordSet to something that can be consumed by the index
RecordSet normalizedRecordSet = probeKeyNormalizer.apply(indexSplit.getKeyRecordSet());
ConnectorPageSource result = index.lookup(normalizedRecordSet);
source = new PageSourceOperator(result, operatorContext);
Object splitInfo = split.getInfo();
if (splitInfo != null) {
operatorContext.setInfoSupplier(Suppliers.ofInstance(new SplitOperatorInfo(splitInfo)));
}
return Optional::empty;
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestExampleRecordSet method testCursorSimple.
@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());
}
Aggregations