Java Code Examples for org.apache.calcite.sql.SqlJoin#getCondition()

The following examples show how to use org.apache.calcite.sql.SqlJoin#getCondition() . 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 File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/** Returns the set of field names in the join condition specified by USING
 * or implicitly by NATURAL, de-duplicated and in order. */
private List<String> usingNames(SqlJoin join) {
	switch (join.getConditionType()) {
		case USING:
			final ImmutableList.Builder<String> list = ImmutableList.builder();
			final Set<String> names = catalogReader.nameMatcher().createSet();
			for (SqlNode node : (SqlNodeList) join.getCondition()) {
				final String name = ((SqlIdentifier) node).getSimple();
				if (names.add(name)) {
					list.add(name);
				}
			}
			return list.build();
		case NONE:
			if (join.isNatural()) {
				final RelDataType t0 = getValidatedNodeType(join.getLeft());
				final RelDataType t1 = getValidatedNodeType(join.getRight());
				return SqlValidatorUtil.deriveNaturalJoinColumnList(
					catalogReader.nameMatcher(), t0, t1);
			}
	}
	return null;
}
 
Example 2
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
/** Returns the set of field names in the join condition specified by USING
 * or implicitly by NATURAL, de-duplicated and in order. */
private List<String> usingNames(SqlJoin join) {
	switch (join.getConditionType()) {
		case USING:
			final ImmutableList.Builder<String> list = ImmutableList.builder();
			final Set<String> names = catalogReader.nameMatcher().createSet();
			for (SqlNode node : (SqlNodeList) join.getCondition()) {
				final String name = ((SqlIdentifier) node).getSimple();
				if (names.add(name)) {
					list.add(name);
				}
			}
			return list.build();
		case NONE:
			if (join.isNatural()) {
				final RelDataType t0 = getValidatedNodeType(join.getLeft());
				final RelDataType t1 = getValidatedNodeType(join.getRight());
				return SqlValidatorUtil.deriveNaturalJoinColumnList(
					catalogReader.nameMatcher(), t0, t1);
			}
	}
	return null;
}
 
Example 3
Source File: FlinkCalciteSqlValidator.java    From flink with 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 4
Source File: FlinkCalciteSqlValidator.java    From flink with 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 5
Source File: SqlValidatorImpl.java    From Flink-CEPplus with 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 File: SqlValidatorImpl.java    From flink with 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 7
Source File: SqlValidatorImpl.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void validateJoin(SqlJoin join, SqlValidatorScope scope) {
  SqlNode condition = join.getCondition();
  checkIfFlattenIsPartOfJoinCondition(condition);
  super.validateJoin(join, scope);
}