use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.
the class TestSqlParser method testQuantifiedComparison.
@Test
public void testQuantifiedComparison() {
assertExpression("col1 < ANY (SELECT col2 FROM table1)", new QuantifiedComparisonExpression(ComparisonExpressionType.LESS_THAN, QuantifiedComparisonExpression.Quantifier.ANY, identifier("col1"), new SubqueryExpression(simpleQuery(selectList(new SingleColumn(identifier("col2"))), table(QualifiedName.of("table1"))))));
assertExpression("col1 = ALL (VALUES ROW(1), ROW(2))", new QuantifiedComparisonExpression(ComparisonExpressionType.EQUAL, QuantifiedComparisonExpression.Quantifier.ALL, identifier("col1"), new SubqueryExpression(query(values(row(new LongLiteral("1")), row(new LongLiteral("2")))))));
assertExpression("col1 >= SOME (SELECT 10)", new QuantifiedComparisonExpression(ComparisonExpressionType.GREATER_THAN_OR_EQUAL, QuantifiedComparisonExpression.Quantifier.SOME, identifier("col1"), new SubqueryExpression(simpleQuery(selectList(new LongLiteral("10"))))));
}
use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.
the class TestSqlParser method testShowPartitions.
@Test
public void testShowPartitions() {
assertStatement("SHOW PARTITIONS FROM t", new ShowPartitions(QualifiedName.of("t"), Optional.empty(), ImmutableList.of(), Optional.empty()));
assertStatement("SHOW PARTITIONS FROM t WHERE x = 1", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(), Optional.empty()));
assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.empty()));
assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT 10", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.of("10")));
assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT ALL", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.of("ALL")));
}
use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.
the class TestSqlParser method testArithmeticUnary.
@Test
public void testArithmeticUnary() {
assertExpression("9", new LongLiteral("9"));
assertExpression("+9", positive(new LongLiteral("9")));
assertExpression("+ 9", positive(new LongLiteral("9")));
assertExpression("++9", positive(positive(new LongLiteral("9"))));
assertExpression("+ +9", positive(positive(new LongLiteral("9"))));
assertExpression("+ + 9", positive(positive(new LongLiteral("9"))));
assertExpression("+++9", positive(positive(positive(new LongLiteral("9")))));
assertExpression("+ + +9", positive(positive(positive(new LongLiteral("9")))));
assertExpression("+ + + 9", positive(positive(positive(new LongLiteral("9")))));
assertExpression("-9", negative(new LongLiteral("9")));
assertExpression("- 9", negative(new LongLiteral("9")));
assertExpression("- + 9", negative(positive(new LongLiteral("9"))));
assertExpression("-+9", negative(positive(new LongLiteral("9"))));
assertExpression("+ - + 9", positive(negative(positive(new LongLiteral("9")))));
assertExpression("+-+9", positive(negative(positive(new LongLiteral("9")))));
assertExpression("- -9", negative(negative(new LongLiteral("9"))));
assertExpression("- - 9", negative(negative(new LongLiteral("9"))));
assertExpression("- + - + 9", negative(positive(negative(positive(new LongLiteral("9"))))));
assertExpression("-+-+9", negative(positive(negative(positive(new LongLiteral("9"))))));
assertExpression("+ - + - + 9", positive(negative(positive(negative(positive(new LongLiteral("9")))))));
assertExpression("+-+-+9", positive(negative(positive(negative(positive(new LongLiteral("9")))))));
assertExpression("- - -9", negative(negative(negative(new LongLiteral("9")))));
assertExpression("- - - 9", negative(negative(negative(new LongLiteral("9")))));
}
use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.
the class TestSqlParser method testPrecedenceAndAssociativity.
@Test
public void testPrecedenceAndAssociativity() throws Exception {
assertExpression("1 AND 2 OR 3", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
assertExpression("1 OR 2 AND 3", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, new LongLiteral("1"), new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, new LongLiteral("2"), new LongLiteral("3"))));
assertExpression("NOT 1 AND 2", new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
assertExpression("NOT 1 OR 2", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
assertExpression("-1 + 2", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.ADD, negative(new LongLiteral("1")), new LongLiteral("2")));
assertExpression("1 - 2 - 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.SUBTRACT, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.SUBTRACT, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
assertExpression("1 / 2 / 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.DIVIDE, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.DIVIDE, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
assertExpression("1 + 2 * 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.ADD, new LongLiteral("1"), new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.MULTIPLY, new LongLiteral("2"), new LongLiteral("3"))));
}
use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.
the class TestSqlParser method testLimitAll.
@Test
public void testLimitAll() {
Query valuesQuery = query(values(row(new LongLiteral("1"), new StringLiteral("1")), row(new LongLiteral("2"), new StringLiteral("2"))));
assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) LIMIT ALL", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of("ALL")));
}
Aggregations