Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast string to integral type not compatible with Spark #15

Closed
andygrove opened this issue Feb 13, 2024 · 2 comments · Fixed by #307
Closed

Cast string to integral type not compatible with Spark #15

andygrove opened this issue Feb 13, 2024 · 2 comments · Fixed by #307
Labels
bug Something isn't working

Comments

@andygrove
Copy link
Member

scala> val inputs = Seq("123", "-123", "86374").toDF("n")
inputs: org.apache.spark.sql.DataFrame = [n: string]

scala> inputs.write.parquet("test.parquet")
24/02/13 07:40:14 INFO src/lib.rs: Comet native library initialized
                                                                                
scala> val df = spark.read.parquet("test.parquet")
df: org.apache.spark.sql.DataFrame = [n: string]

scala> import org.apache.spark.sql.types._
import org.apache.spark.sql.types._

scala> val df2 = df.withColumn("converted", col("n").cast(DataTypes.ShortType))
df2: org.apache.spark.sql.DataFrame = [n: string, converted: smallint]

scala> df2.show
+-----+---------+
|    n|converted|
+-----+---------+
|86374|    20838|
| -123|     -123|
|  123|      123|
+-----+---------+

scala> spark.conf.set("spark.comet.enabled", false)

scala> df2.show
+-----+---------+
|    n|converted|
+-----+---------+
|86374|     null|
| -123|     -123|
|  123|      123|
+-----+---------+
@andygrove andygrove added the bug Something isn't working label Feb 13, 2024
@viirya
Copy link
Member

viirya commented Feb 13, 2024

Yea, I can reproduce this. I debugged this a bit. Looks like it is because the function we use to do string to integer cast: Alexhuszagh/rust-lexical#105, which doesn't handle overflow case.

@viirya
Copy link
Member

viirya commented Feb 13, 2024

Waitting for a fix from lexical may be not practical as the ticket was created 6 months ago, I'm going to fix it at arrow-rs instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants