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 ability to set ORDER / NOORDER sequence on columns with IDENTITY #493

Merged
merged 2 commits into from
May 10, 2024

Conversation

DanielTatarkin
Copy link
Contributor

@DanielTatarkin DanielTatarkin commented Apr 24, 2024

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-889850: Add autoincrement support without (explicit) sequences #436

  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.

    CREATE TABLE DDL supports optional ORDER | NOORDER value for AUTOINCREMENT | IDENTITY sequences on a column. Before this change, using a column with a sequence like Column(NUMBER, Identity(start=1, increment=1, order=True) would default to session parameter NOORDER_SEQUENCE_AS_DEFAULT TRUE by default which would always set NOORDER instead of what is being set in the column definition.

    For us, this lead to discrepancies between ORM defined models and the Snowflake state seen by Alembic.

@DanielTatarkin DanielTatarkin requested a review from a team as a code owner April 24, 2024 22:18
Copy link

github-actions bot commented Apr 24, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@DanielTatarkin
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@DanielTatarkin
Copy link
Contributor Author

Semi-related issue #494

Copy link
Collaborator

@sfc-gh-mraba sfc-gh-mraba left a comment

Choose a reason for hiding this comment

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

Hi,

Thank you for your contribution 💪

Pls provide test cases proving correctness of proposed solution.

Example test case could look like this

def test_table_create_order():
    metadata= MetaData()
    table = Table("test_table", m, Column("pk", Integer, Identity(start=1, increment=1, order=True)))
    ddl_schema = schema.CreateTable(table)
    res = _schema.compile(dialect=SnowflakeDialect())
    expected = "..."
    assert res.string == expected, res.string

src/snowflake/sqlalchemy/base.py Outdated Show resolved Hide resolved
@DanielTatarkin
Copy link
Contributor Author

DanielTatarkin commented Apr 30, 2024

Hi,

Thank you for your contribution 💪

Pls provide test cases proving correctness of proposed solution.

Example test case could look like this

def test_table_create_order():
    metadata= MetaData()
    table = Table("test_table", m, Column("pk", Integer, Identity(start=1, increment=1, order=True)))
    ddl_schema = schema.CreateTable(table)
    res = _schema.compile(dialect=SnowflakeDialect())
    expected = "..."
    assert res.string == expected, res.string

@sfc-gh-mraba thank you for the example, I added a unit test to tests/test_sequence.py (test_table_with_identity), let me know if the location is appropriate.

@sfc-gh-mraba sfc-gh-mraba mentioned this pull request May 10, 2024
4 tasks
@sfc-gh-mraba sfc-gh-mraba merged commit 9b2f325 into snowflakedb:main May 10, 2024
41 of 71 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
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-889850: Add autoincrement support without (explicit) sequences
2 participants