Skip to content

Added flag to allow override SnowflakeDialect div_is_floor_div flag#545

Merged
sfc-gh-jmartinezramirez merged 4 commits into
mainfrom
SNOW-1812881-division
Jan 9, 2025
Merged

Added flag to allow override SnowflakeDialect div_is_floor_div flag#545
sfc-gh-jmartinezramirez merged 4 commits into
mainfrom
SNOW-1812881-division

Conversation

@sfc-gh-jmartinezramirez

@sfc-gh-jmartinezramirez sfc-gh-jmartinezramirez commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1812881: Division broken #543

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding new credentials
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    The default behavior of the flag div_is_floor_div was changed to False. This ensures that Python and Snowflake operators match the right division. In this first version a flag would be added force_div_is_floor_div to override the current behavior.

@jochenott

Copy link
Copy Markdown

Looks good. You might want to enable these sqlalchemy-provided tests again, which I believe should pass now:
https://github.com/snowflakedb/snowflake-sqlalchemy/blob/main/tests/sqlalchemy_test_suite/test_suite_20.py#L84-L99

Comment thread src/snowflake/sqlalchemy/snowdialect.py Outdated
Comment thread DESCRIPTION.md
- v1.7.0(November 22, 2024)
- (Unreleased)
- Added `force_div_is_floordiv` flag to override `div_is_floordiv` new default value `False` in `SnowflakeDialect`.
- With the flag in `False`, the `/` division operator will be treated as a float division and `//` as a floor division.

@jochenott jochenott Nov 22, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is not how it works.

This flag is a signal from the dialect towards sqlalchemy that describes the behavior of this sql implementation (Snowflake). So if select 4/5 returns 0, div_is_floordiv must be set to True. If it returns 0.8, this flag must be set to False.

So the previous value of div_is_floordiv = True for snowflake was just a bug, which should be fixed. Just as for other bugs, there is no need to make this configurable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @jochenott

We agree that the correct value for the flag div_is_floordiv in Snowflake should be False. However, current users expect the / and // operators to work as true divisions, although / should behave as a true division and // as a floor division. That's why the behavioral change will be introduced as a flag, which will be removed in a future major release.

Thank you for pointing out this code issue and your contribution!!!

@sfc-gh-jmartinezramirez sfc-gh-jmartinezramirez force-pushed the SNOW-1812881-division branch 4 times, most recently from d187421 to 85f5fd0 Compare November 23, 2024 00:53
Comment thread tests/test_core.py Outdated
Comment thread tests/test_core.py Outdated
@sfc-gh-jmartinezramirez sfc-gh-jmartinezramirez changed the title Changed SnowflakeDialect flag div_is_floor_div to False Added flag to allow override SnowflakeDialect div_is_floor_div flag Dec 6, 2024
@jochenott

Copy link
Copy Markdown

Anything missing to get this merged and released?

…division operator as floor div.

Changed flag div_is_floor_div to False.
…that will be introduce, using new flag force_div_floordiv allow to test the new division behavior.

Update sa14:scripts to ignore feature_v20 from execution
Added tests to validate results of true and floor divisions using `force_div_is_floordiv` flag.
@sfc-gh-jmartinezramirez sfc-gh-jmartinezramirez merged commit b9b26e5 into main Jan 9, 2025
@sfc-gh-jmartinezramirez sfc-gh-jmartinezramirez deleted the SNOW-1812881-division branch January 9, 2025 13:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SNOW-1812881: Division broken

5 participants