You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ayushdg (via GitHub)" <gi...@apache.org> on 2023/03/30 02:00:47 UTC

[GitHub] [arrow-datafusion] ayushdg opened a new pull request, #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

ayushdg opened a new pull request, #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785

   # 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 #5626 
   
   # Rationale for this change
   Some part of the codebase use `sqlToRel`'s options for `enable_ident_normalization` to decide whether to normalize identifiers or not, but it isn't enforced consistently throughout the codebase.
   <!--
    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.  
   -->
   
   # What changes are included in this PR?
   Make planner:normalize_ident public.
   All methods implementing `SqlToRel` use `enable_ident_normalization` while normalizing. 
   <!--
   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.
   -->
   
   # Are these changes tested?
   - [ ] TODO: Add tests
   <!--
   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)?
   -->
   
   # Are there any user-facing changes?
   No.
   <!--
   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.
   -->


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#issuecomment-1493422401

   @ayushdg  please let me know if you would to make changes to this PR or if we should merge it as is


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] Jefffrey commented on pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#issuecomment-1491812127

   > While working on this PR, I also noticed that there are places not related to the planner which also normalize names such as column. I wonder if it's valuable to also make these method configurable to enable ident normalization?
   > 
   > https://github.com/apache/arrow-datafusion/blob/c09edade14d456f1d2161c5ebb8c1e51e592a8ef/datafusion/common/src/column.rs#L73
   
   I had some thoughts about this previously (not this specific function, but still applicable): https://github.com/apache/arrow-datafusion/pull/5183#discussion_r1096603578
   
   Generally I'm not sure how exactly to be able to toggle normalization at that level (the common crate) without API changes to dependent functions, like `from_qualified_name(...)` in `Column` as you've highlighted


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ayushdg commented on a diff in pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "ayushdg (via GitHub)" <gi...@apache.org>.
ayushdg commented on code in PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#discussion_r1158804738


##########
datafusion/sql/src/expr/identifier.rs:
##########
@@ -47,7 +46,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             // interpret names with '.' as if they were
             // compound identifiers, but this is not a compound
             // identifier. (e.g. it is "foo.bar" not foo.bar)
-            let normalize_ident = normalize_ident(id);
+            let normalize_ident =

Review Comment:
   Do you have a preference for whether a new struct should be created to normalize ident or if we could just add the `normalize` method as an implementation for `SqlToRel`



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ayushdg commented on pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "ayushdg (via GitHub)" <gi...@apache.org>.
ayushdg commented on PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#issuecomment-1490776492

   While working on this PR, I also noticed that there are places not related to the planner which also normalize names such as column. I wonder if it's valuable to also make these method configurable to enable ident normalization?
   
   https://github.com/apache/arrow-datafusion/blob/c09edade14d456f1d2161c5ebb8c1e51e592a8ef/datafusion/common/src/column.rs#L73


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ayushdg commented on a diff in pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "ayushdg (via GitHub)" <gi...@apache.org>.
ayushdg commented on code in PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#discussion_r1160296352


##########
datafusion/sql/src/statement.rs:
##########


Review Comment:
   In cases like this with helper methods that get called from `SqlToRel` impl methods is there a better approach than adding a normalizer argument to each of these methods?
   https://github.com/apache/arrow-datafusion/blob/c5e935a15f22d16d8ca244e68b128f7c5ff28375/datafusion/sql/src/statement.rs#L54-L65
   
   



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#discussion_r1160615332


##########
datafusion/sql/src/statement.rs:
##########


Review Comment:
   I can't think of any at the moment



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ayushdg commented on a diff in pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "ayushdg (via GitHub)" <gi...@apache.org>.
ayushdg commented on code in PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#discussion_r1155547100


##########
datafusion/sql/src/expr/identifier.rs:
##########
@@ -47,7 +46,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             // interpret names with '.' as if they were
             // compound identifiers, but this is not a compound
             // identifier. (e.g. it is "foo.bar" not foo.bar)
-            let normalize_ident = normalize_ident(id);
+            let normalize_ident =

Review Comment:
   I agree that a refactor here to make normalize ident a part of the SqlToRel planner itself makes more sense that constantly getting this info from the options.



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ayushdg commented on pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "ayushdg (via GitHub)" <gi...@apache.org>.
ayushdg commented on PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#issuecomment-1502324346

   Thanks @alamb let me know if anything else is needed, or if the pr is good to merge as is. 


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5785: Planner: normalize_ident only when enable_ident_normalization is enabled

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5785:
URL: https://github.com/apache/arrow-datafusion/pull/5785#discussion_r1154717138


##########
datafusion/sql/src/expr/identifier.rs:
##########
@@ -47,7 +46,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             // interpret names with '.' as if they were
             // compound identifiers, but this is not a compound
             // identifier. (e.g. it is "foo.bar" not foo.bar)
-            let normalize_ident = normalize_ident(id);
+            let normalize_ident =

Review Comment:
   It would be really nice to refactor the code to make it harder to miss such functions. Maybe we could add a struct like
   
   ```rust
   struct IdentNormalizer {
     bool normalize;
   }
   
   impl IdentNormalizer {
     fn normalize(id: Ident) -> String {
     ...
      }
   }
   ```
   
   And then we could change `SqlToRel` so it had a normalizer field, and remove the `fn normalize_ident` entirely -- that way the compiler could help make sure there are no more missing `normalize_ident` callsites (b/c they would all have to be changed to `self.normalizer.normalize(...)`



##########
datafusion/sql/src/planner.rs:
##########
@@ -424,7 +424,7 @@ pub fn object_name_to_qualifier(
         .join(" AND ")
 }
 
-fn normalize_ident(id: Ident, enable_normalization: bool) -> String {
+pub fn normalize_ident(id: Ident, enable_normalization: bool) -> String {

Review Comment:
   What would you think about making `crate::utils::normalize_ident` pub instead? making something public that only does something if `true` is passed in seems somewhat strange to me



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org