andygrove commented on code in PR #6455:
URL: https://github.com/apache/datafusion-comet/pull/6455#discussion_r4149742403
##########
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:
04492d8 now declares it `DECIMAL(7, 2)`, so 99999.999 also covers rounding
up past the precision.
--
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]