/** * Parses the avro file and sends dimension rows to a consumer. * * @param dimension The dimension object used to configure the dimension * @param avroFilePath The path of the AVRO data file (.avro) * @param consumer A consumer to process records from the avro file * * @throws IllegalArgumentException thrown if JSON object `fields` is not present */ public void parseAvroFileDimensionRows(Dimension dimension, String avroFilePath, Consumer<DimensionRow> consumer) throws IllegalArgumentException { GenericDatumReader datumReader = new GenericDatumReader(); // Creates an AVRO DataFileReader object that reads the AVRO data file one record at a time try (DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new File(avroFilePath), datumReader)) { streamDimensionRows(dataFileReader, dimension).forEach(consumer); } catch (IOException e) { String msg = String.format("Unable to process the file, at the location %s", avroFilePath); LOG.error(msg, e); throw new IllegalArgumentException(msg, e); } }
/** * Parses the avro file and returns the dimension rows. * * @param dimension The dimension object used to configure the dimension * @param avroFilePath The path of the AVRO data file (.avro) * * @return A set of dimension rows * * @throws IllegalArgumentException thrown if JSON object `fields` is not present */ public Set<DimensionRow> parseAvroFileDimensionRows(Dimension dimension, String avroFilePath) throws IllegalArgumentException { GenericDatumReader datumReader = new GenericDatumReader(); // Creates an AVRO DataFileReader object that reads the AVRO data file one record at a time try (DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new File(avroFilePath), datumReader)) { return streamDimensionRows(dataFileReader, dimension).collect(Collectors.toSet()); } catch (IOException e) { String msg = String.format("Unable to process the file, at the location %s", avroFilePath); LOG.error(msg, e); throw new IllegalArgumentException(msg, e); } }