Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db00ffd

Browse files
committed
ORC-120. Add option to force positional matching of schema evolution.
Fixes apache#72 Signed-off-by: Owen O'Malley <[email protected]>
1 parent ee1ead7 commit db00ffd

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

java/core/src/java/org/apache/orc/OrcConf.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ public enum OrcConf {
137137
KRYO_SARG("orc.kryo.sarg", "orc.kryo.sarg", null,
138138
"The kryo and base64 encoded SearchArgument for predicate pushdown."),
139139
SARG_COLUMNS("orc.sarg.column.names", "org.sarg.column.names", null,
140-
"The list of column names for the SearchArgument.")
140+
"The list of column names for the SearchArgument."),
141+
FORCE_POSITIONAL_EVOLUTION("orc.force.positional.evolution",
142+
"orc.force.positional.evolution", false,
143+
"Require schema evolution to match the top level columns using position\n" +
144+
"rather than column names. This provides backwards compatibility with\n" +
145+
"Hive 2.1.")
141146
;
142147

143148
private final String attribute;

java/core/src/java/org/apache/orc/Reader.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public static class Options {
159159
private TypeDescription schema = null;
160160
private DataReader dataReader = null;
161161
private Boolean tolerateMissingSchema = null;
162+
private boolean forcePositionalEvolution;
162163

163164
public Options() {
164165
// PASS
@@ -168,6 +169,7 @@ public Options(Configuration conf) {
168169
useZeroCopy = OrcConf.USE_ZEROCOPY.getBoolean(conf);
169170
skipCorruptRecords = OrcConf.SKIP_CORRUPT_DATA.getBoolean(conf);
170171
tolerateMissingSchema = OrcConf.TOLERATE_MISSING_SCHEMA.getBoolean(conf);
172+
forcePositionalEvolution = OrcConf.FORCE_POSITIONAL_EVOLUTION.getBoolean(conf);
171173
}
172174

173175
/**
@@ -249,6 +251,17 @@ public Options tolerateMissingSchema(boolean value) {
249251
return this;
250252
}
251253

254+
/**
255+
* Set whether to force schema evolution to be positional instead of
256+
* based on the column names.
257+
* @param value force positional evolution
258+
* @return this
259+
*/
260+
public Options forcePositionalEvolution(boolean value) {
261+
this.forcePositionalEvolution = value;
262+
return this;
263+
}
264+
252265
public boolean[] getInclude() {
253266
return include;
254267
}
@@ -293,6 +306,10 @@ public DataReader getDataReader() {
293306
return dataReader;
294307
}
295308

309+
public boolean getForcePositionalEvolution() {
310+
return forcePositionalEvolution;
311+
}
312+
296313
public Options clone() {
297314
Options result = new Options();
298315
result.include = include;

java/core/src/java/org/apache/orc/impl/SchemaEvolution.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public SchemaEvolution(TypeDescription fileSchema,
9595
this.readerFileTypes =
9696
new TypeDescription[this.readerSchema.getMaximumId() + 1];
9797
int positionalLevels = 0;
98-
if (!hasColumnNames(isAcid? getBaseRow(fileSchema) : fileSchema)){
98+
if (options.getForcePositionalEvolution()) {
99+
positionalLevels = isAcid ? 2 : 1;
100+
buildConversion(fileSchema, this.readerSchema, positionalLevels);
101+
} else if (!hasColumnNames(isAcid? getBaseRow(fileSchema) : fileSchema)) {
99102
if (!this.fileSchema.equals(this.readerSchema)) {
100103
if (!allowMissingMetadata) {
101104
throw new RuntimeException("Found that schema metadata is missing"

java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,4 +1073,16 @@ public void testTypeConversion() throws IOException {
10731073
((LongColumnVector) batch.cols[2]).vector[r]);
10741074
}
10751075
}
1076+
1077+
@Test
1078+
public void testPositionalEvolution() throws IOException {
1079+
options.forcePositionalEvolution(true);
1080+
TypeDescription file = TypeDescription.fromString("struct<x:int,y:int,z:int>");
1081+
TypeDescription read = TypeDescription.fromString("struct<z:int,x:int,a:int,b:int>");
1082+
SchemaEvolution evo = new SchemaEvolution(file, read, options);
1083+
assertEquals(1, evo.getFileType(1).getId());
1084+
assertEquals(2, evo.getFileType(2).getId());
1085+
assertEquals(3, evo.getFileType(3).getId());
1086+
assertEquals(null, evo.getFileType(4));
1087+
}
10761088
}

0 commit comments

Comments
 (0)