-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add parser option for parsing SQL numeric literals as decimal #4102
Conversation
435e059
to
046da82
Compare
@kmitchener @viirya @Dandandan PTAL |
datafusion/sql/src/planner.rs
Outdated
"SELECT 1, 1.0, 0.1, .1, 12.34", | ||
"Projection: Int64(1), Decimal128(Some(10),2,1), Decimal128(Some(1),2,1), Decimal128(Some(1),1,1), Decimal128(Some(1234),4,2)\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.1
should be Decimal(1, 1), I think.
scala> sql("select 0.1")
res0: org.apache.spark.sql.DataFrame = [0.1: decimal(1,1)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should try to use the min precision to represent the value in the decimal literal
let number = n.parse::<i128>().map_err(|_| { | ||
DataFusionError::from(ParserError(format!( | ||
"Cannot parse {} as i128 when building decimal", | ||
n | ||
))) | ||
})?; | ||
Ok(Expr::Literal(ScalarValue::Decimal128(Some(number), 38, 0))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get the minimum precision to handle this number?
scala> sql("select 10000000000000000000")
res10: org.apache.spark.sql.DataFrame = [10000000000000000000: decimal(20,0)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viirya Could you take another look when you have time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to do it. Let me take another look.
8f2e730
to
cd6c86b
Compare
datafusion/sql/src/planner.rs
Outdated
} | ||
|
||
/// Convert SQL data type to relational representation of data type | ||
pub fn convert_data_type(sql_type: &SQLDataType) -> Result<DataType> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this committed in accidentally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this change adds this and convert_simple_data_type
. Otherwise other change looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is from a merge conflict. I will fix.
Benchmark runs are scheduled for baseline = ebb24c5 and contender = 406c108. 406c108 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
🎉 |
Which issue does this PR close?
Part of #4072
Rationale for this change
Main motivation is to get benchmark query q6 returning the correct results but this is also the correct behavior for SQL
What changes are included in this PR?
Are there any user-facing changes?