-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
PARQUET-34: Extend Contains support to all ColumnFilterPredicate types #1370
Merged
gszadovszky
merged 2 commits into
apache:master
from
clairemcginty:parquet-34-extended-support
Jun 14, 2024
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,13 +115,13 @@ public void run() throws IOException { | |
|
||
addVisitBegin("In"); | ||
for (TypeInfo info : TYPES) { | ||
addInNotInCase(info, true); | ||
addInNotInCase(info, true, false); | ||
} | ||
addVisitEnd(); | ||
|
||
addVisitBegin("NotIn"); | ||
for (TypeInfo info : TYPES) { | ||
addInNotInCase(info, false); | ||
addInNotInCase(info, false, false); | ||
} | ||
addVisitEnd(); | ||
|
||
|
@@ -133,25 +133,25 @@ public void run() throws IOException { | |
|
||
addVisitBegin("Lt"); | ||
for (TypeInfo info : TYPES) { | ||
addInequalityCase(info, "<"); | ||
addInequalityCase(info, "<", false); | ||
} | ||
addVisitEnd(); | ||
|
||
addVisitBegin("LtEq"); | ||
for (TypeInfo info : TYPES) { | ||
addInequalityCase(info, "<="); | ||
addInequalityCase(info, "<=", false); | ||
} | ||
addVisitEnd(); | ||
|
||
addVisitBegin("Gt"); | ||
for (TypeInfo info : TYPES) { | ||
addInequalityCase(info, ">"); | ||
addInequalityCase(info, ">", false); | ||
} | ||
addVisitEnd(); | ||
|
||
addVisitBegin("GtEq"); | ||
for (TypeInfo info : TYPES) { | ||
addInequalityCase(info, ">="); | ||
addInequalityCase(info, ">=", false); | ||
} | ||
addVisitEnd(); | ||
|
||
|
@@ -245,7 +245,7 @@ private void addEqNotEqCase(TypeInfo info, boolean isEq, boolean expectMultipleR | |
add(" }\n\n"); | ||
} | ||
|
||
private void addInequalityCase(TypeInfo info, String op) throws IOException { | ||
private void addInequalityCase(TypeInfo info, String op, boolean expectMultipleResults) throws IOException { | ||
if (!info.supportsInequality) { | ||
add(" if (clazz.equals(" + info.className + ".class)) {\n"); | ||
add(" throw new IllegalArgumentException(\"Operator " + op + " not supported for " + info.className | ||
|
@@ -268,12 +268,17 @@ private void addInequalityCase(TypeInfo info, String op) throws IOException { | |
+ " public void update(" | ||
+ info.primitiveName + " value) {\n"); | ||
|
||
add(" setResult(comparator.compare(value, target) " + op + " 0);\n"); | ||
if (!expectMultipleResults) { | ||
add(" setResult(comparator.compare(value, target) " + op + " 0);\n"); | ||
} else { | ||
add(" if (!isKnown() && comparator.compare(value, target) " + op + " 0)" | ||
+ " { setResult(true); }\n"); | ||
} | ||
|
||
add(" }\n" + " };\n" + " }\n\n"); | ||
} | ||
|
||
private void addInNotInCase(TypeInfo info, boolean isEq) throws IOException { | ||
private void addInNotInCase(TypeInfo info, boolean isEq, boolean expectMultipleResults) throws IOException { | ||
add(" if (clazz.equals(" + info.className + ".class)) {\n" + " if (pred.getValues().contains(null)) {\n" | ||
+ " valueInspector = new ValueInspector() {\n" | ||
+ " @Override\n" | ||
|
@@ -299,22 +304,23 @@ private void addInNotInCase(TypeInfo info, boolean isEq) throws IOException { | |
+ "\n" | ||
+ " @Override\n" | ||
+ " public void update(" | ||
+ info.primitiveName + " value) {\n" + " boolean set = false;\n"); | ||
+ info.primitiveName + " value) {\n"); | ||
|
||
if (expectMultipleResults) { | ||
add(" if (isKnown()) return;\n"); | ||
} | ||
add(" for (" + info.primitiveName + " i : target) {\n"); | ||
|
||
add(" if(" + compareEquality("value", "i", isEq) + ") {\n"); | ||
|
||
add(" setResult(true);\n"); | ||
|
||
add(" set = true;\n"); | ||
|
||
add(" break;\n"); | ||
add(" setResult(true);\n return;\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simplified the existing ValueInspector logic a bit for @Override
public void update(int value) {
boolean set = false;
for (int i : target) {
if(comparator.compare(value, i) != 0) {
setResult(true);
set = true;
break;
}
}
if (!set) setResult(false);
}
};
} Now it's: @Override
public void update(int value) {
for (int i : target) {
if(comparator.compare(value, i) == 0 ) {
setResult(true);
return;
}
}
setResult(false);
} |
||
|
||
add(" }\n"); | ||
|
||
add(" }\n"); | ||
add(" if (!set) setResult(false);\n"); | ||
if (!expectMultipleResults) { | ||
add(" setResult(false);\n"); | ||
} | ||
add(" }\n"); | ||
|
||
add(" };\n" + " }\n" + " }\n\n"); | ||
|
@@ -338,33 +344,45 @@ private void addContainsUpdateCase(TypeInfo info, String... inspectors) throws I | |
add(" checkSatisfied();\n" + " }\n"); | ||
} | ||
|
||
private void addContainsInspectorVisitor(String op, boolean isSupported) throws IOException { | ||
if (isSupported) { | ||
add(" @Override\n" | ||
+ " public <T extends Comparable<T>> ValueInspector visit(" + op + "<T> pred) {\n" | ||
+ " ColumnPath columnPath = pred.getColumn().getColumnPath();\n" | ||
+ " Class<T> clazz = pred.getColumn().getColumnType();\n" | ||
+ " ValueInspector valueInspector = null;\n"); | ||
|
||
for (TypeInfo info : TYPES) { | ||
switch (op) { | ||
case "Eq": | ||
addEqNotEqCase(info, true, true); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException("Op " + op + " not implemented for Contains filter"); | ||
} | ||
} | ||
private void addContainsInspectorVisitor(String op) throws IOException { | ||
add(" @Override\n" | ||
+ " public <T extends Comparable<T>> ValueInspector visit(" + op + "<T> pred) {\n" | ||
+ " ColumnPath columnPath = pred.getColumn().getColumnPath();\n" | ||
+ " Class<T> clazz = pred.getColumn().getColumnType();\n" | ||
+ " ValueInspector valueInspector = null;\n"); | ||
|
||
add(" return valueInspector;" + " }\n"); | ||
} else { | ||
add(" @Override\n" | ||
+ " public <T extends Comparable<T>> ValueInspector visit(" + op + "<T> pred) {\n" | ||
+ " throw new UnsupportedOperationException(\"" + op | ||
+ " not supported for Contains predicate\");\n" | ||
+ " }\n" | ||
+ "\n"); | ||
for (TypeInfo info : TYPES) { | ||
switch (op) { | ||
case "Eq": | ||
addEqNotEqCase(info, true, true); | ||
break; | ||
case "NotEq": | ||
addEqNotEqCase(info, false, true); | ||
break; | ||
case "Lt": | ||
addInequalityCase(info, "<", true); | ||
break; | ||
case "LtEq": | ||
addInequalityCase(info, "<=", true); | ||
break; | ||
case "Gt": | ||
addInequalityCase(info, ">", true); | ||
break; | ||
case "GtEq": | ||
addInequalityCase(info, ">=", true); | ||
break; | ||
case "In": | ||
addInNotInCase(info, true, true); | ||
break; | ||
case "NotIn": | ||
addInNotInCase(info, false, true); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException("Op " + op + " not implemented for Contains filter"); | ||
} | ||
} | ||
|
||
add(" return valueInspector;" + " }\n"); | ||
} | ||
|
||
private void addContainsBegin() throws IOException { | ||
|
@@ -476,12 +494,14 @@ private void addContainsBegin() throws IOException { | |
+ " );\n" | ||
+ " }\n"); | ||
|
||
addContainsInspectorVisitor("Eq", true); | ||
addContainsInspectorVisitor("NotEq", false); | ||
addContainsInspectorVisitor("Lt", false); | ||
addContainsInspectorVisitor("LtEq", false); | ||
addContainsInspectorVisitor("Gt", false); | ||
addContainsInspectorVisitor("GtEq", false); | ||
addContainsInspectorVisitor("Eq"); | ||
addContainsInspectorVisitor("NotEq"); | ||
addContainsInspectorVisitor("Lt"); | ||
addContainsInspectorVisitor("LtEq"); | ||
addContainsInspectorVisitor("Gt"); | ||
addContainsInspectorVisitor("GtEq"); | ||
addContainsInspectorVisitor("In"); | ||
addContainsInspectorVisitor("NotIn"); | ||
|
||
add(" @Override\n" | ||
+ " public ValueInspector visit(Operators.And pred) {\n" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I know it means the same logically, but I think it is more readable to wrap in a parenthesis since the
instanceof
and the related cast are tightly related.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense! updated