|
15 | 15 | from sqlmesh.utils.errors import SQLMeshError |
16 | 16 | from sqlmesh.utils import optional_import |
17 | 17 | from tests.core.engine_adapter import to_sql_calls |
| 18 | +from sqlmesh.core.model.kind import ViewKind |
18 | 19 |
|
19 | 20 | pytestmark = [pytest.mark.engine, pytest.mark.snowflake] |
20 | 21 |
|
@@ -727,3 +728,67 @@ def test_table_format_iceberg(snowflake_mocked_engine_adapter: SnowflakeEngineAd |
727 | 728 | 'CREATE ICEBERG TABLE IF NOT EXISTS "test"."table" ("a" INT) CATALOG=\'snowflake\' EXTERNAL_VOLUME=\'test\'', |
728 | 729 | 'CREATE ICEBERG TABLE IF NOT EXISTS "test"."table" CATALOG=\'snowflake\' EXTERNAL_VOLUME=\'test\' AS SELECT CAST("a" AS INT) AS "a" FROM (SELECT CAST("a" AS INT) AS "a") AS "_subquery"', |
729 | 730 | ] |
| 731 | + |
| 732 | + |
| 733 | +def test_create_view_with_schema_and_grants( |
| 734 | + snowflake_mocked_engine_adapter: SnowflakeEngineAdapter, |
| 735 | +): |
| 736 | + adapter = snowflake_mocked_engine_adapter |
| 737 | + |
| 738 | + model_v = load_sql_based_model( |
| 739 | + d.parse(f""" |
| 740 | + MODEL ( |
| 741 | + name test.v, |
| 742 | + kind VIEW, |
| 743 | + description 'normal **view** from integration test', |
| 744 | + dialect 'snowflake' |
| 745 | + ); |
| 746 | +
|
| 747 | + select 1 as "ID", 'foo' as "NAME"; |
| 748 | + """) |
| 749 | + ) |
| 750 | + |
| 751 | + model_mv = load_sql_based_model( |
| 752 | + d.parse(f""" |
| 753 | + MODEL ( |
| 754 | + name test.mv, |
| 755 | + kind VIEW ( |
| 756 | + materialized true |
| 757 | + ), |
| 758 | + description 'materialized **view** from integration test', |
| 759 | + dialect 'snowflake' |
| 760 | + ); |
| 761 | +
|
| 762 | + select 1 as "ID", 'foo' as "NAME"; |
| 763 | + """) |
| 764 | + ) |
| 765 | + |
| 766 | + assert isinstance(model_v.kind, ViewKind) |
| 767 | + assert isinstance(model_mv.kind, ViewKind) |
| 768 | + |
| 769 | + adapter.create_view( |
| 770 | + "target_view", |
| 771 | + model_v.render_query_or_raise(), |
| 772 | + model_v.columns_to_types, |
| 773 | + materialized=model_v.kind.materialized, |
| 774 | + view_properties=model_v.render_physical_properties(), |
| 775 | + table_description=model_v.description, |
| 776 | + column_descriptions=model_v.column_descriptions, |
| 777 | + ) |
| 778 | + |
| 779 | + adapter.create_view( |
| 780 | + "target_materialized_view", |
| 781 | + model_mv.render_query_or_raise(), |
| 782 | + model_mv.columns_to_types, |
| 783 | + materialized=model_mv.kind.materialized, |
| 784 | + view_properties=model_mv.render_physical_properties(), |
| 785 | + table_description=model_mv.description, |
| 786 | + column_descriptions=model_mv.column_descriptions, |
| 787 | + ) |
| 788 | + |
| 789 | + assert to_sql_calls(adapter) == [ |
| 790 | + # normal view - COPY GRANTS goes after the column list |
| 791 | + """CREATE OR REPLACE VIEW "target_view" ("ID", "NAME") COPY GRANTS COMMENT='normal **view** from integration test' AS SELECT 1 AS "ID", 'foo' AS "NAME\"""", |
| 792 | + # materialized view - COPY GRANTS goes before the column list |
| 793 | + """CREATE OR REPLACE MATERIALIZED VIEW "target_materialized_view" COPY GRANTS ("ID", "NAME") COMMENT='materialized **view** from integration test' AS SELECT 1 AS "ID", 'foo' AS "NAME\"""", |
| 794 | + ] |
0 commit comments