Search in sources :

Example 6 with VARCHAR

use of io.prestosql.spi.type.VarcharType.VARCHAR in project hetu-core by openlookeng.

the class TestValuesNodeStats method testStatsForValuesNode.

@Test
public void testStatsForValuesNode() {
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("a", BIGINT), pb.symbol("b", DOUBLE)), ImmutableList.of(ImmutableList.of(pb.binaryOperation(OperatorType.ADD, constant(3L, BIGINT), constant(3L, BIGINT)), constant(13.5e0, DOUBLE)), ImmutableList.of(constant(55L, BIGINT), constantNull(DOUBLE)), ImmutableList.of(constant(6L, BIGINT), constant(13.5e0, DOUBLE))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(3).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0).setLowValue(6).setHighValue(55).setDistinctValuesCount(2).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setNullsFraction(0.33333333333333333).setLowValue(13.5).setHighValue(13.5).setDistinctValuesCount(1).build()).build()));
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("v", createVarcharType(30))), ImmutableList.of(constantExpressions(VARCHAR, utf8Slice("Alice")), constantExpressions(VARCHAR, utf8Slice("has")), constantExpressions(VARCHAR, utf8Slice("a cat")), ImmutableList.of(constantNull(VARCHAR))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(4).addSymbolStatistics(new Symbol("v"), SymbolStatsEstimate.builder().setNullsFraction(0.25).setDistinctValuesCount(3).build()).build()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder.constantExpressions(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) Test(org.testng.annotations.Test) Expressions.constantNull(io.prestosql.sql.relational.Expressions.constantNull) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) OperatorType(io.prestosql.spi.function.OperatorType) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) UNKNOWN(io.prestosql.spi.type.UnknownType.UNKNOWN) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 7 with VARCHAR

use of io.prestosql.spi.type.VarcharType.VARCHAR in project hetu-core by openlookeng.

the class TestSpatialJoinOperator method testYield.

