Java Code Examples for org.apache.calcite.rel.type.RelDataTypeFactory#createSqlIntervalType()
The following examples show how to use
org.apache.calcite.rel.type.RelDataTypeFactory#createSqlIntervalType() .
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: TypeInferenceUtils.java From Bats with Apache License 2.0 | 6 votes |
/** * 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.getFamily() == SqlTypeFamily.INTERVAL_DAY_TIME) { type = typeFactory.createSqlIntervalType( new SqlIntervalQualifier( TimeUnit.DAY, TimeUnit.MINUTE, SqlParserPos.ZERO)); } else if (sqlTypeName.getFamily() == SqlTypeFamily.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); }
Example 2
Source File: View.java From Bats with Apache License 2.0 | 5 votes |
private RelDataType getType(Field field, RelDataTypeFactory factory) { RelDataType type; final SqlTypeName typeName = field.getType(); final Integer precision = field.getPrecision(); final Integer scale = field.getScale(); if (field.isInterval()) { type = factory.createSqlIntervalType(field.getIntervalQualifier()); } else if (precision != null) { type = scale != null ? factory.createSqlType(typeName, precision, scale) : factory.createSqlType(typeName, precision); } else if (typeName == SqlTypeName.MAP) { if (field.isMapTypesPresent()) { type = factory.createMapType(getType(field.getKeyType(), factory), getType(field.getValueType(), factory)); } else { /* For older views that doesn't have info about map key and value types, chosen type is ANY. Because use of raw MAP type causes creation of MAP cast expression that can't be serialized by ExpressionStringBuilder's visitCastExpression(CastExpression e, StringBuilder sb) method. See DRILL-6944 for more details. */ type = factory.createSqlType(SqlTypeName.ANY); } } else { type = factory.createSqlType(field.getType()); } return field.getIsNullable() ? factory.createTypeWithNullability(type, true) : type; }
Example 3
Source File: View.java From dremio-oss with Apache License 2.0 | 5 votes |
public RelDataType getRowType(RelDataTypeFactory factory) { List<RelDataType> types = Lists.newArrayList(); List<String> names = Lists.newArrayList(); for (FieldType field : fields) { names.add(field.getName()); RelDataType type; if ( SqlTypeFamily.INTERVAL_YEAR_MONTH == field.getType().getFamily() || SqlTypeFamily.INTERVAL_DAY_TIME == field.getType().getFamily() ) { type = factory.createSqlIntervalType( field.getIntervalQualifier() ); } else if (field.getType().equals(SqlTypeName.ARRAY) || field.getType().equals(SqlTypeName.MAP)) { type = factory.createSqlType(SqlTypeName.ANY); } else if (field.getPrecision() == null && field.getScale() == null) { type = factory.createSqlType(field.getType()); } else if (field.getPrecision() != null && field.getScale() == null) { type = factory.createSqlType(field.getType(), field.getPrecision()); } else { type = factory.createSqlType(field.getType(), field.getPrecision(), field.getScale()); } if (field.getIsNullable()) { types.add(factory.createTypeWithNullability(type, true)); } else { types.add(type); } } return factory.createStructType(types, names); }
Example 4
Source File: TypeInferenceUtils.java From dremio-oss with Apache License 2.0 | 4 votes |
/** * 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 * @param precision precision, null if the type does not support precision, or to fallback to default precision * @return RelDataType Type of call */ public static RelDataType createCalciteTypeWithNullability(RelDataTypeFactory typeFactory, SqlTypeName sqlTypeName, boolean isNullable, Integer precision) { RelDataType type; switch (sqlTypeName) { case TIMESTAMP: type = precision == null ? typeFactory.createSqlType(sqlTypeName) : typeFactory.createSqlType(sqlTypeName, precision); break; case INTERVAL_YEAR: case INTERVAL_YEAR_MONTH: case INTERVAL_MONTH: type = typeFactory.createSqlIntervalType( new SqlIntervalQualifier( TimeUnit.YEAR, TimeUnit.MONTH, SqlParserPos.ZERO)); break; case INTERVAL_DAY: case INTERVAL_DAY_HOUR: case INTERVAL_DAY_MINUTE: case INTERVAL_DAY_SECOND: case INTERVAL_HOUR: case INTERVAL_HOUR_MINUTE: case INTERVAL_HOUR_SECOND: case INTERVAL_MINUTE: case INTERVAL_MINUTE_SECOND: case INTERVAL_SECOND: type = typeFactory.createSqlIntervalType( new SqlIntervalQualifier( TimeUnit.DAY, TimeUnit.MINUTE, SqlParserPos.ZERO)); break; case VARCHAR: type = typeFactory.createSqlType(sqlTypeName, TypeHelper.VARCHAR_DEFAULT_CAST_LEN); default: type = typeFactory.createSqlType(sqlTypeName); } return typeFactory.createTypeWithNullability(type, isNullable); }