@Test public void testGetDirectorySchema() throws IOException { Configuration conf = new Configuration(); conf.set("fs.default.name", "file: conf.set("mapred.job.tracker", "local"); Path mockAvroFilePath = new Path(AVRO_DIR); Assert.assertNotNull(AvroUtils.getDirectorySchema(mockAvroFilePath, conf, true)); }
public static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest) throws IOException { Schema schema = null; try (Closer closer = Closer.create()) { List<FileStatus> files = getDirectorySchemaHelper(directory, fs); if (files == null || files.size() == 0) { LOG.warn("There is no previous avro file in the directory: " + directory); } else { FileStatus file = latest ? files.get(0) : files.get(files.size() - 1); LOG.debug("Path to get the avro schema: " + file); FsInput fi = new FsInput(file.getPath(), fs.getConf()); GenericDatumReader<GenericRecord> genReader = new GenericDatumReader<>(); schema = closer.register(new DataFileReader<>(fi, genReader)).getSchema(); } } catch (IOException ioe) { throw new IOException("Cannot get the schema for directory " + directory, ioe); } return schema; }
AvroUtils { public static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest) throws IOException { Schema schema = null; try (Closer closer = Closer.create()) { List<FileStatus> files = getDirectorySchemaHelper(directory, fs); if (files == null || files.size() == 0) { LOG.warn("There is no previous avro file in the directory: " + directory); } else { FileStatus file = latest ? files.get(0) : files.get(files.size() - 1); LOG.debug("Path to get the avro schema: " + file); FsInput fi = new FsInput(file.getPath(), fs.getConf()); GenericDatumReader<GenericRecord> genReader = new GenericDatumReader<>(); schema = closer.register(new DataFileReader<>(fi, genReader)).getSchema(); } } catch (IOException ioe) { throw new IOException("Cannot get the schema for directory " + directory, ioe); } return schema; } }
AvroUtils { public static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest) throws IOException { Schema schema = null; try (Closer closer = Closer.create()) { List<FileStatus> files = getDirectorySchemaHelper(directory, fs); if (files == null || files.size() == 0) { LOG.warn("There is no previous avro file in the directory: " + directory); } else { FileStatus file = latest ? files.get(0) : files.get(files.size() - 1); LOG.debug("Path to get the avro schema: " + file); FsInput fi = new FsInput(file.getPath(), fs.getConf()); GenericDatumReader<GenericRecord> genReader = new GenericDatumReader<>(); schema = closer.register(new DataFileReader<>(fi, genReader)).getSchema(); } } catch (IOException ioe) { throw new IOException("Cannot get the schema for directory " + directory, ioe); } return schema; }  }
AvroUtils { public static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest) throws IOException { Schema schema = null; try (Closer closer = Closer.create()) { List<FileStatus> files = getDirectorySchemaHelper(directory, fs); if (files == null || files.size() == 0) { LOG.warn("There is no previous avro file in the directory: " + directory); } else { FileStatus file = latest ? files.get(0) : files.get(files.size() - 1); LOG.debug("Path to get the avro schema: " + file); FsInput fi = new FsInput(file.getPath(), fs.getConf()); GenericDatumReader<GenericRecord> genReader = new GenericDatumReader<>(); schema = closer.register(new DataFileReader<>(fi, genReader)).getSchema(); } } catch (IOException ioe) { throw new IOException("Cannot get the schema for directory " + directory, ioe); } return schema; }  static boolean checkReaderWriterCompatibility(Schema readerSchema, Schema writerSchema, boolean ignoreNamespace); static Schema addSchemaCreationTime(Schema inputSchema, Schema outputSchema); static String getSchemaCreationTime(Schema inputSchema); static Schema setSchemaCreationTime(Schema inputSchema, String creationTime); static List<Field> deepCopySchemaFields(Schema readerSchema); static void convertFieldToSchemaWithProps(Map<String,JsonNode> fieldProps, Schema targetSchemaObj); static Optional<Schema> getFieldSchema(Schema schema, String fieldLocation); static Optional<Field> getField(Schema schema, String fieldLocation); static Optional<Object> getFieldValue(GenericRecord record, String fieldLocation); static Map<String, Object> getMultiFieldValue(GenericRecord record, String fieldLocation); @SuppressWarnings("unchecked") static Map<String, String> toStringMap(Object map); static GenericRecord convertRecordSchema(GenericRecord record, Schema newSchema); static byte[] recordToByteArray(GenericRecord record); static Schema getSchemaFromDataFile(Path dataFile, FileSystem fs); static Schema parseSchemaFromFile(Path filePath, FileSystem fs); static void writeSchemaToFile(Schema schema, Path filePath, FileSystem fs, boolean overwrite); static void writeSchemaToFile(Schema schema, Path filePath, Path tempFilePath, FileSystem fs, boolean overwrite); static void writeSchemaToFile(Schema schema, Path filePath, FileSystem fs, boolean overwrite, FsPermission perm); static void writeSchemaToFile(Schema schema, Path filePath, Path tempFilePath, FileSystem fs, boolean overwrite,
      FsPermission perm); static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest); static Schema getDirectorySchema(Path directory, Configuration conf, boolean latest); static Schema nullifyFieldsForSchemaMerge(Schema oldSchema, Schema newSchema); static Optional<Schema> removeUncomparableFields(Schema schema); static Schema switchName(Schema schema, String newName); static Schema switchNamespace(Schema schema, Map<String, String> namespaceOverride); static Path serializeAsPath(GenericRecord record, boolean includeFieldNames, boolean replacePathSeparators); static String sanitizeSchemaString(String schemaString); static GenericRecord slowDeserializeGenericRecord(byte[] serializedRecord, Schema schema); static Schema decorateRecordSchema(Schema inputSchema, @Nonnull List<Field> fieldList); static GenericRecord decorateRecord(GenericRecord inputRecord, @Nonnull Map<String, Object> fieldMap,
      Schema outputSchema); static GenericRecord overrideNameAndNamespace(GenericRecord input, String nameOverride, Optional<Map<String, String>> namespaceOverride); static Schema overrideNameAndNamespace(Schema input, String nameOverride, Optional<Map<String, String>> namespaceOverride); static boolean isSchemaRecursive(Schema schema, Optional<Logger> logger); static Pair<Schema, List<SchemaEntry>> dropRecursiveFields(Schema schema); }
