Skip to content

Commit

Permalink
ORC-1121: Fix column coversion check bug which causes column filters …
Browse files Browse the repository at this point in the history
…don't work (#1055)

### What changes were proposed in this pull request?

Add a map in `SchemaEvolution` which contains the mapping from the file column id to the reader column id, the mapping will be used in `SchemaEvolution.isPPDSafeConversion()`

### Why are the changes needed?

`RecordReaderImpl.pickRowGroups()`  calls `SchemaEvolution.isPPDSafeConversion()` with file column id rather than reader column id which is required, this causes column filters can't work effectively and recordReader can't skip row groups which are not matched, so we need find the corresponding reader column id via file column id to ensure `SchemaEvolution.isPPDSafeConversion()` can work correctly.

### How was this patch tested?

UT

(cherry picked from commit e22f537)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
PengleiShi authored and dongjoon-hyun committed Mar 8, 2022
1 parent d70dc54 commit 1593a9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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

0 comments on commit 1593a9e

Please sign in to comment.