use of io.trino.spi.type.Type in project trino by trinodb.
the class MaterializedResult method appendToPage.
private static void appendToPage(PageBuilder pageBuilder, MaterializedRow row) {
for (int field = 0; field < row.getFieldCount(); field++) {
Type type = pageBuilder.getType(field);
Object value = row.getField(field);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(field);
writeValue(type, blockBuilder, value);
}
pageBuilder.declarePosition();
}
use of io.trino.spi.type.Type in project trino by trinodb.
the class TestSqlStage method createExchangePlanFragment.
private static PlanFragment createExchangePlanFragment() {
PlanNode planNode = new RemoteSourceNode(new PlanNodeId("exchange"), ImmutableList.of(new PlanFragmentId("source")), ImmutableList.of(new Symbol("column")), Optional.empty(), REPARTITION, RetryPolicy.NONE);
ImmutableMap.Builder<Symbol, Type> types = ImmutableMap.builder();
for (Symbol symbol : planNode.getOutputSymbols()) {
types.put(symbol, VARCHAR);
}
return new PlanFragment(new PlanFragmentId("exchange_fragment_id"), planNode, types.buildOrThrow(), SOURCE_DISTRIBUTION, ImmutableList.of(planNode.getId()), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), planNode.getOutputSymbols()), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
}
use of io.trino.spi.type.Type in project trino by trinodb.
the class TestPagesSerde method testRoundTrip.
@Test
public void testRoundTrip() {
PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde();
BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(null, 5);
VARCHAR.writeString(expectedBlockBuilder, "alice");
VARCHAR.writeString(expectedBlockBuilder, "bob");
VARCHAR.writeString(expectedBlockBuilder, "charlie");
VARCHAR.writeString(expectedBlockBuilder, "dave");
Block expectedBlock = expectedBlockBuilder.build();
Page expectedPage = new Page(expectedBlock, expectedBlock, expectedBlock);
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
writePages(serde, sliceOutput, expectedPage, expectedPage, expectedPage);
List<Type> types = ImmutableList.of(VARCHAR, VARCHAR, VARCHAR);
Iterator<Page> pageIterator = readPages(serde, sliceOutput.slice().getInput());
assertPageEquals(types, pageIterator.next(), expectedPage);
assertPageEquals(types, pageIterator.next(), expectedPage);
assertPageEquals(types, pageIterator.next(), expectedPage);
assertFalse(pageIterator.hasNext());
}
use of io.trino.spi.type.Type in project trino by trinodb.
the class TestDriver method testNormalFinish.
@Test
public void testNormalFinish() {
List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
ValuesOperator source = new ValuesOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"), rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
Operator sink = createSinkOperator(types);
Driver driver = Driver.createDriver(driverContext, source, sink);
assertSame(driver.getDriverContext(), driverContext);
assertFalse(driver.isFinished());
ListenableFuture<Void> blocked = driver.processFor(new Duration(1, TimeUnit.SECONDS));
assertTrue(blocked.isDone());
assertTrue(driver.isFinished());
assertTrue(sink.isFinished());
assertTrue(source.isFinished());
}
use of io.trino.spi.type.Type in project trino by trinodb.
the class TestDriver method testConcurrentClose.
// The race can be reproduced somewhat reliably when the invocationCount is 10K, but we use 1K iterations to cap the test runtime.
@Test(invocationCount = 1_000, timeOut = 10_000)
public void testConcurrentClose() {
List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), "values");
ValuesOperator source = new ValuesOperator(operatorContext, rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
Operator sink = createSinkOperator(types);
Driver driver = Driver.createDriver(driverContext, source, sink);
// let these threads race
// don't want to call isFinishedInternal in processFor
scheduledExecutor.submit(() -> driver.processFor(new Duration(1, TimeUnit.NANOSECONDS)));
scheduledExecutor.submit(driver::close);
while (!driverContext.isDone()) {
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MILLISECONDS);
}
}
Aggregations