@Test public void testCreateSqlType() { RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); DataType kylinDataType = DataType.getType("array<string>"); RelDataType relDataType = OLAPTable.createSqlType(typeFactory, kylinDataType, true); Assert.assertTrue(relDataType instanceof ArraySqlType); Assert.assertEquals(SqlTypeName.ARRAY, relDataType.getSqlTypeName()); Assert.assertTrue(relDataType.getComponentType() instanceof BasicSqlType); Assert.assertEquals(SqlTypeName.VARCHAR, relDataType.getComponentType().getSqlTypeName()); Assert.assertTrue(relDataType.isNullable()); kylinDataType = DataType.getType("array<>"); boolean catchedEx = false; try { OLAPTable.createSqlType(typeFactory, kylinDataType, true); } catch (IllegalArgumentException ex) { Assert.assertEquals("Unrecognized data type array<>", ex.getMessage()); catchedEx = true; } Assert.assertTrue(catchedEx); kylinDataType = DataType.getType("array<AAA>"); catchedEx = false; try { OLAPTable.createSqlType(typeFactory, kylinDataType, true); } catch (IllegalArgumentException ex) { Assert.assertTrue(ex.getMessage().startsWith("bad data type -- aaa")); catchedEx = true; } Assert.assertTrue(catchedEx); }
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); if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; }
OLAPTable extends AbstractQueryableTable implements TranslatableTable { 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); if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; } }
OLAPTable extends AbstractQueryableTable implements TranslatableTable { 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); if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; } OLAPTable(OLAPSchema schema, TableDesc tableDesc, boolean exposeMore); }
OLAPTable extends AbstractQueryableTable implements TranslatableTable { 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); if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; } OLAPTable(OLAPSchema schema, TableDesc tableDesc, boolean exposeMore); OLAPSchema getSchema(); TableDesc getSourceTable(); String getTableName(); List<ColumnDesc> getSourceColumns(); @Override RelDataType getRowType(RelDataTypeFactory typeFactory); static RelDataType createSqlType(RelDataTypeFactory typeFactory, DataType dataType, boolean isNullable); @Override RelNode toRel(ToRelContext context, RelOptTable relOptTable); @Override Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName); @Override Statistic getStatistic(); @Override String toString(); Enumerable<Object[]> executeOLAPQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeLookupTableQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeColumnDictionaryQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeHiveQuery(DataContext optiqContext, int ctxSeq); }
OLAPTable extends AbstractQueryableTable implements TranslatableTable { 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); if (isNullable) { result = typeFactory.createTypeWithNullability(result, true); } else { result = typeFactory.createTypeWithNullability(result, false); } return result; } OLAPTable(OLAPSchema schema, TableDesc tableDesc, boolean exposeMore); OLAPSchema getSchema(); TableDesc getSourceTable(); String getTableName(); List<ColumnDesc> getSourceColumns(); @Override RelDataType getRowType(RelDataTypeFactory typeFactory); static RelDataType createSqlType(RelDataTypeFactory typeFactory, DataType dataType, boolean isNullable); @Override RelNode toRel(ToRelContext context, RelOptTable relOptTable); @Override Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, String tableName); @Override Statistic getStatistic(); @Override String toString(); Enumerable<Object[]> executeOLAPQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeLookupTableQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeColumnDictionaryQuery(DataContext optiqContext, int ctxSeq); Enumerable<Object[]> executeHiveQuery(DataContext optiqContext, int ctxSeq); static final Map<SqlTypeName, String> DATATYPE_MAPPING; }