Search in sources :

Example 1 with DoubleLiteral

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

the class TestSqlParser method testArrayConstructor.

@Test
public void testArrayConstructor() {
    assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of()));
    assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))));
    assertExpression("ARRAY [1e0, 2.5e0]", new ArrayConstructor(ImmutableList.of(new DoubleLiteral("1.0"), new DoubleLiteral("2.5"))));
    assertExpression("ARRAY ['hi']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"))));
    assertExpression("ARRAY ['hi', 'hello']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"), new StringLiteral("hello"))));
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 2 with DoubleLiteral

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

the class TestSqlParser method testDouble.

@Test
public void testDouble() {
    assertExpression("123E7", new DoubleLiteral("123E7"));
    assertExpression("123.E7", new DoubleLiteral("123E7"));
    assertExpression("123.0E7", new DoubleLiteral("123E7"));
    assertExpression("123E+7", new DoubleLiteral("123E7"));
    assertExpression("123E-7", new DoubleLiteral("123E-7"));
    assertExpression("123.456E7", new DoubleLiteral("123.456E7"));
    assertExpression("123.456E+7", new DoubleLiteral("123.456E7"));
    assertExpression("123.456E-7", new DoubleLiteral("123.456E-7"));
    assertExpression(".4E42", new DoubleLiteral(".4E42"));
    assertExpression(".4E+42", new DoubleLiteral(".4E42"));
    assertExpression(".4E-42", new DoubleLiteral(".4E-42"));
}
Also used : DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 3 with DoubleLiteral

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

the class TestSqlParser method testNumbers.

@Test
public void testNumbers() {
    assertExpression("9223372036854775807", new LongLiteral("9223372036854775807"));
    assertExpression("-9223372036854775808", new LongLiteral("-9223372036854775808"));
    assertExpression("1E5", new DoubleLiteral("1E5"));
    assertExpression("1E-5", new DoubleLiteral("1E-5"));
    assertExpression(".1E5", new DoubleLiteral(".1E5"));
    assertExpression(".1E-5", new DoubleLiteral(".1E-5"));
    assertExpression("1.1E5", new DoubleLiteral("1.1E5"));
    assertExpression("1.1E-5", new DoubleLiteral("1.1E-5"));
    assertExpression("-1E5", new DoubleLiteral("-1E5"));
    assertExpression("-1E-5", new DoubleLiteral("-1E-5"));
    assertExpression("-.1E5", new DoubleLiteral("-.1E5"));
    assertExpression("-.1E-5", new DoubleLiteral("-.1E-5"));
    assertExpression("-1.1E5", new DoubleLiteral("-1.1E5"));
    assertExpression("-1.1E-5", new DoubleLiteral("-1.1E-5"));
    assertExpression(".1", new DecimalLiteral(".1"));
    assertExpression("1.2", new DecimalLiteral("1.2"));
    assertExpression("-1.2", new DecimalLiteral("-1.2"));
}
Also used : LongLiteral(io.prestosql.sql.tree.LongLiteral) DecimalLiteral(io.prestosql.sql.tree.DecimalLiteral) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 4 with DoubleLiteral

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

the class TestSqlParser method testValues.

@Test
public void testValues() {
    Query valuesQuery = query(values(row(new StringLiteral("a"), new LongLiteral("1"), new DoubleLiteral("2.2")), row(new StringLiteral("b"), new LongLiteral("2"), new DoubleLiteral("3.3"))));
    assertStatement("VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0)", valuesQuery);
    assertStatement("SELECT * FROM (VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0))", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery)));
}
Also used : QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 5 with DoubleLiteral

use of io.prestosql.sql.tree.DoubleLiteral 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)

Aggregations

DoubleLiteral (io.prestosql.sql.tree.DoubleLiteral)13 Test (org.testng.annotations.Test)10 StringLiteral (io.prestosql.sql.tree.StringLiteral)8 LongLiteral (io.prestosql.sql.tree.LongLiteral)6 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)5 SymbolReference (io.prestosql.sql.tree.SymbolReference)5 GenericLiteral (io.prestosql.sql.tree.GenericLiteral)4 DecimalLiteral (io.prestosql.sql.tree.DecimalLiteral)3 Expression (io.prestosql.sql.tree.Expression)3 Slice (io.airlift.slice.Slice)2 RowExpression (io.prestosql.spi.relation.RowExpression)2 BooleanLiteral (io.prestosql.sql.tree.BooleanLiteral)2 Cast (io.prestosql.sql.tree.Cast)2 NullLiteral (io.prestosql.sql.tree.NullLiteral)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1