CalciteUtils { public static RelDataType toCalciteRowType(Schema schema, RelDataTypeFactory dataTypeFactory) { RelDataTypeFactory.Builder builder = new RelDataTypeFactory.Builder(dataTypeFactory); IntStream.range(0, schema.getFieldCount()) .forEach( idx -> builder.add( schema.getField(idx).getName(), toRelDataType(dataTypeFactory, schema, idx))); return builder.build(); }  static boolean isDateTimeType(FieldType fieldType); static boolean isStringType(FieldType fieldType); static Schema toSchema(RelDataType tableInfo); static SqlTypeName toSqlTypeName(FieldType type); static FieldType toFieldType(SqlTypeName sqlTypeName); static Schema.Field toField(RelDataTypeField calciteField); static Schema.Field toField(String name, RelDataType calciteType); static FieldType toFieldType(RelDataType calciteType); static RelDataType toCalciteRowType(Schema schema, RelDataTypeFactory dataTypeFactory); static RelDataType toRelDataType(RelDataTypeFactory dataTypeFactory, FieldType fieldType); static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory typeFactory, Type type); static final FieldType TINY_INT; static final FieldType SMALL_INT; static final FieldType INTEGER; static final FieldType BIG_INT; static final FieldType FLOAT; static final FieldType DOUBLE; static final FieldType DECIMAL; static final FieldType BOOLEAN; static final FieldType VARBINARY; static final FieldType VARCHAR; static final FieldType CHAR; static final FieldType DATE; static final FieldType NULLABLE_DATE; static final FieldType TIME; static final FieldType NULLABLE_TIME; static final FieldType TIME_WITH_LOCAL_TZ; static final FieldType TIMESTAMP; static final FieldType NULLABLE_TIMESTAMP; static final FieldType TIMESTAMP_WITH_LOCAL_TZ; static final FieldType NULLABLE_TIMESTAMP_WITH_LOCAL_TZ; }
@Test public void testToCalciteRowType() { final Schema schema = Schema.builder() .addField("f1", Schema.FieldType.BYTE) .addField("f2", Schema.FieldType.INT16) .addField("f3", Schema.FieldType.INT32) .addField("f4", Schema.FieldType.INT64) .addField("f5", Schema.FieldType.FLOAT) .addField("f6", Schema.FieldType.DOUBLE) .addField("f7", Schema.FieldType.DECIMAL) .addField("f8", Schema.FieldType.BOOLEAN) .addField("f9", Schema.FieldType.BYTES) .addField("f10", Schema.FieldType.STRING) .build(); final Map<String, RelDataType> fields = calciteRowTypeFields(schema); assertEquals(10, fields.size()); fields.values().forEach(x -> assertFalse(x.isNullable())); assertEquals(SqlTypeName.TINYINT, fields.get("f1").getSqlTypeName()); assertEquals(SqlTypeName.SMALLINT, fields.get("f2").getSqlTypeName()); assertEquals(SqlTypeName.INTEGER, fields.get("f3").getSqlTypeName()); assertEquals(SqlTypeName.BIGINT, fields.get("f4").getSqlTypeName()); assertEquals(SqlTypeName.FLOAT, fields.get("f5").getSqlTypeName()); assertEquals(SqlTypeName.DOUBLE, fields.get("f6").getSqlTypeName()); assertEquals(SqlTypeName.DECIMAL, fields.get("f7").getSqlTypeName()); assertEquals(SqlTypeName.BOOLEAN, fields.get("f8").getSqlTypeName()); assertEquals(SqlTypeName.VARBINARY, fields.get("f9").getSqlTypeName()); assertEquals(SqlTypeName.VARCHAR, fields.get("f10").getSqlTypeName()); }