Search in sources :

Example 6 with FunctionCall

use of io.trino.sql.tree.FunctionCall in project trino by trinodb.

the class TestSetTimeZoneTask method testSetTimeZoneVarcharFunctionCall.

@Test
public void testSetTimeZoneVarcharFunctionCall() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 25), "/"), new StringLiteral(new NodeLocation(1, 30), "America"), new StringLiteral(new NodeLocation(1, 41), "Los_Angeles")))));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "America/Los_Angeles");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 7 with FunctionCall

use of io.trino.sql.tree.FunctionCall in project trino by trinodb.

the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeFunctionCall.

@Test
public void testSetTimeZoneIntervalDayTimeTypeFunctionCall() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('8h')");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "8h")))));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "+08:00");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 8 with FunctionCall

use of io.trino.sql.tree.FunctionCall in project trino by trinodb.

the class TestSetSessionTask method testSetSessionWithParameters.

@Test
public void testSetSessionWithParameters() {
    FunctionCall functionCall = new TestingFunctionResolution(transactionManager, plannerContext).functionCallBuilder(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new Parameter(0)).build();
    testSetSessionWithParameters("bar", functionCall, "banana", ImmutableList.of(new StringLiteral("ana")));
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) StringLiteral(io.trino.sql.tree.StringLiteral) Parameter(io.trino.sql.tree.Parameter) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 9 with FunctionCall

use of io.trino.sql.tree.FunctionCall in project trino by trinodb.

the class TestLogicalPlanner method testAllFieldsDereferenceFromNonDeterministic.

@Test
public void testAllFieldsDereferenceFromNonDeterministic() {
    FunctionCall randomFunction = new FunctionCall(getQueryRunner().getMetadata().resolveFunction(TEST_SESSION, QualifiedName.of("rand"), ImmutableList.of()).toQualifiedName(), ImmutableList.of());
    assertPlan("SELECT (x, x).* FROM (SELECT rand()) T(x)", any(project(ImmutableMap.of("output_1", expression("row[1]"), "output_2", expression("row[2]")), project(ImmutableMap.of("row", expression("ROW(\"rand\", \"rand\")")), values(ImmutableList.of("rand"), ImmutableList.of(ImmutableList.of(randomFunction)))))));
    assertPlan("SELECT (rand(), rand()).* FROM (VALUES 1) t(x)", any(project(ImmutableMap.of("output_1", expression("r[1]"), "output_2", expression("r[2]")), values(ImmutableList.of("r"), ImmutableList.of(ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))))))));
    // Ensure the calls to rand() are not duplicated by the ORDER BY clause
    assertPlan("SELECT (rand(), rand()).* FROM (VALUES 1, 2) t(x) ORDER BY 1", anyTree(node(SortNode.class, any(project(ImmutableMap.of("output_1", expression("row[1]"), "output_2", expression("row[2]")), values(ImmutableList.of("row"), ImmutableList.of(ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))), ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))))))))));
}
Also used : FunctionCall(io.trino.sql.tree.FunctionCall) Row(io.trino.sql.tree.Row) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 10 with FunctionCall

use of io.trino.sql.tree.FunctionCall in project trino by trinodb.

the class TestLogicalPlanner method testDoNotPlanUnreferencedRowPatternMeasures.

