Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bf0eb2a
[SPARK-38432][SQL] Reactor framework so as JDBC dialect could compile…
beliefer Mar 8, 2022
3b7151d
Update code
beliefer Mar 8, 2022
e2414cd
Update coe
beliefer Mar 9, 2022
bb6c66f
Update code
beliefer Mar 9, 2022
7336d67
Update code
beliefer Mar 10, 2022
8d33793
Update code
beliefer Mar 10, 2022
12518a7
Update code
beliefer Mar 10, 2022
a4855c9
Update code
beliefer Mar 10, 2022
143d935
Update code
beliefer Mar 10, 2022
d0128eb
Update code
beliefer Mar 10, 2022
8c523cd
Update code
beliefer Mar 10, 2022
f1997bc
Update code
beliefer Mar 12, 2022
d7fe80f
Update code
beliefer Mar 12, 2022
0fae987
Update code
beliefer Mar 12, 2022
0d657e7
Update code
beliefer Mar 12, 2022
b06097d
Update code
beliefer Mar 12, 2022
cec5041
Update code
beliefer Mar 13, 2022
0b23738
Update code
beliefer Mar 14, 2022
872a0ba
Update code
beliefer Mar 14, 2022
f377ab3
Update code
beliefer Mar 14, 2022
968d525
Update code
beliefer Mar 14, 2022
d925cfb
Update code
beliefer Mar 14, 2022
edb90f3
Update code
beliefer Mar 15, 2022
d0f61b4
Update code
beliefer Mar 15, 2022
0cb1a5f
Update code
beliefer Mar 15, 2022
2c294fa
Update code
beliefer Mar 15, 2022
806e875
Update code
beliefer Mar 17, 2022
875037e
Update code
beliefer Mar 17, 2022
deba3ba
Update code
beliefer Mar 17, 2022
4b834af
Update code
beliefer Mar 17, 2022
082e370
Update code
beliefer Mar 17, 2022
867042d
Update code
beliefer Mar 18, 2022
82dda6d
Update code
beliefer Mar 18, 2022
cc94d95
Update code
beliefer Mar 18, 2022
b5d2721
Update code
beliefer Mar 18, 2022
ab5fcc0
Update code
beliefer Mar 19, 2022
406ca9a
Update code
beliefer Mar 19, 2022
fe185b7
Update code
beliefer Mar 21, 2022
1396a4e
Update code
beliefer Mar 22, 2022
fc6039f
Update code
beliefer Mar 22, 2022
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
2 changes: 2 additions & 0 deletions project/MimaExcludes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ object MimaExcludes {
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.spark.sql.util.ExecutionListenerManager.this"),
// [SPARK-37786][SQL] StreamingQueryListener support use SQLConf.get to get corresponding SessionState's SQLConf
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.spark.sql.streaming.StreamingQueryManager.this"),
// [SPARK-38432][SQL] Reactor framework so as JDBC dialect could compile filter by self way
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.sources.Filter.toV2"),

// [SPARK-37600][BUILD] Upgrade to Hadoop 3.3.2
ProblemFilters.exclude[MissingClassProblem]("org.apache.hadoop.shaded.net.jpountz.lz4.LZ4Compressor"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.connector.expressions;

import java.util.Arrays;

import org.apache.spark.annotation.Evolving;

/**
Expand All @@ -26,8 +28,23 @@
*/
@Evolving
public interface Expression {
Expression[] EMPTY_EXPRESSION = new Expression[0];

/**
* Format the expression as a human readable SQL-like string.
*/
default String describe() { return this.toString(); }

/**
* Returns an array of the children of this node. Children should not change.
*/
Expression[] children();

/**
* List of fields or columns that are referenced by this expression.
*/
default NamedReference[] references() {
return Arrays.stream(children()).map(e -> e.references())
.flatMap(Arrays::stream).distinct().toArray(NamedReference[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,19 @@

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

import org.apache.spark.annotation.Evolving;
import org.apache.spark.sql.connector.expressions.filter.Predicate;
import org.apache.spark.sql.connector.util.V2ExpressionSQLBuilder;

// scalastyle:off line.size.limit
/**
* The general representation of SQL scalar expressions, which contains the upper-cased
* expression name and all the children expressions.
* expression name and all the children expressions. Please also see {@link Predicate}
* for the supported predicate expressions.
* <p>
* The currently supported SQL scalar expressions:
* <ol>
* <li>Name: <code>IS_NULL</code>
* <ul>
* <li>SQL semantic: <code>expr IS NULL</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>IS_NOT_NULL</code>
* <ul>
* <li>SQL semantic: <code>expr IS NOT NULL</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>=</code>
* <ul>
* <li>SQL semantic: <code>expr1 = expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>!=</code>
* <ul>
* <li>SQL semantic: <code>expr1 != expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&lt;&gt;</code>
* <ul>
* <li>SQL semantic: <code>expr1 &lt;&gt; expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&lt;=&gt;</code>
* <ul>
* <li>SQL semantic: <code>expr1 &lt;=&gt; expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&lt;</code>
* <ul>
* <li>SQL semantic: <code>expr1 &lt; expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&lt;=</code>
* <ul>
* <li>SQL semantic: <code>expr1 &lt;= expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&gt;</code>
* <ul>
* <li>SQL semantic: <code>expr1 &gt; expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>&gt;=</code>
* <ul>
* <li>SQL semantic: <code>expr1 &gt;= expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>+</code>
* <ul>
* <li>SQL semantic: <code>expr1 + expr2</code></li>
Expand Down Expand Up @@ -138,24 +80,6 @@
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>AND</code>
* <ul>
* <li>SQL semantic: <code>expr1 AND expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>OR</code>
* <ul>
* <li>SQL semantic: <code>expr1 OR expr2</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>NOT</code>
* <ul>
* <li>SQL semantic: <code>NOT expr</code></li>
* <li>Since version: 3.3.0</li>
* </ul>
* </li>
* <li>Name: <code>~</code>
* <ul>
* <li>SQL semantic: <code>~ expr</code></li>
Expand All @@ -176,7 +100,6 @@
*
* @since 3.3.0
*/
// scalastyle:on line.size.limit
@Evolving
public class GeneralScalarExpression implements Expression, Serializable {
private String name;
Expand All @@ -190,6 +113,19 @@ public GeneralScalarExpression(String name, Expression[] children) {
public String name() { return name; }
public Expression[] children() { return children; }

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GeneralScalarExpression that = (GeneralScalarExpression) o;
return Objects.equals(name, that.name) && Arrays.equals(children, that.children);
}

@Override
public int hashCode() {
return Objects.hash(name, children);
Copy link

Choose a reason for hiding this comment

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

@beliefer , should it be Arrays.hashCode(children)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arrays.hashCode(children) only get part hash code from children. Objects.hash(name, children) considers the name too.

Copy link

@asiunov asiunov Jun 9, 2023

Choose a reason for hiding this comment

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

Sorry, I meant return Objects.hash(name, Arrays.hashCode(children));. Otherwise hash of array children is just the array reference's hash, i.e. it does not consider elements' hashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got it. Thank you for the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix it. Thanks.

}

@Override
public String toString() {
V2ExpressionSQLBuilder builder = new V2ExpressionSQLBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ public interface Literal<T> extends Expression {
* Returns the SQL data type of the literal.
*/
DataType dataType();

@Override
default Expression[] children() { return EMPTY_EXPRESSION; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ public interface NamedReference extends Expression {
* Each string in the returned array represents a field name.
*/
String[] fieldNames();

@Override
default Expression[] children() { return EMPTY_EXPRESSION; }

@Override
default NamedReference[] references() { return new NamedReference[]{ this }; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ public interface SortOrder extends Expression {
* Returns the null ordering.
*/
NullOrdering nullOrdering();

@Override
default Expression[] children() { return new Expression[]{ expression() }; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ public interface Transform extends Expression {
*/
String name();

/**
* Returns all field references in the transform arguments.
*/
NamedReference[] references();

/**
* Returns the arguments passed to the transform function.
*/
Expression[] arguments();

@Override
default Expression[] children() { return arguments(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public Avg(Expression column, boolean isDistinct) {
public Expression column() { return input; }
public boolean isDistinct() { return isDistinct; }

@Override
public Expression[] children() { return new Expression[]{ input }; }

@Override
public String toString() {
if (isDistinct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public Count(Expression column, boolean isDistinct) {
public Expression column() { return input; }
public boolean isDistinct() { return isDistinct; }

@Override
public Expression[] children() { return new Expression[]{ input }; }

@Override
public String toString() {
if (isDistinct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.connector.expressions.aggregate;

import org.apache.spark.annotation.Evolving;
import org.apache.spark.sql.connector.expressions.Expression;

/**
* An aggregate function that returns the number of rows in a group.
Expand All @@ -30,6 +31,9 @@ public final class CountStar implements AggregateFunc {
public CountStar() {
}

@Override
public Expression[] children() { return EMPTY_EXPRESSION; }

@Override
public String toString() { return "COUNT(*)"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.apache.spark.annotation.Evolving;
import org.apache.spark.sql.connector.expressions.Expression;
import org.apache.spark.sql.connector.expressions.NamedReference;

/**
* The general implementation of {@link AggregateFunc}, which contains the upper-cased function
Expand All @@ -46,21 +45,23 @@
public final class GeneralAggregateFunc implements AggregateFunc {
private final String name;
private final boolean isDistinct;
private final NamedReference[] inputs;
private final Expression[] children;

public String name() { return name; }
public boolean isDistinct() { return isDistinct; }
public NamedReference[] inputs() { return inputs; }

public GeneralAggregateFunc(String name, boolean isDistinct, NamedReference[] inputs) {
public GeneralAggregateFunc(String name, boolean isDistinct, Expression[] children) {
this.name = name;
this.isDistinct = isDistinct;
this.inputs = inputs;
this.children = children;
}

@Override
public Expression[] children() { return children; }

@Override
public String toString() {
String inputsString = Arrays.stream(inputs)
String inputsString = Arrays.stream(children)
.map(Expression::describe)
.collect(Collectors.joining(", "));
if (isDistinct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public final class Max implements AggregateFunc {

public Expression column() { return input; }

@Override
public Expression[] children() { return new Expression[]{ input }; }

@Override
public String toString() { return "MAX(" + input.describe() + ")"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public final class Min implements AggregateFunc {

public Expression column() { return input; }

@Override
public Expression[] children() { return new Expression[]{ input }; }

@Override
public String toString() { return "MIN(" + input.describe() + ")"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public Sum(Expression column, boolean isDistinct) {
public Expression column() { return input; }
public boolean isDistinct() { return isDistinct; }

@Override
public Expression[] children() { return new Expression[]{ input }; }

@Override
public String toString() {
if (isDistinct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,30 @@

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;
import org.apache.spark.sql.connector.expressions.Literal;
import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.DataTypes;

/**
* A filter that always evaluates to {@code false}.
* A predicate that always evaluates to {@code false}.
*
* @since 3.3.0
*/
@Evolving
public final class AlwaysFalse extends Filter {
public final class AlwaysFalse extends Predicate implements Literal<Boolean> {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return true;
public AlwaysFalse() {
super("ALWAYS_FALSE", new Predicate[]{});
}

@Override
public int hashCode() {
return Objects.hash();
public Boolean value() {
return false;
}

@Override
public String toString() { return "FALSE"; }
public DataType dataType() {
return DataTypes.BooleanType;
}

@Override
public NamedReference[] references() { return EMPTY_REFERENCE; }
public String toString() { return "FALSE"; }
}
Loading