Search in sources :

Example 1 with LongLiteral

use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.

the class TestCountConstantOptimizer method testCountConstantOptimizer.

@Test
public void testCountConstantOptimizer() throws Exception {
    CountConstantOptimizer optimizer = new CountConstantOptimizer();
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    Symbol countAggregationSymbol = new Symbol("count");
    Signature countAggregationSignature = new Signature("count", FunctionKind.AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
    ImmutableMap<Symbol, FunctionCall> aggregations = ImmutableMap.of(countAggregationSymbol, new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new SymbolReference("expr"))));
    ImmutableMap<Symbol, Signature> functions = ImmutableMap.of(countAggregationSymbol, countAggregationSignature);
    ValuesNode valuesNode = new ValuesNode(planNodeIdAllocator.getNextId(), ImmutableList.of(new Symbol("col")), ImmutableList.of(ImmutableList.of()));
    AggregationNode eligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new LongLiteral("42"))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
    assertTrue(((AggregationNode) optimizer.optimize(eligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
    AggregationNode ineligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new FunctionCall(QualifiedName.of("function"), ImmutableList.of(new Identifier("x"))))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
    assertFalse(((AggregationNode) optimizer.optimize(ineligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
}
Also used : SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Symbol(com.facebook.presto.sql.planner.Symbol) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) Identifier(com.facebook.presto.sql.tree.Identifier) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 2 with LongLiteral

use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.

the class TestSqlParser method testCreateSchema.

@Test
public void testCreateSchema() {
    assertStatement("CREATE SCHEMA test", new CreateSchema(QualifiedName.of("test"), false, ImmutableMap.of()));
    assertStatement("CREATE SCHEMA IF NOT EXISTS test", new CreateSchema(QualifiedName.of("test"), true, ImmutableMap.of()));
    assertStatement("CREATE SCHEMA test WITH (a = 'apple', b = 123)", new CreateSchema(QualifiedName.of("test"), false, ImmutableMap.of("a", new StringLiteral("apple"), "b", new LongLiteral("123"))));
}
Also used : StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) CreateSchema(com.facebook.presto.sql.tree.CreateSchema) Test(org.testng.annotations.Test)

Example 3 with LongLiteral

use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.

the class TestSqlParser method testArrayConstructor.

@Test
public void testArrayConstructor() throws Exception {
    assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of()));
    assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))));
    assertExpression("ARRAY [1.0, 2.5]", 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(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) ArrayConstructor(com.facebook.presto.sql.tree.ArrayConstructor) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 4 with LongLiteral

use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.

the class TestSqlParser method testCall.

@Test
public void testCall() throws Exception {
    assertStatement("CALL foo()", new Call(QualifiedName.of("foo"), ImmutableList.of()));
    assertStatement("CALL foo(123, a => 1, b => 'go', 456)", new Call(QualifiedName.of("foo"), ImmutableList.of(new CallArgument(new LongLiteral("123")), new CallArgument("a", new LongLiteral("1")), new CallArgument("b", new StringLiteral("go")), new CallArgument(new LongLiteral("456")))));
}
Also used : Call(com.facebook.presto.sql.tree.Call) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) CallArgument(com.facebook.presto.sql.tree.CallArgument) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Example 5 with LongLiteral

use of com.facebook.presto.sql.tree.LongLiteral in project presto by prestodb.

the class TestSqlParser method testBetween.

@Test
public void testBetween() throws Exception {
    assertExpression("1 BETWEEN 2 AND 3", new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3")));
    assertExpression("1 NOT BETWEEN 2 AND 3", new NotExpression(new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3"))));
}
Also used : BetweenPredicate(com.facebook.presto.sql.tree.BetweenPredicate) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) NotExpression(com.facebook.presto.sql.tree.NotExpression) 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