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
11 changes: 10 additions & 1 deletion java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ public class RecordReaderImpl implements RecordReader {
static int findColumns(SchemaEvolution evolution,
String columnName) {
try {
return evolution.getFileSchema().findSubtype(columnName).getId();
final TypeDescription targetSchema;
if (evolution.getPositionalColumns()) {
targetSchema = evolution.getReaderBaseSchema();
} else {
targetSchema = evolution.getFileSchema();
}
return targetSchema.findSubtype(columnName).getId();
} catch (IllegalArgumentException e) {
if (LOG.isDebugEnabled()){
LOG.debug("{}", e.getMessage());
}
return -1;
}
}
Expand Down
15 changes: 13 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 @@ -59,6 +59,9 @@ public class SchemaEvolution {
// indexed by reader column id
private final boolean[] ppdSafeConversion;

// columns are indexed, not named between Reader & File schema
private final boolean positionalColumns;

private static final Logger LOG =
LoggerFactory.getLogger(SchemaEvolution.class);
private static final Pattern missingMetadataPattern =
Expand All @@ -82,8 +85,8 @@ public SchemaEvolution(TypeDescription fileSchema,
this.hasConversion = false;
this.isOnlyImplicitConversion = true;
this.fileSchema = fileSchema;
isAcid = checkAcidSchema(fileSchema);
includeAcidColumns = options.getIncludeAcidColumns();
this.isAcid = checkAcidSchema(fileSchema);
this.includeAcidColumns = options.getIncludeAcidColumns();
this.readerColumnOffset = isAcid ? acidEventFieldNames.size() : 0;
if (readerSchema != null) {
if (isAcid) {
Expand Down Expand Up @@ -134,6 +137,7 @@ public SchemaEvolution(TypeDescription fileSchema,
}
buildIdentityConversion(this.readerSchema);
}
this.positionalColumns = options.getForcePositionalEvolution();
this.ppdSafeConversion = populatePpdSafeConversion();
}

Expand Down Expand Up @@ -236,6 +240,13 @@ public boolean[] getReaderIncluded() {
public boolean[] getFileIncluded() {
return fileIncluded;
}

/**
* Get whether the columns are handled via position or name
*/
public boolean getPositionalColumns() {
return this.positionalColumns;
}

/**
* Determine if there is implicit conversion from a file to reader type.
Expand Down
28 changes: 26 additions & 2 deletions java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.apache.orc.util.BloomFilter;
import org.apache.orc.DataReader;
import org.apache.orc.RecordReader;
import org.apache.orc.TestVectorOrcFile;
import org.apache.orc.TypeDescription;
import org.apache.orc.Writer;
import org.apache.orc.impl.RecordReaderImpl.Location;
Expand All @@ -84,8 +85,6 @@
import org.apache.orc.util.BloomFilterIO;
import org.apache.orc.util.BloomFilterUtf8;
import org.junit.Test;
import org.mockito.MockSettings;
import org.mockito.Mockito;

public class TestRecordReaderImpl {

Expand All @@ -102,6 +101,31 @@ public void testFindColumn() throws Exception {
assertEquals(3, RecordReaderImpl.findColumns(evo, "e"));
}

@Test
public void testForcePositionalEvolution() throws Exception {
Configuration conf = new Configuration();

Path oldFilePath = new Path(TestVectorOrcFile.getFileFromClasspath("orc-file-11-format.orc"));
Reader reader = OrcFile.createReader(oldFilePath,
OrcFile.readerOptions(conf).filesystem(FileSystem.getLocal(conf)));

TypeDescription fileSchema =
TypeDescription.fromString("struct<col0:boolean,col1:tinyint,col2:smallint,"
+ "col3:int,col4:bigint,col5:float,col6:double,col7:"
+ "binary,col8:string,col9:struct<list:array<struct<int1:int,"
+ "string1:string>>>,col10:array<struct<int1:int,string1:string>>,"
+ "col11:map<string,struct<int1:int,string1:string>>,col12:timestamp,"
+ "col13:decimal(38,10)>");

SchemaEvolution evo = new SchemaEvolution(fileSchema, reader.getSchema(),
new Reader.Options(conf).forcePositionalEvolution(true));
assertEquals(4, RecordReaderImpl.findColumns(evo, "int1"));

evo = new SchemaEvolution(fileSchema, reader.getSchema(),
new Reader.Options(conf).forcePositionalEvolution(false));
assertEquals(-1, RecordReaderImpl.findColumns(evo, "int1"));
}

/**
* Create a predicate leaf. This is used by another test.
*/
Expand Down