comphead commented on PR #5050:
URL: 
https://github.com/apache/datafusion-comet/pull/5050#issuecomment-5152333021

   @andygrove @0lai0 WDYT instead of listing ops if we scan an entire input 
plan and fallback if there is negative decimals?
   Something like
   
   
   ```
   object NegativeScaleDecimalFinder {
   
       /** True if `dt` is (or nests) a `DecimalType` with negative scale. */
       def hasNegativeScaleDecimal(dt: DataType): Boolean = dt match {
         case d: DecimalType         => d.scale < 0
         case ArrayType(elem, _)     => hasNegativeScaleDecimal(elem)
         case MapType(k, v, _)       => hasNegativeScaleDecimal(k) || 
hasNegativeScaleDecimal(v)
         case s: StructType          => s.fields.exists(f => 
hasNegativeScaleDecimal(f.dataType))
         case _                      => false
       }
   
       /** True if any expression in the plan (or its subqueries) produces a 
negative-scale decimal. */
       def planHasNegativeScaleDecimal(plan: QueryPlan[_]): Boolean = {
         def exprHas(e: Expression): Boolean =
           hasNegativeScaleDecimal(e.dataType) || e.children.exists(exprHas)
   
         plan.exists { node =>
           node.output.exists(a => hasNegativeScaleDecimal(a.dataType)) ||
           node.expressions.exists(exprHas) ||
           node.subqueries.exists(planHasNegativeScaleDecimal)
         }
       }
     
       /** Returns the offending nodes for easier debugging. */
       def findNegativeScaleDecimalNodes(plan: QueryPlan[_]): Seq[QueryPlan[_]] 
= {
         plan.collect {
           case node if node.output.exists(a => 
hasNegativeScaleDecimal(a.dataType)) ||
                        node.expressions.exists(e =>
                          hasNegativeScaleDecimal(e.dataType) ||
                          e.find(x => 
hasNegativeScaleDecimal(x.dataType)).isDefined) =>
             node
         }
       }
     }
   ```


-- 
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