use of io.prestosql.sql.tree.JoinCriteria 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.JoinCriteria in project hetu-core by openlookeng.
the class RelationPlanner method planLateralJoin.
private RelationPlan planLateralJoin(Join join, RelationPlan leftPlan, Lateral lateral) {
RelationPlan rightPlan = process(lateral.getQuery(), null);
PlanBuilder leftPlanBuilder = initializePlanBuilder(leftPlan);
PlanBuilder rightPlanBuilder = initializePlanBuilder(rightPlan);
Expression filterExpression;
if (!join.getCriteria().isPresent()) {
filterExpression = TRUE_LITERAL;
} else {
JoinCriteria criteria = join.getCriteria().get();
if (criteria instanceof JoinUsing || criteria instanceof NaturalJoin) {
throw notSupportedException(join, "Lateral join with criteria other than ON");
}
filterExpression = (Expression) getOnlyElement(criteria.getNodes());
}
List<Symbol> rewriterOutputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getFieldMappings()).addAll(rightPlan.getFieldMappings()).build();
// this node is not used in the plan. It is only used for creating the TranslationMap.
PlanNode dummy = new ValuesNode(idAllocator.getNextId(), ImmutableList.<Symbol>builder().addAll(leftPlanBuilder.getRoot().getOutputSymbols()).addAll(rightPlanBuilder.getRoot().getOutputSymbols()).build(), ImmutableList.of());
RelationPlan intermediateRelationPlan = new RelationPlan(dummy, analysis.getScope(join), rewriterOutputSymbols);
TranslationMap translationMap = new TranslationMap(intermediateRelationPlan, analysis, lambdaDeclarationToSymbolMap);
translationMap.setFieldMappings(rewriterOutputSymbols);
translationMap.putExpressionMappingsFrom(leftPlanBuilder.getTranslations());
translationMap.putExpressionMappingsFrom(rightPlanBuilder.getTranslations());
Expression rewrittenFilterCondition = translationMap.rewrite(filterExpression);
PlanBuilder planBuilder = subqueryPlanner.appendLateralJoin(leftPlanBuilder, rightPlanBuilder, lateral.getQuery(), true, LateralJoinNode.Type.typeConvert(join.getType()), rewrittenFilterCondition);
List<Symbol> outputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getRoot().getOutputSymbols()).addAll(rightPlan.getRoot().getOutputSymbols()).build();
return new RelationPlan(planBuilder.getRoot(), analysis.getScope(join), outputSymbols);
}
use of io.prestosql.sql.tree.JoinCriteria in project hetu-core by openlookeng.
the class HiveAstBuilder method visitJoinRelation.
// *************** from clause *****************
@Override
public Node visitJoinRelation(HiveSqlParser.JoinRelationContext context) {
Relation leftRelation = (Relation) visit(context.left);
Relation rightRelation;
Optional<JoinCriteria> criteria = Optional.empty();
// Semi Join
if (context.semiJoin() != null) {
addDiff(DiffType.UNSUPPORTED, context.semiJoin().LEFT().getText(), "[LEFT SEMI JOIN] is not supported");
addDiff(DiffType.UNSUPPORTED, context.semiJoin().SEMI().getText(), null);
addDiff(DiffType.UNSUPPORTED, context.semiJoin().JOIN().getText(), null);
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Left semi join", context.semiJoin());
}
// Cross join
if (context.crossJoin() != null) {
if (context.crossJoin().joinCriteria() != null) {
addDiff(DiffType.UNSUPPORTED, context.crossJoin().CROSS().getText(), "[CROSS JOIN] must not contain join condition");
addDiff(DiffType.UNSUPPORTED, context.crossJoin().JOIN().getText(), null);
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Cross join must not contain join condition", context.crossJoin().joinCriteria());
}
rightRelation = (Relation) visit(context.crossJoin().right);
return new Join(getLocation(context), Join.Type.CROSS, leftRelation, rightRelation, criteria);
}
// Inner join
if (context.innerJoin() != null) {
if (context.innerJoin().joinCriteria() == null) {
if (context.innerJoin().INNER() != null) {
addDiff(DiffType.UNSUPPORTED, context.innerJoin().INNER().getText(), null);
}
addDiff(DiffType.UNSUPPORTED, context.innerJoin().JOIN().getText(), "[INNER JOIN] must contain join condition");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Inner join must contain join condition", context.innerJoin());
}
rightRelation = (Relation) visit(context.innerJoin().right);
criteria = Optional.of(new JoinOn((Expression) visit(context.innerJoin().joinCriteria().booleanExpression())));
return new Join(getLocation(context), Join.Type.INNER, leftRelation, rightRelation, criteria);
}
// Outer join
HiveSqlParser.OuterJoinContext outerJoinContext = context.outerJoin();
// Get join type
Join.Type joinType;
if (outerJoinContext.joinType().LEFT() != null) {
joinType = Join.Type.LEFT;
} else if (outerJoinContext.joinType().RIGHT() != null) {
joinType = Join.Type.RIGHT;
} else {
joinType = Join.Type.FULL;
}
// Get right relation
rightRelation = (Relation) visit(outerJoinContext.rightRelation);
// Get join criteria
criteria = Optional.of(new JoinOn((Expression) visit(outerJoinContext.joinCriteria().booleanExpression())));
return new Join(getLocation(context), joinType, leftRelation, rightRelation, criteria);
}
use of io.prestosql.sql.tree.JoinCriteria in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitJoinRelation.
@Override
public Node visitJoinRelation(ImpalaSqlParser.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());
}
if (context.joinType().SEMI() != null) {
addDiff(DiffType.UNSUPPORTED, context.joinType().SEMI().getText(), "[SEMI] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "SEMI", context);
}
if (context.joinType().ANTI() != null) {
addDiff(DiffType.UNSUPPORTED, context.joinType().ANTI().getText(), "[ANTI] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "ANTI", context);
}
if (context.joinType().INNER() != null && (context.joinType().LEFT() != null || context.joinType().RIGHT() != null)) {
addDiff(DiffType.UNSUPPORTED, context.joinType().INNER().getText(), "[LEFT INNER || RIGHT INNER] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "LEFT INNER || RIGHT INNER", context);
}
JoinCriteria criteria;
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));
}
Aggregations