Java Code Examples for org.apache.calcite.sql.validate.SqlValidator#getTypeFactory()
The following examples show how to use
org.apache.calcite.sql.validate.SqlValidator#getTypeFactory() .
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: SqlDataTypeSpec.java From Bats with Apache License 2.0 | 6 votes |
/** * Throws an error if the type is not found. */ public RelDataType deriveType(SqlValidator validator) { RelDataType type = null; if (typeName.isSimple()) { if (null != collectionsTypeName) { final String collectionName = collectionsTypeName.getSimple(); if (SqlTypeName.get(collectionName) == null) { throw validator.newValidationError(this, RESOURCE.unknownDatatypeName(collectionName)); } } RelDataTypeFactory typeFactory = validator.getTypeFactory(); type = deriveType(typeFactory); } if (type == null) { type = validator.getValidatedNodeType(typeName); } return type; }
Example 2
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 6 votes |
/** * Recreates a given RelDataType with nullability iff any of the operands * of a call are nullable. */ public static RelDataType makeNullableIfOperandsAre( final SqlValidator validator, final SqlValidatorScope scope, final SqlCall call, RelDataType type) { for (SqlNode operand : call.getOperandList()) { RelDataType operandType = validator.deriveType(scope, operand); if (containsNullable(operandType)) { RelDataTypeFactory typeFactory = validator.getTypeFactory(); type = typeFactory.createTypeWithNullability(type, true); break; } } return type; }
Example 3
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Recreates a given RelDataType with nullability iff any of the operands * of a call are nullable. */ public static RelDataType makeNullableIfOperandsAre( final SqlValidator validator, final SqlValidatorScope scope, final SqlCall call, RelDataType type) { for (SqlNode operand : call.getOperandList()) { RelDataType operandType = validator.deriveType(scope, operand); if (containsNullable(operandType)) { RelDataTypeFactory typeFactory = validator.getTypeFactory(); type = typeFactory.createTypeWithNullability(type, true); break; } } return type; }
Example 4
Source File: SqlCallBinding.java From Bats with Apache License 2.0 | 5 votes |
/** * Creates a call binding. * * @param validator Validator * @param scope Scope of call * @param call Call node */ public SqlCallBinding( SqlValidator validator, SqlValidatorScope scope, SqlCall call) { super( validator.getTypeFactory(), call.getOperator()); this.validator = validator; this.scope = scope; this.call = call; }
Example 5
Source File: SqlOperator.java From Bats with Apache License 2.0 | 5 votes |
protected List<RelDataType> constructArgTypeList( SqlValidator validator, SqlValidatorScope scope, SqlCall call, List<SqlNode> args, boolean convertRowArgToColumnList) { // Scope for operands. Usually the same as 'scope'. final SqlValidatorScope operandScope = scope.getOperandScope(call); final ImmutableList.Builder<RelDataType> argTypeBuilder = ImmutableList.builder(); for (SqlNode operand : args) { RelDataType nodeType; // for row arguments that should be converted to ColumnList // types, set the nodeType to a ColumnList type but defer // validating the arguments of the row constructor until we know // for sure that the row argument maps to a ColumnList type if (operand.getKind() == SqlKind.ROW && convertRowArgToColumnList) { RelDataTypeFactory typeFactory = validator.getTypeFactory(); nodeType = typeFactory.createSqlType(SqlTypeName.COLUMN_LIST); ((SqlValidatorImpl) validator).setValidatedNodeType(operand, nodeType); } else { nodeType = validator.deriveType(operandScope, operand); } argTypeBuilder.add(nodeType); } return argTypeBuilder.build(); }
Example 6
Source File: CalciteResult.java From Bats with Apache License 2.0 | 5 votes |
public ParseResult(SqlValidator validator, String sql, SqlNode sqlNode, RelDataType rowType) { super(); this.sql = sql; this.sqlNode = sqlNode; this.rowType = rowType; this.typeFactory = validator.getTypeFactory(); }
Example 7
Source File: ExtendedSqlRowTypeNameSpec.java From flink with Apache License 2.0 | 5 votes |
@Override public RelDataType deriveType(SqlValidator sqlValidator) { final RelDataTypeFactory typeFactory = sqlValidator.getTypeFactory(); return typeFactory.createStructType( fieldTypes.stream() .map(dt -> dt.deriveType(sqlValidator)) .collect(Collectors.toList()), fieldNames.stream() .map(SqlIdentifier::toString) .collect(Collectors.toList())); }
Example 8
Source File: CalcitePrepare.java From calcite with Apache License 2.0 | 5 votes |
public ParseResult(CalcitePrepareImpl prepare, SqlValidator validator, String sql, SqlNode sqlNode, RelDataType rowType) { super(); this.prepare = prepare; this.sql = sql; this.sqlNode = sqlNode; this.rowType = rowType; this.typeFactory = validator.getTypeFactory(); }
Example 9
Source File: SqlCallBinding.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a call binding. * * @param validator Validator * @param scope Scope of call * @param call Call node */ public SqlCallBinding( SqlValidator validator, SqlValidatorScope scope, SqlCall call) { super( validator.getTypeFactory(), call.getOperator()); this.validator = validator; this.scope = scope; this.call = call; }
Example 10
Source File: SqlDataTypeSpec.java From calcite with Apache License 2.0 | 5 votes |
/** * Converts this type specification to a {@link RelDataType}. * * <p>Throws an error if the type is not found. * * @param nullable Whether the type is nullable if the type specification * does not explicitly state */ public RelDataType deriveType(SqlValidator validator, boolean nullable) { RelDataType type; type = typeNameSpec.deriveType(validator); // Fix-up the nullability, default is false. final RelDataTypeFactory typeFactory = validator.getTypeFactory(); type = fixUpNullability(typeFactory, type, nullable); return type; }
Example 11
Source File: SqlOperator.java From calcite with Apache License 2.0 | 5 votes |
protected List<RelDataType> constructArgTypeList( SqlValidator validator, SqlValidatorScope scope, SqlCall call, List<SqlNode> args, boolean convertRowArgToColumnList) { // Scope for operands. Usually the same as 'scope'. final SqlValidatorScope operandScope = scope.getOperandScope(call); final ImmutableList.Builder<RelDataType> argTypeBuilder = ImmutableList.builder(); for (SqlNode operand : args) { RelDataType nodeType; // for row arguments that should be converted to ColumnList // types, set the nodeType to a ColumnList type but defer // validating the arguments of the row constructor until we know // for sure that the row argument maps to a ColumnList type if (operand.getKind() == SqlKind.ROW && convertRowArgToColumnList) { RelDataTypeFactory typeFactory = validator.getTypeFactory(); nodeType = typeFactory.createSqlType(SqlTypeName.COLUMN_LIST); ((SqlValidatorImpl) validator).setValidatedNodeType(operand, nodeType); } else { nodeType = validator.deriveType(operandScope, operand); } argTypeBuilder.add(nodeType); } return argTypeBuilder.build(); }
Example 12
Source File: SqlRowTypeNameSpec.java From calcite with Apache License 2.0 | 5 votes |
@Override public RelDataType deriveType(SqlValidator sqlValidator) { final RelDataTypeFactory typeFactory = sqlValidator.getTypeFactory(); return typeFactory.createStructType( fieldTypes.stream() .map(dt -> dt.deriveType(sqlValidator)) .collect(Collectors.toList()), fieldNames.stream() .map(SqlIdentifier::toString) .collect(Collectors.toList())); }
Example 13
Source File: SqlSequenceValueOperator.java From Bats with Apache License 2.0 | 4 votes |
@Override public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { final RelDataTypeFactory typeFactory = validator.getTypeFactory(); return typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.BIGINT), false); }
Example 14
Source File: HiveUDFOperatorWithoutInference.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { RelDataTypeFactory factory = validator.getTypeFactory(); return factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.ANY), true); }
Example 15
Source File: SqlSequenceValueOperator.java From calcite with Apache License 2.0 | 4 votes |
@Override public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { final RelDataTypeFactory typeFactory = validator.getTypeFactory(); return typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.BIGINT), false); }