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 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
20 changes: 11 additions & 9 deletions java/core/src/java/org/apache/orc/impl/SchemaEvolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class SchemaEvolution {
*/
private final boolean includeAcidColumns;

// indexed by reader column id
// indexed by file column id
private final boolean[] ppdSafeConversion;

// columns are indexed, not named between Reader & File schema
Expand Down Expand Up @@ -296,13 +296,13 @@ private boolean typesAreImplicitConversion(final TypeDescription fileType,

/**
* Check if column is safe for ppd evaluation
* @param colId reader column id
* @param fileColId file column id
* @return true if the specified column is safe for ppd evaluation else false
*/
public boolean isPPDSafeConversion(final int colId) {
public boolean isPPDSafeConversion(final int fileColId) {
if (hasConversion()) {
return !(colId < 0 || colId >= ppdSafeConversion.length) &&
ppdSafeConversion[colId];
return !(fileColId < 0 || fileColId >= ppdSafeConversion.length) &&
ppdSafeConversion[fileColId];
}

// when there is no schema evolution PPD is safe
Expand All @@ -314,9 +314,9 @@ private boolean[] populatePpdSafeConversion() {
return null;
}

boolean[] result = new boolean[readerSchema.getMaximumId() + 1];
boolean[] result = new boolean[fileSchema.getMaximumId() + 1];
boolean safePpd = validatePPDConversion(fileSchema, readerSchema);
result[readerSchema.getId()] = safePpd;
result[fileSchema.getId()] = safePpd;
return populatePpdSafeConversionForChildren(result,
readerSchema.getChildren());
}
Expand All @@ -337,12 +337,14 @@ private boolean[] populatePpdSafeConversionForChildren(
for (TypeDescription child : children) {
TypeDescription fileType = getFileType(child.getId());
safePpd = validatePPDConversion(fileType, child);
ppdSafeConversion[child.getId()] = safePpd;
if (fileType != null) {
ppdSafeConversion[fileType.getId()] = safePpd;
}
populatePpdSafeConversionForChildren(ppdSafeConversion,
child.getChildren());
}
}
return ppdSafeConversion;
return ppdSafeConversion;
}

private boolean validatePPDConversion(final TypeDescription fileType,
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