use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class AstBuilder method visitLambda.
@Override
public Node visitLambda(SqlBaseParser.LambdaContext context) {
List<LambdaArgumentDeclaration> arguments = visit(context.identifier(), Identifier.class).stream().map(LambdaArgumentDeclaration::new).collect(toList());
Expression body = (Expression) visit(context.expression());
return new LambdaExpression(getLocation(context), arguments, body);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class AstBuilder method visitInsertCube.
@Override
public Node visitInsertCube(SqlBaseParser.InsertCubeContext context) {
QualifiedName cubeName = getQualifiedName(context.qualifiedName());
Optional<Expression> optionalExpression = visitIfPresent(context.expression(), Expression.class);
return new InsertCube(getLocation(context), cubeName, optionalExpression, false);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class AstBuilder method visitInsertOverwriteCube.
@Override
public Node visitInsertOverwriteCube(SqlBaseParser.InsertOverwriteCubeContext context) {
QualifiedName cubeName = getQualifiedName(context.qualifiedName());
Optional<Expression> optionalExpression = visitIfPresent(context.expression(), Expression.class);
return new InsertCube(getLocation(context), cubeName, optionalExpression, true);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class AstBuilder method visitJoinRelation.
// *************** from clause *****************
@Override
public Node visitJoinRelation(SqlBaseParser.JoinRelationContext context) {
Relation left = (Relation) visit(context.left);
Relation right;
if (context.CROSS() != null) {
right = (Relation) visit(context.right);
return new Join(getLocation(context), Join.Type.CROSS, left, right, Optional.empty());
}
JoinCriteria criteria;
if (context.NATURAL() != null) {
right = (Relation) visit(context.right);
criteria = new NaturalJoin();
} else {
right = (Relation) visit(context.rightRelation);
if (context.joinCriteria().ON() != null) {
criteria = new JoinOn((Expression) visit(context.joinCriteria().booleanExpression()));
} else if (context.joinCriteria().USING() != null) {
criteria = new JoinUsing(visit(context.joinCriteria().identifier(), Identifier.class));
} else {
throw new IllegalArgumentException("Unsupported join criteria");
}
}
Join.Type joinType;
if (context.joinType().LEFT() != null) {
joinType = Join.Type.LEFT;
} else if (context.joinType().RIGHT() != null) {
joinType = Join.Type.RIGHT;
} else if (context.joinType().FULL() != null) {
joinType = Join.Type.FULL;
} else {
joinType = Join.Type.INNER;
}
return new Join(getLocation(context), joinType, left, right, Optional.of(criteria));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestDesugarTryExpressionRewriter method testTryExpressionDesugaringRewriter.
@Test
public void testTryExpressionDesugaringRewriter() {
// 1 + try(2)
Expression before = new ArithmeticBinaryExpression(ADD, new DecimalLiteral("1"), new TryExpression(new DecimalLiteral("2")));
// 1 + try_function(() -> 2)
Expression after = new ArithmeticBinaryExpression(ADD, new DecimalLiteral("1"), new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of(TryFunction.NAME)).addArgument(new FunctionType(ImmutableList.of(), createDecimalType(1)), new LambdaExpression(ImmutableList.of(), new DecimalLiteral("2"))).build());
assertEquals(DesugarTryExpressionRewriter.rewrite(before, tester().getMetadata(), tester().getTypeAnalyzer(), tester().getSession(), new PlanSymbolAllocator()), after);
}
Aggregations