From 4ce709b4be36f9a508da8eba90657fb55b241301 Mon Sep 17 00:00:00 2001 From: Ruslan Altynnikov <> Date: Sat, 26 Aug 2023 15:07:50 +0200 Subject: [PATCH] Cover both reader and writer. --- .../org/apache/avro/tool/DataFileReadTool.java | 14 +++++++------- .../org/apache/avro/tool/DataFileWriteTool.java | 2 +- .../apache/avro/tool/TestDataFileRepairTool.java | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java index 626542f27ce..87ff94aa592 100644 --- a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java +++ b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java @@ -104,14 +104,14 @@ public int run(InputStream stdin, PrintStream out, PrintStream err, List return 0; } - private static Schema getSchema(String readerSchemaStr, String readerSchemaFile) throws IOException { + static Schema getSchema(String schemaStr, String schemaFile) throws IOException { Schema readerSchema = null; - if (readerSchemaFile != null) { - LOG.info("Reading schema from file'{}'", readerSchemaFile); - readerSchema = Util.parseSchemaFromFS(readerSchemaFile); - } else if (readerSchemaStr != null) { - LOG.info("Reading schema from string '{}'", readerSchemaStr); - readerSchema = new Schema.Parser().parse(readerSchemaStr); + if (schemaFile != null) { + LOG.info("Reading schema from file '{}'", schemaFile); + readerSchema = Util.parseSchemaFromFS(schemaFile); + } else if (schemaStr != null) { + LOG.info("Reading schema from string '{}'", schemaStr); + readerSchema = new Schema.Parser().parse(schemaStr); } return readerSchema; } diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java index b763a00bee4..4bf2f79a0b2 100644 --- a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java +++ b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java @@ -72,7 +72,7 @@ public int run(InputStream stdin, PrintStream out, PrintStream err, List p.printHelpOn(err); return 1; } - Schema schema = (schemafile != null) ? Util.parseSchemaFromFS(schemafile) : new Schema.Parser().parse(schemastr); + Schema schema = DataFileReadTool.getSchema(schemastr, schemafile); DatumReader reader = new GenericDatumReader<>(schema); diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java index b73fc964b2f..0e24b8915f0 100644 --- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java +++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java @@ -180,7 +180,7 @@ void repairAfterCorruptRecord() throws Exception { } private void checkFileContains(File repairedFile, String... lines) throws IOException { - DataFileReader r = new DataFileReader<>(repairedFile, new GenericDatumReader<>(SCHEMA)); + DataFileReader r = new DataFileReader<>(repairedFile, new GenericDatumReader<>(SCHEMA)); for (String line : lines) { assertEquals(line, r.next().toString()); }