Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-1121: Fix column coversion check bug which causes column filters don't work #1055

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions java/core/src/java/org/apache/orc/impl/SchemaEvolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
public class SchemaEvolution {
// indexed by reader column id
private final TypeDescription[] readerFileTypes;
// key: file column id, value: reader column id
private final Map<Integer, Integer> typeIdsMap = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use an array just like readerFileTypes.

BTW, for readability, I'd suggest renaming readerFileTypes to readerIdToFileTypes and renaming typeIdsMap to fileIdToReaderIds.

// indexed by reader column id
private final boolean[] readerIncluded;
// the offset to the first column id ignoring any ACID columns
Expand Down Expand Up @@ -126,6 +128,11 @@ public SchemaEvolution(TypeDescription fileSchema,
}
}
buildConversion(fileSchema, this.readerSchema, positionalLevels);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this File to Reader id mapping should be part of buildConversion

for (int i = 0; i < readerFileTypes.length; i++) {
if (readerFileTypes[i] != null) {
this.typeIdsMap.put(readerFileTypes[i].getId(), i);
}
}
this.positionalColumns = options.getForcePositionalEvolution();
this.ppdSafeConversion = populatePpdSafeConversion();
}
Expand Down Expand Up @@ -296,13 +303,13 @@ private boolean typesAreImplicitConversion(final TypeDescription fileType,

/**
* Check if column is safe for ppd evaluation
* @param colId reader column id
* @param colId file column id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, can we also rename colId to fileColId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* @return true if the specified column is safe for ppd evaluation else false
*/
public boolean isPPDSafeConversion(final int colId) {
if (hasConversion()) {
return !(colId < 0 || colId >= ppdSafeConversion.length) &&
ppdSafeConversion[colId];
Integer readerTypeId = typeIdsMap.get(colId);
return readerTypeId != null && ppdSafeConversion[readerTypeId];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use ppdSafeConversion[] in this method, I think changing ppdSafeConversion[] to be indexed by file column ids is a simpler solution, i.e. modifying the assignment in populatePpdSafeConversion and populatePpdSafeConversionForChildren to use file ids.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use ppdSafeConversion[] in this method, I think changing ppdSafeConversion[] to be indexed by file column ids is a simpler solution, i.e. modifying the assignment in populatePpdSafeConversion and populatePpdSafeConversionForChildren to use file ids.

This looks better. Done

}

// when there is no schema evolution PPD is safe
Expand Down
10 changes: 10 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 @@ -853,6 +853,16 @@ public void testSafePpdEvaluation() throws IOException {
assertTrue(both1.isPPDSafeConversion(2));
assertTrue(both1.isPPDSafeConversion(3));
assertFalse(both1.isPPDSafeConversion(4));

// column pruning
readerStruct1 = TypeDescription.createStruct()
.addField("f2", TypeDescription.createString());
both1 = new SchemaEvolution(fileStruct1, readerStruct1, options);
assertTrue(both1.hasConversion());
assertFalse(both1.isPPDSafeConversion(0));
assertFalse(both1.isPPDSafeConversion(1));
assertTrue(both1.isPPDSafeConversion(2));
assertFalse(both1.isPPDSafeConversion(3));
}

@Test
Expand Down