public PhysType project(List<Integer> integers, JavaRowFormat format) { RelDataType projectedRowType = typeFactory.createStructType( Lists.transform(integers, new Function<Integer, RelDataTypeField>() { public RelDataTypeField apply(Integer index) { return rowType.getFieldList().get(index); } })); return of(typeFactory, projectedRowType, format.optimize(projectedRowType)); }
private RelDataType getRelDataType( Connection connection, String catalogName, String schemaName, String tableName) throws SQLException { DatabaseMetaData metaData = connection.getMetaData(); final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null); final RelDataTypeFactory.FieldInfoBuilder fieldInfo = new RelDataTypeFactory.FieldInfoBuilder(); while (resultSet.next()) { final String columnName = resultSet.getString(4); final int dataType = resultSet.getInt(5); final int size = resultSet.getInt(7); final int scale = resultSet.getInt(9); RelDataType sqlType = zzz(dataType, size, scale); boolean nullable = resultSet.getBoolean(11); if (nullable) { sqlType = typeFactory.createTypeWithNullability(sqlType, true); } fieldInfo.add(columnName, sqlType); } resultSet.close(); return typeFactory.createStructType(fieldInfo); }
public PhysType project( final List<Integer> integers, JavaRowFormat format) { RelDataType projectedRowType = typeFactory.createStructType( new AbstractList<Map.Entry<String, RelDataType>>() { public Map.Entry<String, RelDataType> get(int index) { return rowType.getFieldList().get(index); } public int size() { return integers.size(); } } ); return of(typeFactory, projectedRowType, format.optimize(projectedRowType)); }
static PhysType of( final JavaTypeFactory typeFactory, Type javaRowClass) { final Types.RecordType recordType = (Types.RecordType) javaRowClass; final List<Types.RecordField> recordFields = recordType.getRecordFields(); RelDataType rowType = typeFactory.createStructType( new AbstractList<Map.Entry<String, RelDataType>>() { public Map.Entry<String, RelDataType> get(int index) { final Types.RecordField field = recordFields.get(index); return Pair.of( field.getName(), typeFactory.createType(field.getType())); } public int size() { return recordFields.size(); } }); // Do not optimize if there are 0 or 1 fields. return new PhysTypeImpl( typeFactory, rowType, javaRowClass, JavaRowFormat.CUSTOM); }
@Override protected Collection<TableInSchema> initialTables() { final List<TableInSchema> list = new ArrayList<TableInSchema>(); final RelDataType mapType = typeFactory.createMapType( typeFactory.createSqlType(SqlTypeName.VARCHAR), typeFactory.createSqlType(SqlTypeName.ANY)); final RelDataType rowType = typeFactory.createStructType( new RelDataTypeFactory.FieldInfoBuilder().add("_MAP", mapType)); for (String collection : mongoDb.getCollectionNames()) { final MongoTable table = new MongoTable(this, collection, rowType); list.add( new TableInSchemaImpl(this, collection, TableType.TABLE, table)); } return list; } }
/** Creates a RangeTable. */ public static RangeTable create( Schema schema, String tableName, String columnName, int start, int end) { final JavaTypeFactory typeFactory = schema.getTypeFactory(); final RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER); final RelDataType rowType = typeFactory.createStructType( RelDataTypeFactory.FieldInfoBuilder .of(columnName, integerType)); return new RangeTable( schema, Object[].class, rowType, tableName, start, end); }
typeFactory.createSqlType(SqlTypeName.INTEGER)); List<String> names = Arrays.asList("x", "y"); RelDataType inputRowType = typeFactory.createStructType(types, names); final RexProgramBuilder builder = new RexProgramBuilder(inputRowType, rexBuilder);
typeFactory.createSqlType(SqlTypeName.INTEGER)); List<String> names = Arrays.asList("x", "y"); RelDataType inputRowType = typeFactory.createStructType(types, names); final RexProgramBuilder builder = new RexProgramBuilder(inputRowType, rexBuilder);