Search in sources :

Example 21 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.

the class ValuesMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;
    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
        if (isExpression(rowExpression)) {
            return castToExpression(rowExpression);
        }
        ConstantExpression expression = (ConstantExpression) rowExpression;
        if (expression.getType().getJavaType() == boolean.class) {
            return new BooleanLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == long.class) {
            return new LongLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == double.class) {
            return new DoubleLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == Slice.class) {
            return new StringLiteral(String.valueOf(expression.getValue()));
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableList()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> toSymbolReference(valuesNode.getOutputSymbols().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Example 22 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testCubeRangeVisitorRightSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorRightSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new SymbolReference(C_TINYINT.getName()));
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    assertNotNull(transformed);
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) CubeRangeCanonicalizer(io.prestosql.operator.CubeRangeCanonicalizer) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 23 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new Cast(new SymbolReference(C_TINYINT.getName()), "integer"));
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    assertNotNull(transformed);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) CubeRangeCanonicalizer(io.prestosql.operator.CubeRangeCanonicalizer) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 24 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.

the class TestShadowing method testCreateTableAsSelect.

@Test
public void testCreateTableAsSelect() throws Exception {
    handle.execute("CREATE TABLE \"my_test_table\" (column1 BIGINT, column2 DOUBLE)");
    SqlParser parser = new SqlParser();
    Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE my_test_table AS SELECT 1 column1, CAST('2.0' AS DOUBLE) column2 LIMIT 1", ImmutableList.of(), null, null, ImmutableMap.of());
    QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS));
    Query rewrittenQuery = rewriter.shadowQuery(query);
    assertEquals(rewrittenQuery.getPreQueries().size(), 1);
    assertEquals(rewrittenQuery.getPostQueries().size(), 1);
    CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0));
    assertEquals(createTableAs.getName().getParts().size(), 1);
    assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_"));
    assertFalse(createTableAs.getName().getSuffix().contains("my_test_table"));
    assertEquals(statementToQueryType(parser, rewrittenQuery.getQuery()), READ);
    Table table = new Table(createTableAs.getName());
    SingleColumn column1 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("COLUMN1"))));
    SingleColumn column2 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new FunctionCall(QualifiedName.of("round"), ImmutableList.of(new Identifier("COLUMN2"), new LongLiteral("1"))))));
    Select select = new Select(false, ImmutableList.of(column1, column2));
    QuerySpecification querySpecification = new QuerySpecification(select, Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    assertEquals(parser.createStatement(rewrittenQuery.getQuery()), new io.prestosql.sql.tree.Query(Optional.empty(), querySpecification, Optional.empty(), Optional.empty(), Optional.empty()));
    assertEquals(parser.createStatement(rewrittenQuery.getPostQueries().get(0)), new DropTable(createTableAs.getName(), true));
}
Also used : Table(io.prestosql.sql.tree.Table) DropTable(io.prestosql.sql.tree.DropTable) CreateTable(io.prestosql.sql.tree.CreateTable) LongLiteral(io.prestosql.sql.tree.LongLiteral) SqlParser(io.prestosql.sql.parser.SqlParser) Duration(io.airlift.units.Duration) SingleColumn(io.prestosql.sql.tree.SingleColumn) DropTable(io.prestosql.sql.tree.DropTable) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) Identifier(io.prestosql.sql.tree.Identifier) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) FunctionCall(io.prestosql.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 25 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.

the class HeuristicIndexUtilsTest method testExtractPartitions.

@Test
public void testExtractPartitions() {
    Expression equalExpName = new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"));
    System.out.println(equalExpName);
    assertEquals(HeuristicIndexUtils.extractPartitions(equalExpName), ImmutableList.of("a=1"));
    Expression equalExpNameExp = new ComparisonExpression(EQUAL, nameExp("a"), new LongLiteral("1"));
    System.out.println(equalExpNameExp);
    assertEquals(HeuristicIndexUtils.extractPartitions(equalExpName), ImmutableList.of("a=1"));
    Expression equalExp2Name = new ComparisonExpression(EQUAL, name("a"), new LongLiteral("2"));
    System.out.println(equalExp2Name);
    Expression orExp = new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, equalExpName, equalExp2Name);
    System.out.println(orExp);
    assertEquals(HeuristicIndexUtils.extractPartitions(orExp), ImmutableList.of("a=1", "a=2"));
    Expression inExpInteger = new InPredicate(name("a"), new InListExpression(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3"), new LongLiteral("4"), new LongLiteral("5"), new LongLiteral("6"))));
    System.out.println(inExpInteger);
    assertEquals(HeuristicIndexUtils.extractPartitions(inExpInteger), ImmutableList.of("a=1", "a=2", "a=3", "a=4", "a=5", "a=6"));
    Expression inExpBigInt = new InPredicate(name("a"), new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2), bigintLiteral(3), bigintLiteral(4), bigintLiteral(5), bigintLiteral(6))));
    System.out.println(inExpBigInt);
    assertEquals(HeuristicIndexUtils.extractPartitions(inExpInteger), ImmutableList.of("a=1", "a=2", "a=3", "a=4", "a=5", "a=6"));
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) Test(org.testng.annotations.Test)

Aggregations

LongLiteral (io.prestosql.sql.tree.LongLiteral)56 Test (org.testng.annotations.Test)42 StringLiteral (io.prestosql.sql.tree.StringLiteral)19 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)16 Expression (io.prestosql.sql.tree.Expression)16 Identifier (io.prestosql.sql.tree.Identifier)15 FunctionCall (io.prestosql.sql.tree.FunctionCall)11 Query (io.prestosql.sql.tree.Query)11 QueryUtil.simpleQuery (io.prestosql.sql.QueryUtil.simpleQuery)10 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)10 Table (io.prestosql.sql.tree.Table)10 WithQuery (io.prestosql.sql.tree.WithQuery)10 Symbol (io.prestosql.spi.plan.Symbol)9 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)9 CreateTable (io.prestosql.sql.tree.CreateTable)9 DropTable (io.prestosql.sql.tree.DropTable)9 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)8 AllColumns (io.prestosql.sql.tree.AllColumns)8 Cast (io.prestosql.sql.tree.Cast)8 NotExpression (io.prestosql.sql.tree.NotExpression)8