本文整理汇总了Java中org.apache.calcite.rel.type.RelDataTypeFactory.createTypeWithNullability方法的典型用法代码示例。如果您正苦于以下问题:Java RelDataTypeFactory.createTypeWithNullability方法的具体用法?Java RelDataTypeFactory.createTypeWithNullability怎么用?Java RelDataTypeFactory.createTypeWithNullability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.rel.type.RelDataTypeFactory
的用法示例。
在下文中一共展示了RelDataTypeFactory.createTypeWithNullability方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getField
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
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 */
RelDataTypeField newField = new RelDataTypeFieldImpl(fieldName, fields.size(), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true));
/* Add the name to our list of field names */
fields.add(newField);
return newField;
}
示例2: createCalciteTypeWithNullability
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private RelDataType createCalciteTypeWithNullability(RelDataTypeFactory typeFactory,
SqlTypeName sqlTypeName,
boolean isNullable) {
RelDataType type;
if (sqlTypeName == SqlTypeName.INTERVAL_DAY_TIME) {
type = typeFactory.createSqlIntervalType(
new SqlIntervalQualifier(
TimeUnit.DAY,
TimeUnit.MINUTE,
SqlParserPos.ZERO));
} else if (sqlTypeName == SqlTypeName.INTERVAL_YEAR_MONTH) {
type = typeFactory.createSqlIntervalType(
new SqlIntervalQualifier(
TimeUnit.YEAR,
TimeUnit.MONTH,
SqlParserPos.ZERO));
} else if (sqlTypeName == SqlTypeName.VARCHAR) {
type = typeFactory.createSqlType(sqlTypeName, TypeHelper.VARCHAR_DEFAULT_CAST_LEN);
} else {
type = typeFactory.createSqlType(sqlTypeName);
}
return typeFactory.createTypeWithNullability(type, isNullable);
}
示例3: convertCall
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
final List<SqlNode> operands = call.getOperandList();
final List<RexNode> exprs = new LinkedList<>();
RelDataTypeFactory typeFactory = cx.getTypeFactory();
//RelDataType nullableReturnType =
for (SqlNode node: operands) {
exprs.add(cx.convertExpression(node));
}
// Determine NULL-able using 2nd argument's Null-able.
RelDataType returnType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable());
return rexBuilder.makeCall(returnType, call.getOperator(), exprs);
}
示例4: convertCall
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
final List<SqlNode> operands = call.getOperandList();
final List<RexNode> exprs = new LinkedList<>();
String timeUnit = ((SqlIntervalQualifier) operands.get(0)).timeUnitRange.toString();
RelDataTypeFactory typeFactory = cx.getTypeFactory();
//RelDataType nullableReturnType =
for (SqlNode node: operands) {
exprs.add(cx.convertExpression(node));
}
final RelDataType returnType
= typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable());
return rexBuilder.makeCall(returnType, call.getOperator(), exprs);
}
示例5: convertCall
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlLiteral literal = (SqlLiteral) call.getOperandList().get(0);
final String value = ((NlsString)literal.getValue()).getValue();
TimeUnitRange range = VALID_PERIODS.get(value.toLowerCase());
Preconditions.checkNotNull(range, "Unhandle range type: %s.", value);
List<RexNode> exprs = new ArrayList<>();
exprs.add(rexBuilder.makeFlag(range));
exprs.add(cx.convertExpression(call.getOperandList().get(1)));
RelDataTypeFactory typeFactory = cx.getTypeFactory();
final RelDataType returnType
= typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable());
return rexBuilder.makeCall(returnType, SqlStdOperatorTable.EXTRACT, exprs);
}
示例6: getReturnType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private static RelDataType getReturnType(final SqlOperatorBinding opBinding, final BaseFunctionHolder func) {
final RelDataTypeFactory factory = opBinding.getTypeFactory();
// least restrictive type (nullable ANY type)
final RelDataType nullableAnyType = factory.createTypeWithNullability(
factory.createSqlType(SqlTypeName.ANY),
true);
if(!func.isReturnTypeIndependent()){
return nullableAnyType;
}
CompleteType returnType = func.getReturnType(null);
if(returnType.isList() || returnType.isComplex() || returnType.isUnion() || returnType.isLate()){
return nullableAnyType;
}
final TypeProtos.MinorType minorType = returnType.toMinorType();
final SqlTypeName sqlTypeName = getCalciteTypeFromMinorType(minorType);
if (sqlTypeName == null) {
return nullableAnyType;
}
return createCalciteTypeWithNullability(factory, sqlTypeName, true);
}
示例7: inferReturnType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
final RelDataTypeFactory factory = opBinding.getTypeFactory();
boolean isNullable = true;
int precision = 0;
for(RelDataType relDataType : opBinding.collectOperandTypes()) {
if(!relDataType.isNullable()) {
isNullable = false;
}
// If the underlying columns cannot offer information regarding the precision (i.e., the length) of the VarChar,
// Dremio uses the largest to represent it
if(relDataType.getPrecision() == TypeHelper.VARCHAR_DEFAULT_CAST_LEN
|| relDataType.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
precision = TypeHelper.VARCHAR_DEFAULT_CAST_LEN;
} else {
precision += relDataType.getPrecision();
}
}
return factory.createTypeWithNullability(
factory.createSqlType(SqlTypeName.VARCHAR, precision),
isNullable);
}
示例8: inferReturnType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
final TimeUnit unit = (TimeUnit) opBinding.getOperandLiteralValue(0);
switch (unit) {
case HOUR:
case MINUTE:
case SECOND:
case MILLISECOND:
case MICROSECOND:
return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
opBinding.getOperandType(1).isNullable()
|| opBinding.getOperandType(2).isNullable());
default:
return opBinding.getOperandType(2);
}
}
示例9: inferReturnType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override public RelDataType
inferReturnType(SqlOperatorBinding opBinding) {
final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
final RelDataType leftType = opBinding.getOperandType(0);
final IntervalSqlType unitType =
(IntervalSqlType) opBinding.getOperandType(1);
switch (unitType.getIntervalQualifier().getStartUnit()) {
case HOUR:
case MINUTE:
case SECOND:
case MILLISECOND:
case MICROSECOND:
return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
leftType.isNullable() || unitType.isNullable());
default:
return leftType;
}
}
示例10: createCalciteTypeWithNullability
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
* Given a {@link SqlTypeName} and nullability, create a RelDataType from the RelDataTypeFactory
*
* @param typeFactory RelDataTypeFactory used to create the RelDataType
* @param sqlTypeName the given SqlTypeName
* @param isNullable the nullability of the created RelDataType
* @return RelDataType Type of call
*/
public static RelDataType createCalciteTypeWithNullability(RelDataTypeFactory typeFactory,
SqlTypeName sqlTypeName,
boolean isNullable) {
RelDataType type;
if (sqlTypeName == SqlTypeName.INTERVAL_DAY_TIME) {
type = typeFactory.createSqlIntervalType(
new SqlIntervalQualifier(
TimeUnit.DAY,
TimeUnit.MINUTE,
SqlParserPos.ZERO));
} else if (sqlTypeName == SqlTypeName.INTERVAL_YEAR_MONTH) {
type = typeFactory.createSqlIntervalType(
new SqlIntervalQualifier(
TimeUnit.YEAR,
TimeUnit.MONTH,
SqlParserPos.ZERO));
} else if (sqlTypeName == SqlTypeName.VARCHAR) {
type = typeFactory.createSqlType(sqlTypeName, Types.MAX_VARCHAR_LENGTH);
} else {
type = typeFactory.createSqlType(sqlTypeName);
}
return typeFactory.createTypeWithNullability(type, isNullable);
}
示例11: deriveSumType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Override
public RelDataType deriveSumType(RelDataTypeFactory typeFactory, RelDataType argumentType) {
if (argumentType instanceof BasicSqlType) {
switch (argumentType.getSqlTypeName()) {
case INTEGER:
case SMALLINT:
case TINYINT:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
argumentType.isNullable());
case DECIMAL:
return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.DECIMAL, 19, argumentType.getScale()),
argumentType.isNullable());
default:
break;
}
}
return argumentType;
}
示例12: makeNullableIfOperandsAre
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
* 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;
}
示例13: getReturnType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public RelDataType getReturnType(RelDataTypeFactory typeFactory,
SqlOperatorBinding opBinding) {
// Strict and semi-strict functions can return null even if their Java
// functions return a primitive type. Because when one of their arguments
// is null, they won't even be called.
final RelDataType returnType = getReturnType(typeFactory);
switch (getNullPolicy(method)) {
case STRICT:
for (RelDataType type : opBinding.collectOperandTypes()) {
if (type.isNullable()) {
return typeFactory.createTypeWithNullability(returnType, true);
}
}
break;
case SEMI_STRICT:
return typeFactory.createTypeWithNullability(returnType, true);
}
return returnType;
}
示例14: toSql
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/** Converts a type in Java format to a SQL-oriented type. */
public static RelDataType toSql(final RelDataTypeFactory typeFactory,
RelDataType type) {
if (type instanceof RelRecordType) {
return typeFactory.createStructType(
Lists.transform(type.getFieldList(),
new Function<RelDataTypeField, RelDataType>() {
public RelDataType apply(RelDataTypeField a0) {
return toSql(typeFactory, a0.getType());
}
}),
type.getFieldNames());
}
if (type instanceof JavaType) {
return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(type.getSqlTypeName()),
type.isNullable());
}
return type;
}
示例15: makeNullableIfOperandsAre
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
* 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;
}