Search in sources :

Example 91 with Type

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();
}
Also used : RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TimeWithTimeZoneType(io.trino.spi.type.TimeWithTimeZoneType) TimeType(io.trino.spi.type.TimeType) Type(io.trino.spi.type.Type) TimestampType(io.trino.spi.type.TimestampType) VarcharType(io.trino.spi.type.VarcharType) MapType(io.trino.spi.type.MapType) CharType(io.trino.spi.type.CharType) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 92 with Type

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());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) Type(io.trino.spi.type.Type) PlanNode(io.trino.sql.planner.plan.PlanNode) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) ImmutableMap(com.google.common.collect.ImmutableMap) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 93 with Type

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());
}
Also used : Type(io.trino.spi.type.Type) Block(io.trino.spi.block.Block) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Page(io.trino.spi.Page) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 94 with Type

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());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageConsumerOperator(io.trino.testing.PageConsumerOperator) Type(io.trino.spi.type.Type) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 95 with Type

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);
    }
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageConsumerOperator(io.trino.testing.PageConsumerOperator) Type(io.trino.spi.type.Type) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Aggregations

Type (io.trino.spi.type.Type)688 Test (org.testng.annotations.Test)266 ArrayType (io.trino.spi.type.ArrayType)218 ImmutableList (com.google.common.collect.ImmutableList)191 RowType (io.trino.spi.type.RowType)177 List (java.util.List)155 VarcharType (io.trino.spi.type.VarcharType)134 Page (io.trino.spi.Page)126 ArrayList (java.util.ArrayList)126 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)114 Block (io.trino.spi.block.Block)110 MapType (io.trino.spi.type.MapType)107 DecimalType (io.trino.spi.type.DecimalType)102 TrinoException (io.trino.spi.TrinoException)98 Optional (java.util.Optional)98 Map (java.util.Map)97 ImmutableMap (com.google.common.collect.ImmutableMap)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)92 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)86 BlockBuilder (io.trino.spi.block.BlockBuilder)72