@Test
public void testDoNotPlanUnreferencedRowPatternMeasures() {
    // row pattern measure `label` is not referenced
    assertPlan("SELECT val OVER w " + "          FROM (VALUES (1, 90)) t(id, value) " + "          WINDOW w AS ( " + "                   ORDER BY id " + "                   MEASURES " + "                            RUNNING LAST(value) AS val, " + "                            CLASSIFIER() AS label " + "                   ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING " + "                   PATTERN (A+) " + "                   DEFINE A AS true " + "          )", output(project(patternRecognition(builder -> builder.specification(specification(ImmutableList.of(), ImmutableList.of("id"), ImmutableMap.of("id", ASC_NULLS_LAST))).addMeasure("val", "LAST(value)", INTEGER).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).pattern(new IrQuantified(new IrLabel("A"), oneOrMore(true))).addVariableDefinition(new IrLabel("A"), "true"), values(ImmutableList.of("id", "value"), ImmutableList.of(ImmutableList.of(new LongLiteral("1"), new LongLiteral("90"))))))));
    // row pattern measure `label` is not referenced
    assertPlan("SELECT min(value) OVER w " + "          FROM (VALUES (1, 90)) t(id, value) " + "          WINDOW w AS ( " + "                   ORDER BY id " + "                   MEASURES CLASSIFIER() AS label " + "                   ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING " + "                   PATTERN (A+) " + "                   DEFINE A AS true " + "          )", output(project(patternRecognition(builder -> builder.specification(specification(ImmutableList.of(), ImmutableList.of("id"), ImmutableMap.of("id", ASC_NULLS_LAST))).addFunction("min", functionCall("min", ImmutableList.of("value"))).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).pattern(new IrQuantified(new IrLabel("A"), oneOrMore(true))).addVariableDefinition(new IrLabel("A"), "true"), values(ImmutableList.of("id", "value"), ImmutableList.of(ImmutableList.of(new LongLiteral("1"), new LongLiteral("90"))))))));
}
Also used : CREATED(io.trino.sql.planner.LogicalPlanner.Stage.CREATED) PlanMatchPattern.aggregation(io.trino.sql.planner.assertions.PlanMatchPattern.aggregation) ROW_NUMBER(io.trino.sql.planner.plan.TopNRankingNode.RankingType.ROW_NUMBER) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) CorrelatedJoinNode(io.trino.sql.planner.plan.CorrelatedJoinNode) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanMatchPattern.assignUniqueId(io.trino.sql.planner.assertions.PlanMatchPattern.assignUniqueId) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) PlanMatchPattern.markDistinct(io.trino.sql.planner.assertions.PlanMatchPattern.markDistinct) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) AddLocalExchanges(io.trino.sql.planner.optimizations.AddLocalExchanges) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) Map(java.util.Map) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Assert.assertFalse(org.testng.Assert.assertFalse) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) Range(io.trino.spi.predicate.Range) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) Domain(io.trino.spi.predicate.Domain) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanMatchPattern.aliasToIndex(io.trino.sql.planner.assertions.PlanMatchPattern.aliasToIndex) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) QueryTemplate.queryTemplate(io.trino.tests.QueryTemplate.queryTemplate) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) ValueSet(io.trino.spi.predicate.ValueSet) PlanMatchPattern.strictConstrainedTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictConstrainedTableScan) PlanMatchPattern.apply(io.trino.sql.planner.assertions.PlanMatchPattern.apply) ValuesNode(io.trino.sql.planner.plan.ValuesNode) TASK_CONCURRENCY(io.trino.SystemSessionProperties.TASK_CONCURRENCY) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) REAL(io.trino.spi.type.RealType.REAL) Session(io.trino.Session) OPTIMIZE_HASH_GENERATION(io.trino.SystemSessionProperties.OPTIMIZE_HASH_GENERATION) PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) PARTITIONED(io.trino.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) LimitNode(io.trino.sql.planner.plan.LimitNode) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.patternRecognition(io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition) REPLICATE(io.trino.sql.planner.plan.ExchangeNode.Type.REPLICATE) DISTRIBUTED_SORT(io.trino.SystemSessionProperties.DISTRIBUTED_SORT) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) ColumnHandle(io.trino.spi.connector.ColumnHandle) AggregationNode(io.trino.sql.planner.plan.AggregationNode) JOIN_REORDERING_STRATEGY(io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) StringLiteral(io.trino.sql.tree.StringLiteral) MorePredicates(io.trino.util.MorePredicates) QueryTemplate(io.trino.tests.QueryTemplate) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) RANK(io.trino.sql.planner.plan.TopNRankingNode.RankingType.RANK) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) SortOrder(io.trino.spi.connector.SortOrder) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.windowFrame(io.trino.sql.planner.assertions.PlanMatchPattern.windowFrame) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) MorePredicates.isInstanceOfAny(io.trino.util.MorePredicates.isInstanceOfAny) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) Domain.multipleValues(io.trino.spi.predicate.Domain.multipleValues) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) SUBQUERY_MULTIPLE_ROWS(io.trino.spi.StandardErrorCode.SUBQUERY_MULTIPLE_ROWS) PlanMatchPattern.strictTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictTableScan) PlanMatchPattern.any(io.trino.sql.planner.assertions.PlanMatchPattern.any) CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) PlanMatchPattern.constrainedTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScan) REPLICATED(io.trino.sql.planner.plan.JoinNode.DistributionType.REPLICATED) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) WINDOW(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.WINDOW) JoinNode(io.trino.sql.planner.plan.JoinNode) INTEGER(io.trino.spi.type.IntegerType.INTEGER) FunctionCall(io.trino.sql.tree.FunctionCall) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ExpressionMatcher(io.trino.sql.planner.assertions.ExpressionMatcher) RowNumberSymbolMatcher(io.trino.sql.planner.assertions.RowNumberSymbolMatcher) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RowType(io.trino.spi.type.RowType) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) EnforceSingleRowNode(io.trino.sql.planner.plan.EnforceSingleRowNode) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode) FORCE_SINGLE_NODE_OUTPUT(io.trino.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) String.format(java.lang.String.format) IrQuantifier.oneOrMore(io.trino.sql.planner.rowpattern.ir.IrQuantifier.oneOrMore) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) List(java.util.List) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) FILTERING_SEMI_JOIN_TO_INNER(io.trino.SystemSessionProperties.FILTERING_SEMI_JOIN_TO_INNER) Entry(java.util.Map.Entry) ApplyNode(io.trino.sql.planner.plan.ApplyNode) Optional(java.util.Optional) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) PlanMatchPattern.rowNumber(io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber) UNBOUNDED_FOLLOWING(io.trino.sql.tree.FrameBound.Type.UNBOUNDED_FOLLOWING) PlanMatchPattern.anyNot(io.trino.sql.planner.assertions.PlanMatchPattern.anyNot) DESCENDING(io.trino.sql.tree.SortItem.Ordering.DESCENDING) PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Assert.assertEquals(org.testng.Assert.assertEquals) IrQuantified(io.trino.sql.planner.rowpattern.ir.IrQuantified) OPTIMIZED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED) SortNode(io.trino.sql.planner.plan.SortNode) PlanMatchPattern.specification(io.trino.sql.planner.assertions.PlanMatchPattern.specification) Cast(io.trino.sql.tree.Cast) ImmutableList(com.google.common.collect.ImmutableList) JoinReorderingStrategy(io.trino.sql.planner.OptimizerConfig.JoinReorderingStrategy) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) DynamicFilterPattern(io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern) ProjectNode(io.trino.sql.planner.plan.ProjectNode) LAST(io.trino.sql.tree.SortItem.NullOrdering.LAST) PARTIAL(io.trino.sql.planner.plan.AggregationNode.Step.PARTIAL) PlanMatchPattern.identityProject(io.trino.sql.planner.assertions.PlanMatchPattern.identityProject) TopNNode(io.trino.sql.planner.plan.TopNNode) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) TupleDomain(io.trino.spi.predicate.TupleDomain) PlanMatchPattern.singleGroupingSet(io.trino.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) QualifiedName(io.trino.sql.tree.QualifiedName) Consumer(java.util.function.Consumer) DistributionType(io.trino.sql.planner.plan.SemiJoinNode.DistributionType) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) CheckSubqueryNodesAreRewritten(io.trino.sql.planner.optimizations.CheckSubqueryNodesAreRewritten) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) DistinctLimitNode(io.trino.sql.planner.plan.DistinctLimitNode) Row(io.trino.sql.tree.Row) FINAL(io.trino.sql.planner.plan.AggregationNode.Step.FINAL) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) LongLiteral(io.trino.sql.tree.LongLiteral) IrQuantified(io.trino.sql.planner.rowpattern.ir.IrQuantified) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

FunctionCall (io.trino.sql.tree.FunctionCall)69 Test (org.testng.annotations.Test)32 StringLiteral (io.trino.sql.tree.StringLiteral)31 ImmutableList (com.google.common.collect.ImmutableList)29 QualifiedName (io.trino.sql.tree.QualifiedName)29 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)25 Expression (io.trino.sql.tree.Expression)25 LongLiteral (io.trino.sql.tree.LongLiteral)25 Optional (java.util.Optional)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 Identifier (io.trino.sql.tree.Identifier)19 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)18 ResolvedFunction (io.trino.metadata.ResolvedFunction)17 Assignments (io.trino.sql.planner.plan.Assignments)16 Cast (io.trino.sql.tree.Cast)15 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)14 BIGINT (io.trino.spi.type.BigintType.BIGINT)13 PlanMatchPattern.project (io.trino.sql.planner.assertions.PlanMatchPattern.project)13 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)13 MetadataManager.createTestMetadataManager (io.trino.metadata.MetadataManager.createTestMetadataManager)12