org.apache.calcite.rel.type.DynamicRecordType Java Examples
The following examples show how to use
org.apache.calcite.rel.type.DynamicRecordType.
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: SqlIdentifier.java From Bats with Apache License 2.0 | 6 votes |
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) { // for "star" column, whether it's static or dynamic return not_monotonic directly. if (Util.last(names).equals("") || DynamicRecordType.isDynamicStarColName(Util.last(names))) { return SqlMonotonicity.NOT_MONOTONIC; } // First check for builtin functions which don't have parentheses, // like "LOCALTIME". final SqlValidator validator = scope.getValidator(); SqlCall call = SqlUtil.makeCall( validator.getOperatorTable(), this); if (call != null) { return call.getMonotonicity(scope); } final SqlQualified qualified = scope.fullyQualify(this); final SqlIdentifier fqId = qualified.identifier; return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names)); }
Example #2
Source File: DelegatingScope.java From Bats with Apache License 2.0 | 6 votes |
/** Returns whether {@code rowType} contains more than one star column. * Having more than one star columns implies ambiguous column. */ private boolean hasAmbiguousUnresolvedStar(RelDataType rowType, RelDataTypeField field, String columnName) { if (field.isDynamicStar() && !DynamicRecordType.isDynamicStarColName(columnName)) { int count = 0; for (RelDataTypeField possibleStar : rowType.getFieldList()) { if (possibleStar.isDynamicStar()) { if (++count > 1) { return true; } } } } return false; }
Example #3
Source File: RelDataTypeHolder.java From Bats with Apache License 2.0 | 6 votes |
public RelDataTypeField getField(RelDataTypeFactory typeFactory, String fieldName) { /* First check if this field name exists in our field list */ for (RelDataTypeField f : fields) { if (fieldName.equalsIgnoreCase(f.getName())) { return f; } } /* This field does not exist in our field list add it */ final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName) ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY; // This field does not exist in our field list add it RelDataTypeField newField = new RelDataTypeFieldImpl( fieldName, fields.size(), typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true)); /* Add the name to our list of field names */ fields.add(newField); return newField; }
Example #4
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 6 votes |
protected SqlNode expandDynamicStar(SqlIdentifier id, SqlIdentifier fqId) { if (DynamicRecordType.isDynamicStarColName(Util.last(fqId.names)) && !DynamicRecordType.isDynamicStarColName(Util.last(id.names))) { // Convert a column ref into ITEM(*, 'col_name') // for a dynamic star field in dynTable's rowType. SqlNode[] inputs = new SqlNode[2]; inputs[0] = fqId; inputs[1] = SqlLiteral.createCharString( Util.last(id.names), id.getParserPosition()); return new SqlBasicCall( SqlStdOperatorTable.ITEM, inputs, id.getParserPosition()); } return fqId; }
Example #5
Source File: SqlIdentifier.java From calcite with Apache License 2.0 | 6 votes |
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) { // for "star" column, whether it's static or dynamic return not_monotonic directly. if (Util.last(names).equals("") || DynamicRecordType.isDynamicStarColName(Util.last(names))) { return SqlMonotonicity.NOT_MONOTONIC; } // First check for builtin functions which don't have parentheses, // like "LOCALTIME". final SqlValidator validator = scope.getValidator(); final SqlCall call = validator.makeNullaryCall(this); if (call != null) { return call.getMonotonicity(scope); } final SqlQualified qualified = scope.fullyQualify(this); final SqlIdentifier fqId = qualified.identifier; return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names)); }
Example #6
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public SqlNode visit(SqlIdentifier id) { // First check for builtin functions which don't have // parentheses, like "LOCALTIME". SqlCall call = SqlUtil.makeCall( validator.getOperatorTable(), id); if (call != null) { return call.accept(this); } final SqlIdentifier fqId = getScope().fullyQualify(id).identifier; SqlNode expandedExpr = fqId; // Convert a column ref into ITEM(*, 'col_name'). // select col_name from (select * from dynTable) // SqlIdentifier "col_name" would be resolved to a dynamic star field in dynTable's rowType. // Expand such SqlIdentifier to ITEM operator. if (DynamicRecordType.isDynamicStarColName(Util.last(fqId.names)) && !DynamicRecordType.isDynamicStarColName(Util.last(id.names))) { SqlNode[] inputs = new SqlNode[2]; inputs[0] = fqId; inputs[1] = SqlLiteral.createCharString( Util.last(id.names), id.getParserPosition()); SqlBasicCall item_call = new SqlBasicCall( SqlStdOperatorTable.ITEM, inputs, id.getParserPosition()); expandedExpr = item_call; } validator.setOriginal(expandedExpr, id); return expandedExpr; }
Example #7
Source File: AbstractTypeCoercion.java From calcite with Apache License 2.0 | 4 votes |
/** * Cast column at index {@code index} to target type. * * @param scope Validator scope for the node list * @param nodeList Column node list * @param index Index of column * @param targetType Target type to cast to */ protected boolean coerceColumnType( SqlValidatorScope scope, SqlNodeList nodeList, int index, RelDataType targetType) { // Transform the JavaType to SQL type because the SqlDataTypeSpec // does not support deriving JavaType yet. if (RelDataTypeFactoryImpl.isJavaType(targetType)) { targetType = ((JavaTypeFactory) factory).toSql(targetType); } // This will happen when there is a star/dynamic-star column in the select list, // and the source is values expression, i.e. `select * from (values(1, 2, 3))`. // There is no need to coerce the column type, only remark // the inferred row type has changed, we will then add in type coercion // when expanding star/dynamic-star. // See SqlToRelConverter#convertSelectList for details. if (index >= nodeList.getList().size()) { // Can only happen when there is a star(*) in the column, // just return true. return true; } final SqlNode node = nodeList.get(index); if (node instanceof SqlDynamicParam) { // Do not support implicit type coercion for dynamic param. return false; } if (node instanceof SqlIdentifier) { // Do not expand a star/dynamic table col. SqlIdentifier node1 = (SqlIdentifier) node; if (node1.isStar()) { return true; } else if (DynamicRecordType.isDynamicStarColName(Util.last(node1.names))) { // Should support implicit cast for dynamic table. return false; } } if (node instanceof SqlCall) { SqlCall node2 = (SqlCall) node; if (node2.getOperator().kind == SqlKind.AS) { final SqlNode operand = node2.operand(0); if (!needToCast(scope, operand, targetType)) { return false; } RelDataType targetType2 = syncAttributes(validator.deriveType(scope, operand), targetType); final SqlNode casted = castTo(operand, targetType2); node2.setOperand(0, casted); updateInferredType(casted, targetType2); return true; } } if (!needToCast(scope, node, targetType)) { return false; } RelDataType targetType3 = syncAttributes(validator.deriveType(scope, node), targetType); final SqlNode node3 = castTo(node, targetType3); nodeList.set(index, node3); updateInferredType(node3, targetType3); return true; }