本文整理汇总了Java中org.apache.calcite.rel.type.RelDataTypeFactory类的典型用法代码示例。如果您正苦于以下问题:Java RelDataTypeFactory类的具体用法?Java RelDataTypeFactory怎么用?Java RelDataTypeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RelDataTypeFactory类属于org.apache.calcite.rel.type包,在下文中一共展示了RelDataTypeFactory类的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: getRowType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
/**
* This method constructs a {@link org.apache.calcite.rel.type.RelDataType} based on the
* {@link org.apache.drill.exec.store.RecordDataType}'s field sql types and field names.
*
* @param factory helps construct a {@link org.apache.calcite.rel.type.RelDataType}
* @return the constructed type
*/
public final RelDataType getRowType(RelDataTypeFactory factory) {
final List<SqlTypeName> types = getFieldSqlTypeNames();
final List<String> names = getFieldNames();
final List<RelDataType> fields = Lists.newArrayList();
for (final SqlTypeName typeName : types) {
switch (typeName) {
case VARCHAR:
fields.add(factory.createSqlType(typeName, Integer.MAX_VALUE));
break;
default:
fields.add(factory.createSqlType(typeName));
}
}
return factory.createStructType(fields, names);
}
示例5: getRowType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
List<RelDataType> typeList = Lists.newArrayList();
List<String> fieldNameList = Lists.newArrayList();
List<FieldSchema> hiveFields = hiveTable.getCols();
for(FieldSchema hiveField : hiveFields) {
fieldNameList.add(hiveField.getName());
typeList.add(getNullableRelDataTypeFromHiveType(
typeFactory, TypeInfoUtils.getTypeInfoFromTypeString(hiveField.getType())));
}
for (FieldSchema field : hiveTable.getPartitionKeys()) {
fieldNameList.add(field.getName());
typeList.add(getNullableRelDataTypeFromHiveType(
typeFactory, TypeInfoUtils.getTypeInfoFromTypeString(field.getType())));
}
return typeFactory.createStructType(typeList, fieldNameList);
}
示例6: toCalciteType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
public RelDataType toCalciteType(RelDataTypeFactory typeFactory) {
final MinorType type = toMinorType();
if (isList()) {
// RelDataType childType = convertFieldToRelDataType(field.getChildren().iterator().next(), typeFactory);
// return typeFactory.createArrayType(childType, -1);
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true);
}
if (isStruct()) {
// return convertFieldsToStruct(field.getChildren(), typeFactory);
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true);
}
final SqlTypeName sqlTypeName = getCalciteTypeFromMinorType(type);
if(isVariableWidthScalar()){
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName, 1 << 16), true);
}
if(isDecimal()){
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName, getPrecision(), getScale()), true);
}
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName), true);
}
示例7: deriveSumType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
@Override
public RelDataType deriveSumType(
RelDataTypeFactory typeFactory, RelDataType argumentType) {
SqlTypeName sqlTypeName = argumentType.getSqlTypeName();
switch (sqlTypeName) {
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), argumentType.isNullable());
case FLOAT:
case DOUBLE:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE), argumentType.isNullable());
}
return argumentType;
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: setProjectedRowType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
private void setProjectedRowType(List<SchemaPath> projectedColumns){
if(projectedColumns != null){
LinkedHashSet<String> firstLevelPaths = new LinkedHashSet<>();
for(SchemaPath p : projectedColumns){
firstLevelPaths.add(p.getRootSegment().getNameSegment().getPath());
}
final RelDataTypeFactory factory = getCluster().getTypeFactory();
final FieldInfoBuilder builder = new FieldInfoBuilder(factory);
final Map<String, RelDataType> fields = new HashMap<>();
for(Field field : getBatchSchema()){
if(firstLevelPaths.contains(field.getName())){
fields.put(field.getName(), CompleteType.fromField(field).toCalciteType(factory));
}
}
Preconditions.checkArgument(firstLevelPaths.size() == fields.size(), "Projected column base size %d is not equal to outcome rowtype %d.", firstLevelPaths.size(), fields.size());
for(String path : firstLevelPaths){
builder.add(path, fields.get(path));
}
this.rowType = builder.build();
} else {
this.rowType = deriveRowType();
}
}
示例13: getRowType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
/**
* This method constructs a {@link org.apache.calcite.rel.type.RelDataType} based on the
* {@link com.dremio.exec.store.RecordDataType}'s field sql types and field names.
*
* @param factory helps construct a {@link org.apache.calcite.rel.type.RelDataType}
* @return the constructed type
*/
public final RelDataType getRowType(RelDataTypeFactory factory) {
final List<SqlTypeName> types = getFieldSqlTypeNames();
final List<String> names = getFieldNames();
final List<RelDataType> fields = Lists.newArrayList();
for (final SqlTypeName typeName : types) {
switch (typeName) {
case VARCHAR:
fields.add(factory.createSqlType(typeName, Integer.MAX_VALUE));
break;
default:
fields.add(factory.createSqlType(typeName));
}
}
return factory.createStructType(fields, names);
}
示例14: convertTypeNotNull
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
private static RelDataType convertTypeNotNull(int type,
RelDataTypeFactory typeFactory) {
switch (type) {
case ColumnTypes.BOOLEAN:
return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
case ColumnTypes.INTEGER:
return typeFactory.createSqlType(SqlTypeName.INTEGER);
case ColumnTypes.STRING:
return typeFactory.createSqlType(SqlTypeName.VARCHAR);
case ColumnTypes.BYTEARRAY:
return typeFactory.createSqlType(SqlTypeName.VARBINARY);
case ColumnTypes.LONG:
return typeFactory.createSqlType(SqlTypeName.BIGINT);
case ColumnTypes.TIMESTAMP:
return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
default:
return typeFactory.createSqlType(SqlTypeName.ANY);
}
}
示例15: getRowType
import org.apache.calcite.rel.type.RelDataTypeFactory; //导入依赖的package包/类
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
RelDataType type = super.getRowType(typeFactory);
// force add the star field, this is a dynamic row
type.getFieldCount();
// add the sort/partition keys that the mapper should produce
if (key != null) {
for (String field : key.getKeyNames()) {
type.getField(field, true, false);
}
}
// since we don't support pushing the key combination into the filter building, we need to
// support the key schema elements in our key schema so hash/sort can be used in the filter.
List<KeySchemaElement> keys = desc.getKeySchema();
for (KeySchemaElement elem : keys) {
type.getField(elem.getAttributeName(), true, false);
}
return type;
}