feat: run user-defined generators inside the native generate operator #7253
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7253"
general
weight: 0.35
rich7420
Which issue does this PR close?
Closes #7252.
Stacked on #7251 (
inline/stack), whose commits appear here until it merges. The last three commits are new.Rationale for this change
A
GenerateExecwhose generator Comet has no native implementation of falls back to Spark. That costs a columnar-to-row transition before it and a row-to-columnar transition after it, and leaves the rest of the stage in Spark. This affects:GenericUDTFs used inLATERAL VIEW;json_tuple;ReplicateRowsgenerator thatEXCEPT ALLandINTERSECT ALLplan (now lowered to a native expression, see below);The generator itself still runs on the JVM one row at a time, so the gain is keeping the stage native around it. The JVM generator works a batch at a time: it evaluates every row of a batch, and holds all the rows one input row generates, before passing any on. The user guide says so.
What changes are included in this PR?
The issue proposed returning generated columns plus a parent-row index. This uses a simpler shape that fits the existing UDF bridge, which requires one output value per input row:
CometGeneratorUDF(aCometUDF): for each input row, it returns the rows the generator emits as onearray<struct>element.CometExplodeExecthen unnests and flattens that the way #7251 does forinline. An input row that emits nothing gets an empty array, soouterkeeps it as one row of nulls, through the existing null handling.CometVectorrows, and writes the output with Comet'sArrowWriterinto a vector fromCometBatchKernelCodegen.allocateOutput, so the list and struct field names match what the native side declares.releasePlan, so the state a Hive UDTF keeps carries across batches. The serde folds a per-occurrence number into the digest, so two identical generators in one plan don't share an instance.terminate(): a newterminateexpression on theExplodeproto is the same UDF called with a flag set.ExplodeExecevaluates it once the input is exhausted and emits its rows with the last input row's other columns, which it keeps as a one-row copy. That matches Spark'sGenerateExec, which pairs them with the last row as Hive does.outerdoes not apply to these rows. With no input rows, the other columns are null.CometGeneratorUDF.declineReasonandCometGeneratorUDF.calls. The generator falls back when:- it is nondeterministic (the existing gate);
- its tree holds a subquery, an unevaluable node or a native UDF call;
- it calls code outside Spark (
CometInvokeTargets);- its output type cannot be serialized.
ReplicateRows: it is lowered toinline(array_repeat(named_struct(...), n)), soEXCEPT ALLandINTERSECT ALLrun fully native. A NULL or negative count gives no rows, as in Spark, and a count beyondInt.MaxValueis clamped rather than wrapped. The JVM generator is the fallback if the expression does not convert.spark.comet.exec.jvmGenerator.enabled, on by default.CometScalaUDF.closureSerializeis pulled out for reuse, andArrowWriterandArrowFieldWriterare widened fromprivate[arrow]toprivate[comet].Python UDTFs (
@udtf) plan as their own exec nodes and are not covered.How are these changes tested?
ExplodeExectests:-
terminaterows carry the last input row across several batches;- with no input rows the other columns are null;
- an empty
terminateadds noouterrow, including over an empty input whose carried column is non-nullable;- with
terminateset, the planner declares the carried columns nullable.CometGenerateExecSuite:- a test Hive
GenericUDTF(registered without a Hive session) that keeps a running count and emits a total fromclose(). The suite checks it runs natively against Spark: with and withoutLATERAL VIEW OUTER, with no input rows, and as two identical UDTFs in one plan;- a three-partition run with AQE off, checking that each partition ends with its own
close()row;-
json_tuple, andEXCEPT ALLthroughReplicateRows, both checked to run natively;- the fallback reason when the config is off;
- the state of the UDTF across batch boundaries, using a batch size of 2 and of 1;
- a generator that reuses one row and byte array, checking each row is kept apart;
- an empty
terminateover a non-nullable carried column;-
EXCEPT ALLandINTERSECT ALLwith counts of zero, one and many, checked to plan noJvmScalarUdf.json_tuple.sql, andexcept_all.sqloverDECIMAL,BINARY,FLOATandDOUBLE(NaN,-0.0, infinity),DATE,TIMESTAMP,TIMESTAMP_NTZ, array and struct columns with NULLs.CometGenerateExecSuite(66 passed), and theinline,stack,explode,json_tupleandexcept_allSQL files.