You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement Spark-compatible cast between decimals with different precision and scale #375
java.lang.ArithmeticException: Cannot convert 12345.68 (bytes: [B@4f834a43, integer: 1234568) to decimal with precision: 6 and scale: 2
at org.apache.comet.vector.CometVector.getDecimal(CometVector.java:86)
I was trying to take a look at this one - I added this test in the CometCastSuite -
test("cast between decimals with different precision and scale") {
valdf= generateDecimalsPrecision38Scale18()
valdf1= df.withColumn("b", col("a").cast(DataTypes.createDecimalType(10, 2)))
df1.show(false)
castTest(generateDecimalsPrecision38Scale18(), DataTypes.createDecimalType(10, 2))
}
But castTest fails with the following assertion error -
Expected only Comet native operators, but found Sort.
plan:Sort [a#30ASCNULLSFIRST], true, 0+-Project [a#30, cast(a#30asdecimal(10,2)) AS a#32]
+-CometCoalesceCoalesce1, [a#30], 1+-CometScan parquet [a#30] Batched:true, DataFilters: [], Format:CometParquet, Location:InMemoryFileIndex(1 paths)[file:/private/var/folders/jx/23vwhfzn2ts493_2twyz1dpc0000gn/T/spark-5f..., PartitionFilters: [], PushedFilters: [], ReadSchema: struct<a:decimal(38,18)>
Also this code inside the test(....) produces following plan
spark.sql(s"select a, cast(a as decimal(10,2)) from t2 order by a").explain()
==PhysicalPlan==AdaptiveSparkPlan isFinalPlan=false+-CometSort [a#4, a#9], [a#4ASCNULLSFIRST]
+-CometColumnarExchange rangepartitioning(a#4ASCNULLSFIRST, 10), ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=13]
+-LocalTableScan [a#4, a#9]
Update : Figured out that, removing .coalesce(1) makes the plan CometSort but assertion fails in Project now
Thanks for looking into this @himadripal. The issue is that the projection is falling back to Spark because org.apache.comet.expressions.CometCast#isSupported is either returning Unsupported or Incompatible for a cast between decimal types, so the first step is to update this method to say that this cast is now supported.
Activity
viirya commentedon May 3, 2024
This looks simple to fix. We currently throw an exception if cannot convert the byes to decimal, but looks like Spark returns null.
caicancai commentedon May 6, 2024
@andygrove Do you mind letting me try it? In my spare time, I have been fixing the compatibility issues of calcite in spark sql type conversion.
viirya commentedon May 6, 2024
@caicancai Thanks. Please go ahead to create a PR for the open tickets which no one claims working on it.
caicancai commentedon May 18, 2024
I am working on it.
himadripal commentedon Nov 14, 2024
I was trying to take a look at this one - I added this test in the CometCastSuite -
It gives me result like this
But
castTestfails with the following assertion error -Also this code inside the test(....) produces following plan
Update : Figured out that, removing
.coalesce(1)makes the plan CometSort but assertion fails inProjectnow@viirya @andygrove can you provide guidance here on how to proceed ?
andygrove commentedon Nov 14, 2024
Thanks for looking into this @himadripal. The issue is that the projection is falling back to Spark because
org.apache.comet.expressions.CometCast#isSupportedis either returningUnsupportedorIncompatiblefor a cast between decimal types, so the first step is to update this method to say that this cast is now supported.andygrove commentedon Nov 14, 2024
You may want to set
spark.comet.explainFallback.enabled=trueas well so that you can see the reason why queries are falling back to Spark.himadripal commentedon Nov 14, 2024
thank you @andygrove for the guidance and tip. I'll explore
spark.comet.explainFallback.enabled=trueas well.himadripal commentedon Dec 27, 2024
this arrow pr will fix this issue completely. waiting for arrow release and then Datafusion release later.
fix: enable full decimal to decimal support (apache#1385)
fix: enable full decimal to decimal support (apache#1385)