org.apache.calcite.rel.type.RelProtoDataType Java Examples
The following examples show how to use
org.apache.calcite.rel.type.RelProtoDataType.
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: DruidTable.java From calcite with Apache License 2.0 | 6 votes |
/** * Creates a Druid table. * * @param schema Druid schema that contains this table * @param dataSource Druid data source name * @param protoRowType Field names and types * @param metricFieldNames Names of fields that are metrics * @param intervals Default interval if query does not constrain the time, or null * @param timestampFieldName Name of the column that contains the time */ public DruidTable(DruidSchema schema, String dataSource, RelProtoDataType protoRowType, Set<String> metricFieldNames, String timestampFieldName, List<Interval> intervals, Map<String, List<ComplexMetric>> complexMetrics, Map<String, SqlTypeName> allFields) { this.timestampFieldName = Objects.requireNonNull(timestampFieldName); this.schema = Objects.requireNonNull(schema); this.dataSource = Objects.requireNonNull(dataSource); this.protoRowType = protoRowType; this.metricFieldNames = ImmutableSet.copyOf(metricFieldNames); this.intervals = intervals != null ? ImmutableList.copyOf(intervals) : ImmutableList.of(DEFAULT_INTERVAL); this.complexMetrics = complexMetrics == null ? ImmutableMap.of() : ImmutableMap.copyOf(complexMetrics); this.allFields = allFields == null ? ImmutableMap.of() : ImmutableMap.copyOf(allFields); }
Example #2
Source File: UdfTest.java From calcite with Apache License 2.0 | 6 votes |
public List<FunctionParameter> getParameters() { final List<FunctionParameter> parameters = new ArrayList<>(); for (final Ord<RelProtoDataType> type : Ord.zip(getParams())) { parameters.add( new FunctionParameter() { public int getOrdinal() { return type.i; } public String getName() { return "arg" + type.i; } public RelDataType getType(RelDataTypeFactory typeFactory) { return type.e.apply(typeFactory); } public boolean isOptional() { return false; } }); } return parameters; }
Example #3
Source File: ColumnLoader.java From calcite with Apache License 2.0 | 6 votes |
/** Creates a column loader, and performs the load. * * @param typeFactory Type factory * @param sourceTable Source data * @param protoRowType Logical row type * @param repList Physical row types, or null if not known */ ColumnLoader(JavaTypeFactory typeFactory, Enumerable<T> sourceTable, RelProtoDataType protoRowType, List<ColumnMetaData.Rep> repList) { this.typeFactory = typeFactory; final RelDataType rowType = protoRowType.apply(typeFactory); if (repList == null) { repList = Collections.nCopies(rowType.getFieldCount(), ColumnMetaData.Rep.OBJECT); } sourceTable.into(list); final int[] sorts = {-1}; load(rowType, repList, sorts); this.sortField = sorts[0]; }
Example #4
Source File: CloneSchema.java From calcite with Apache License 2.0 | 5 votes |
public static <T> Table createCloneTable(final JavaTypeFactory typeFactory, final RelProtoDataType protoRowType, final List<RelCollation> collations, final List<ColumnMetaData.Rep> repList, final Enumerable<T> source) { final Type elementType; if (source instanceof QueryableTable) { elementType = ((QueryableTable) source).getElementType(); } else if (protoRowType.apply(typeFactory).getFieldCount() == 1) { if (repList != null) { elementType = repList.get(0).clazz; } else { elementType = Object.class; } } else { elementType = Object[].class; } return new ArrayTable( elementType, protoRowType, Suppliers.memoize(() -> { final ColumnLoader loader = new ColumnLoader<>(typeFactory, source, protoRowType, repList); final List<RelCollation> collation2 = collations.isEmpty() && loader.sortField >= 0 ? RelCollations.createSingleton(loader.sortField) : collations; return new ArrayTable.Content(loader.representationValues, loader.size(), collation2); })); }
Example #5
Source File: CalciteSchema.java From Bats with Apache License 2.0 | 5 votes |
/** Defines a type within this schema. */ public TypeEntry add(String name, RelProtoDataType type) { final TypeEntry entry = new TypeEntryImpl(this, name, type); typeMap.put(name, entry); return entry; }
Example #6
Source File: RedisTable.java From calcite with Apache License 2.0 | 5 votes |
static Table create( RedisSchema schema, String tableName, RedisConfig redisConfig, RelProtoDataType protoRowType) { RedisTableFieldInfo tableFieldInfo = schema.getTableFieldInfo(tableName); Map<String, Object> allFields = RedisEnumerator.deduceRowType(tableFieldInfo); return new RedisTable(schema, tableName, protoRowType, allFields, tableFieldInfo.getDataFormat(), redisConfig); }
Example #7
Source File: TableFunctionReturnTypeInference.java From Bats with Apache License 2.0 | 5 votes |
public TableFunctionReturnTypeInference( RelProtoDataType unexpandedOutputType, List<String> paramNames, boolean isPassthrough) { super(unexpandedOutputType); this.paramNames = paramNames; this.isPassthrough = isPassthrough; }
Example #8
Source File: CachingCalciteSchema.java From Bats with Apache License 2.0 | 5 votes |
protected TypeEntry getImplicitType(String name, boolean caseSensitive) { final long now = System.currentTimeMillis(); final NameSet implicitTypeNames = implicitTypeCache.get(now); for (String typeName : implicitTypeNames.range(name, caseSensitive)) { final RelProtoDataType type = schema.getType(typeName); if (type != null) { return typeEntry(name, type); } } return null; }
Example #9
Source File: SimpleCalciteSchema.java From Bats with Apache License 2.0 | 5 votes |
protected TypeEntry getImplicitType(String name, boolean caseSensitive) { // Check implicit types. RelProtoDataType type = schema.getType(name); if (type != null) { return typeEntry(name, type); } return null; }
Example #10
Source File: RedisTable.java From calcite with Apache License 2.0 | 5 votes |
public RedisTable( RedisSchema schema, String tableName, RelProtoDataType protoRowType, Map<String, Object> allFields, String dataFormat, RedisConfig redisConfig) { this.schema = schema; this.tableName = tableName; this.protoRowType = protoRowType; this.allFields = allFields == null ? ImmutableMap.of() : ImmutableMap.copyOf(allFields); this.dataFormat = dataFormat; this.redisConfig = redisConfig; }
Example #11
Source File: ViewTable.java From calcite with Apache License 2.0 | 5 votes |
public ViewTable(Type elementType, RelProtoDataType rowType, String viewSql, List<String> schemaPath, List<String> viewPath) { super(elementType); this.viewSql = viewSql; this.schemaPath = ImmutableList.copyOf(schemaPath); this.protoRowType = rowType; this.viewPath = viewPath == null ? null : ImmutableList.copyOf(viewPath); }
Example #12
Source File: TableFunctionReturnTypeInference.java From calcite with Apache License 2.0 | 5 votes |
public TableFunctionReturnTypeInference( RelProtoDataType unexpandedOutputType, List<String> paramNames, boolean isPassthrough) { super(unexpandedOutputType); this.paramNames = paramNames; this.isPassthrough = isPassthrough; }
Example #13
Source File: ModifiableViewTable.java From Bats with Apache License 2.0 | 5 votes |
/** Creates a ModifiableViewTable. */ public ModifiableViewTable(Type elementType, RelProtoDataType rowType, String viewSql, List<String> schemaPath, List<String> viewPath, Table table, Path tablePath, RexNode constraint, ImmutableIntList columnMapping) { super(elementType, rowType, viewSql, schemaPath, viewPath); this.table = table; this.tablePath = tablePath; this.constraint = constraint; this.columnMapping = columnMapping; this.initializerExpressionFactory = new ModifiableViewTableInitializerExpressionFactory(); }
Example #14
Source File: ListTable.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a ListTable. */ ListTable( Type elementType, RelProtoDataType protoRowType, Expression expression, List list) { super(elementType); this.protoRowType = protoRowType; this.expression = expression; this.list = list; }
Example #15
Source File: MockCatalogReader.java From calcite with Apache License 2.0 | 5 votes |
protected void registerType(final List<String> names, final RelProtoDataType relProtoDataType) { assert names.get(0).equals(DEFAULT_CATALOG); final List<String> schemaPath = Util.skipLast(names); final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, SqlNameMatchers.withCaseSensitive(true)); schema.add(Util.last(names), relProtoDataType); }
Example #16
Source File: RedisTable.java From calcite with Apache License 2.0 | 5 votes |
static Table create( RedisSchema schema, String tableName, Map operand, RelProtoDataType protoRowType) { RedisConfig redisConfig = new RedisConfig(schema.host, schema.port, schema.database, schema.password); return create(schema, tableName, redisConfig, protoRowType); }
Example #17
Source File: CloneSchema.java From calcite with Apache License 2.0 | 5 votes |
@Deprecated // to be removed before 2.0 public static <T> Table createCloneTable(final JavaTypeFactory typeFactory, final RelProtoDataType protoRowType, final List<ColumnMetaData.Rep> repList, final Enumerable<T> source) { return createCloneTable(typeFactory, protoRowType, ImmutableList.of(), repList, source); }
Example #18
Source File: RedisTableFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public Table create(SchemaPlus schema, String tableName, Map operand, RelDataType rowType) { final RedisSchema redisSchema = schema.unwrap(RedisSchema.class); final RelProtoDataType protoRowType = rowType != null ? RelDataTypeImpl.proto(rowType) : null; return RedisTable.create(redisSchema, tableName, operand, protoRowType); }
Example #19
Source File: MutableArrayTable.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a MutableArrayTable. * * @param name Name of table within its schema * @param protoStoredRowType Prototype of row type of stored columns (all * columns except virtual columns) * @param protoRowType Prototype of row type (all columns) * @param initializerExpressionFactory How columns are populated */ MutableArrayTable(String name, RelProtoDataType protoStoredRowType, RelProtoDataType protoRowType, InitializerExpressionFactory initializerExpressionFactory) { super(name); this.protoStoredRowType = Objects.requireNonNull(protoStoredRowType); this.protoRowType = Objects.requireNonNull(protoRowType); this.initializerExpressionFactory = Objects.requireNonNull(initializerExpressionFactory); }
Example #20
Source File: JdbcSchema.java From calcite with Apache License 2.0 | 5 votes |
RelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName, String schemaName, String tableName) throws SQLException { final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null); // Temporary type factory, just for the duration of this method. Allowable // because we're creating a proto-type, not a type; before being used, the // proto-type will be copied into a real type factory. final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder(); while (resultSet.next()) { final String columnName = resultSet.getString(4); final int dataType = resultSet.getInt(5); final String typeString = resultSet.getString(6); final int precision; final int scale; switch (SqlType.valueOf(dataType)) { case TIMESTAMP: case TIME: precision = resultSet.getInt(9); // SCALE scale = 0; break; default: precision = resultSet.getInt(7); // SIZE scale = resultSet.getInt(9); // SCALE break; } RelDataType sqlType = sqlType(typeFactory, dataType, precision, scale, typeString); boolean nullable = resultSet.getInt(11) != DatabaseMetaData.columnNoNulls; fieldInfo.add(columnName, sqlType).nullable(nullable); } resultSet.close(); return RelDataTypeImpl.proto(fieldInfo.build()); }
Example #21
Source File: JdbcSchema.java From calcite with Apache License 2.0 | 5 votes |
RelProtoDataType getRelDataType(String catalogName, String schemaName, String tableName) throws SQLException { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); return getRelDataType(metaData, catalogName, schemaName, tableName); } finally { close(connection, null, null); } }
Example #22
Source File: GeodeEnumerator.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a GeodeEnumerator. * * @param results Geode result set ({@link SelectResults}) * @param protoRowType The type of resulting rows */ GeodeEnumerator(SelectResults results, RelProtoDataType protoRowType) { if (results == null) { LOGGER.warn("Null OQL results!"); } this.iterator = (results == null) ? Collections.emptyIterator() : results.iterator(); this.current = null; final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); this.fieldTypes = protoRowType.apply(typeFactory).getFieldList(); }
Example #23
Source File: Table.java From kareldb with Apache License 2.0 | 5 votes |
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { if (getRelDef() == null) { return null; } RelProtoDataType protoRowType = RelDataTypeImpl.proto(getRowType()); return protoRowType.apply(typeFactory); }
Example #24
Source File: CsvTableFactory.java From calcite with Apache License 2.0 | 5 votes |
public CsvTable create(SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) { String fileName = (String) operand.get("file"); final File base = (File) operand.get(ModelHandler.ExtraOperand.BASE_DIRECTORY.camelName); final Source source = Sources.file(base, fileName); final RelProtoDataType protoRowType = rowType != null ? RelDataTypeImpl.proto(rowType) : null; return new CsvScannableTable(source, protoRowType); }
Example #25
Source File: CassandraEnumerator.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a CassandraEnumerator. * * @param results Cassandra result set ({@link com.datastax.driver.core.ResultSet}) * @param protoRowType The type of resulting rows */ CassandraEnumerator(ResultSet results, RelProtoDataType protoRowType) { this.iterator = results.iterator(); this.current = null; final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); this.fieldTypes = protoRowType.apply(typeFactory).getFieldList(); }
Example #26
Source File: CalciteSchema.java From calcite with Apache License 2.0 | 5 votes |
/** Defines a type within this schema. */ public TypeEntry add(String name, RelProtoDataType type) { final TypeEntry entry = new TypeEntryImpl(this, name, type); typeMap.put(name, entry); return entry; }
Example #27
Source File: FileTable.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a FileTable. */ private FileTable(Source source, String selector, Integer index, RelProtoDataType protoRowType, List<Map<String, Object>> fieldConfigs) throws Exception { super(Object[].class); this.protoRowType = protoRowType; this.reader = new FileReader(source, selector, index); this.converter = new FileRowConverter(this.reader, fieldConfigs); }
Example #28
Source File: QueryOperationCatalogViewTable.java From flink with Apache License 2.0 | 5 votes |
private QueryOperationCatalogViewTable( QueryOperationCatalogView catalogView, RelProtoDataType rowType, FlinkStatistic statistic) { this.catalogView = catalogView; this.rowType = rowType; this.statistic = statistic; }
Example #29
Source File: SimpleCalciteSchema.java From calcite with Apache License 2.0 | 5 votes |
protected TypeEntry getImplicitType(String name, boolean caseSensitive) { // Check implicit types. RelProtoDataType type = schema.getType(name); if (type != null) { return typeEntry(name, type); } return null; }
Example #30
Source File: MaterializedViewTable.java From calcite with Apache License 2.0 | 5 votes |
public MaterializedViewTable(Type elementType, RelProtoDataType relDataType, String viewSql, List<String> viewSchemaPath, List<String> viewPath, MaterializationKey key) { super(elementType, relDataType, viewSql, viewSchemaPath, viewPath); this.key = key; }