Skip to content
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

Add Support for PythonUDAF expression #937

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.45
Pow,2.45
PreciseTimestampConversion,2.45
PromotePrecision,2.45
PythonUDF,2.45
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.45
RLike,2.45
RaiseError,2.45
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-databricks-aws-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.45
Pow,2.45
PreciseTimestampConversion,2.45
PromotePrecision,2.45
PythonUDF,2.45
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.45
RLike,2.45
RaiseError,2.45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.73
Pow,2.73
PreciseTimestampConversion,2.73
PromotePrecision,2.73
PythonUDF,2.73
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.73
RLike,2.73
RaiseError,2.73
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-dataproc-gke-l4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ PosExplode,3.74
Pow,3.74
PreciseTimestampConversion,3.74
PromotePrecision,3.74
PythonUDF,3.74
PythonUDF,1.2
PythonUDAF,1.2
Quarter,3.74
RLike,3.74
RaiseError,3.74
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-dataproc-gke-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ PosExplode,3.65
Pow,3.65
PreciseTimestampConversion,3.65
PromotePrecision,3.65
PythonUDF,3.65
PythonUDF,1.2
PythonUDAF,1.2
Quarter,3.65
RLike,3.65
RaiseError,3.65
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-dataproc-l4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,4.16
Pow,4.16
PreciseTimestampConversion,4.16
PromotePrecision,4.16
PythonUDF,4.16
PythonUDF,1.2
PythonUDAF,1.2
Quarter,4.16
RLike,4.16
RaiseError,4.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ PosExplode,4.25
Pow,4.25
PreciseTimestampConversion,4.25
PromotePrecision,4.25
PythonUDF,4.25
PythonUDF,1.2
PythonUDAF,1.2
Quarter,4.25
RLike,4.25
RaiseError,4.25
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-dataproc-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,4.88
Pow,4.88
PreciseTimestampConversion,4.88
PromotePrecision,4.88
PythonUDF,4.88
PythonUDF,1.2
PythonUDAF,1.2
Quarter,4.88
RLike,4.88
RaiseError,4.88
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-emr-a10.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.59
Pow,2.59
PreciseTimestampConversion,2.59
PromotePrecision,2.59
PythonUDF,2.59
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.59
RLike,2.59
RaiseError,2.59
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-emr-a10G.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.59
Pow,2.59
PreciseTimestampConversion,2.59
PromotePrecision,2.59
PythonUDF,2.59
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.59
RLike,2.59
RaiseError,2.59
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-emr-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ PosExplode,2.07
Pow,2.07
PreciseTimestampConversion,2.07
PromotePrecision,2.07
PythonUDF,2.07
PythonUDF,1.2
PythonUDAF,1.2
Quarter,2.07
RLike,2.07
RaiseError,2.07
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/operatorsScore-onprem-a100.csv
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ PosExplode,4
Pow,4
PreciseTimestampConversion,4
PromotePrecision,4
PythonUDF,4
PythonUDF,1.2
PythonUDAF,1.2
Quarter,4
RLike,4
RaiseError,4
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/resources/supportedExprs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,14 @@ Empty2Null,S, ,None,project,input,NA,NA,NA,NA,NA,NA,NA,NA,NA,S,NA,NA,NA,NA,NA,NA
Empty2Null,S, ,None,project,result,NA,NA,NA,NA,NA,NA,NA,NA,NA,S,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
KnownNullable,S, ,None,project,input,S,S,S,S,S,S,S,S,PS,S,S,S,S,S,PS,PS,PS,S,S,S
KnownNullable,S, ,None,project,result,S,S,S,S,S,S,S,S,PS,S,S,S,S,S,PS,PS,PS,S,S,S
PythonUDAF,TNEW, ,None,aggregation,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,TNEW, ,None,aggregation,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,TNEW, ,None,reduction,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,TNEW, ,None,reduction,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,TNEW, ,None,window,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,TNEW, ,None,window,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,TNEW, ,None,project,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,TNEW, ,None,project,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,S, ,None,aggregation,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,S, ,None,aggregation,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,S, ,None,reduction,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,S, ,None,reduction,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,S, ,None,window,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,S, ,None,window,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
PythonUDAF,S, ,None,project,param,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NS,PS,NS,PS,NS,NS,NS
PythonUDAF,S, ,None,project,result,S,S,S,S,S,S,S,S,PS,S,NS,NS,NS,NA,PS,NS,PS,NA,NA,NA
EphemeralSubstring,S,`substr`; `substring`,None,project,str,NA,NA,NA,NA,NA,NA,NA,NA,NA,S,NA,NA,NS,NA,NA,NA,NA,NA,NS,NS
EphemeralSubstring,S,`substr`; `substring`,None,project,pos,NA,NA,NA,S,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NS,NS
EphemeralSubstring,S,`substr`; `substring`,None,project,len,NA,NA,NA,S,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NS,NS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed 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 com.nvidia.spark.rapids.tool.planparser

