4949/**
5050 * Utility for rewriting CLP UDFs (e.g., <code>CLP_GET_*</code>) in {@link RowExpression} trees.
5151 * <p>
52- * This optimizer traverses a query plan and rewrites calls to <code>CLP_GET_*</code> UDFs into
52+ * Traverses a query plan and rewrites calls to <code>CLP_GET_*</code> UDFs into
5353 * {@link VariableReferenceExpression}s with meaningful names derived from their arguments.
5454 * <p>
5555 * This enables querying fields that are not part of the original table schema but are available
@@ -62,7 +62,7 @@ public final class ClpUdfRewriter
6262
6363 public ClpUdfRewriter (FunctionMetadataManager functionManager )
6464 {
65- this .functionManager = requireNonNull (functionManager );
65+ this .functionManager = requireNonNull (functionManager , "functionManager is null" );
6666 }
6767
6868 @ Override
@@ -73,14 +73,14 @@ public PlanNode optimize(PlanNode maxSubplan, ConnectorSession session, Variable
7373
7474 /**
7575 * Collects all existing variable assignments from {@link TableScanNode} instances that map
76- * column handles to {@link VariableReferenceExpression}s.
76+ * {@link ColumnHandle}s to {@link VariableReferenceExpression}s.
7777 * <p>
7878 * This method traverses the given plan subtree, visiting the {@link TableScanNode} and
7979 * extracting its assignments. The resulting map allows tracking which scan-level variables
8080 * already exist for specific columns, so that subsequent optimizer passes (e.g., CLP UDF
8181 * rewriting) can reuse them instead of creating duplicates.
8282 * <p>
83- * The returned map is keyed by the column handle , and the value is the
83+ * The key of the returned map is the {@link ColumnHandle} , and the value is the
8484 * {@link VariableReferenceExpression} assigned to it in the scan node.
8585 *
8686 * @param root the root {@link PlanNode} of the plan subtree
@@ -137,24 +137,26 @@ public PlanNode visitFilter(FilterNode node, RewriteContext<Void> context)
137137 }
138138
139139 /**
140- * Rewrites <code>CLP_GET_*</code> UDFs in a {@link RowExpression}, collecting each resulting
141- * variable into the given map along with its associated {@link ColumnHandle}.
140+ * Rewrites <code>CLP_GET_*</code> UDFs in a {@link RowExpression}, collecting each
141+ * resulting variable into the given map along with its associated {@link ColumnHandle}.
142142 * <p>
143- * Each <code>CLP_GET_*</code> UDF must take a single constant string argument, which is used to
144- * construct the name of the variable reference (e.g. <code>CLP_GET_STRING('foo')</code> becomes
145- * a variable name <code>foo</code>). Invalid usages (e.g., non-constant arguments) will throw a
146- * {@link PrestoException}.
143+ * Each <code>CLP_GET_*</code> UDF must take a single constant string argument, which is
144+ * used to construct the name of the variable reference (e.g.
145+ * <code>CLP_GET_STRING('foo')</code> becomes a variable name <code>foo</code>). Invalid
146+ * usages (e.g., non-constant arguments) will throw a {@link PrestoException}.
147147 *
148148 * @param expression the input expression to analyze and possibly rewrite
149149 * @param functionManager function manager used to resolve function metadata
150150 * @param variableAllocator variable allocator used to create new variable references
151- * @return a possibly rewritten {@link RowExpression} with <code>CLP_GET_*</code> calls replaced
151+ * @return a possibly rewritten {@link RowExpression} with <code>CLP_GET_*</code> calls
152+ * replaced
152153 */
153154 private RowExpression rewriteClpUdfs (
154155 RowExpression expression ,
155156 FunctionMetadataManager functionManager ,
156157 VariableAllocator variableAllocator )
157158 {
159+ // Handle CLP_GET_* function calls
158160 if (expression instanceof CallExpression ) {
159161 CallExpression call = (CallExpression ) expression ;
160162 String functionName = functionManager .getFunctionMetadata (call .getFunctionHandle ()).getName ().getObjectName ().toUpperCase ();
@@ -191,6 +193,7 @@ private RowExpression rewriteClpUdfs(
191193 return new CallExpression (call .getDisplayName (), call .getFunctionHandle (), call .getType (), rewrittenArgs );
192194 }
193195
196+ // Handle special forms (e.g., AND, OR, etc.)
194197 if (expression instanceof SpecialFormExpression ) {
195198 SpecialFormExpression special = (SpecialFormExpression ) expression ;
196199
@@ -258,8 +261,8 @@ else if (c == '_') {
258261 }
259262
260263 /**
261- * Builds a new {@link TableScanNode} that includes additional variables and column handles
262- * for rewritten CLP UDFs.
264+ * Builds a new {@link TableScanNode} that includes additional
265+ * {@link VariableReferenceExpression}s and {@link ColumnHandle}s for rewritten CLP UDFs.
263266 *
264267 * @param node the original table scan node
265268 * @return the updated table scan node
0 commit comments