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 4 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 @@ -191,6 +191,7 @@ Pow,2.45
PreciseTimestampConversion,2.45
PromotePrecision,2.45
PythonUDF,2.45
PythonUDAF,2.45
Quarter,2.45
RLike,2.45
RaiseError,2.45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,2.45
PreciseTimestampConversion,2.45
PromotePrecision,2.45
PythonUDF,2.45
PythonUDAF,2.45
Quarter,2.45
RLike,2.45
RaiseError,2.45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,2.73
PreciseTimestampConversion,2.73
PromotePrecision,2.73
PythonUDF,2.73
PythonUDAF,2.73
Quarter,2.73
RLike,2.73
RaiseError,2.73
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-dataproc-gke-l4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Pow,3.74
PreciseTimestampConversion,3.74
PromotePrecision,3.74
PythonUDF,3.74
PythonUDAF,3.74
Quarter,3.74
RLike,3.74
RaiseError,3.74
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-dataproc-gke-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Pow,3.65
PreciseTimestampConversion,3.65
PromotePrecision,3.65
PythonUDF,3.65
PythonUDAF,3.65
Quarter,3.65
RLike,3.65
RaiseError,3.65
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-dataproc-l4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,4.16
PreciseTimestampConversion,4.16
PromotePrecision,4.16
PythonUDF,4.16
PythonUDAF,4.16
Quarter,4.16
RLike,4.16
RaiseError,4.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Pow,4.25
PreciseTimestampConversion,4.25
PromotePrecision,4.25
PythonUDF,4.25
PythonUDAF,4.25
Quarter,4.25
RLike,4.25
RaiseError,4.25
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-dataproc-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,4.88
PreciseTimestampConversion,4.88
PromotePrecision,4.88
PythonUDF,4.88
PythonUDAF,4.88
Quarter,4.88
RLike,4.88
RaiseError,4.88
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-emr-a10.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,2.59
PreciseTimestampConversion,2.59
PromotePrecision,2.59
PythonUDF,2.59
PythonUDAF,2.59
Quarter,2.59
RLike,2.59
RaiseError,2.59
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-emr-a10G.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,2.59
PreciseTimestampConversion,2.59
PromotePrecision,2.59
PythonUDF,2.59
PythonUDAF,2.59
Quarter,2.59
RLike,2.59
RaiseError,2.59
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-emr-t4.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Pow,2.07
PreciseTimestampConversion,2.07
PromotePrecision,2.07
PythonUDF,2.07
PythonUDAF,2.07
Quarter,2.07
RLike,2.07
RaiseError,2.07
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/operatorsScore-onprem-a100.csv
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Pow,4
PreciseTimestampConversion,4
PromotePrecision,4
PythonUDF,4
PythonUDAF,4
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
Expand Up @@ -297,10 +297,12 @@ object ExecInfo {
// check is the node has a dataset operations and if so change to not supported
val rddCheckRes = RDDCheckHelper.isDatasetOrRDDPlan(nodeName, node.desc)
val ds = dataSet || rddCheckRes.isRDD
val containsPythonUDF = ExecHelper.isPythonUDF(node)
val finalSupported = isSupported || containsPythonUDF

// if the expression is RDD because of the node name, then we do not want to add the
// unsupportedExpressions because it becomes bogus.
val finalUnsupportedExpr = if (rddCheckRes.nodeDescRDD) {
val finalUnsupportedExpr = if (rddCheckRes.nodeDescRDD || containsPythonUDF) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is correct.
The code comment just above that change is explaining that we avoid parsing the node content when it is rddCheckRes.nodeDescRDD . But the new code tries to check if it is pythonUDF anyway which could lead to bogus results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for the confusion. I will address this in the next iteration.

Seq.empty[UnsupportedExpr]
} else {
unsupportedExprs
Expand All @@ -313,7 +315,7 @@ object ExecInfo {
duration,
nodeId,
opType,
isSupported,
finalSupported,
children,
stages,
shouldRemove,
Copy link
Collaborator

@parthosa parthosa Apr 16, 2024

Choose a reason for hiding this comment

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

Do we need to make changes to the usage of variable containsUDF when passing to createExecNoNode()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so. Now containsUDF denotes that the exec contains Scala UDFs after we changed the matching regex, so for python UDFs, this value would remain false as intended.

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 @@ -355,9 +355,13 @@ object RDDCheckHelper {
}


object ExecHelper {
object ExecHelper extends Logging {
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,21 @@ 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)
val batchEvalPythonExec = execInfo.filter(_.exec.contains("BatchEvalPython"))
assertSizeAndSupported(1, batchEvalPythonExec)
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is something I missing here. I cannot find anywhere in the code that we handle BatchEvalPython exec.
How come that the result shows it as supported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BatchEvalPython should not be supported. I will fix this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Have we confirmed that for a fact?
I mean did we verify that it is most likely that BatchEvalPython is associated with PythonUDF and PythonUDAF? if that's the case then all we need to do is considering that the entire exec is supported with being conservative on the speedup factor.
As far as I can see in the plugin code, the RAPIDS has very limited capability accelerating those expressions anyway. So, the speedup should be near 1.

}

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