org.apache.calcite.sql.SqlWith Java Examples

The following examples show how to use org.apache.calcite.sql.SqlWith. 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 5 votes vote down vote up
private SqlSelect getInnerSelect(SqlNode node) {
	for (;;) {
		if (node instanceof SqlSelect) {
			return (SqlSelect) node;
		} else if (node instanceof SqlOrderBy) {
			node = ((SqlOrderBy) node).query;
		} else if (node instanceof SqlWith) {
			node = ((SqlWith) node).body;
		} else {
			return null;
		}
	}
}
 
Example #2
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void registerWith(
	SqlValidatorScope parentScope,
	SqlValidatorScope usingScope,
	SqlWith with,
	SqlNode enclosingNode,
	String alias,
	boolean forceNullable,
	boolean checkUpdate) {
	final WithNamespace withNamespace =
		new WithNamespace(this, with, enclosingNode);
	registerNamespace(usingScope, alias, withNamespace, forceNullable);

	SqlValidatorScope scope = parentScope;
	for (SqlNode withItem_ : with.withList) {
		final SqlWithItem withItem = (SqlWithItem) withItem_;
		final WithScope withScope = new WithScope(scope, withItem);
		scopes.put(withItem, withScope);

		registerQuery(scope, null, withItem.query, with,
			withItem.name.getSimple(), false);
		registerNamespace(null, alias,
			new WithItemNamespace(this, withItem, enclosingNode),
			false);
		scope = withScope;
	}

	registerQuery(scope, null, with.body, enclosingNode, alias, forceNullable,
		checkUpdate);
}
 
Example #3
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private SqlSelect getInnerSelect(SqlNode node) {
	for (;;) {
		if (node instanceof SqlSelect) {
			return (SqlSelect) node;
		} else if (node instanceof SqlOrderBy) {
			node = ((SqlOrderBy) node).query;
		} else if (node instanceof SqlWith) {
			node = ((SqlWith) node).body;
		} else {
			return null;
		}
	}
}
 
Example #4
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private void registerWith(
	SqlValidatorScope parentScope,
	SqlValidatorScope usingScope,
	SqlWith with,
	SqlNode enclosingNode,
	String alias,
	boolean forceNullable,
	boolean checkUpdate) {
	final WithNamespace withNamespace =
		new WithNamespace(this, with, enclosingNode);
	registerNamespace(usingScope, alias, withNamespace, forceNullable);

	SqlValidatorScope scope = parentScope;
	for (SqlNode withItem_ : with.withList) {
		final SqlWithItem withItem = (SqlWithItem) withItem_;
		final WithScope withScope = new WithScope(scope, withItem);
		scopes.put(withItem, withScope);

		registerQuery(scope, null, withItem.query, with,
			withItem.name.getSimple(), false);
		registerNamespace(null, alias,
			new WithItemNamespace(this, withItem, enclosingNode),
			false);
		scope = withScope;
	}

	registerQuery(scope, null, with.body, enclosingNode, alias, forceNullable,
		checkUpdate);
}
 
Example #5
Source File: ConvSqlWriter.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void writeWith(SqlCall call, int leftPrec, int rightPrec) {
    final SqlWith with = (SqlWith) call;
    final SqlWriter.Frame frame = this.startList(SqlWriter.FrameTypeEnum.WITH, "WITH", "");
    for (SqlNode node : with.withList) {
        this.sep(",");
        node.unparse(this, 0, 0);
    }
    with.body.unparse(this, 100, 100);
    this.endList(frame);
}
 
Example #6
Source File: ConvSqlWriter.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void writeWith(SqlCall call, int leftPrec, int rightPrec) {
    final SqlWith with = (SqlWith) call;
    final SqlWriter.Frame frame = this.startList(SqlWriter.FrameTypeEnum.WITH, "WITH", "");
    for (SqlNode node : with.withList) {
        this.sep(",");
        node.unparse(this, 0, 0);
    }
    with.body.unparse(this, 100, 100);
    this.endList(frame);
}
 
