Hi Team, I have been trying to `load local avro fi...
# troubleshooting
k
Hi Team, I have been trying to
load local avro files
, convert them into source / stream to process but in vain. I have tried
FileSource.forRecordStreamFormat
but no luck. Does anyone happen to solve a problem like this before ?
πŸ’― 1
b
@Kaiwen Yuan I am looking for something similiar but for BulkFiles and parquet
k
ok, after some efforts, I kinda got it work. Basically, you will need to load avro files as dataset in one env, do collect; then in a stream env, you connect with "fromCollection".
b
any chance you can post your code? πŸ™
my current code looks something like the following:
Copy code
val format =  ParquetColumnarRowInputFormat.createPartitionedFormat(
        hadoopConfig=new Configuration(),
        producedRowType=rowType,
        producedTypeInfo=rowTypeInfo,
        partitionKeys=partitionKeys,
        extractor=extractor,
        batchSize=2048,
        isUtcTimestamp=true,
        isCaseSensitive=false
      )

    // // Monitor the Paths to read data as unbounded data
    val source = FileSource
      .forBulkFileFormat(format, datalakeS3Path)
      .monitorContinuously(Duration.ofMillis(5L))
      .build()

    val dataStream = env.fromSource(source, WatermarkStrategy.noWatermarks(), "DataLake")

    dataStream
k
Copy code
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        
        AvroInputFormat<User> users = new AvroInputFormat<User>(new Path(avroFilePath), User.class);
        DataSet<User> userDataSet = env.createInput(users); 
        List<User> userDataList = userDataSet.collect();

        StreamExecutionEnvironment streamEnv = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<User> stream = streamEnv.fromCollection(userDataList);
I tried the filesource api but in vain
You basically want to treat them as DataSet, load them into memory, then use a stream env to load it out to connect the rest
b
@Kaiwen Yuan thank you! frustrating that
FileSource
api is not easy to use
k
yeah, I wasted 2 days on it 😞
b
same!
s
hi @Kaiwen Yuan and @Benjamin Leff, did you had any success concerning the FileSource ? I am also trying to read avro files, but the
AvroInputFormat
is for the old API. I saw what you did but I don't want (nor can...) collect my dataset, so your solution would not work for me πŸ˜•
b
unfortunately i did not. due to a few reasons, we moved away from flink for this use case