andygrove commented on code in PR #6455:
URL: https://github.com/apache/datafusion-comet/pull/6455#discussion_r4149554973
##########
spark/src/test/scala/org/apache/comet/CometCodegenSuite.scala:
##########
@@ -2346,6 +2393,44 @@ object CometCodegenSuite {
class NotSerializableTarget {
def twice(s: UTF8String): UTF8String = UTF8String.fromString(s.toString +
s.toString)
}
+
+ /**
+ * DSv2 function catalog for the #6425 test. `as_money` declares
`DECIMAL(10, 2)` and
+ * `as_wide_money` declares `DECIMAL(20, 12)`.
+ */
+ class DecimalFunctionCatalog extends FunctionCatalog {
+ private val functions = Map(
+ "as_money" -> new ScaleZeroDecimalFunction(10, 2),
+ "as_wide_money" -> new ScaleZeroDecimalFunction(20, 12))
+ private var catalogName: String = _
+
+ override def initialize(name: String, options: CaseInsensitiveStringMap):
Unit =
+ catalogName = name
+
+ override def name(): String = catalogName
+
+ override def listFunctions(namespace: Array[String]): Array[Identifier] =
+ functions.keys.map(Identifier.of(namespace, _)).toArray
+
+ override def loadFunction(ident: Identifier): UnboundFunction =
+ functions.getOrElse(ident.name(), throw new
NoSuchFunctionException(ident))
+ }
+
+ /**
+ * Returns its `INT` argument as `Decimal(v)`, at scale 0, whatever scale it
declares. `invoke`
+ * is an instance method, so Spark lowers a call to `Invoke`. The function
binds to itself.
+ */
+ class ScaleZeroDecimalFunction(precision: Int, scale: Int)
+ extends UnboundFunction
+ with ScalarFunction[Decimal] {
+ override def name(): String = "scale_zero_decimal"
+ override def description(): String = s"int -> decimal($precision, $scale),
at scale 0"
+ override def bind(inputType: StructType): BoundFunction = this
+ override def inputTypes(): Array[DataType] = Array(IntegerType)
+ override def resultType(): DataType = DecimalType(precision, scale)
+ def invoke(v: Int): Decimal = Decimal(v)
Review Comment:
Added in 4cf7c1c6a8. There's now a third function, `mills_as_money`, which
returns its argument as thousandths into a `DECIMAL(10, 2)`, so the rescale has
to round. It gives -1.01 for -1005, 1.00 for 1004 and 0.01 for 5, the same as
Spark. I also added -99999999 and -100000000 rows for the negative side of the
overflow boundary.
--
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]