You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "peasee (via GitHub)" <gi...@apache.org> on 2024/10/13 23:42:27 UTC
[PR] fix: Add Int32 type override for Dialects [datafusion]
peasee opened a new pull request, #12916:
URL: https://github.com/apache/datafusion/pull/12916
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #12915.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
* To fix a bug with casting integers in MySQL
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
* Adds an option to the `Dialect` to specify the cast type for Int32 integers, replicating the existing behavior for Int64 integers.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Yes.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
No.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12916:
URL: https://github.com/apache/datafusion/pull/12916#discussion_r1803534270
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
Maybe @phillipleblanc or @sgrebnov can offer some help here
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "peasee (via GitHub)" <gi...@apache.org>.
peasee commented on code in PR #12916:
URL: https://github.com/apache/datafusion/pull/12916#discussion_r1802137013
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
> MySQL integer is signed by default
I'm not sure what you mean by this. There's already a rule to rewrite `BIGINT` as `SIGNED`, but not for `INTEGER`. On the current version, it generates `CAST(.. INTEGER)` which isn't supported.
> Also where do we specify it's integer and not eg bigint or tinyint?
you cannot specify the size of an integer in cast with MySQL - it always casts to `BIGINT`. `SIGNED INTEGER` does work, but it's syntactic sugar and is identical to `SIGNED`.
https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_cast
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #12916:
URL: https://github.com/apache/datafusion/pull/12916#discussion_r1801346825
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
MySQL integer is signed by default
Also where do we specify it's integer and not eg bigint or tinyint?
https://dev.mysql.com/doc/refman/8.4/en/integer-types.html
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
perhaps `SIGNED INTEGER` would work (it does in my MySQL)
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "sgrebnov (via GitHub)" <gi...@apache.org>.
sgrebnov commented on code in PR #12916:
URL: https://github.com/apache/datafusion/pull/12916#discussion_r1804189834
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
The change LGTM
1. MySQL `cast` does not support `Integer` or `BigInt` which are currently used by default to unparse Int32 and Int64 unparsing. List of supported types for MySQL cast:
https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_cast
1. So this PR fallbacks to using `SIGNED [INTEGER]` similar to `int64_cast_dtype` which will produce a signed BIGINT. I prefer just `SIGNED` to be consistent with `int64_cast_dtype` (or update both)
Possible alternative is to see if we can get rid of casting at all when it is unnecessary
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "sgrebnov (via GitHub)" <gi...@apache.org>.
sgrebnov commented on code in PR #12916:
URL: https://github.com/apache/datafusion/pull/12916#discussion_r1804189834
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -282,6 +288,10 @@ impl Dialect for MySqlDialect {
ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
}
+ fn int32_cast_dtype(&self) -> ast::DataType {
+ ast::DataType::Custom(ObjectName(vec![Ident::new("SIGNED")]), vec![])
Review Comment:
The change LGTM
1. MySQL `cast` does not support `Integer` or `BigInt` which are currently used by default to unparse Int32 and Int64 unparsing. List of supported types for MySQL cast:
https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_cast
1. So this PR fallbacks to using `SIGNED [INTEGER]` similar to `int64_cast_dtype` which will produce a signed BIGINT. I prefer just `SIGNED` to be consistent with `int64_cast_dtype` (or update both)
Possible alternative is to see if we can get rid of casting at all when it is unnecessary as Int32 cast intention and BigInt are different
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add Int32 type override for Dialects [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12916:
URL: https://github.com/apache/datafusion/pull/12916
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org