Java Code Examples for org.apache.calcite.sql.JoinConditionType

The following examples show how to use org.apache.calcite.sql.JoinConditionType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quark   Source File: RelToSqlConverter.java    License: Apache License 2.0 6 votes vote down vote up
public Result visitJoin(Join e) {
  final Result leftResult = visitChild(0, e.getLeft());
  final Result rightResult = visitChild(1, e.getRight());
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext =
      rightResult.qualifiedContext();
  SqlNode sqlCondition = convertConditionToSqlNode(e.getCondition(),
      leftContext,
      rightContext,
      e.getLeft().getRowType().getFieldCount());
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType(e.getJoinType()).symbol(POS),
          rightResult.asFrom(),
          JoinConditionType.ON.symbol(POS),
          sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 2
Source Project: calcite   Source File: RelToSqlConverter.java    License: Apache License 2.0 6 votes vote down vote up
/** @see #dispatch */
public Result visit(Correlate e) {
  final Result leftResult =
      visitChild(0, e.getLeft())
          .resetAlias(e.getCorrelVariable(), e.getRowType());
  parseCorrelTable(e, leftResult);
  final Result rightResult = visitChild(1, e.getRight());
  final SqlNode rightLateral =
      SqlStdOperatorTable.LATERAL.createCall(POS, rightResult.node);
  final SqlNode rightLateralAs =
      SqlStdOperatorTable.AS.createCall(POS, rightLateral,
          new SqlIdentifier(rightResult.neededAlias, POS));

  final SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          JoinType.COMMA.symbol(POS),
          rightLateralAs,
          JoinConditionType.NONE.symbol(POS),
          null);
  return result(join, leftResult, rightResult);
}
 
Example 3
Source Project: Bats   Source File: RelToSqlConverter.java    License: Apache License 2.0 5 votes vote down vote up
/** @see #dispatch */
public Result visit(Join e) {
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (isCrossJoin(e)) {
    joinType = dialect.emulateJoinTypeForCrossJoin();
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    sqlCondition = convertConditionToSqlNode(e.getCondition(),
        leftContext,
        rightContext,
        e.getLeft().getRowType().getFieldCount());
  }
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType.symbol(POS),
          rightResult.asFrom(),
          condType,
          sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 4
Source Project: Flink-CEPplus   Source File: SqlValidatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void lookupJoinHints(
	SqlJoin join,
	SqlValidatorScope scope,
	SqlParserPos pos,
	Collection<SqlMoniker> hintList) {
	SqlNode left = join.getLeft();
	SqlNode right = join.getRight();
	SqlNode condition = join.getCondition();
	lookupFromHints(left, scope, pos, hintList);
	if (hintList.size() > 0) {
		return;
	}
	lookupFromHints(right, scope, pos, hintList);
	if (hintList.size() > 0) {
		return;
	}
	final JoinConditionType conditionType = join.getConditionType();
	final SqlValidatorScope joinScope = scopes.get(join);
	switch (conditionType) {
		case ON:
			condition.findValidOptions(this, joinScope, pos, hintList);
			return;
		default:

			// No suggestions.
			// Not supporting hints for other types such as 'Using' yet.
			return;
	}
}
 
Example 5
Source Project: flink   Source File: SqlValidatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void lookupJoinHints(
	SqlJoin join,
	SqlValidatorScope scope,
	SqlParserPos pos,
	Collection<SqlMoniker> hintList) {
	SqlNode left = join.getLeft();
	SqlNode right = join.getRight();
	SqlNode condition = join.getCondition();
	lookupFromHints(left, scope, pos, hintList);
	if (hintList.size() > 0) {
		return;
	}
	lookupFromHints(right, scope, pos, hintList);
	if (hintList.size() > 0) {
		return;
	}
	final JoinConditionType conditionType = join.getConditionType();
	final SqlValidatorScope joinScope = scopes.get(join);
	switch (conditionType) {
		case ON:
			condition.findValidOptions(this, joinScope, pos, hintList);
			return;
		default:

			// No suggestions.
			// Not supporting hints for other types such as 'Using' yet.
			return;
	}
}
 
Example 6
Source Project: dremio-oss   Source File: RelToSqlConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see #dispatch
 */
public Result visit(Join e) {
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (e.getJoinType() == JoinRelType.INNER && e.getCondition().isAlwaysTrue()) {
    joinType = JoinType.COMMA;
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    final RexNode condition = e.getCondition() != null
      ? simplifyDatetimePlus(e.getCondition(), e.getCluster().getRexBuilder())
      : null;
    sqlCondition = convertConditionToSqlNode(
      condition,
      leftContext,
      rightContext,
      e.getLeft().getRowType().getFieldCount());
  }
  SqlNode join =
    new SqlJoin(POS,
      leftResult.asFrom(),
      SqlLiteral.createBoolean(false, POS),
      joinType.symbol(POS),
      rightResult.asFrom(),
      condType,
      sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 7
Source Project: dremio-oss   Source File: DremioRelToSqlConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see #dispatch
 */
@Override
public SqlImplementor.Result visit(Join e) {
  final DremioRelToSqlConverter.Result leftResult = (DremioRelToSqlConverter.Result) visitChild(0, e.getLeft()).resetAlias();
  final DremioRelToSqlConverter.Result rightResult = (DremioRelToSqlConverter.Result) visitChild(1, e.getRight()).resetAlias();

  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  final Context joinContext = leftContext.implementor().joinContext(leftContext, rightContext);
  final RexNode condition = e.getCondition() == null ?
    null :
    this.simplifyDatetimePlus(e.getCondition(), e.getCluster().getRexBuilder());
  sqlCondition = joinContext.toSql(null, condition);

  final SqlNode join =
    new SqlJoin(POS,
      leftResult.asFrom(),
      SqlLiteral.createBoolean(false, POS),
      joinType.symbol(POS),
      rightResult.asFrom(),
      condType,
      sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 8
Source Project: calcite   Source File: RelToSqlConverter.java    License: Apache License 2.0 5 votes vote down vote up
/** @see #dispatch */
public Result visit(Join e) {
  if (e.getJoinType() == JoinRelType.ANTI || e.getJoinType() == JoinRelType.SEMI) {
    return visitAntiOrSemiJoin(e);
  }
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (isCrossJoin(e)) {
    joinType = dialect.emulateJoinTypeForCrossJoin();
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    sqlCondition = convertConditionToSqlNode(e.getCondition(),
        leftContext,
        rightContext,
        e.getLeft().getRowType().getFieldCount(),
        dialect);
  }
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType.symbol(POS),
          rightResult.asFrom(),
          condType,
          sqlCondition);
  return result(join, leftResult, rightResult);
}