Search in sources :

Example 56 with ComparisonExpression

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

the class TestPushPredicateIntoTableScan method nonDeterministicPredicate.

@Test
public void nonDeterministicPredicate() {
    Type orderStatusType = createVarcharType(1);
    tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(LogicalExpression.and(new ComparisonExpression(EQUAL, new SymbolReference("orderstatus"), new StringLiteral("O")), new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0"))), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", orderStatusType)), ImmutableMap.of(p.symbol("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))))).matches(filter(new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0")), constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus"))));
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Test(org.testng.annotations.Test) CatalogName(io.trino.connector.CatalogName) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) SchemaTableName(io.trino.spi.connector.SchemaTableName) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) BIGINT(io.trino.spi.type.BigintType.BIGINT) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) Optional(java.util.Optional) ConnectorTablePartitioning(io.trino.spi.connector.ConnectorTablePartitioning) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) Session(io.trino.Session) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) TupleDomain(io.trino.spi.predicate.TupleDomain) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) QualifiedName(io.trino.sql.tree.QualifiedName) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 57 with ComparisonExpression

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

the class TestSqlParser method testExists.

@Test
public void testExists() {
    assertStatement("SELECT EXISTS(SELECT 1)", simpleQuery(selectList(exists(simpleQuery(selectList(new LongLiteral("1")))))));
    assertStatement("SELECT EXISTS(SELECT 1) = EXISTS(SELECT 2)", simpleQuery(selectList(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, exists(simpleQuery(selectList(new LongLiteral("1")))), exists(simpleQuery(selectList(new LongLiteral("2"))))))));
    assertStatement("SELECT NOT EXISTS(SELECT 1) = EXISTS(SELECT 2)", simpleQuery(selectList(new NotExpression(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, exists(simpleQuery(selectList(new LongLiteral("1")))), exists(simpleQuery(selectList(new LongLiteral("2")))))))));
    assertStatement("SELECT (NOT EXISTS(SELECT 1)) = EXISTS(SELECT 2)", simpleQuery(selectList(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new NotExpression(exists(simpleQuery(selectList(new LongLiteral("1"))))), exists(simpleQuery(selectList(new LongLiteral("2"))))))));
}
Also used : QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) LongLiteral(io.trino.sql.tree.LongLiteral) NotExpression(io.trino.sql.tree.NotExpression) Test(org.junit.jupiter.api.Test)

Example 58 with ComparisonExpression

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

the class TestSqlParser method testDelete.

@Test
public void testDelete() {
    assertStatement("DELETE FROM t", new Delete(table(QualifiedName.of("t")), Optional.empty()));
    assertStatement("DELETE FROM \"awesome table\"", new Delete(table(QualifiedName.of("awesome table")), Optional.empty()));
    assertStatement("DELETE FROM t WHERE a = b", new Delete(table(QualifiedName.of("t")), Optional.of(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new Identifier("a"), new Identifier("b")))));
}
Also used : Delete(io.trino.sql.tree.Delete) MergeDelete(io.trino.sql.tree.MergeDelete) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) Test(org.junit.jupiter.api.Test)

Aggregations

ComparisonExpression (io.trino.sql.tree.ComparisonExpression)58 Test (org.testng.annotations.Test)30 ImmutableList (com.google.common.collect.ImmutableList)24 Expression (io.trino.sql.tree.Expression)23 Symbol (io.trino.sql.planner.Symbol)22 SymbolReference (io.trino.sql.tree.SymbolReference)21 ImmutableMap (com.google.common.collect.ImmutableMap)18 LongLiteral (io.trino.sql.tree.LongLiteral)17 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)15 FunctionCall (io.trino.sql.tree.FunctionCall)15 GenericLiteral (io.trino.sql.tree.GenericLiteral)15 QualifiedName (io.trino.sql.tree.QualifiedName)15 Optional (java.util.Optional)15 StringLiteral (io.trino.sql.tree.StringLiteral)14 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)13 Type (io.trino.spi.type.Type)12 BIGINT (io.trino.spi.type.BigintType.BIGINT)11 FilterNode (io.trino.sql.planner.plan.FilterNode)11 ResolvedFunction (io.trino.metadata.ResolvedFunction)10 GREATER_THAN (io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN)10