ambition119 edited a comment on issue #8387: [FLINK-11982] [table] File System Connector's support JSON Format and JSON file BatchTableSource URL: https://github.com/apache/flink/pull/8387#issuecomment-491298616 > Hi @ambition119 > I agree with @StephanEwen that this PR mixes the concepts of `connector`(file) and `format`(json). > > I don't necessarily understand the comment that `JsonRowFormatFactory` does not support File System Connector. First, there is no file system connector, and second of all this is a format factory thus it should have no notion of connector. > > I think you could rework your `JsonBatchTableSource` and `JsonRowInputFormat` to accept any `DeserializationSchema<Row>` similar to how `org.apache.flink.streaming.connectors.kafka.KafkaTableSourceBase` works. > > Another issue on a more conceptual layer is that the proposed `RowInputFormat` assumes that each line in a file is a separate record. I agree this is probably the most common case, but not the only one. > Files can be also written with a different layout (e.g. Parquet), thus we should differentiate that also on the connector level. > > I'm guessing you might have been inspired by `CsvTableSource`, but it was one of the first `TableSource`s that was written before we decided to split connectors and formats and its design is flawed. It also uses `RowCsvInputFormat` that as I said in the previous paragraph applies custom block(in this case line) splitting based on configurable delimiter. Thank you for your reply and discussion. First of all, the naming of this PR is a bit confusing. The code function mainly supports json files, such as local or hdfs, so I can rename it to **JsonFileXxx.** Second, flink does exist File System Connector, the official document is https://ci.apache.org/projects/flink/flink-docs-release-1.8/dev/table/connect.html#file-system-connector, provide [CsvBatchTableSourceFactory](https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/resources/META-INF/services/org.apache.flink.table.factories.TableFactory#L16) to support reading of csv files.  flink master show unit test info [FileSystem connector CSV Format](https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/descriptors/TableDescriptorTest.scala#L59), and example: ```java public static void main(String[] args) throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tEnv = BatchTableEnvironment.create(env); FileSystem connector = new FileSystem().path("/path/to/csv/in.csv"); OldCsv oldCsv = new OldCsv() .field("a", Types.STRING()) .field("b", Types.INT()) .field("c", Types.BOOLEAN()); Schema schema = new Schema() .field("a", Types.STRING()) .field("b", Types.INT()) .field("c", Types.BOOLEAN()); tEnv.connect(connector) .withFormat(oldCsv) .withSchema(schema) .registerTableSource("csvTable"); String fullSql = "select * FROM csvTable"; Table fullTable = tEnv.sqlQuery(fullSql); DataSet<Row> fullDS = tEnv.toDataSet(fullTable, Row.class); List<Row> result = fullDS.collect(); System.out.println(result); } ``` Third, for example, the hive support json file also is one line a separate record, otherwise it is not supported. eg: ```json { "fruit": [{ "weight": 8, "type": "apple" }, { "weight": 9, "type": "pear" }], "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "category": "fiction", "price": 22.99, "isbn": "0-395-19395-8", "email": "amy@only_for_json_udf_test.net", "owner": "amy", "zip_code": "94025", "fb_id": "1234" } ``` thanks.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
