Search in sources :

Example 6 with ResolvedFunction

use of io.trino.metadata.ResolvedFunction in project trino by trinodb.

the class TestPageProcessorCompiler method testSanityFilterOnDictionary.

@Test
public void testSanityFilterOnDictionary() {
    CallExpression lengthVarchar = new CallExpression(functionResolution.resolveFunction(QualifiedName.of("length"), fromTypes(VARCHAR)), ImmutableList.of(field(0, VARCHAR)));
    ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan, ImmutableList.of(lengthVarchar, constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, VARCHAR)), MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
    // test filter caching
    Page outputPage2 = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage2.getPositionCount(), 100);
    assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
    // both output pages must have the same dictionary
    assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) ResolvedFunction(io.trino.metadata.ResolvedFunction) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.trino.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 7 with ResolvedFunction

use of io.trino.metadata.ResolvedFunction in project trino by trinodb.

the class TestPageProcessorCompiler method testSanityFilterOnRLE.

@Test
public void testSanityFilterOnRLE() {
    ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get();
    Page page = new Page(createRLEBlock(5L, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) ResolvedFunction(io.trino.metadata.ResolvedFunction) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 8 with ResolvedFunction

use of io.trino.metadata.ResolvedFunction in project trino by trinodb.

the class TestTypeValidator method testValidWindow.

@Test
public void testValidWindow() {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
    ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of("sum"), fromTypes(DOUBLE));
    WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    WindowNode.Function function = new WindowNode.Function(resolvedFunction, ImmutableList.of(columnC.toSymbolReference()), frame, false);
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
    PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
    assertTypesValid(node);
}
Also used : WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) WindowFrame(io.trino.sql.tree.WindowFrame) PlanNode(io.trino.sql.planner.plan.PlanNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Test(org.testng.annotations.Test)

Example 9 with ResolvedFunction

use of io.trino.metadata.ResolvedFunction in project trino by trinodb.

the class TestTypeValidator method testInvalidWindowFunctionSignature.

@Test
public void testInvalidWindowFunctionSignature() {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", BIGINT);
    ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of("sum"), fromTypes(DOUBLE));
    WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    WindowNode.Function function = new WindowNode.Function(resolvedFunction, ImmutableList.of(columnC.toSymbolReference()), frame, false);
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
    PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
    assertThatThrownBy(() -> assertTypesValid(node)).isInstanceOf(IllegalArgumentException.class).hasMessageMatching("type of symbol 'sum(_[0-9]+)?' is expected to be bigint, but the actual type is double");
}
Also used : WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) WindowFrame(io.trino.sql.tree.WindowFrame) PlanNode(io.trino.sql.planner.plan.PlanNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Test(org.testng.annotations.Test)

Example 10 with ResolvedFunction

use of io.trino.metadata.ResolvedFunction in project trino by trinodb.

the class TestReplaceWindowWithRowNumber method test.

@Test
public void test() {
    ResolvedFunction rowNumberFunction = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("row_number"), fromTypes());
    tester().assertThat(new ReplaceWindowWithRowNumber(tester().getMetadata())).on(p -> {
        Symbol a = p.symbol("a");
        Symbol rowNumberSymbol = p.symbol("row_number_1");
        return p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.empty()), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(rowNumberFunction)), p.values(a));
    }).matches(rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.empty()).partitionBy(ImmutableList.of("a")), values("a")));
    tester().assertThat(new ReplaceWindowWithRowNumber(tester().getMetadata())).on(p -> {
        Symbol a = p.symbol("a");
        Symbol rowNumberSymbol = p.symbol("row_number_1");
        return p.window(new WindowNode.Specification(ImmutableList.of(), Optional.empty()), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(rowNumberFunction)), p.values(a));
    }).matches(rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.empty()).partitionBy(ImmutableList.of()), values("a")));
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) ResolvedFunction(io.trino.metadata.ResolvedFunction) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) SortOrder(io.trino.spi.connector.SortOrder) QualifiedName(io.trino.sql.tree.QualifiedName) ImmutableList(com.google.common.collect.ImmutableList) Optional(java.util.Optional) WindowNode(io.trino.sql.planner.plan.WindowNode) PlanMatchPattern.rowNumber(io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Aggregations

ResolvedFunction (io.trino.metadata.ResolvedFunction)51 Test (org.testng.annotations.Test)31 WindowNode (io.trino.sql.planner.plan.WindowNode)21 ImmutableList (com.google.common.collect.ImmutableList)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 Symbol (io.trino.sql.planner.Symbol)20 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)18 DEFAULT_FRAME (io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME)18 QualifiedName (io.trino.sql.tree.QualifiedName)18 Optional (java.util.Optional)18 OrderingScheme (io.trino.sql.planner.OrderingScheme)17 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)17 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)17 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)15 FunctionCall (io.trino.sql.tree.FunctionCall)14 SortOrder (io.trino.spi.connector.SortOrder)12 Type (io.trino.spi.type.Type)12 Expression (io.trino.sql.tree.Expression)11 BIGINT (io.trino.spi.type.BigintType.BIGINT)10 PlanMatchPattern.topNRanking (io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking)9