import com.nvidia.spark.rapids.tool.qualification.PluginTypeChecker

import org.apache.spark.internal.Logging
import org.apache.spark.sql.execution.ui.SparkPlanGraphNode

case class BatchEvalPythonExecParser(
node: SparkPlanGraphNode,
checker: PluginTypeChecker,
sqlID: Long) extends ExecParser with Logging {

val fullExecName = node.name + "Exec"

override def parse: ExecInfo = {
val duration = None
// TODO - add in parsing expressions - average speedup across?
ExecInfo(node, sqlID, node.name, "", 1.0, duration, node.id, true, None)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.nvidia.spark.rapids.tool.planparser
import com.nvidia.spark.rapids.tool.qualification.PluginTypeChecker

import org.apache.spark.sql.execution.ui.SparkPlanGraphNode
import org.apache.spark.sql.rapids.tool.ExecHelper

case class ProjectExecParser(
node: SparkPlanGraphNode,
Expand All @@ -33,8 +34,9 @@ case class ProjectExecParser(
val exprString = node.desc.replaceFirst("Project ", "")
val expressions = SQLPlanParser.parseProjectExpressions(exprString)
val notSupportedExprs = checker.getNotSupportedExprs(expressions)
val containsPythonUDF = ExecHelper.isPythonUDF(node)
val (speedupFactor, isSupported) = if (checker.isExecSupported(fullExecName) &&
notSupportedExprs.isEmpty) {
(notSupportedExprs.isEmpty || containsPythonUDF)) {
(checker.getSpeedupFactor(fullExecName), true)
} else {
(1.0, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ object SQLPlanParser extends Logging {
AggregateInPandasExecParser(node, checker, sqlID).parse
case "ArrowEvalPython" =>
ArrowEvalPythonExecParser(node, checker, sqlID).parse
case "BatchEvalPython" =>
BatchEvalPythonExecParser(node, checker, sqlID).parse
case "BatchScan" =>
BatchScanExecParser(node, checker, sqlID, app).parse
case "BroadcastExchange" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ abstract class AppBase(
}
}

private val UDFRegex = ".*UDF.*"
private val UDFRegex = ".*(?<!python)UDF.*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this won't match pythonUDAF


private val potentialIssuesRegexMap = Map(
UDFRegex -> "UDF",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ object RDDCheckHelper {

object ExecHelper {
private val UDFRegExLookup = Set(
".*UDF.*".r
".*(?<!python)UDF.*".r
)

private val pythonUDFRegExLookUp = Set(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here as my previous comment. There are three regular expressions that look overlapping.

".*pythonUDF.*".r
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not take pythonUDAF into considerations.

)

// we don't want to mark the *InPandas and ArrowEvalPythonExec as unsupported with UDF
Expand Down Expand Up @@ -385,6 +389,10 @@ object ExecHelper {
}
}

def isPythonUDF(node: SparkPlanGraphNode): Boolean = {
pythonUDFRegExLookUp.exists(regEx => node.desc.matches(regEx.regex))
}

def shouldBeRemoved(nodeName: String): Boolean = {
execsToBeRemoved.contains(nodeName)
}
Expand Down
153 changes: 153 additions & 0 deletions core/src/test/resources/spark-events-qualification/python_udf_eventlog

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,19 @@ class SQLPlanParserSuite extends BaseTestSuite {
}
}

test("Python UDFs should be supported") {
val eventLog = s"$qualLogDir/python_udf_eventlog"
val pluginTypeChecker = new PluginTypeChecker()
val app = createAppFromEventlog(eventLog)
assert(app.sqlPlans.size == 1)
val parsedPlans = app.sqlPlans.map { case (sqlID, plan) =>
SQLPlanParser.parseSQLPlan(app.appId, plan, sqlID, "", pluginTypeChecker, app)
}
val execInfo = getAllExecsFromPlan(parsedPlans.toSeq)
val projectExec = execInfo.filter(_.exec.contains("Project"))
assertSizeAndSupported(2, projectExec)
}

test("Expression not supported in FilterExec") {
TrampolineUtil.withTempDir { eventLogDir =>
val (eventLog, _) = ToolTestUtils.generateEventLog(eventLogDir,
Expand Down
88 changes: 0 additions & 88 deletions scripts/sync_plugin_files/override_supported_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,94 +77,6 @@
}
]
},
{
"Expression": "PythonUDAF",
"Context": "aggregation",
"Params": "param",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "aggregation",
"Params": "result",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "reduction",
"Params": "param",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "reduction",
"Params": "result",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "window",
"Params": "param",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "window",
"Params": "result",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "project",
"Params": "param",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "PythonUDAF",
"Context": "project",
"Params": "result",
"override": [
{
"key": "Supported",
"value": "TNEW"
}
]
},
{
"Expression": "RoundCeil",
"Context": "project",
Expand Down