-
Notifications
You must be signed in to change notification settings - Fork 14k
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
fix(snowflake): opt-in denormalization of column names #24982
Changes from 1 commit
a6346db
ddee4b3
7376203
114e867
af500e2
8847cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""add_normalize_columns_to_sqla_model | ||
|
||
Revision ID: 9f4a086c2676 | ||
Revises: 4448fa6deeb1 | ||
Create Date: 2023-08-14 09:38:11.897437 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '9f4a086c2676' | ||
down_revision = '4448fa6deeb1' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
from superset import db | ||
from superset.migrations.shared.utils import paginated_update | ||
|
||
|
||
Base = declarative_base() | ||
|
||
class SqlaTable(Base): | ||
__tablename__ = "tables" | ||
|
||
id = sa.Column(sa.Integer, primary_key=True) | ||
normalize_columns = sa.Column(sa.Boolean) | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
"tables", | ||
sa.Column("normalize_columns", sa.Boolean(), nullable=True, default=False), | ||
) | ||
|
||
bind = op.get_bind() | ||
session = db.Session(bind=bind) | ||
|
||
for table in paginated_update(session.query(SqlaTable)): | ||
table.normalize_columns = True | ||
|
||
|
||
def downgrade(): | ||
op.drop_column("tables", "normalize_columns") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ def test_external_metadata_by_name_for_physical_table(self): | |
"database_name": tbl.database.database_name, | ||
"schema_name": tbl.schema, | ||
"table_name": tbl.table_name, | ||
"normalize_columns": tbl.normalize_columns, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some tests that create a dataset with/without this value to check for api backwards compatibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll do that 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
} | ||
) | ||
url = f"/datasource/external_metadata_by_name/?q={params}" | ||
|
@@ -133,6 +134,7 @@ def test_external_metadata_by_name_for_virtual_table(self): | |
"database_name": tbl.database.database_name, | ||
"schema_name": tbl.schema, | ||
"table_name": tbl.table_name, | ||
"normalize_columns": tbl.normalize_columns, | ||
} | ||
) | ||
url = f"/datasource/external_metadata_by_name/?q={params}" | ||
|
@@ -151,6 +153,7 @@ def test_external_metadata_by_name_from_sqla_inspector(self): | |
"database_name": example_database.database_name, | ||
"table_name": "test_table", | ||
"schema_name": get_example_default_schema(), | ||
"normalize_columns": False, | ||
} | ||
) | ||
url = f"/datasource/external_metadata_by_name/?q={params}" | ||
|
@@ -164,6 +167,7 @@ def test_external_metadata_by_name_from_sqla_inspector(self): | |
"datasource_type": "table", | ||
"database_name": "foo", | ||
"table_name": "bar", | ||
"normalize_columns": False, | ||
} | ||
) | ||
url = f"/datasource/external_metadata_by_name/?q={params}" | ||
|
@@ -180,6 +184,7 @@ def test_external_metadata_by_name_from_sqla_inspector(self): | |
"datasource_type": "table", | ||
"database_name": example_database.database_name, | ||
"table_name": "fooooooooobarrrrrr", | ||
"normalize_columns": False, | ||
} | ||
) | ||
url = f"/datasource/external_metadata_by_name/?q={params}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between
NULL
andFALSE
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@john-bodley they're essentially the same. Would you prefer I change it to just
nullable=True
without a default value, or just have the default value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only need two states, then I would stick with
TRUE
andFALSE
, i.e., non-nullable, unless there's a performance or storage cost for usingFALSE
rather thanNULL
—which likely will be the predominant value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems SQLAlchemy is slightly flaky when it comes to assigning default values with the NULL constraint in place. I dug around, and found that the
is_sqllab_viz
flag on theSqlaTable
model is expected to work similarly, and there the migration also had to allow fornullable=True
. So reverting back to that.