@Test
public void testYield() {
    // create a filter function that yields for every probe match
    // verify we will yield #match times totally
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    // force a yield for every match
    AtomicInteger filterFunctionCalls = new AtomicInteger();
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> {
        filterFunctionCalls.incrementAndGet();
        driverContext.getYieldSignal().forceYieldForTesting();
        return true;
    }));
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POLYGON_A, "A").pageBreak().row(POLYGON_B, "B");
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.contains(probe), Optional.empty(), Optional.of(filterFunction), buildPages);
    // 10 points in polygon A (x0...x9)
    // 10 points in polygons A and B (y0...y9)
    // 10 points in polygon B (z0...z9)
    // 40 total matches
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR));
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(1 + 0.1 * i, 1 + 0.1 * i), "x" + i);
    }
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(4.5 + 0.01 * i, 4.5 + 0.01 * i), "y" + i);
    }
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(6 + 0.1 * i, 6 + 0.1 * i), "z" + i);
    }
    List<Page> probeInput = probePages.build();
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);
    Operator operator = joinOperatorFactory.createOperator(driverContext);
    assertTrue(operator.needsInput());
    operator.addInput(probeInput.get(0));
    operator.finish();
    // we will yield 40 times due to filterFunction
    for (int i = 0; i < 40; i++) {
        driverContext.getYieldSignal().setWithDelay(5 * SECONDS.toNanos(1), driverContext.getYieldExecutor());
        assertNull(operator.getOutput());
        assertEquals(filterFunctionCalls.get(), i + 1, "Expected join to stop processing (yield) after calling filter function once");
        driverContext.getYieldSignal().reset();
    }
    // delayed yield is not going to prevent operator from producing a page now (yield won't be forced because filter function won't be called anymore)
    driverContext.getYieldSignal().setWithDelay(5 * SECONDS.toNanos(1), driverContext.getYieldExecutor());
    Page output = operator.getOutput();
    assertNotNull(output);
    // make sure we have 40 matches
    assertEquals(output.getPositionCount(), 40);
}
Also used : Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) PagesSpatialIndexFactory(io.prestosql.operator.PagesSpatialIndexFactory) MaterializedResult(io.prestosql.testing.MaterializedResult) GeoFunctions.stPoint(io.prestosql.plugin.geospatial.GeoFunctions.stPoint) KdbTree(io.prestosql.geospatial.KdbTree) KdbTreeUtils(io.prestosql.geospatial.KdbTreeUtils) Type(io.prestosql.sql.planner.plan.SpatialJoinNode.Type) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) OperatorAssertion.assertOperatorEquals(io.prestosql.operator.OperatorAssertion.assertOperatorEquals) Slices(io.airlift.slice.Slices) PipelineContext(io.prestosql.operator.PipelineContext) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) Node.newInternal(io.prestosql.geospatial.KdbTree.Node.newInternal) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PrestoException(io.prestosql.spi.PrestoException) SynchronousQueue(java.util.concurrent.SynchronousQueue) TestingFactory(io.prestosql.operator.PagesIndex.TestingFactory) RowPagesBuilder.rowPagesBuilder(io.prestosql.RowPagesBuilder.rowPagesBuilder) BeforeMethod(org.testng.annotations.BeforeMethod) ValuesOperator(io.prestosql.operator.ValuesOperator) Collections.emptyIterator(java.util.Collections.emptyIterator) Assert.assertNotNull(org.testng.Assert.assertNotNull) List(java.util.List) Driver(io.prestosql.operator.Driver) Optional(java.util.Optional) MaterializedResult.resultBuilder(io.prestosql.testing.MaterializedResult.resultBuilder) TEST_SESSION(io.prestosql.SessionTestUtils.TEST_SESSION) PagesSpatialIndex(io.prestosql.operator.PagesSpatialIndex) Operator(io.prestosql.operator.Operator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Slice(io.airlift.slice.Slice) DataProvider(org.testng.annotations.DataProvider) Assert.assertNull(org.testng.Assert.assertNull) Rectangle(io.prestosql.geospatial.Rectangle) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TaskContext(io.prestosql.operator.TaskContext) LEFT(io.prestosql.sql.planner.plan.SpatialJoinNode.Type.LEFT) Assert.assertEquals(org.testng.Assert.assertEquals) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) OperatorFactory(io.prestosql.operator.OperatorFactory) InternalJoinFilterFunction(io.prestosql.operator.InternalJoinFilterFunction) GeoFunctions.stGeometryFromText(io.prestosql.plugin.geospatial.GeoFunctions.stGeometryFromText) OperatorAssertion.toPages(io.prestosql.operator.OperatorAssertion.toPages) INNER(io.prestosql.sql.planner.plan.SpatialJoinNode.Type.INNER) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) StandardJoinFilterFunction(io.prestosql.operator.StandardJoinFilterFunction) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) SpatialPredicate(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialPredicate) ExecutorService(java.util.concurrent.ExecutorService) DriverContext(io.prestosql.operator.DriverContext) Page(io.prestosql.spi.Page) TestingTaskContext(io.prestosql.testing.TestingTaskContext) Ints(com.google.common.primitives.Ints) SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) JoinFilterFunctionCompiler(io.prestosql.sql.gen.JoinFilterFunctionCompiler) Node.newLeaf(io.prestosql.geospatial.KdbTree.Node.newLeaf) Assert(io.prestosql.testing.assertions.Assert) GEOMETRY(io.prestosql.plugin.geospatial.GeometryType.GEOMETRY) RowPagesBuilder(io.prestosql.RowPagesBuilder) Assert.assertTrue(org.testng.Assert.assertTrue) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ValuesOperator(io.prestosql.operator.ValuesOperator) Operator(io.prestosql.operator.Operator) DriverContext(io.prestosql.operator.DriverContext) TaskContext(io.prestosql.operator.TaskContext) TestingTaskContext(io.prestosql.testing.TestingTaskContext) RowPagesBuilder(io.prestosql.RowPagesBuilder) Page(io.prestosql.spi.Page) InternalJoinFilterFunction(io.prestosql.operator.InternalJoinFilterFunction) GeoFunctions.stPoint(io.prestosql.plugin.geospatial.GeoFunctions.stPoint) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) OperatorFactory(io.prestosql.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) PagesSpatialIndexFactory(io.prestosql.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 8 with VARCHAR

use of io.prestosql.spi.type.VarcharType.VARCHAR in project hetu-core by openlookeng.

the class TestScanFilterAndProjectOperator method testPageSourceLazyLoad.

@Test
public void testPageSourceLazyLoad() {
    Block inputBlock = BlockAssertions.createLongSequenceBlock(0, 100);
    // If column 1 is loaded, test will fail
    Page input = new Page(100, inputBlock, new LazyBlock(100, lazyBlock -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.empty(), projections, "key");
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new LazyPagePageProjection()));
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new SinglePagePageSource(input), cursorProcessor, () -> pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), null, ImmutableList.of(BIGINT), new DataSize(0, BYTE), 0, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), false, Optional.empty(), 0, 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), ImmutableList.of(new Page(inputBlock)));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Test(org.testng.annotations.Test) AbstractTestFunctions(io.prestosql.operator.scalar.AbstractTestFunctions) MaterializedResult(io.prestosql.testing.MaterializedResult) BlockAssertions.toValues(io.prestosql.block.BlockAssertions.toValues) TEST_TABLE_HANDLE(io.prestosql.testing.TestingHandles.TEST_TABLE_HANDLE) MAX_BATCH_SIZE(io.prestosql.operator.project.PageProcessor.MAX_BATCH_SIZE) Assert.assertEquals(io.prestosql.testing.assertions.Assert.assertEquals) Expressions.call(io.prestosql.sql.relational.Expressions.call) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) KILOBYTE(io.airlift.units.DataSize.Unit.KILOBYTE) Method(java.lang.reflect.Method) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) EQUAL(io.prestosql.spi.function.OperatorType.EQUAL) LazyPagePageProjection(io.prestosql.operator.project.TestPageProcessor.LazyPagePageProjection) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) LazyBlock(io.prestosql.spi.block.LazyBlock) RowPagesBuilder.rowPagesBuilder(io.prestosql.RowPagesBuilder.rowPagesBuilder) CatalogName(io.prestosql.spi.connector.CatalogName) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) Metadata(io.prestosql.metadata.Metadata) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSize(io.airlift.units.DataSize) PageProcessor(io.prestosql.operator.project.PageProcessor) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) List(java.util.List) ConnectorPageSource(io.prestosql.spi.connector.ConnectorPageSource) SelectAllFilter(io.prestosql.operator.project.TestPageProcessor.SelectAllFilter) TestingTaskContext.createTaskContext(io.prestosql.testing.TestingTaskContext.createTaskContext) Optional(java.util.Optional) TEST_SESSION(io.prestosql.SessionTestUtils.TEST_SESSION) Assert.assertNull(org.testng.Assert.assertNull) FixedPageSource(io.prestosql.spi.connector.FixedPageSource) PageRecordSet(io.prestosql.operator.index.PageRecordSet) ExpressionCompiler(io.prestosql.sql.gen.ExpressionCompiler) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) Split(io.prestosql.metadata.Split) Supplier(java.util.function.Supplier) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) TestingSplit(io.prestosql.testing.TestingSplit) BlockAssertions(io.prestosql.block.BlockAssertions) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) ExecutorService(java.util.concurrent.ExecutorService) SequencePageBuilder(io.prestosql.SequencePageBuilder) Lifespan(io.prestosql.execution.Lifespan) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) Page(io.prestosql.spi.Page) Signature.internalScalarFunction(io.prestosql.spi.function.Signature.internalScalarFunction) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Expressions.field(io.prestosql.sql.relational.Expressions.field) RowExpression(io.prestosql.spi.relation.RowExpression) Assert.assertTrue(org.testng.Assert.assertTrue) RecordPageSource(io.prestosql.spi.connector.RecordPageSource) BYTE(io.airlift.units.DataSize.Unit.BYTE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CursorProcessor(io.prestosql.operator.project.CursorProcessor) PageAssertions.assertPageEquals(io.prestosql.operator.PageAssertions.assertPageEquals) CursorProcessor(io.prestosql.operator.project.CursorProcessor) RowExpression(io.prestosql.spi.relation.RowExpression) Page(io.prestosql.spi.Page) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) LazyBlock(io.prestosql.spi.block.LazyBlock) PageProcessor(io.prestosql.operator.project.PageProcessor) LazyPagePageProjection(io.prestosql.operator.project.TestPageProcessor.LazyPagePageProjection) DataSize(io.airlift.units.DataSize) LazyBlock(io.prestosql.spi.block.LazyBlock) Block(io.prestosql.spi.block.Block) SelectAllFilter(io.prestosql.operator.project.TestPageProcessor.SelectAllFilter) CatalogName(io.prestosql.spi.connector.CatalogName) UUID(java.util.UUID) Split(io.prestosql.metadata.Split) TestingSplit(io.prestosql.testing.TestingSplit) MaterializedResult(io.prestosql.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 9 with VARCHAR

use of io.prestosql.spi.type.VarcharType.VARCHAR in project hetu-core by openlookeng.

the class TestSignatureBinder method testFunction.

@Test
public void testFunction() {
    Signature simple = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("function(integer,integer)")).build();
    assertThat(simple).boundTo("integer").fails();
    assertThat(simple).boundTo("function(integer,integer)").succeeds();
    // TODO: Support coercion of return type of lambda
    assertThat(simple).boundTo("function(integer,smallint)").withCoercion().fails();
    assertThat(simple).boundTo("function(integer,bigint)").withCoercion().fails();
    Signature applyTwice = functionSignature().returnType(parseTypeSignature("V")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T,U)"), parseTypeSignature("function(U,V)")).typeVariableConstraints(typeVariable("T"), typeVariable("U"), typeVariable("V")).build();
    assertThat(applyTwice).boundTo("integer", "integer", "integer").fails();
    assertThat(applyTwice).boundTo("integer", "function(integer,varchar)", "function(varchar,double)").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("U", VARCHAR).setTypeVariable("V", DOUBLE).build());
    assertThat(applyTwice).boundTo("integer", new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("U", VARCHAR).setTypeVariable("V", DOUBLE).build());
    assertThat(applyTwice).boundTo(// pass function argument to non-function position of a function
    new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).fails();
    assertThat(applyTwice).boundTo(new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), // pass non-function argument to function position of a function
    "integer", new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).fails();
    Signature flatMap = functionSignature().returnType(parseTypeSignature("array(T)")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T, array(T))")).typeVariableConstraints(typeVariable("T")).build();
    assertThat(flatMap).boundTo("array(integer)", "function(integer, array(integer))").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).build());
    Signature varargApply = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")).typeVariableConstraints(typeVariable("T")).setVariableArity(true).build();
    assertThat(varargApply).boundTo("integer", "function(integer, integer)", "function(integer, integer)", "function(integer, integer)").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).build());
    assertThat(varargApply).boundTo("integer", "function(integer, integer)", "function(integer, double)", "function(double, double)").fails();
    Signature loop = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")).typeVariableConstraints(typeVariable("T")).build();
    assertThat(loop).boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, BIGINT).getTypeSignature())).fails();
    assertThat(loop).boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, BIGINT).getTypeSignature())).withCoercion().produces(BoundVariables.builder().setTypeVariable("T", BIGINT).build());
    // TODO: Support coercion of return type of lambda
    assertThat(loop).withCoercion().boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, SMALLINT).getTypeSignature())).fails();
    // TODO: Support coercion of return type of lambda
    // Without coercion support for return type of lambda, the return type of lambda must be `varchar(x)` to avoid need for coercions.
    Signature varcharApply = functionSignature().returnType(parseTypeSignature("varchar")).argumentTypes(parseTypeSignature("varchar"), parseTypeSignature("function(varchar, varchar(x))", ImmutableSet.of("x"))).build();
    assertThat(varcharApply).withCoercion().boundTo("varchar(10)", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, createVarcharType(1)).getTypeSignature())).succeeds();
    Signature sortByKey = functionSignature().returnType(parseTypeSignature("array(T)")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T,E)")).typeVariableConstraints(typeVariable("T"), orderableTypeParameter("E")).build();
    assertThat(sortByKey).boundTo("array(integer)", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, VARCHAR).getTypeSignature())).produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("E", VARCHAR).build());
}
Also used : TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) StandardTypes(io.prestosql.spi.type.StandardTypes) Signature.orderableTypeParameter(io.prestosql.spi.function.Signature.orderableTypeParameter) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) TypeVariableConstraint(io.prestosql.spi.function.TypeVariableConstraint) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) DecimalType(io.prestosql.spi.type.DecimalType) Test(org.testng.annotations.Test) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) Signature.comparableTypeParameter(io.prestosql.spi.function.Signature.comparableTypeParameter) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SignatureBuilder(io.prestosql.spi.function.SignatureBuilder) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) Signature(io.prestosql.spi.function.Signature) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) Assert.fail(org.testng.Assert.fail) FunctionType(io.prestosql.spi.type.FunctionType) Set(java.util.Set) Assert.assertNotNull(org.testng.Assert.assertNotNull) Signature.typeVariable(io.prestosql.spi.function.Signature.typeVariable) String.format(java.lang.String.format) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature.withVariadicBound(io.prestosql.spi.function.Signature.withVariadicBound) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) FunctionType(io.prestosql.spi.type.FunctionType) Test(org.testng.annotations.Test)

