Search in sources :

Example 16 with LongLiteral

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"))))));
}
Also used : LongLiteral(com.facebook.presto.sql.tree.LongLiteral) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) SingleColumn(com.facebook.presto.sql.tree.SingleColumn) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) Test(org.testng.annotations.Test)

Example 17 with LongLiteral

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")));
}
Also used : QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) SortItem(com.facebook.presto.sql.tree.SortItem) Identifier(com.facebook.presto.sql.tree.Identifier) ShowPartitions(com.facebook.presto.sql.tree.ShowPartitions) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Example 18 with LongLiteral

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")))));
}
Also used : LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Example 19 with LongLiteral

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"))));
}
Also used : LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) NotExpression(com.facebook.presto.sql.tree.NotExpression) Test(org.testng.annotations.Test)

Example 20 with LongLiteral

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")));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Aggregations

LongLiteral (com.facebook.presto.sql.tree.LongLiteral)25 Test (org.testng.annotations.Test)20 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)11 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)9 Query (com.facebook.presto.sql.tree.Query)7 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)6 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)6 Expression (com.facebook.presto.sql.tree.Expression)6 Identifier (com.facebook.presto.sql.tree.Identifier)6 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)6 WithQuery (com.facebook.presto.sql.tree.WithQuery)6 NotExpression (com.facebook.presto.sql.tree.NotExpression)5 AllColumns (com.facebook.presto.sql.tree.AllColumns)4 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)3 Cast (com.facebook.presto.sql.tree.Cast)3 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)3 DoubleLiteral (com.facebook.presto.sql.tree.DoubleLiteral)3 DropTable (com.facebook.presto.sql.tree.DropTable)3 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)3 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)3