andygrove opened a new issue, #6999:
URL: https://github.com/apache/datafusion-comet/issues/6999

   ### What is the problem the feature request solves?
   
   Location: 
spark/src/main/scala/org/apache/spark/sql/comet/CometWindowExec.scala:214
   Symbol: CometWindow.windowExprToProto
   
   `windowExprToProto` builds `lBoundProto` and `uBoundProto` with two mirrored 
~50-line match blocks. Both evaluate the ROWS offset (Integer/Long), call 
`rangeBoundLiteral`, and emit the same fallback reasons. They differ only in 
the proto builder (Lower/UpperWindowFrameBound, Preceding/Following), the 
unbounded case, and the 'lower'/'upper' wording. This code changes often (it is 
threaded with issue-linked fallback fixes), and a fix applied to one bound can 
easily be missed on the other.
   
   Suggested fix:
   
   Add a helper `boundOffset(e: Expression, frameType: FrameType, isLower: 
Boolean): Either[String, OffsetSpec]`. Here `OffsetSpec` is either a `Long` row 
offset or a range-offset literal, and the error message is built from `if 
(isLower) "lower" else "upper"`. Each bound match then shrinks to the 
UnboundedX/CurrentRow cases plus one case that maps the helper's result onto 
Preceding or Following. Call `withFallbackReason` once on `Left`. Behavior is 
unchanged because the helper runs exactly the same eval/rangeBoundLiteral 
checks and produces the same messages.
   
   Code context:
   
   ```scala
             case e if frameType == RowFrame =>
               val offset = e.eval() match {
                 case i: Integer => i.toLong
                 case l: Long => l
                 case _ =>
                   withFallbackReason(windowExpr, s"Unsupported ROWS frame 
lower offset: $e (${e.dataType})")
                   return None
               }
               OperatorOuterClass.LowerWindowFrameBound.newBuilder()
                 
.setPreceding(OperatorOuterClass.Preceding.newBuilder().setOffset(offset).build())
                 .build()
             ... (repeated verbatim for uBound with 
Following/UpperWindowFrameBound)
   ```
   
   ### Describe the potential solution
   
   _No response_
   
   ### Additional context
   
   _No response_
   
   ### Willingness to contribute
   
   None


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to