org.apache.calcite.sql.SqlWithItem Java Examples

The following examples show how to use org.apache.calcite.sql.SqlWithItem. 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
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 File: SqlValidatorImpl.java    From flink with 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 File: WithNamespace.java    From Bats with 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 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 #5
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 #6
Source File: PushDownUtil.java    From kylin-on-parquet-v2 with 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 File: ConvSqlWriter.java    From kylin-on-parquet-v2 with 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 File: PushDownUtil.java    From kylin with 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 File: ConvSqlWriter.java    From kylin with 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 File: WithNamespace.java    From calcite with 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 File: WithItemNamespace.java    From Bats with 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 File: WithScope.java    From Bats with 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 File: WithItemNamespace.java    From calcite with 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 File: WithScope.java    From calcite with 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 File: SqlValidator.java    From Bats with Apache License 2.0 votes vote down vote up
void validateWithItem(SqlWithItem withItem); 
Example #16
Source File: SqlValidator.java    From calcite with Apache License 2.0 votes vote down vote up
void validateWithItem(SqlWithItem withItem);