From 904a2738dabe95ce9a8f5ca4a4b69355769c6ef3 Mon Sep 17 00:00:00 2001 From: sychen Date: Fri, 7 Apr 2023 18:22:17 +0800 Subject: [PATCH 1/2] empty field name --- .../java/org/apache/orc/impl/ParserUtils.java | 2 -- .../org/apache/orc/TestTypeDescription.java | 5 ++++ .../org/apache/orc/impl/TestWriterImpl.java | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/java/core/src/java/org/apache/orc/impl/ParserUtils.java b/java/core/src/java/org/apache/orc/impl/ParserUtils.java index 6491fb8bae..5b70e8f3f8 100644 --- a/java/core/src/java/org/apache/orc/impl/ParserUtils.java +++ b/java/core/src/java/org/apache/orc/impl/ParserUtils.java @@ -110,8 +110,6 @@ public static String parseName(ParserUtils.StringPosition source) { if (!closed) { source.position = start; throw new IllegalArgumentException("Unmatched quote at " + source); - } else if (buffer.length() == 0) { - throw new IllegalArgumentException("Empty quoted field name at " + source); } return buffer.toString(); } else { diff --git a/java/core/src/test/org/apache/orc/TestTypeDescription.java b/java/core/src/test/org/apache/orc/TestTypeDescription.java index 7dba23a9f9..0efb62ed72 100644 --- a/java/core/src/test/org/apache/orc/TestTypeDescription.java +++ b/java/core/src/test/org/apache/orc/TestTypeDescription.java @@ -523,4 +523,9 @@ public void testHashCode() { // Should not throw NPE TypeDescription.fromString("int").hashCode(); } + + @Test + public void testEmptyFieldName() { + TypeDescription.fromString("struct<``:string>"); + } } diff --git a/java/core/src/test/org/apache/orc/impl/TestWriterImpl.java b/java/core/src/test/org/apache/orc/impl/TestWriterImpl.java index e5d2616cc6..14204495b2 100644 --- a/java/core/src/test/org/apache/orc/impl/TestWriterImpl.java +++ b/java/core/src/test/org/apache/orc/impl/TestWriterImpl.java @@ -189,4 +189,30 @@ public void testCloseIsIdempotent() throws IOException { w.close(); w.close(); } + + @Test + public void testEmptyFieldName() throws Exception { + conf.set(OrcConf.OVERWRITE_OUTPUT_FILE.getAttribute(), "true"); + VectorizedRowBatch b = schema.createRowBatch(); + LongColumnVector f1 = (LongColumnVector) b.cols[0]; + TypeDescription schema = TypeDescription.fromString("struct<``:int>"); + Writer w = OrcFile.createWriter(testFilePath, OrcFile.writerOptions(conf).setSchema(schema)); + long value = 0; + long rowCount = 1024; + while (value < rowCount) { + f1.vector[b.size] = Long.MIN_VALUE + value; + value += 1; + b.size += 1; + if (b.size == b.getMaxSize()) { + w.addRowBatch(b); + b.reset(); + } + } + assertEquals(0, w.getStripes().size()); + w.close(); + assertEquals(1, w.getStripes().size()); + assertEquals(rowCount, w.getNumberOfRows()); + Reader r = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf)); + assertEquals(r.getStripes(), w.getStripes()); + } } From e0701ed9e5ae2a088582c9bdae7c9c18135208b6 Mon Sep 17 00:00:00 2001 From: sychen Date: Fri, 7 Apr 2023 19:13:27 +0800 Subject: [PATCH 2/2] fix UT --- .../core/src/test/org/apache/orc/TestTypeDescription.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/java/core/src/test/org/apache/orc/TestTypeDescription.java b/java/core/src/test/org/apache/orc/TestTypeDescription.java index 0efb62ed72..4947145f15 100644 --- a/java/core/src/test/org/apache/orc/TestTypeDescription.java +++ b/java/core/src/test/org/apache/orc/TestTypeDescription.java @@ -174,14 +174,6 @@ public void testQuotedField1() { assertTrue(e.getMessage().contains("Unmatched quote at 'struct<^`abc'")); } - @Test - public void testQuotedField2() { - IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { - TypeDescription.fromString("struct<``:int>"); - }); - assertTrue(e.getMessage().contains("Empty quoted field name at 'struct<``^:int>'")); - } - @Test public void testParserUnknownCategory() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {