-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-39139][SQL] DS V2 supports push down DS V2 UDF #36593
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
Changes from all commits
b788e7f
f8b1a69
98ebe02
d982314
7a88fbf
d45342d
a49e6c0
c731225
7aaf5d3
b8d1e7d
3ebf334
ac46914
d7d3993
a2dbbc8
a093ed8
0f63383
0771f19
2dee8e5
3d985fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.internal.connector.ToStringSQLBuilder; | ||
|
||
/** | ||
* The general representation of user defined scalar function, which contains the upper-cased | ||
* function name, canonical function name and all the children expressions. | ||
* | ||
* @since 3.4.0 | ||
*/ | ||
@Evolving | ||
public class UserDefinedScalarFunc implements Expression, Serializable { | ||
private String name; | ||
private String canonicalName; | ||
private Expression[] children; | ||
|
||
public UserDefinedScalarFunc(String name, String canonicalName, Expression[] children) { | ||
this.name = name; | ||
this.canonicalName = canonicalName; | ||
this.children = children; | ||
} | ||
|
||
public String name() { return name; } | ||
public String canonicalName() { return canonicalName; } | ||
|
||
@Override | ||
public Expression[] children() { return children; } | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
UserDefinedScalarFunc that = (UserDefinedScalarFunc) o; | ||
return Objects.equals(name, that.name) && Objects.equals(canonicalName, that.canonicalName) && | ||
Arrays.equals(children, that.children); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, canonicalName, children); | ||
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. @beliefer , should it be |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringSQLBuilder builder = new ToStringSQLBuilder(); | ||
return builder.build(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,9 @@ | |
|
||
package org.apache.spark.sql.connector.expressions.aggregate; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.connector.expressions.Expression; | ||
import org.apache.spark.sql.internal.connector.ToStringSQLBuilder; | ||
|
||
/** | ||
* The general implementation of {@link AggregateFunc}, which contains the upper-cased function | ||
|
@@ -47,27 +45,21 @@ public final class GeneralAggregateFunc implements AggregateFunc { | |
private final boolean isDistinct; | ||
private final Expression[] children; | ||
|
||
public String name() { return name; } | ||
public boolean isDistinct() { return isDistinct; } | ||
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. unnecessary change? 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. Just put these get-like method together. |
||
|
||
public GeneralAggregateFunc(String name, boolean isDistinct, Expression[] children) { | ||
this.name = name; | ||
this.isDistinct = isDistinct; | ||
this.children = children; | ||
} | ||
|
||
public String name() { return name; } | ||
public boolean isDistinct() { return isDistinct; } | ||
|
||
@Override | ||
public Expression[] children() { return children; } | ||
|
||
@Override | ||
public String toString() { | ||
String inputsString = Arrays.stream(children) | ||
.map(Expression::describe) | ||
.collect(Collectors.joining(", ")); | ||
if (isDistinct) { | ||
return name + "(DISTINCT " + inputsString + ")"; | ||
} else { | ||
return name + "(" + inputsString + ")"; | ||
} | ||
ToStringSQLBuilder builder = new ToStringSQLBuilder(); | ||
return builder.build(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.aggregate; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.connector.expressions.Expression; | ||
import org.apache.spark.sql.internal.connector.ToStringSQLBuilder; | ||
|
||
/** | ||
* The general representation of user defined aggregate function, which implements | ||
* {@link AggregateFunc}, contains the upper-cased function name, the canonical function name, | ||
* the `isDistinct` flag and all the inputs. Note that Spark cannot push down aggregate with | ||
* this function partially to the source, but can only push down the entire aggregate. | ||
* | ||
* @since 3.4.0 | ||
*/ | ||
@Evolving | ||
public class UserDefinedAggregateFunc implements AggregateFunc { | ||
private final String name; | ||
private String canonicalName; | ||
private final boolean isDistinct; | ||
private final Expression[] children; | ||
|
||
public UserDefinedAggregateFunc( | ||
String name, String canonicalName, boolean isDistinct, Expression[] children) { | ||
this.name = name; | ||
this.canonicalName = canonicalName; | ||
this.isDistinct = isDistinct; | ||
this.children = children; | ||
} | ||
|
||
public String name() { return name; } | ||
public String canonicalName() { return canonicalName; } | ||
public boolean isDistinct() { return isDistinct; } | ||
|
||
@Override | ||
public Expression[] children() { return children; } | ||
|
||
@Override | ||
public String toString() { | ||
ToStringSQLBuilder builder = new ToStringSQLBuilder(); | ||
return builder.build(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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.internal.connector | ||
|
||
import org.apache.spark.sql.connector.util.V2ExpressionSQLBuilder | ||
|
||
/** | ||
* The builder to generate `toString` information of V2 expressions. | ||
*/ | ||
class ToStringSQLBuilder extends V2ExpressionSQLBuilder { | ||
override protected def visitUserDefinedScalarFunction( | ||
funcName: String, canonicalName: String, inputs: Array[String]) = | ||
s"""$funcName(${inputs.mkString(", ")})""" | ||
|
||
override protected def visitUserDefinedAggregateFunction( | ||
funcName: String, | ||
canonicalName: String, | ||
isDistinct: Boolean, | ||
inputs: Array[String]): String = { | ||
val distinct = if (isDistinct) "DISTINCT " else "" | ||
s"""$funcName($distinct${inputs.mkString(", ")})""" | ||
} | ||
} |
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.
what's wrong with the previous code?
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.
The previous code let the toString display as
Option(...)
.