Skip to content

Commit

Permalink
CDPD-5851: ORC-562:Don't wrap readerSchema in acidSchema, if readerSc…
Browse files Browse the repository at this point in the history
…hema is already acid

Fixes apache#442

Signed-off-by: Owen O'Malley <omalley@apache.org>
(cherry picked from commit 2db32a8)
Change-Id: Icfc548d19b0d0cc62b3e0e90ea164c791ece0a94
  • Loading branch information
Laszlo Pinter committed Nov 12, 2019
1 parent 1902208 commit 5786913
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions java/core/src/java/org/apache/orc/impl/SchemaEvolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ public SchemaEvolution(TypeDescription fileSchema,
this.isOnlyImplicitConversion = true;
this.fileSchema = fileSchema;
this.isAcid = checkAcidSchema(fileSchema);
boolean readerSchemaIsAcid = readerSchema == null ? false : checkAcidSchema(readerSchema);
this.includeAcidColumns = options.getIncludeAcidColumns();
this.readerColumnOffset = isAcid ? acidEventFieldNames.size() : 0;
this.readerColumnOffset = isAcid && !readerSchemaIsAcid ? acidEventFieldNames.size() : 0;
if (readerSchema != null) {
if (isAcid) {
if (isAcid && !readerSchemaIsAcid) {
this.readerSchema = createEventSchema(readerSchema);
} else {
this.readerSchema = readerSchema;
Expand Down
20 changes: 20 additions & 0 deletions java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -1668,4 +1668,24 @@ public void testCheckAcidSchema() {
assertTrue("Schema (" + ccSchema +") was found to be non-acid ", evoCc.isAcid());
assertTrue("Schema (" + lcSchema +") was found to be non-acid ", evoLc.isAcid());
}

@Test
public void testAcidReaderSchema() {
String acidSchema = "struct<operation:int,originalTransaction:bigint,bucket:int," +
"rowId:bigint,currentTransaction:bigint," +
"row:struct<a:int,b:int>>";

TypeDescription fileSchema = TypeDescription.fromString(acidSchema);
TypeDescription readerSchema = TypeDescription.fromString(acidSchema);
SchemaEvolution schemaEvolution = new SchemaEvolution(fileSchema, readerSchema, options);

assertEquals(String.format("Reader schema %s is not acid", schemaEvolution.getReaderSchema().toString()),
acidSchema, schemaEvolution.getReaderSchema().toString());

String notAcidSchema ="struct<a:int,b:int>";
readerSchema = TypeDescription.fromString(notAcidSchema);
schemaEvolution = new SchemaEvolution(fileSchema, readerSchema, options);
assertEquals(String.format("Reader schema %s is not acid", schemaEvolution.getReaderSchema().toString()),
acidSchema, schemaEvolution.getReaderSchema().toString());
}
}

0 comments on commit 5786913

Please sign in to comment.