-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36556][SQL] Add DSV2 filters #33803
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
Closed
Closed
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b8ba3a5
[SPARK-36556][SQL] Add DSV2 filters
huaxingao a7983da
fix style
huaxingao 71e9c17
remove extra blank line
huaxingao 14e3c69
address comments
huaxingao 5d08453
address comments
huaxingao 444f91b
change tests names
huaxingao 1a1a98b
add co-author
dbtsai f7f17c2
address comments
huaxingao 612edcf
change column type to Expression
huaxingao a56fbd0
STRING CONTAINS -> CONTAINS
huaxingao 31d41ef
make lint-java happy
huaxingao 2d86c4a
address comments
huaxingao d1b4ec1
remove extra white space and add interface FilterColExpr
huaxingao ed0b009
remove subtype FilterColExpr and use FieldReference for left side of …
huaxingao 14ac369
address comments
huaxingao 8c6f18c
Use UTF8String in Filters and implement equals/hashCode
huaxingao 3c200a5
address comments
huaxingao 1bdf241
fix java doc
huaxingao 091b91e
truncate string if there are more than 50 elements in the IN set
huaxingao b50cf33
make lint scala happy :)
huaxingao 997e171
divide filters into sub-categories
huaxingao 0c246f6
address comments
huaxingao 2cf8ebe
address comments
huaxingao d30b1a1
address comments
huaxingao 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
50 changes: 50 additions & 0 deletions
50
...catalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/AlwaysFalse.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * A filter that always evaluates to {@code false}. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public final class AlwaysFalse extends Filter { | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { return "FALSE"; } | ||
|
|
||
| @Override | ||
| public NamedReference[] references() { return EMPTY_REFERENCE; } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/AlwaysTrue.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * A filter that always evaluates to {@code true}. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public final class AlwaysTrue extends Filter { | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { return "TRUE"; } | ||
|
|
||
| @Override | ||
| public NamedReference[] references() { return EMPTY_REFERENCE; } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/And.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
|
|
||
| /** | ||
| * A filter that evaluates to {@code true} iff both {@code left} and {@code right} evaluate to | ||
| * {@code true}. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public final class And extends BinaryFilter { | ||
|
|
||
| public And(Filter left, Filter right) { | ||
| super(left, right); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("(%s) AND (%s)", left.describe(), right.describe()); | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
...yst/src/main/java/org/apache/spark/sql/connector/expressions/filter/BinaryComparison.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.Literal; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * Base class for {@link EqualNullSafe}, {@link EqualTo}, {@link GreaterThan}, | ||
| * {@link GreaterThanOrEqual}, {@link LessThan}, {@link LessThanOrEqual} | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| abstract class BinaryComparison extends Filter { | ||
| protected final NamedReference column; | ||
| protected final Literal<?> value; | ||
|
|
||
| protected BinaryComparison(NamedReference column, Literal<?> value) { | ||
| this.column = column; | ||
| this.value = value; | ||
| } | ||
|
|
||
| public NamedReference column() { return column; } | ||
| public Literal<?> value() { return value; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| BinaryComparison that = (BinaryComparison) o; | ||
| return Objects.equals(column, that.column) && Objects.equals(value, that.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(column, value); | ||
| } | ||
|
|
||
| @Override | ||
| public NamedReference[] references() { return new NamedReference[] { column }; } | ||
| } |
65 changes: 65 additions & 0 deletions
65
...atalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/BinaryFilter.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * Base class for {@link And}, {@link Or} | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| abstract class BinaryFilter extends Filter { | ||
| protected final Filter left; | ||
| protected final Filter right; | ||
|
|
||
| protected BinaryFilter(Filter left, Filter right) { | ||
| this.left = left; | ||
| this.right = right; | ||
| } | ||
|
|
||
| public Filter left() { return left; } | ||
| public Filter right() { return right; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| BinaryFilter and = (BinaryFilter) o; | ||
| return Objects.equals(left, and.left) && Objects.equals(right, and.right); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(left, right); | ||
| } | ||
|
|
||
| @Override | ||
| public NamedReference[] references() { | ||
| NamedReference[] refLeft = left.references(); | ||
| NamedReference[] refRight = right.references(); | ||
| NamedReference[] arr = new NamedReference[refLeft.length + refRight.length]; | ||
| System.arraycopy(refLeft, 0, arr, 0, refLeft.length); | ||
| System.arraycopy(refRight, 0, arr, refLeft.length, refRight.length); | ||
| return arr; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...talyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/EqualNullSafe.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.Literal; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * Performs equality comparison, similar to {@link EqualTo}. However, this differs from | ||
| * {@link EqualTo} in that it returns {@code true} (rather than NULL) if both inputs are NULL, | ||
| * and {@code false} (rather than NULL) if one of the input is NULL and the other is not NULL. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public final class EqualNullSafe extends BinaryComparison { | ||
|
|
||
| public EqualNullSafe(NamedReference column, Literal<?> value) { | ||
| super(column, value); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { return this.column.describe() + " <=> " + value.describe(); } | ||
| } |
39 changes: 39 additions & 0 deletions
39
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/EqualTo.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.Literal; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * A filter that evaluates to {@code true} iff the {@code column} evaluates to a value | ||
| * equal to {@code value}. | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public final class EqualTo extends BinaryComparison { | ||
|
|
||
| public EqualTo(NamedReference column, Literal<?> value) { | ||
| super(column, value); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { return column.describe() + " = " + value.describe(); } | ||
| } |
41 changes: 41 additions & 0 deletions
41
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/filter/Filter.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions.filter; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.expressions.Expression; | ||
| import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
|
||
| /** | ||
| * Filter base class | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public abstract class Filter implements Expression { | ||
|
|
||
| protected static final NamedReference[] EMPTY_REFERENCE = new NamedReference[0]; | ||
|
|
||
| /** | ||
| * Returns list of columns that are referenced by this filter. | ||
| */ | ||
| public abstract NamedReference[] references(); | ||
|
|
||
| @Override | ||
| public String describe() { return this.toString(); } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.