Search in sources :

Example 1 with BuiltInFunctionHandle

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

the class TestDeterminismEvaluator method testDeterminismEvaluator.

@Test
public void testDeterminismEvaluator() {
    RowExpressionDeterminismEvaluator determinismEvaluator = new RowExpressionDeterminismEvaluator(createTestMetadataManager());
    CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
    assertFalse(determinismEvaluator.isDeterministic(random));
    InputReferenceExpression col0 = field(0, BIGINT);
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression lessThanExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, constant(10L, BIGINT)), Optional.empty());
    assertTrue(determinismEvaluator.isDeterministic(lessThanExpression));
    CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
    assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 2 with BuiltInFunctionHandle

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

the class TestScanFilterAndProjectOperator method testRecordCursorYield.

@Test
public void testRecordCursorYield() {
    // create a generic long function that yields for projection on every row
    // verify we will yield #row times totally
    // create a table with 15 rows
    int length = 15;
    Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(BIGINT), length, 0);
    DriverContext driverContext = newDriverContext();
    // set up generic long function with a callback to force yield
    Metadata localMetadata = functionAssertions.getMetadata();
    localMetadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(new GenericLongFunction("record_cursor", value -> {
        driverContext.getYieldSignal().forceYieldForTesting();
        return value;
    })));
    ExpressionCompiler compiler = new ExpressionCompiler(localMetadata, new PageFunctionCompiler(localMetadata, 0));
    List<RowExpression> projections = ImmutableList.of(call(QualifiedObjectName.valueOfDefaultFunction("generic_long_record_cursor").toString(), new BuiltInFunctionHandle(internalScalarFunction(QualifiedObjectName.valueOfDefaultFunction("generic_long_record_cursor"), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()))), BIGINT, field(0, BIGINT)));
    Supplier<CursorProcessor> cursorProcessor = compiler.compileCursorProcessor(Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new RecordPageSource(new PageRecordSet(ImmutableList.of(BIGINT), 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();
    // start driver; get null value due to yield for the first 15 times
    for (int i = 0; i < length; i++) {
        driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
        assertNull(operator.getOutput());
        driverContext.getYieldSignal().reset();
    }
    // the 16th yield is not going to prevent the operator from producing a page
    driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
    Page output = operator.getOutput();
    driverContext.getYieldSignal().reset();
    assertNotNull(output);
    assertEquals(toValues(BIGINT, output.getBlock(0)), toValues(BIGINT, input.getBlock(0)));
}
Also used : PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) CursorProcessor(io.prestosql.operator.project.CursorProcessor) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) PageRecordSet(io.prestosql.operator.index.PageRecordSet) RecordPageSource(io.prestosql.spi.connector.RecordPageSource) 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) 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 3 with BuiltInFunctionHandle

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

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 4 with BuiltInFunctionHandle

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

the class TestHivePageSourceProvider method testModifyDomainGreaterThanOrEqual.

@Test
public void testModifyDomainGreaterThanOrEqual() {
    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_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("GREATER_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().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 5 with BuiltInFunctionHandle

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

the class TestFunctionAndTypeManager method testIdentityCast.

@Test
public void testIdentityCast() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    FunctionHandle exactOperator = functionAndTypeManager.lookupCast(CastType.CAST, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature());
    assertEquals(exactOperator, new BuiltInFunctionHandle(new Signature(CAST.getFunctionName(), SCALAR, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature())));
}
Also used : FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) LiteralEncoder.getMagicLiteralFunctionSignature(io.prestosql.sql.planner.LiteralEncoder.getMagicLiteralFunctionSignature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)38 Signature (io.prestosql.spi.function.Signature)25 CallExpression (io.prestosql.spi.relation.CallExpression)23 Test (org.testng.annotations.Test)23 RowExpression (io.prestosql.spi.relation.RowExpression)13 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)13 Page (io.prestosql.spi.Page)10 TypeSignature (io.prestosql.spi.type.TypeSignature)10 PageProcessor (io.prestosql.operator.project.PageProcessor)9 OperatorType (io.prestosql.spi.function.OperatorType)8 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)8 DataSize (io.airlift.units.DataSize)6 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)6 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)6 PageFunctionCompiler (io.prestosql.sql.gen.PageFunctionCompiler)6 Metadata (io.prestosql.metadata.Metadata)5 FunctionHandle (io.prestosql.spi.function.FunctionHandle)5 Domain (io.prestosql.spi.predicate.Domain)5 ExpressionCompiler (io.prestosql.sql.gen.ExpressionCompiler)5 ArrayList (java.util.ArrayList)5