Skip to content
Closed
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
4 changes: 4 additions & 0 deletions java/core/src/java/org/apache/orc/OrcConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public enum OrcConf {
"Require schema evolution to match the top level columns using position\n" +
"rather than column names. This provides backwards compatibility with\n" +
"Hive 2.1."),
FORCE_POSITIONAL_EVOLUTION_LEVEL("orc.force.positional.evolution.level",
"orc.force.positional.evolution.level", 1,
"Require schema evolution to match the the defined no. of level columns using position\n" +
"rather than column names. This provides backwards compatibility with Hive 2.1."),
ROWS_BETWEEN_CHECKS("orc.rows.between.memory.checks", "orc.rows.between.memory.checks", 5000,
"How often should MemoryManager check the memory sizes? Measured in rows\n" +
"added to all of the writers. Valid range is [1,10000] and is primarily meant for" +
Expand Down
18 changes: 18 additions & 0 deletions java/core/src/java/org/apache/orc/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Options implements Cloneable {
private boolean[] include;
private long offset = 0;
private long length = Long.MAX_VALUE;
private int positionalEvolutionLevel;
private SearchArgument sarg = null;
private String[] columnNames = null;
private Boolean useZeroCopy = null;
Expand All @@ -203,6 +204,7 @@ public Options(Configuration conf) {
skipCorruptRecords = OrcConf.SKIP_CORRUPT_DATA.getBoolean(conf);
tolerateMissingSchema = OrcConf.TOLERATE_MISSING_SCHEMA.getBoolean(conf);
forcePositionalEvolution = OrcConf.FORCE_POSITIONAL_EVOLUTION.getBoolean(conf);
positionalEvolutionLevel = OrcConf.FORCE_POSITIONAL_EVOLUTION_LEVEL.getInt(conf);
isSchemaEvolutionCaseAware =
OrcConf.IS_SCHEMA_EVOLUTION_CASE_SENSITIVE.getBoolean(conf);
}
Expand Down Expand Up @@ -297,6 +299,18 @@ public Options forcePositionalEvolution(boolean value) {
return this;
}

/**
* Set no. of levels to force schema evolution to be positional instead of
* based on the column names.
* @param value force positional evolution
* @return this
*/
public Options positionalEvolutionLevel(int value) {
this.positionalEvolutionLevel = value;
return this;
}


/**
* Set boolean flag to determine if the comparision of field names in schema
* evolution is case sensitive
Expand Down Expand Up @@ -364,6 +378,10 @@ public boolean getForcePositionalEvolution() {
return forcePositionalEvolution;
}

public int getPositionalEvolutionLevel() {
return positionalEvolutionLevel;
}

public boolean getIsSchemaEvolutionCaseAware() {
return isSchemaEvolutionCaseAware;
}
Expand Down
4 changes: 2 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 @@ -106,7 +106,7 @@ public SchemaEvolution(TypeDescription fileSchema,
new TypeDescription[this.readerSchema.getMaximumId() + 1];
int positionalLevels = 0;
if (options.getForcePositionalEvolution()) {
positionalLevels = isAcid ? 2 : 1;
positionalLevels = isAcid ? 2 : options.getPositionalEvolutionLevel();
buildConversion(fileSchema, this.readerSchema, positionalLevels);
} else if (!hasColumnNames(isAcid? getBaseRow(fileSchema) : fileSchema)) {
if (!this.fileSchema.equals(this.readerSchema)) {
Expand All @@ -120,7 +120,7 @@ public SchemaEvolution(TypeDescription fileSchema,
+ " caused by a writer earlier than HIVE-4243. The reader will"
+ " reconcile schemas based on index. File type: " +
this.fileSchema + ", reader type: " + this.readerSchema);
positionalLevels = isAcid ? 2 : 1;
positionalLevels = isAcid ? 2 : options.getPositionalEvolutionLevel();
}
}
}
Expand Down
13 changes: 13 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 @@ -1719,6 +1719,19 @@ public void testPositionalEvolution() throws IOException {
assertEquals(null, evo.getFileType(4));
}

@Test
public void testPositionalEvolutionLevel() throws IOException {
options.forcePositionalEvolution(true);
options.positionalEvolutionLevel(2);
TypeDescription file = TypeDescription.fromString("struct<a:int,b:struct<y:int,y:int>>");
TypeDescription read = TypeDescription.fromString("struct<a:int,b:struct<y:int,y:int>>");
SchemaEvolution evo = new SchemaEvolution(file, read, options);
assertEquals(1, evo.getFileType(1).getId());
assertEquals(2, evo.getFileType(2).getId());
assertEquals(3, evo.getFileType(3).getId());
assertEquals(4, evo.getFileType(4).getId());
}

// These are helper methods that pull some of the common code into one
// place.

Expand Down