Java Code Examples for org.apache.flink.table.api.Table#printSchema()
The following examples show how to use
org.apache.flink.table.api.Table#printSchema() .
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: FlinkTaskInstanceBusiness.java From PoseidonX with Apache License 2.0 | 5 votes |
/** * 处理具体sql业务逻辑 * @param flinkComponent */ private void dealFlinkTaskLogicComponent(FlinkTaskLogicComponent flinkComponent) { System.out.println(flinkComponent.getLogicSql()); Table resultTable = tEnv.sql( flinkComponent.getLogicSql()); TableSink tableSink = tableSinkMap.get(flinkComponent.getTargetOutputComponentName()); resultTable.printSchema(); resultTable.writeToSink(tableSink); }
Example 2
Source File: TCFlinkAvroSQL.java From df_data_service with Apache License 2.0 | 4 votes |
public static void tcFlinkAvroSQL(String SchemaRegistryHostPort, String srcTopic, String targetTopic, String sqlState) { System.out.println("tcFlinkAvroSQL"); String resultFile = "testResult"; String jarPath = "C:/Users/dadu/Coding/df_data_service/target/df-data-service-1.1-SNAPSHOT-fat.jar"; //String jarPath = "/Users/will/Documents/Coding/GitHub/df_data_service/target/df-data-service-1.1-SNAPSHOT-fat.jar"; StreamExecutionEnvironment env = StreamExecutionEnvironment.createRemoteEnvironment("localhost", 6123, jarPath) .setParallelism(1); StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env); Properties properties = new Properties(); properties.setProperty(ConstantApp.PK_KAFKA_HOST_PORT.replace("_", "."), "localhost:9092"); properties.setProperty(ConstantApp.PK_KAFKA_CONSUMER_GROURP, "consumer_test"); //properties.setProperty(ConstantApp.PK_SCHEMA_SUB_OUTPUT, "test"); properties.setProperty(ConstantApp.PK_KAFKA_SCHEMA_REGISTRY_HOST_PORT.replace("_", "."), SchemaRegistryHostPort); properties.setProperty(ConstantApp.PK_FLINK_TABLE_SINK_KEYS, "symbol"); String[] srcTopicList = srcTopic.split(","); for (int i = 0; i < srcTopicList.length; i++) { properties.setProperty(ConstantApp.PK_SCHEMA_SUB_INPUT, srcTopicList[i]); properties.setProperty(ConstantApp.PK_SCHEMA_ID_INPUT, SchemaRegistryClient.getLatestSchemaIDFromProperty(properties, ConstantApp.PK_SCHEMA_SUB_INPUT) + ""); properties.setProperty(ConstantApp.PK_SCHEMA_STR_INPUT, SchemaRegistryClient.getLatestSchemaFromProperty(properties, ConstantApp.PK_SCHEMA_SUB_INPUT).toString()); tableEnv.registerTableSource(srcTopicList[i], new Kafka010AvroTableSource(srcTopicList[i], properties)); } try { Table result = tableEnv.sql(sqlState); result.printSchema(); System.out.println("generated avro schema is = " + SchemaRegistryClient.tableAPIToAvroSchema(result, targetTopic)); SchemaRegistryClient.addSchemaFromTableResult(SchemaRegistryHostPort, targetTopic, result); // delivered properties properties.setProperty(ConstantApp.PK_SCHEMA_SUB_OUTPUT, targetTopic); properties.setProperty(ConstantApp.PK_SCHEMA_ID_OUTPUT, SchemaRegistryClient.getLatestSchemaIDFromProperty(properties, ConstantApp.PK_SCHEMA_SUB_OUTPUT) + ""); properties.setProperty(ConstantApp.PK_SCHEMA_STR_OUTPUT, SchemaRegistryClient.getLatestSchemaFromProperty(properties, ConstantApp.PK_SCHEMA_SUB_OUTPUT).toString()); System.out.println(Paths.get(resultFile).toAbsolutePath()); Kafka09AvroTableSink avro_sink = new Kafka09AvroTableSink(targetTopic, properties, new FlinkFixedPartitioner()); result.writeToSink(avro_sink); //result.writeToSink(new CsvTableSink(resultFile, "|", 1, FileSystem.WriteMode.OVERWRITE)); env.execute("tcFlinkAvroSQL"); } catch (Exception e) { e.printStackTrace(); } }