Example 10 with VARCHAR

use of io.prestosql.spi.type.VarcharType.VARCHAR in project hetu-core by openlookeng.

the class TestHashJoinOperator method testOuterJoinWithNullBuildAndFilterFunction.

@Test(dataProvider = "hashJoinTestValues")
public void testOuterJoinWithNullBuildAndFilterFunction(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
    TaskContext taskContext = createTaskContext();
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> ImmutableSet.of("a", "c").contains(VARCHAR.getSlice(rightPage.getBlock(0), rightPosition).toStringAscii())));
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR)).row("a").row((String) null).row((String) null).row("a").row("b");
    BuildSideSetup buildSideSetup = setupBuildSide(parallelBuild, taskContext, Ints.asList(0), 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("b").row("c").build();
    OperatorFactory joinOperatorFactory = probeOuterJoinOperatorFactory(lookupSourceFactory, probePages);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(buildSideSetup);
    // expected
    MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("a", "a").row("a", "a").row("b", null).row("c", null).build();
    assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Also used : Arrays(java.util.Arrays) TaskStateMachine(io.prestosql.execution.TaskStateMachine) OperatorAssertion.without(io.prestosql.operator.OperatorAssertion.without) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) Collections.singletonList(java.util.Collections.singletonList) Assert.assertEquals(io.prestosql.testing.assertions.Assert.assertEquals) Future(java.util.concurrent.Future) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Arrays.asList(java.util.Arrays.asList) SingleStreamSpillerFactory(io.prestosql.spiller.SingleStreamSpillerFactory) Map(java.util.Map) Path(java.nio.file.Path) Assert.assertFalse(org.testng.Assert.assertFalse) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) JoinFilterFunctionFactory(io.prestosql.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory) Iterators.unmodifiableIterator(com.google.common.collect.Iterators.unmodifiableIterator) OperatorAssertion.assertOperatorEqualsWithSimpleStateComparison(io.prestosql.operator.OperatorAssertion.assertOperatorEqualsWithSimpleStateComparison) ExceededMemoryLimitException(io.prestosql.ExceededMemoryLimitException) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) TEST_SESSION(io.prestosql.SessionTestUtils.TEST_SESSION) Iterables(com.google.common.collect.Iterables) FIXED_HASH_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION) OperatorAssertion.dropChannel(io.prestosql.operator.OperatorAssertion.dropChannel) ArrayList(java.util.ArrayList) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Lifespan(io.prestosql.execution.Lifespan) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ValuesOperatorFactory(io.prestosql.operator.ValuesOperator.ValuesOperatorFactory) LocalExchangeSinkOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) MaterializedRow(io.prestosql.testing.MaterializedRow) ExecutionException(java.util.concurrent.ExecutionException) RowPagesBuilder(io.prestosql.RowPagesBuilder) HashBuilderOperatorFactory(io.prestosql.operator.HashBuilderOperator.HashBuilderOperatorFactory) PageBuffer(io.prestosql.operator.index.PageBuffer) SingleStreamSpiller(io.prestosql.spiller.SingleStreamSpiller) RoaringBitmap(org.roaringbitmap.RoaringBitmap) MaterializedResult(io.prestosql.testing.MaterializedResult) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OperatorAssertion.assertOperatorEquals(io.prestosql.operator.OperatorAssertion.assertOperatorEquals) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) LocalExchangeSinkFactoryId(io.prestosql.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId) PartitioningSpillerFactory(io.prestosql.spiller.PartitioningSpillerFactory) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) ImmutableMap(com.google.common.collect.ImmutableMap) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collections.nCopies(java.util.Collections.nCopies) RowPagesBuilder.rowPagesBuilder(io.prestosql.RowPagesBuilder.rowPagesBuilder) BeforeMethod(org.testng.annotations.BeforeMethod) GenericPartitioningSpillerFactory(io.prestosql.spiller.GenericPartitioningSpillerFactory) Assert.assertNotNull(org.testng.Assert.assertNotNull) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TEST_SNAPSHOT_SESSION(io.prestosql.SessionTestUtils.TEST_SNAPSHOT_SESSION) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) Booleans(com.google.common.primitives.Booleans) LocalExchangeSourceOperator(io.prestosql.operator.exchange.LocalExchangeSourceOperator) IntStream(java.util.stream.IntStream) TaskId(io.prestosql.execution.TaskId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LocalExchangeFactory(io.prestosql.operator.exchange.LocalExchange.LocalExchangeFactory) DataProvider(org.testng.annotations.DataProvider) Assert.assertNull(org.testng.Assert.assertNull) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) RestorableConfig(io.prestosql.spi.snapshot.RestorableConfig) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) ImmutableList(com.google.common.collect.ImmutableList) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Objects.requireNonNull(java.util.Objects.requireNonNull) ExecutorService(java.util.concurrent.ExecutorService) LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) Iterator(java.util.Iterator) LocalExchangeSourceOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) Assert.fail(org.testng.Assert.fail) Page(io.prestosql.spi.Page) TestingTaskContext(io.prestosql.testing.TestingTaskContext) Ints(com.google.common.primitives.Ints) TimeUnit(java.util.concurrent.TimeUnit) PageBufferOperatorFactory(io.prestosql.operator.index.PageBufferOperator.PageBufferOperatorFactory) Assertions.assertEqualsIgnoreOrder(io.airlift.testing.Assertions.assertEqualsIgnoreOrder) Collectors.toList(java.util.stream.Collectors.toList) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) UNGROUPED_EXECUTION(io.prestosql.operator.PipelineExecutionStrategy.UNGROUPED_EXECUTION) Assert.assertTrue(org.testng.Assert.assertTrue) Comparator(java.util.Comparator) BYTE(io.airlift.units.DataSize.Unit.BYTE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestingTaskContext(io.prestosql.testing.TestingTaskContext) RowPagesBuilder(io.prestosql.RowPagesBuilder) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) Page(io.prestosql.spi.Page) Type(io.prestosql.spi.type.Type) ValuesOperatorFactory(io.prestosql.operator.ValuesOperator.ValuesOperatorFactory) LocalExchangeSinkOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory) HashBuilderOperatorFactory(io.prestosql.operator.HashBuilderOperator.HashBuilderOperatorFactory) LocalExchangeSourceOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) PageBufferOperatorFactory(io.prestosql.operator.index.PageBufferOperator.PageBufferOperatorFactory) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)11 VARCHAR (io.prestosql.spi.type.VarcharType.VARCHAR)11 Test (org.testng.annotations.Test)10 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)9 List (java.util.List)9 Optional (java.util.Optional)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)7 RowPagesBuilder.rowPagesBuilder (io.prestosql.RowPagesBuilder.rowPagesBuilder)7 TEST_SESSION (io.prestosql.SessionTestUtils.TEST_SESSION)7 Type (io.prestosql.spi.type.Type)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Ints (com.google.common.primitives.Ints)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 DataSize (io.airlift.units.DataSize)6 BYTE (io.airlift.units.DataSize.Unit.BYTE)6 RowPagesBuilder (io.prestosql.RowPagesBuilder)6 Lifespan (io.prestosql.execution.Lifespan)6 OperatorAssertion.assertOperatorEquals (io.prestosql.operator.OperatorAssertion.assertOperatorEquals)6