@Override public TableSchema getTableSchema() { return new TableSchema( new String[] {"key", "rowtime", "payload"}, new TypeInformation[] {Types.INT, Types.SQL_TIMESTAMP, Types.STRING}); }
private static TableSchema removeTimeAttributes(TableSchema schema) { final TableSchema.Builder builder = TableSchema.builder(); for (int i = 0; i < schema.getFieldCount(); i++) { final TypeInformation<?> type = schema.getFieldTypes()[i]; final TypeInformation<?> convertedType; if (FlinkTypeFactory.isTimeIndicatorType(type)) { convertedType = Types.SQL_TIMESTAMP; } else { convertedType = type; } builder.field(schema.getFieldNames()[i], convertedType); } return builder.build(); } }
private boolean checkForCustomFieldMapping(DescriptorProperties descriptorProperties, TableSchema schema) { final Map<String, String> fieldMapping = SchemaValidator.deriveFieldMapping( descriptorProperties, Optional.of(schema.toRowType())); // until FLINK-9870 is fixed we assume that the table schema is the output type return fieldMapping.size() != schema.getFieldNames().length || !fieldMapping.entrySet().stream().allMatch(mapping -> mapping.getKey().equals(mapping.getValue())); }
/** * Adds a table schema under the given key. */ public void putTableSchema(String key, TableSchema schema) { checkNotNull(key); checkNotNull(schema); final String[] fieldNames = schema.getFieldNames(); final TypeInformation<?>[] fieldTypes = schema.getFieldTypes(); final List<List<String>> values = new ArrayList<>(); for (int i = 0; i < schema.getFieldCount(); i++) { values.add(Arrays.asList(fieldNames[i], TypeStringUtils.writeTypeInfo(fieldTypes[i]))); } putIndexedFixedProperties( key, Arrays.asList(TABLE_SCHEMA_NAME, TABLE_SCHEMA_TYPE), values); }
static RowTypeInfo toRowType(TableSchema schema) { return new RowTypeInfo(schema.getTypes(), schema.getColumnNames()); }
protected void openRow() { if (selectedRow == NO_ROW_SELECTED) { return; } final CliRowView view = new CliRowView( client, resultDescriptor.getResultSchema().getFieldNames(), CliUtils.typesToString(resultDescriptor.getResultSchema().getFieldTypes()), getRow(results.get(selectedRow))); view.open(); // enter view }
final String sourceTopic = "foo"; final String sinkTopic = "bar"; final TableSchema schema = new TableSchema(new String[] {"foo"}, new TypeInformation[] {INT_TYPE_INFO}); .configure(schema.getColumnNames(), schema.getTypes());
@Override public String[] getFieldNames() { return schema.getFieldNames(); }
@Override public TypeInformation<Row> getOutputType() { return schema.toRowType(); }
@Override public TypeInformation<?>[] getFieldTypes() { return schema.getFieldTypes(); }
/** * Returns a table schema under the given key if it exists. */ public Optional<TableSchema> getOptionalTableSchema(String key) { // filter for number of fields final int fieldCount = properties.keySet().stream() .filter((k) -> k.startsWith(key) && k.endsWith('.' + TABLE_SCHEMA_NAME)) .mapToInt((k) -> 1) .sum(); if (fieldCount == 0) { return Optional.empty(); } // validate fields and build schema final TableSchema.Builder schemaBuilder = TableSchema.builder(); for (int i = 0; i < fieldCount; i++) { final String nameKey = key + '.' + i + '.' + TABLE_SCHEMA_NAME; final String typeKey = key + '.' + i + '.' + TABLE_SCHEMA_TYPE; final String name = optionalGet(nameKey).orElseThrow(exceptionSupplier(nameKey)); final TypeInformation<?> type = optionalGet(typeKey) .map(TypeStringUtils::readTypeInfo) .orElseThrow(exceptionSupplier(typeKey)); schemaBuilder.field(name, type); } return Optional.of(schemaBuilder.build()); }
@Override public String[] getFieldNames() { return schema.getColumnNames(); }
@Override public DataType[] getFieldTypes() { return schema.getTypes(); }
private boolean checkFieldsInfo(CreateTmpTableParser.SqlParserResult result, Table table){ List<String> fieldNames = new LinkedList<>(); String fieldsInfo = result.getFieldsInfoStr(); String[] fields = fieldsInfo.split(","); for (int i=0; i < fields.length; i++) { String[] filed = fields[i].split("\\s"); if (filed.length < 2 || fields.length != table.getSchema().getColumnNames().length){ return false; } else { String[] filedNameArr = new String[filed.length - 1]; System.arraycopy(filed, 0, filedNameArr, 0, filed.length - 1); String fieldName = String.join(" ", filedNameArr); fieldNames.add(fieldName); String fieldType = filed[filed.length - 1 ].trim(); Class fieldClass = ClassUtil.stringConvertClass(fieldType); Class tableField = table.getSchema().getType(i).get().getTypeClass(); if (fieldClass == tableField){ continue; } else { return false; } } } tmpFields = String.join(",", fieldNames); return true; }
@Override public AppendStreamTableSink<Row> getAppendStreamTableSink(ExternalCatalogTable table) throws IOException { DescriptorProperties params = new DescriptorProperties(true); table.addProperties(params); TableSchema tableSchema = params.getTableSchema(MockExternalCatalogTable.TABLE_SCHEMA_CONNECTOR_PROPERTY); RowTypeInfo type = new RowTypeInfo(tableSchema.getTypes(), tableSchema.getColumnNames()); return new MockAppendStreamTableSink(type); }
/** * Adds a table schema under the given key. */ public void putTableSchema(String key, TableSchema schema) { checkNotNull(key); checkNotNull(schema); final String[] fieldNames = schema.getFieldNames(); final InternalType[] fieldTypes = schema.getFieldTypes(); final List<List<String>> values = new ArrayList<>(); for (int i = 0; i < schema.getFieldCount(); i++) { values.add(Arrays.asList(fieldNames[i], TypeStringUtils.writeDataType(fieldTypes[i]))); } putIndexedFixedProperties( key, Arrays.asList(TABLE_SCHEMA_NAME, TABLE_SCHEMA_TYPE), values); }
/** * Creates a result. Might start threads or opens sockets so every created result must be closed. */ public <T> DynamicResult<T> createResult(Environment env, TableSchema schema, ExecutionConfig config) { final TypeInformation<Row> outputType = Types.ROW_NAMED(schema.getFieldNames(), schema.getFieldTypes()); if (env.getExecution().isStreamingExecution()) { // determine gateway address (and port if possible) final InetAddress gatewayAddress = getGatewayAddress(env.getDeployment()); final int gatewayPort = getGatewayPort(env.getDeployment()); if (env.getExecution().isChangelogMode()) { return new ChangelogCollectStreamResult<>(outputType, config, gatewayAddress, gatewayPort); } else { return new MaterializedCollectStreamResult<>( outputType, config, gatewayAddress, gatewayPort, env.getExecution().getMaxTableResultRows()); } } else { // Batch Execution if (!env.getExecution().isTableMode()) { throw new SqlExecutionException("Results of batch queries can only be served in table mode."); } return new MaterializedCollectBatchResult<>(outputType, config); } }
@Override public String[] getFieldNames() { return schema.getFieldNames(); }
@Override public TypeInformation<Row> getRecordType() { return schema.toRowType(); }