Java Code Examples for org.apache.calcite.sql.type.SqlTypeName#ARRAY
The following examples show how to use
org.apache.calcite.sql.type.SqlTypeName#ARRAY .
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: PojoTypeConverter.java From marble with Apache License 2.0 | 5 votes |
public SqlTypeName getSqlType(Class clazz) { SqlTypeName typeName = BASIC_TYPES.get(clazz); if (typeName == null) { if (clazz.isArray() || Collection.class.isAssignableFrom(clazz)) { typeName = SqlTypeName.ARRAY; } } if (typeName == null) { throw new IllegalArgumentException( "can't resolve sql type for class:" + clazz); } return typeName; }
Example 2
Source File: OLAPTable.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public static RelDataType createSqlType(RelDataTypeFactory typeFactory, DataType dataType, boolean isNullable) { SqlTypeName sqlTypeName = SQLTYPE_MAPPING.get(dataType.getName()); if (sqlTypeName == null) { for (String reg : REGEX_SQLTYPE_MAPPING.keySet()) { Pattern pattern = Pattern.compile(reg); if (pattern.matcher(dataType.getName()).matches()) { sqlTypeName = REGEX_SQLTYPE_MAPPING.get(reg); break; } } } if (sqlTypeName == null) throw new IllegalArgumentException("Unrecognized data type " + dataType); int precision = dataType.getPrecision(); int scale = dataType.getScale(); RelDataType result; if (sqlTypeName == SqlTypeName.ARRAY) { String innerTypeName = dataType.getName().split("<|>")[1]; result = typeFactory.createArrayType(createSqlType(typeFactory, DataType.getType(innerTypeName), false), -1); } else if (precision >= 0 && scale >= 0) result = typeFactory.createSqlType(sqlTypeName, precision, scale); else if (precision >= 0) result = typeFactory.createSqlType(sqlTypeName, precision); else result = typeFactory.createSqlType(sqlTypeName); // due to left join and uncertain data quality, dimension value can be null if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; }
Example 3
Source File: Checker.java From samza with Apache License 2.0 | 5 votes |
/** * Converts the {@link SamzaSqlFieldType} to the calcite {@link SqlTypeName}. * @param samzaSqlFieldType the samza sql field type. * @return the converted calcite SqlTypeName. */ @VisibleForTesting static SqlTypeName toCalciteSqlType(SamzaSqlFieldType samzaSqlFieldType) { switch (samzaSqlFieldType) { case ANY: case ROW: return SqlTypeName.ANY; case MAP: return SqlTypeName.MAP; case ARRAY: return SqlTypeName.ARRAY; case REAL: return SqlTypeName.REAL; case DOUBLE: return SqlTypeName.DOUBLE; case STRING: return SqlTypeName.VARCHAR; case INT16: case INT32: return SqlTypeName.INTEGER; case FLOAT: return SqlTypeName.FLOAT; case INT64: return SqlTypeName.BIGINT; case BOOLEAN: return SqlTypeName.BOOLEAN; case BYTES: return SqlTypeName.VARBINARY; default: String msg = String.format("Field Type %s is not supported", samzaSqlFieldType); LOG.error(msg); throw new SamzaException(msg); } }
Example 4
Source File: OLAPTable.java From kylin with Apache License 2.0 | 5 votes |
public static RelDataType createSqlType(RelDataTypeFactory typeFactory, DataType dataType, boolean isNullable) { SqlTypeName sqlTypeName = SQLTYPE_MAPPING.get(dataType.getName()); if (sqlTypeName == null) { for (String reg : REGEX_SQLTYPE_MAPPING.keySet()) { Pattern pattern = Pattern.compile(reg); if (pattern.matcher(dataType.getName()).matches()) { sqlTypeName = REGEX_SQLTYPE_MAPPING.get(reg); break; } } } if (sqlTypeName == null) throw new IllegalArgumentException("Unrecognized data type " + dataType); int precision = dataType.getPrecision(); int scale = dataType.getScale(); RelDataType result; if (sqlTypeName == SqlTypeName.ARRAY) { String innerTypeName = dataType.getName().split("<|>")[1]; result = typeFactory.createArrayType(createSqlType(typeFactory, DataType.getType(innerTypeName), false), -1); } else if (precision >= 0 && scale >= 0) result = typeFactory.createSqlType(sqlTypeName, precision, scale); else if (precision >= 0) result = typeFactory.createSqlType(sqlTypeName, precision); else result = typeFactory.createSqlType(sqlTypeName); // due to left join and uncertain data quality, dimension value can be null if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; }