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

The following examples show how to use org.apache.calcite.sql.JoinType. 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: flink   Source File: FlinkCalciteSqlValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void validateJoin(SqlJoin join, SqlValidatorScope scope) {
	// Due to the improper translation of lateral table left outer join in Calcite, we need to
	// temporarily forbid the common predicates until the problem is fixed (see FLINK-7865).
	if (join.getJoinType() == JoinType.LEFT &&
			SqlUtil.stripAs(join.getRight()).getKind() == SqlKind.COLLECTION_TABLE) {
		final SqlNode condition = join.getCondition();
		if (condition != null &&
				(!SqlUtil.isLiteral(condition) || ((SqlLiteral) condition).getValueAs(Boolean.class) != Boolean.TRUE)) {
			throw new ValidationException(
				String.format(
					"Left outer joins with a table function do not accept a predicate such as %s. " +
					"Only literal TRUE is accepted.",
					condition));
		}
	}
	super.validateJoin(join, scope);
}
 
Example 2
Source Project: flink   Source File: FlinkCalciteSqlValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void validateJoin(SqlJoin join, SqlValidatorScope scope) {
	// Due to the improper translation of lateral table left outer join in Calcite, we need to
	// temporarily forbid the common predicates until the problem is fixed (see FLINK-7865).
	if (join.getJoinType() == JoinType.LEFT &&
			SqlUtil.stripAs(join.getRight()).getKind() == SqlKind.COLLECTION_TABLE) {
		final SqlNode condition = join.getCondition();
		if (condition != null &&
				(!SqlUtil.isLiteral(condition) || ((SqlLiteral) condition).getValueAs(Boolean.class) != Boolean.TRUE)) {
			throw new ValidationException(
				String.format(
					"Left outer joins with a table function do not accept a predicate such as %s. " +
					"Only literal TRUE is accepted.",
					condition));
		}
	}
	super.validateJoin(join, scope);
}
 
Example 3
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 4
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 5
Source Project: alchemy   Source File: ISideFunction.java    License: Apache License 2.0 5 votes vote down vote up
default List<Row> dealMissKey(Row input, JoinType joinType) {
    if (joinType == JoinType.LEFT) {
        return fillRecord(input, null);
    } else {
        return null;
    }
}
 
Example 6
Source Project: alchemy   Source File: SideStream.java    License: Apache License 2.0 5 votes vote down vote up
private static SideTable createSideTable(TableSchema leftSchema, RowTypeInfo sideType, JoinType joinType,
    SqlSelect rightSelect, List<String> equalFields, Alias sideAlias, Side side) {
    List<Integer> indexFields = createFieldIndex(leftSchema, equalFields);
    SideTable sideTable = new SideTable();
    sideTable.setConditionIndexs(indexFields);
    sideTable.setConditions(equalFields);
    sideTable.setSide(side);
    sideTable.setJoinType(joinType);
    sideTable.setRowSize(leftSchema.getFieldCount() + sideType.getArity());
    sideTable.setSideAlias(sideAlias);
    sideTable.setSideType(sideType);
    sideTable.setSql(rightSelect.toString());
    return sideTable;
}
 
Example 7
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 8
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 9
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);
}
 
Example 10
Source Project: Bats   Source File: SparkSqlDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override public JoinType emulateJoinTypeForCrossJoin() {
  return JoinType.CROSS;
}
 
Example 11
Source Project: alchemy   Source File: SideTable.java    License: Apache License 2.0 4 votes vote down vote up
public JoinType getJoinType() {
    return joinType;
}
 
Example 12
Source Project: alchemy   Source File: SideTable.java    License: Apache License 2.0 4 votes vote down vote up
public void setJoinType(JoinType joinType) {
    this.joinType = joinType;
}
 
Example 13
Source Project: sylph   Source File: JoinInfo.java    License: Apache License 2.0 4 votes vote down vote up
public JoinType getJoinType()
{
    return joinType;
}
 
Example 14
Source Project: dremio-oss   Source File: DremioSqlDialect.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Indicates if the dialect supports the given join type.
 */
public boolean supportsJoin(JoinType type) {
  return true;
}
 
Example 15
Source Project: calcite   Source File: SparkSqlDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override public JoinType emulateJoinTypeForCrossJoin() {
  return JoinType.CROSS;
}