Example #7
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void validateWith(SqlWith with, SqlValidatorScope scope) {
	final SqlValidatorNamespace namespace = getNamespace(with);
	validateNamespace(namespace, unknownType);
}
 
Example #8
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
public void validateWith(SqlWith with, SqlValidatorScope scope) {
	final SqlValidatorNamespace namespace = getNamespace(with);
	validateNamespace(namespace, unknownType);
}
 
Example #9
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Widen a SqlNode's field type to common type,
 * mainly used for set operations like UNION, INTERSECT and EXCEPT.
 *
 * <p>Rules:
 * <pre>
 *
 *       type1, type2  type3       select a, b, c from t1
 *          \      \      \
 *         type4  type5  type6              UNION
 *          /      /      /
 *       type7  type8  type9       select d, e, f from t2
 * </pre>
 * For struct type (type1, type2, type3) union type (type4, type5, type6),
 * infer the first result column type type7 as the wider type of type1 and type4,
 * the second column type as the wider type of type2 and type5 and so on.
 *
 * @param scope       Validator scope
 * @param query       Query node to update the field type for
 * @param columnIndex Target column index
 * @param targetType  Target type to cast to
 */
public boolean rowTypeCoercion(
    SqlValidatorScope scope,
    SqlNode query,
    int columnIndex,
    RelDataType targetType) {
  final SqlKind kind = query.getKind();
  switch (kind) {
  case SELECT:
    SqlSelect selectNode = (SqlSelect) query;
    SqlValidatorScope scope1 = validator.getSelectScope(selectNode);
    if (!coerceColumnType(scope1, selectNode.getSelectList(), columnIndex, targetType)) {
      return false;
    }
    updateInferredColumnType(scope1, query, columnIndex, targetType);
    return true;
  case VALUES:
    for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
      if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
        return false;
      }
    }
    updateInferredColumnType(scope, query, columnIndex, targetType);
    return true;
  case WITH:
    SqlNode body = ((SqlWith) query).body;
    return rowTypeCoercion(validator.getOverScope(query), body, columnIndex, targetType);
  case UNION:
  case INTERSECT:
  case EXCEPT:
    // Set operations are binary for now.
    final SqlCall operand0 = ((SqlCall) query).operand(0);
    final SqlCall operand1 = ((SqlCall) query).operand(1);
    final boolean coerced = rowTypeCoercion(scope, operand0, columnIndex, targetType)
        && rowTypeCoercion(scope, operand1, columnIndex, targetType);
    // Update the nested SET operator node type.
    if (coerced) {
      updateInferredColumnType(scope, query, columnIndex, targetType);
    }
    return coerced;
  default:
    return false;
  }
}
 
Example #10
Source File: WithNamespace.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a TableConstructorNamespace.
 *
 * @param validator     Validator
 * @param with          WITH clause
 * @param enclosingNode Enclosing node
 */
WithNamespace(SqlValidatorImpl validator,
    SqlWith with,
    SqlNode enclosingNode) {
  super(validator, enclosingNode);
  this.with = with;
}
 
Example #11
Source File: WithNamespace.java    From calcite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a TableConstructorNamespace.
 *
 * @param validator     Validator
 * @param with          WITH clause
 * @param enclosingNode Enclosing node
 */
WithNamespace(SqlValidatorImpl validator,
    SqlWith with,
    SqlNode enclosingNode) {
  super(validator, enclosingNode);
  this.with = with;
}
 
Example #12
Source File: SqlValidator.java    From Bats with Apache License 2.0 votes vote down vote up
void validateWith(SqlWith with, SqlValidatorScope scope); 
Example #13
Source File: SqlValidator.java    From calcite with Apache License 2.0 votes vote down vote up
void validateWith(SqlWith with, SqlValidatorScope scope);