Search in sources :

Example 26 with BuiltInFunctionHandle

use of io.prestosql.spi.function.BuiltInFunctionHandle in project boostkit-bigdata by kunpengcompute.

the class TestHivePageSourceProvider method testModifyDomainLessThanOrEqual.

@Test
public void testModifyDomainLessThanOrEqual() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$less_than_or_equal");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("LESS_THAN", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValue(), Long.valueOf(40));
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValueBlock(), Optional.empty());
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 27 with BuiltInFunctionHandle

use of io.prestosql.spi.function.BuiltInFunctionHandle in project hetu-core by openlookeng.

the class TestScanFilterAndProjectOperator method testPageSourceMergeOutput.

@Test
public void testPageSourceMergeOutput() {
    List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(100, 0).addSequencePage(100, 0).addSequencePage(100, 0).addSequencePage(100, 0).build();
    RowExpression filter = call(EQUAL.getFunctionName().toString(), new BuiltInFunctionHandle(Signature.internalOperator(EQUAL, BOOLEAN.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()))), BOOLEAN, field(0, BIGINT), constant(10L, BIGINT));
    List<RowExpression> projections = ImmutableList.of(field(0, BIGINT));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.of(filter), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.of(filter), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new FixedPageSource(input), cursorProcessor, pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), null, ImmutableList.of(BIGINT), new DataSize(64, KILOBYTE), 2, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), false, Optional.empty(), 0, 0);
    SourceOperator operator = factory.createOperator(newDriverContext());
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    operator.noMoreSplits();
    List<Page> actual = toPages(operator);
    assertEquals(actual.size(), 1);
    List<Page> expected = rowPagesBuilder(BIGINT).row(10L).row(10L).row(10L).row(10L).build();
    assertPageEquals(ImmutableList.of(BIGINT), actual.get(0), expected.get(0));
}
Also used : CursorProcessor(io.prestosql.operator.project.CursorProcessor) RowExpression(io.prestosql.spi.relation.RowExpression) Page(io.prestosql.spi.Page) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FixedPageSource(io.prestosql.spi.connector.FixedPageSource) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProcessor(io.prestosql.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) CatalogName(io.prestosql.spi.connector.CatalogName) UUID(java.util.UUID) Split(io.prestosql.metadata.Split) TestingSplit(io.prestosql.testing.TestingSplit) Test(org.testng.annotations.Test)

Example 28 with BuiltInFunctionHandle

use of io.prestosql.spi.function.BuiltInFunctionHandle in project hetu-core by openlookeng.

the class TestScanFilterAndProjectOperator method testPageYield.

@Test
public void testPageYield() {
    int totalRows = 1000;
    Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(BIGINT), totalRows, 1);
    DriverContext driverContext = newDriverContext();
    // 20 columns; each column is associated with a function that will force yield per projection
    int totalColumns = 20;
    ImmutableList.Builder<SqlScalarFunction> functions = ImmutableList.builder();
    for (int i = 0; i < totalColumns; i++) {
        functions.add(new GenericLongFunction("page_col" + i, value -> {
            driverContext.getYieldSignal().forceYieldForTesting();
            return value;
        }));
    }
    Metadata localMetadata = functionAssertions.getMetadata();
    localMetadata.getFunctionAndTypeManager().registerBuiltInFunctions(functions.build());
    // match each column with a projection
    ExpressionCompiler compiler = new ExpressionCompiler(localMetadata, new PageFunctionCompiler(localMetadata, 0));
    ImmutableList.Builder<RowExpression> projections = ImmutableList.builder();
    for (int i = 0; i < totalColumns; i++) {
        projections.add(call(QualifiedObjectName.valueOfDefaultFunction("generic_long_page_col" + i).toString(), new BuiltInFunctionHandle(internalScalarFunction(QualifiedObjectName.valueOfDefaultFunction("generic_long_page_col" + i), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()))), BIGINT, field(0, BIGINT)));
    }
    Supplier<CursorProcessor> cursorProcessor = compiler.compileCursorProcessor(Optional.empty(), projections.build(), "key");
    Supplier<PageProcessor> pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections.build(), MAX_BATCH_SIZE);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new FixedPageSource(ImmutableList.of(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();
    // exactly 20 blocks (one for each column) and the PageProcessor will be able to create a Page out of it.
    for (int i = 1; i <= totalRows * totalColumns; i++) {
        driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
        Page page = operator.getOutput();
        if (i == totalColumns) {
            assertNotNull(page);
            assertEquals(page.getPositionCount(), totalRows);
            assertEquals(page.getChannelCount(), totalColumns);
            for (int j = 0; j < totalColumns; j++) {
                assertEquals(toValues(BIGINT, page.getBlock(j)), toValues(BIGINT, input.getBlock(0)));
            }
        } else {
            assertNull(page);
        }
        driverContext.getYieldSignal().reset();
    }
}
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) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) CursorProcessor(io.prestosql.operator.project.CursorProcessor) ImmutableList(com.google.common.collect.ImmutableList) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProcessor(io.prestosql.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) UUID(java.util.UUID) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FixedPageSource(io.prestosql.spi.connector.FixedPageSource) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) ExpressionCompiler(io.prestosql.sql.gen.ExpressionCompiler) CatalogName(io.prestosql.spi.connector.CatalogName) Split(io.prestosql.metadata.Split) TestingSplit(io.prestosql.testing.TestingSplit) Test(org.testng.annotations.Test)

Example 29 with BuiltInFunctionHandle

use of io.prestosql.spi.function.BuiltInFunctionHandle in project hetu-core by openlookeng.

the class TestHivePageSourceProvider method testModifyDomainGreaterThan.

@Test
public void testModifyDomainGreaterThan() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$greater_than");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("GREATER_THAN", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValueBlock(), Optional.empty());
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValue(), Long.valueOf(40));
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 30 with BuiltInFunctionHandle

use of io.prestosql.spi.function.BuiltInFunctionHandle in project hetu-core by openlookeng.

the class TestHivePageSourceProvider method testModifyDomainLessThan.

@Test
public void testModifyDomainLessThan() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$less_than");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("LESS_THAN_OR_EQUAL", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValue(), Long.valueOf(40));
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValueBlock(), Optional.empty());
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)56 Signature (io.prestosql.spi.function.Signature)42 CallExpression (io.prestosql.spi.relation.CallExpression)41 TypeSignature (io.prestosql.spi.type.TypeSignature)27 Test (org.testng.annotations.Test)27 RowExpression (io.prestosql.spi.relation.RowExpression)26 ArrayList (java.util.ArrayList)18 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)13 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)12 Type (io.prestosql.spi.type.Type)11 Page (io.prestosql.spi.Page)10 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)10 Domain (io.prestosql.spi.predicate.Domain)10 PageProcessor (io.prestosql.operator.project.PageProcessor)9 FunctionHandle (io.prestosql.spi.function.FunctionHandle)9 HashSet (java.util.HashSet)9 HivePageSourceProvider.modifyDomain (io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain)8 OperatorType (io.prestosql.spi.function.OperatorType)8 InputReferenceExpression (io.prestosql.spi.relation.InputReferenceExpression)7 DataSize (io.airlift.units.DataSize)6