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

Add parser option for parsing SQL numeric literals as decimal #4102

Merged
merged 8 commits into from
Nov 15, 2022

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Nov 3, 2022

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?

  • Add config to enable parsing numbers as decimal. We cannot enable by default until decimal support is farther along

Are there any user-facing changes?

@github-actions github-actions bot removed the core Core datafusion crate label Nov 3, 2022
@andygrove andygrove changed the title Parse SQL numeric literals as decimal for compliance with ANSI SQL Add parser option for parsing SQL numeric literals as decimal Nov 3, 2022
@andygrove andygrove marked this pull request as ready for review November 3, 2022 23:51
@andygrove
Copy link
Member Author

@kmitchener @viirya @Dandandan PTAL

Comment on lines 2989 to 2990
"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)\
Copy link
Member

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)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Copy link
Contributor

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

Comment on lines +2726 to +2732
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)))
Copy link
Member

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)]

Copy link
Member Author

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?

Copy link
Member

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.

}

/// Convert SQL data type to relational representation of data type
pub fn convert_data_type(sql_type: &SQLDataType) -> Result<DataType> {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

@andygrove andygrove merged commit 406c108 into apache:master Nov 15, 2022
@andygrove andygrove deleted the sql-decimals branch November 15, 2022 22:59
@ursabot
Copy link

ursabot commented Nov 15, 2022

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.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@viirya
Copy link
Member

viirya commented Nov 15, 2022

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants