Java Code Examples for org.apache.calcite.sql.validate.SqlValidatorNamespace

The following examples show how to use org.apache.calcite.sql.validate.SqlValidatorNamespace. 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: Bats   Source File: SqlAdvisorValidator.java    License: Apache License 2.0 5 votes vote down vote up
protected void validateNamespace(final SqlValidatorNamespace namespace,
    RelDataType targetRowType) {
  // Only attempt to validate each namespace once. Otherwise if
  // validation fails, we may end up cycling.
  if (activeNamespaces.add(namespace)) {
    super.validateNamespace(namespace, targetRowType);
  } else {
    namespace.setType(emptyStructType);
  }
}
 
Example 2
Source Project: Bats   Source File: SqlCallBinding.java    License: Apache License 2.0 5 votes vote down vote up
@Override public RelDataType getOperandType(int ordinal) {
  final SqlNode operand = call.operand(ordinal);
  final RelDataType type = validator.deriveType(scope, operand);
  final SqlValidatorNamespace namespace = validator.getNamespace(operand);
  if (namespace != null) {
    return namespace.getType();
  }
  return type;
}
 
Example 3
Source Project: flink   Source File: TypeInferenceOperandChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adopted from {@link org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion}.
 */
private void updateInferredType(SqlValidator validator, SqlNode node, RelDataType type) {
	validator.setValidatedNodeType(node, type);
	final SqlValidatorNamespace namespace = validator.getNamespace(node);
	if (namespace != null) {
		namespace.setType(type);
	}
}
 
Example 4
Source Project: calcite   Source File: SqlAdvisorValidator.java    License: Apache License 2.0 5 votes vote down vote up
protected void validateNamespace(final SqlValidatorNamespace namespace,
    RelDataType targetRowType) {
  // Only attempt to validate each namespace once. Otherwise if
  // validation fails, we may end up cycling.
  if (activeNamespaces.add(namespace)) {
    super.validateNamespace(namespace, targetRowType);
  } else {
    namespace.setType(emptyStructType);
  }
}
 
Example 5
Source Project: calcite   Source File: AbstractTypeCoercion.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Update inferred type for a SqlNode.
 */
protected void updateInferredType(SqlNode node, RelDataType type) {
  validator.setValidatedNodeType(node, type);
  final SqlValidatorNamespace namespace = validator.getNamespace(node);
  if (namespace != null) {
    namespace.setType(type);
  }
}
 
Example 6
Source Project: calcite   Source File: SqlCallBinding.java    License: Apache License 2.0 5 votes vote down vote up
@Override public RelDataType getOperandType(int ordinal) {
  final SqlNode operand = call.operand(ordinal);
  final RelDataType type = validator.deriveType(scope, operand);
  final SqlValidatorNamespace namespace = validator.getNamespace(operand);
  if (namespace != null) {
    return namespace.getType();
  }
  return type;
}
 
Example 7
Source Project: calcite   Source File: AbstractSqlTester.java    License: Apache License 2.0 5 votes vote down vote up
public void checkMonotonic(String query,
    SqlMonotonicity expectedMonotonicity) {
  SqlValidator validator = getValidator();
  SqlNode n = parseAndValidate(validator, query);
  final RelDataType rowType = validator.getValidatedNodeType(n);
  final SqlValidatorNamespace selectNamespace = validator.getNamespace(n);
  final String field0 = rowType.getFieldList().get(0).getName();
  final SqlMonotonicity monotonicity =
      selectNamespace.getMonotonicity(field0);
  assertThat(monotonicity, equalTo(expectedMonotonicity));
}