Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-1403: ORC supports reading empty field name #1458

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions java/core/src/java/org/apache/orc/impl/ParserUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions java/core/src/test/org/apache/orc/TestTypeDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>'"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test coverage means it's a feature before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably prefer to just ignore it instead of removing it.

}

@Test
public void testParserUnknownCategory() {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
Expand Down Expand Up @@ -523,4 +515,9 @@ public void testHashCode() {
// Should not throw NPE
TypeDescription.fromString("int").hashCode();
}

@Test
public void testEmptyFieldName() {
TypeDescription.fromString("struct<``:string>");
}
}
26 changes: 26 additions & 0 deletions java/core/src/test/org/apache/orc/impl/TestWriterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}