AvroUtils { public static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest) throws IOException { Schema schema = null; try (Closer closer = Closer.create()) { List<FileStatus> files = getDirectorySchemaHelper(directory, fs); if (files == null || files.size() == 0) { LOG.warn("There is no previous avro file in the directory: " + directory); } else { FileStatus file = latest ? files.get(0) : files.get(files.size() - 1); LOG.debug("Path to get the avro schema: " + file); FsInput fi = new FsInput(file.getPath(), fs.getConf()); GenericDatumReader<GenericRecord> genReader = new GenericDatumReader<>(); schema = closer.register(new DataFileReader<>(fi, genReader)).getSchema(); } } catch (IOException ioe) { throw new IOException("Cannot get the schema for directory " + directory, ioe); } return schema; }  static boolean checkReaderWriterCompatibility(Schema readerSchema, Schema writerSchema, boolean ignoreNamespace); static Schema addSchemaCreationTime(Schema inputSchema, Schema outputSchema); static String getSchemaCreationTime(Schema inputSchema); static Schema setSchemaCreationTime(Schema inputSchema, String creationTime); static List<Field> deepCopySchemaFields(Schema readerSchema); static void convertFieldToSchemaWithProps(Map<String,JsonNode> fieldProps, Schema targetSchemaObj); static Optional<Schema> getFieldSchema(Schema schema, String fieldLocation); static Optional<Field> getField(Schema schema, String fieldLocation); static Optional<Object> getFieldValue(GenericRecord record, String fieldLocation); static Map<String, Object> getMultiFieldValue(GenericRecord record, String fieldLocation); @SuppressWarnings("unchecked") static Map<String, String> toStringMap(Object map); static GenericRecord convertRecordSchema(GenericRecord record, Schema newSchema); static byte[] recordToByteArray(GenericRecord record); static Schema getSchemaFromDataFile(Path dataFile, FileSystem fs); static Schema parseSchemaFromFile(Path filePath, FileSystem fs); static void writeSchemaToFile(Schema schema, Path filePath, FileSystem fs, boolean overwrite); static void writeSchemaToFile(Schema schema, Path filePath, Path tempFilePath, FileSystem fs, boolean overwrite); static void writeSchemaToFile(Schema schema, Path filePath, FileSystem fs, boolean overwrite, FsPermission perm); static void writeSchemaToFile(Schema schema, Path filePath, Path tempFilePath, FileSystem fs, boolean overwrite,
      FsPermission perm); static Schema getDirectorySchema(Path directory, FileSystem fs, boolean latest); static Schema getDirectorySchema(Path directory, Configuration conf, boolean latest); static Schema nullifyFieldsForSchemaMerge(Schema oldSchema, Schema newSchema); static Optional<Schema> removeUncomparableFields(Schema schema); static Schema switchName(Schema schema, String newName); static Schema switchNamespace(Schema schema, Map<String, String> namespaceOverride); static Path serializeAsPath(GenericRecord record, boolean includeFieldNames, boolean replacePathSeparators); static String sanitizeSchemaString(String schemaString); static GenericRecord slowDeserializeGenericRecord(byte[] serializedRecord, Schema schema); static Schema decorateRecordSchema(Schema inputSchema, @Nonnull List<Field> fieldList); static GenericRecord decorateRecord(GenericRecord inputRecord, @Nonnull Map<String, Object> fieldMap,
      Schema outputSchema); static GenericRecord overrideNameAndNamespace(GenericRecord input, String nameOverride, Optional<Map<String, String>> namespaceOverride); static Schema overrideNameAndNamespace(Schema input, String nameOverride, Optional<Map<String, String>> namespaceOverride); static boolean isSchemaRecursive(Schema schema, Optional<Logger> logger); static Pair<Schema, List<SchemaEntry>> dropRecursiveFields(Schema schema); static final String FIELD_LOCATION_DELIMITER; }