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

The following examples show how to use org.apache.calcite.sql.SqlWithItem. 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-CEPplus   Source File: SqlValidatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
public void validateWithItem(SqlWithItem withItem) {
	if (withItem.columnList != null) {
		final RelDataType rowType = getValidatedNodeType(withItem.query);
		final int fieldCount = rowType.getFieldCount();
		if (withItem.columnList.size() != fieldCount) {
			throw newValidationError(withItem.columnList,
				RESOURCE.columnCountMismatch());
		}
		SqlValidatorUtil.checkIdentifierListForDuplicates(
			withItem.columnList.getList(), validationErrorFunction);
	} else {
		// Luckily, field names have not been make unique yet.
		final List<String> fieldNames =
			getValidatedNodeType(withItem.query).getFieldNames();
		final int i = Util.firstDuplicate(fieldNames);
		if (i >= 0) {
			throw newValidationError(withItem.query,
				RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i)));
		}
	}
}
 
Example 2
Source Project: flink   Source File: SqlValidatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
public void validateWithItem(SqlWithItem withItem) {
	if (withItem.columnList != null) {
		final RelDataType rowType = getValidatedNodeType(withItem.query);
		final int fieldCount = rowType.getFieldCount();
		if (withItem.columnList.size() != fieldCount) {
			throw newValidationError(withItem.columnList,
				RESOURCE.columnCountMismatch());
		}
		SqlValidatorUtil.checkIdentifierListForDuplicates(
			withItem.columnList.getList(), validationErrorFunction);
	} else {
		// Luckily, field names have not been make unique yet.
		final List<String> fieldNames =
			getValidatedNodeType(withItem.query).getFieldNames();
		final int i = Util.firstDuplicate(fieldNames);
		if (i >= 0) {
			throw newValidationError(withItem.query,
				RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i)));
		}
	}
}
 
Example 3
Source Project: Bats   Source File: WithNamespace.java    License: Apache License 2.0 5 votes vote down vote up
protected RelDataType validateImpl(RelDataType targetRowType) {
  for (SqlNode withItem : with.withList) {
    validator.validateWithItem((SqlWithItem) withItem);
  }
  final SqlValidatorScope scope2 =
      validator.getWithScope(Util.last(with.withList.getList()));
  validator.validateQuery(with.body, scope2, targetRowType);
  final RelDataType rowType = validator.getValidatedNodeType(with.body);
  validator.setValidatedNodeType(with, rowType);
  return rowType;
}
 
Example 4
Source Project: Flink-CEPplus   Source File: SqlValidatorImpl.java    License: 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 Project: flink   Source File: SqlValidatorImpl.java    License: 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 6
Source Project: kylin-on-parquet-v2   Source File: PushDownUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlNode visit(SqlNodeList nodeList) {
    for (int i = 0; i < nodeList.size(); i++) {
        SqlNode node = nodeList.get(i);
        if (node instanceof SqlWithItem) {
            SqlWithItem item = (SqlWithItem) node;
            item.query.accept(this);
        }
    }
    return null;
}
 
Example 7
Source Project: kylin-on-parquet-v2   Source File: ConvSqlWriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeWithItem(SqlCall call, SqlWithItem.SqlWithItemOperator sqlWithItemOperator, int leftPrec,
                          int rightPrec) {
    final SqlWithItem withItem = (SqlWithItem) call;
    int leftP = sqlWithItemOperator.getLeftPrec();
    int rightP = sqlWithItemOperator.getRightPrec();
    withItem.name.unparse(this, leftP, rightP);
    if (withItem.columnList != null) {
        withItem.columnList.unparse(this, leftP, rightP);
    }
    this.keyword("AS");
    Frame frame = this.startList(FrameTypeEnum.WITH_ITEM, "(", ")");
    withItem.query.unparse(this, 10, 10);
    this.endList(frame);
}
 
Example 8
Source Project: kylin   Source File: PushDownUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlNode visit(SqlNodeList nodeList) {
    for (int i = 0; i < nodeList.size(); i++) {
        SqlNode node = nodeList.get(i);
        if (node instanceof SqlWithItem) {
            SqlWithItem item = (SqlWithItem) node;
            item.query.accept(this);
        }
    }
    return null;
}
 
Example 9
Source Project: kylin   Source File: ConvSqlWriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeWithItem(SqlCall call, SqlWithItem.SqlWithItemOperator sqlWithItemOperator, int leftPrec,
                          int rightPrec) {
    final SqlWithItem withItem = (SqlWithItem) call;
    int leftP = sqlWithItemOperator.getLeftPrec();
    int rightP = sqlWithItemOperator.getRightPrec();
    withItem.name.unparse(this, leftP, rightP);
    if (withItem.columnList != null) {
        withItem.columnList.unparse(this, leftP, rightP);
    }
    this.keyword("AS");
    Frame frame = this.startList(FrameTypeEnum.WITH_ITEM, "(", ")");
    withItem.query.unparse(this, 10, 10);
    this.endList(frame);
}
 
Example 10
Source Project: calcite   Source File: WithNamespace.java    License: Apache License 2.0 5 votes vote down vote up
protected RelDataType validateImpl(RelDataType targetRowType) {
  for (SqlNode withItem : with.withList) {
    validator.validateWithItem((SqlWithItem) withItem);
  }
  final SqlValidatorScope scope2 =
      validator.getWithScope(Util.last(with.withList.getList()));
  validator.validateQuery(with.body, scope2, targetRowType);
  final RelDataType rowType = validator.getValidatedNodeType(with.body);
  validator.setValidatedNodeType(with, rowType);
  return rowType;
}
 
Example 11
Source Project: Bats   Source File: WithItemNamespace.java    License: Apache License 2.0 4 votes vote down vote up
WithItemNamespace(SqlValidatorImpl validator, SqlWithItem withItem,
    SqlNode enclosingNode) {
  super(validator, enclosingNode);
  this.withItem = withItem;
}
 
Example 12
Source Project: Bats   Source File: WithScope.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a WithScope. */
WithScope(SqlValidatorScope parent, SqlWithItem withItem) {
  super(parent);
  this.withItem = withItem;
}
 
Example 13
Source Project: calcite   Source File: WithItemNamespace.java    License: Apache License 2.0 4 votes vote down vote up
WithItemNamespace(SqlValidatorImpl validator, SqlWithItem withItem,
    SqlNode enclosingNode) {
  super(validator, enclosingNode);
  this.withItem = withItem;
}
 
Example 14
Source Project: calcite   Source File: WithScope.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a WithScope. */
WithScope(SqlValidatorScope parent, SqlWithItem withItem) {
  super(parent);
  this.withItem = withItem;
}
 
Example 15
Source Project: Bats   Source File: SqlValidator.java    License: Apache License 2.0 votes vote down vote up
void validateWithItem(SqlWithItem withItem); 
Example 16
Source Project: calcite   Source File: SqlValidator.java    License: Apache License 2.0 votes vote down vote up
void validateWithItem(SqlWithItem withItem);