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"))));
}
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"));
}
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"));
}
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)));
}
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());
}
Aggregations