Skip to content

Commit

Permalink
ORC-562:Don't wrap readerSchema in acidSchema, if readerSchema is alr…
Browse files Browse the repository at this point in the history
…eady acid
  • Loading branch information
Laszlo Pinter committed Oct 30, 2019
1 parent db1fc71 commit 76afd23
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 @@ -2381,4 +2381,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() throws Exception {
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 76afd23

Please sign in to comment.