use of io.trino.RowPagesBuilder in project trino by trinodb.
the class TestTableWriterOperator method testTableWriterInfo.
@Test
public void testTableWriterInfo() {
PageSinkManager pageSinkManager = new PageSinkManager();
pageSinkManager.addConnectorPageSinkProvider(CONNECTOR_ID, new ConstantPageSinkProvider(new TableWriteInfoTestPageSink()));
TableWriterOperator tableWriterOperator = (TableWriterOperator) createTableWriterOperator(pageSinkManager, new DevNullOperatorFactory(1, new PlanNodeId("test")), ImmutableList.of(BIGINT, VARBINARY));
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(BIGINT);
for (int i = 0; i < 100; i++) {
rowPagesBuilder.addSequencePage(100, 0);
}
List<Page> pages = rowPagesBuilder.build();
long peakMemoryUsage = 0;
long validationCpuNanos = 0;
for (int i = 0; i < pages.size(); i++) {
Page page = pages.get(i);
peakMemoryUsage += page.getRetainedSizeInBytes();
validationCpuNanos += page.getPositionCount();
tableWriterOperator.addInput(page);
TableWriterInfo info = tableWriterOperator.getInfo();
assertEquals(info.getPageSinkPeakMemoryUsage(), peakMemoryUsage);
assertEquals((long) (info.getValidationCpuTime().getValue(NANOSECONDS)), validationCpuNanos);
}
}
use of io.trino.RowPagesBuilder in project trino by trinodb.
the class TestTopNRankingOperator method testPartitioned.
@Test(dataProvider = "hashEnabledValues")
public void testPartitioned(boolean hashEnabled) {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), VARCHAR, DOUBLE);
List<Page> input = rowPagesBuilder.row("a", 0.3).row("b", 0.2).row("c", 0.1).row("c", 0.91).pageBreak().row("a", 0.4).pageBreak().row("a", 0.5).row("a", 0.6).row("b", 0.7).row("b", 0.8).pageBreak().row("b", 0.9).build();
TopNRankingOperatorFactory operatorFactory = new TopNRankingOperatorFactory(0, new PlanNodeId("test"), ROW_NUMBER, ImmutableList.of(VARCHAR, DOUBLE), Ints.asList(1, 0), Ints.asList(0), ImmutableList.of(VARCHAR), Ints.asList(1), ImmutableList.of(SortOrder.ASC_NULLS_LAST), 3, false, Optional.empty(), 10, Optional.empty(), joinCompiler, typeOperators, blockTypeOperators);
MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, VARCHAR, BIGINT).row(0.3, "a", 1L).row(0.4, "a", 2L).row(0.5, "a", 3L).row(0.2, "b", 1L).row(0.7, "b", 2L).row(0.8, "b", 3L).row(0.1, "c", 1L).row(0.91, "c", 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.RowPagesBuilder in project trino by trinodb.
the class TestTopNRankingOperator method testRankNullAndNan.
@Test
public void testRankNullAndNan() {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(VARCHAR, DOUBLE);
List<Page> input = rowPagesBuilder.row("a", null).row("b", 0.2).row("b", Double.NaN).row("c", 0.1).row("c", 0.91).pageBreak().row("a", 0.4).pageBreak().row("a", 0.5).row("a", null).row("a", 0.6).row("b", 0.7).row("b", Double.NaN).build();
TopNRankingOperatorFactory operatorFactory = new TopNRankingOperatorFactory(0, new PlanNodeId("test"), RANK, ImmutableList.of(VARCHAR, DOUBLE), Ints.asList(1, 0), Ints.asList(0), ImmutableList.of(VARCHAR), Ints.asList(1), ImmutableList.of(ASC_NULLS_FIRST), 3, false, Optional.empty(), 10, Optional.empty(), joinCompiler, typeOperators, blockTypeOperators);
MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, VARCHAR, BIGINT).row(null, "a", 1L).row(null, "a", 1L).row(0.4, "a", 3L).row(Double.NaN, "b", 1L).row(Double.NaN, "b", 1L).row(0.2, "b", 3L).row(0.1, "c", 1L).row(0.91, "c", 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.RowPagesBuilder in project trino by trinodb.
the class TestHashJoinOperator method testOuterJoinWithNullProbeAndFilterFunction.
@Test(dataProvider = "hashJoinTestValues")
public void testOuterJoinWithNullProbeAndFilterFunction(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
TaskContext taskContext = createTaskContext();
InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> VARCHAR.getSlice(rightPage.getBlock(0), rightPosition).toStringAscii().equals("a")));
// build factory
List<Type> buildTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), buildTypes).row("a").row("b").row("c");
BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.of(filterFunction), false, SINGLE_STREAM_SPILLER_FACTORY);
JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
// probe factory
List<Type> probeTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
List<Page> probeInput = probePages.row("a").row((String) null).row((String) null).row("a").row("b").build();
OperatorFactory joinOperatorFactory = probeOuterJoinOperatorFactory(lookupSourceFactory, probePages, true);
// build drivers and operators
instantiateBuildDrivers(buildSideSetup, taskContext);
buildLookupSource(executor, buildSideSetup);
// expected
MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("a", "a").row(null, null).row(null, null).row("a", "a").row("b", null).build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
use of io.trino.RowPagesBuilder in project trino by trinodb.
the class TestHashJoinOperator method testInnerJoinWithNullOnBothSides.
@Test(dataProvider = "hashJoinTestValues")
public void testInnerJoinWithNullOnBothSides(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
TaskContext taskContext = createTaskContext();
// build factory
List<Type> buildTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), buildTypes).row("a").row((String) null).row((String) null).row("a").row("b");
BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.empty(), false, SINGLE_STREAM_SPILLER_FACTORY);
JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
// probe factory
List<Type> probeTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
List<Page> probeInput = probePages.row("a").row("b").row((String) null).row("c").build();
OperatorFactory joinOperatorFactory = innerJoinOperatorFactory(operatorFactories, lookupSourceFactory, probePages, PARTITIONING_SPILLER_FACTORY, false);
// build drivers and operators
instantiateBuildDrivers(buildSideSetup, taskContext);
buildLookupSource(executor, buildSideSetup);
// expected
MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("a", "a").row("a", "a").row("b", "b").build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Aggregations