use of org.teiid.language.Join.JoinType in project teiid by teiid.
the class HiveSQLConversionVisitor method visit.
@Override
public void visit(Join obj) {
TableReference leftItem = obj.getLeftItem();
TableReference rightItem = obj.getRightItem();
JoinType joinType = obj.getJoinType();
// impala only supports a left linear join
if (baseHiveExecutionFactory.requiresLeftLinearJoin() && rightItem instanceof Join) {
if (leftItem instanceof Join) {
// $NON-NLS-1$
throw new AssertionError("A left linear join structure is required: " + obj);
}
// swap
TableReference tr = leftItem;
leftItem = rightItem;
rightItem = tr;
if (joinType == JoinType.RIGHT_OUTER_JOIN) {
joinType = JoinType.LEFT_OUTER_JOIN;
} else if (joinType == JoinType.LEFT_OUTER_JOIN) {
joinType = JoinType.RIGHT_OUTER_JOIN;
}
}
if (useParensForJoins() && leftItem instanceof Join) {
buffer.append(Tokens.LPAREN);
append(leftItem);
buffer.append(Tokens.RPAREN);
} else {
append(leftItem);
}
buffer.append(Tokens.SPACE);
switch(joinType) {
case CROSS_JOIN:
// Hive just works with "JOIN" keyword no inner or cross
// fixed in - https://issues.apache.org/jira/browse/HIVE-2549
buffer.append(CROSS);
break;
case FULL_OUTER_JOIN:
buffer.append(FULL).append(Tokens.SPACE).append(OUTER);
break;
case INNER_JOIN:
// buffer.append(INNER);
break;
case LEFT_OUTER_JOIN:
buffer.append(LEFT).append(Tokens.SPACE).append(OUTER);
break;
case RIGHT_OUTER_JOIN:
buffer.append(RIGHT).append(Tokens.SPACE).append(OUTER);
break;
default:
buffer.append(UNDEFINED);
}
buffer.append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
if (rightItem instanceof Join && (useParensForJoins() || obj.getJoinType() == Join.JoinType.CROSS_JOIN)) {
buffer.append(Tokens.LPAREN);
append(rightItem);
buffer.append(Tokens.RPAREN);
} else {
append(rightItem);
}
final Condition condition = obj.getCondition();
if (condition != null) {
buffer.append(Tokens.SPACE).append(ON).append(Tokens.SPACE);
append(condition);
}
}
use of org.teiid.language.Join.JoinType in project teiid by teiid.
the class PISQLConversionVisitor method visit.
@Override
public void visit(Join obj) {
TableReference leftItem = obj.getLeftItem();
TableReference rightItem = obj.getRightItem();
JoinType joinType = obj.getJoinType();
boolean ignoreOnClause = false;
Condition condition = obj.getCondition();
if (useParensForJoins() && leftItem instanceof Join) {
buffer.append(Tokens.LPAREN);
append(leftItem);
buffer.append(Tokens.RPAREN);
} else {
append(leftItem);
}
buffer.append(Tokens.SPACE);
switch(joinType) {
case CROSS_JOIN:
if (hasLateralJoin(rightItem)) {
if (!isTVF(rightItem)) {
throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11025, rightItem));
}
buffer.append(CROSS).append(Tokens.SPACE).append(APPLY).append(Tokens.SPACE);
ignoreOnClause = true;
} else {
// "a cross join b" is the same as "a inner join b on (1 = 1)"
buffer.append(INNER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
Literal e1 = LanguageFactory.INSTANCE.createLiteral(new Integer(1), Integer.class);
Comparison criteria = new Comparison(e1, e1, Operator.EQ);
condition = criteria;
}
break;
case FULL_OUTER_JOIN:
// should not get here as capabilities are turned off.
throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "FULL OUTER"));
case INNER_JOIN:
buffer.append(INNER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
break;
case LEFT_OUTER_JOIN:
if (!hasLateralJoin(leftItem) && !hasLateralJoin(rightItem)) {
buffer.append(LEFT).append(Tokens.SPACE).append(OUTER).append(Tokens.SPACE).append(JOIN).append(Tokens.SPACE);
} else if (hasLateralJoin(leftItem)) {
throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "RIGHT OUTER APPLY"));
} else if (hasLateralJoin(rightItem)) {
if (!isTVF(rightItem)) {
throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11025, rightItem));
}
buffer.append(OUTER).append(Tokens.SPACE).append(APPLY).append(Tokens.SPACE);
ignoreOnClause = true;
}
break;
case RIGHT_OUTER_JOIN:
// right outer is never pushed, so we should probably never get here.
throw new TeiidRuntimeException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11024, "RIGHT OUTER"));
default:
buffer.append(UNDEFINED);
}
if (rightItem instanceof Join && (useParensForJoins() || obj.getJoinType() == Join.JoinType.CROSS_JOIN)) {
buffer.append(Tokens.LPAREN);
append(hasLateralJoin(rightItem) ? unwrap(rightItem) : rightItem);
buffer.append(Tokens.RPAREN);
} else {
append(hasLateralJoin(rightItem) ? unwrap(rightItem) : rightItem);
}
if (condition != null && !ignoreOnClause) {
buffer.append(Tokens.SPACE).append(ON).append(Tokens.SPACE);
append(condition);
}
}
Aggregations