我对apache flink还不熟悉,我正在尝试读取一个avro文件,如下所示,
val schema = new Schema()
.field("tconst", "string")
.field("titleType", "string")
.field("primaryTitle", "string")
.field("originalTitle", "string")
.field("isAdult", "int")
.field("startYear", "string")
.field("endYear", "string")
.field("runtimeMinutes", "int")
.field("genres", "string")
val avroFormat: Avro = new Avro()
.avroSchema(
"{" +
" \"type\": \"record\"," +
" \"name\": \"test\"," +
" \"fields\" : [" +
" {\"name\": \"tconst\", \"type\": \"string\"}," +
" {\"name\": \"titleType\", \"type\": \"string\"}" +
" {\"name\": \"primaryTitle\", \"type\": \"string\"}" +
" {\"name\": \"originalTitle\", \"type\": \"string\"}" +
" {\"name\": \"isAdult\", \"type\": \"int\"}" +
" {\"name\": \"startYear\", \"type\": \"string\"}" +
" {\"name\": \"endYear\", \"type\": \"string\"}" +
" {\"name\": \"runtimeMinutes\", \"type\": \"int\"}" +
" {\"name\": \"genres\", \"type\": \"string\"}" +
" ]" +
"}"
)
tableEnv.connect(new FileSystem().path("/Users/x/Documents/test_1.avro"))
.withSchema(schema)
.withFormat(avroFormat)
.registerTableSource("sink")
但是当我运行这个时,我得到了以下错误。
Exception in thread "main" org.apache.flink.table.api.NoMatchingTableFactoryException: Could not find a suitable table factory for 'org.apache.flink.table.factories.BatchTableSourceFactory' in
the classpath.
Reason: No context matches.
The following properties are requested:
connector.path=/Users/x/Documents/test_1.avro
connector.property-version=1
connector.type=filesystem
format.avro-schema=.... // above schema
format.property-version=1
format.type=avro
schema.0.name=tconst
schema.0.type=string
schema.1.name=titleType
schema.1.type=string
schema.2.name=primaryTitle
schema.2.type=string
schema.3.name=originalTitle
schema.3.type=string
schema.4.name=isAdult
schema.4.type=int
schema.5.name=startYear
schema.5.type=string
schema.6.name=endYear
schema.6.type=string
schema.7.name=runtimeMinutes
schema.7.type=int
schema.8.name=genres
schema.8.type=string
The following factories have been considered:
org.apache.flink.api.java.io.jdbc.JDBCTableSourceSinkFactory
org.apache.flink.table.sources.CsvBatchTableSourceFactory
org.apache.flink.table.sources.CsvAppendTableSourceFactory
org.apache.flink.table.sinks.CsvBatchTableSinkFactory
org.apache.flink.table.sinks.CsvAppendTableSinkFactory
org.apache.flink.formats.avro.AvroRowFormatFactory
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactory
在这个avro文件中它有一个 Flink Dataset
使用 AvroOutputFormat
写入文件。
val avroOutputFormat = new AvroOutputFormat[Row](classOf[Row])
flinkDatase.write(avroOutputFormat, "/Users/x/Documents/test_1.avro").setParallelism(1)
我在想,如果这是一个错误的数据类型,可能会导致上述错误。有没有办法找出这个问题的确切原因?
1条答案
按热度按时间aiazj4mn1#
很抱歉误导了你。不幸的是,到目前为止,filesystem connector还不支持avro。
因此,除了使用dataset api之外别无选择。我建议使用avrohugger为avro模式生成适当的scala类。