Repository: TobikoData/sqlmesh
Pull request #2536 (2024-04-30 02:58:01)

fix: mssql integration tests
the tests needed to be fixed because the were written with raw strings and parsed in each dialect. tsql doesn't have a real timestamp type.

the macros were resulting in a syntax error, so i cleaned them up and removed the ones with warnings

i also changed sql server to 2019 for linux compatibility 


Patch:
diff --git a/examples/sushi/macros/utils.py b/examples/sushi/macros/utils.py
index 5442e196..fbc4c04e 100644
--- a/examples/sushi/macros/utils.py
+++ b/examples/sushi/macros/utils.py
@@ -11,10 +11,10 @@ def add_one(evaluator, column: int):
 
 
 @macro()
-def is_positive(evaluator, column):
+def multiply(evaluator, column, num):
     # untyped column will be a sqlglot column and return a sqlglot exp "column > 0"
     assert isinstance(column, exp.Column)
-    return column > 0
+    return column * num
 
 
 @macro()
@@ -25,7 +25,6 @@ def sql_literal(
     string: str,
     column_str: str,
     column_quoted: str,
-    column_with_db: str,
 ):
     assert isinstance(column, str)
     assert isinstance(str_lit, str)
@@ -36,8 +35,6 @@ def sql_literal(
     assert column_str == "a"
     assert isinstance(column_quoted, str)
     assert column_quoted == "b"
-    assert isinstance(column_with_db, exp.Column)
-    assert column_with_db.sql() == "c.d"
 
     return column
 
diff --git a/examples/sushi/models/top_waiters.sql b/examples/sushi/models/top_waiters.sql
index 7712686c..639374d7 100644
--- a/examples/sushi/models/top_waiters.sql
+++ b/examples/sushi/models/top_waiters.sql
@@ -11,8 +11,8 @@ MODEL (
 WITH test_macros AS (
     SELECT
       @ADD_ONE(1) AS lit_two,
-      @IS_POSITIVE(revenue) AS sql_exp,
-      @SQL_LITERAL(revenue::text, 'x', 'y', a, "b", c.d) AS sql_lit,
+      @MULTIPLY(revenue, 2.0) AS sql_exp,
+      @SQL_LITERAL(revenue::text, 'x', 'y', a, "b") AS sql_lit,
     FROM sushi.waiter_revenue_by_day
 )
 SELECT
diff --git a/setup.py b/setup.py
index 50eaa877..bb472d3c 100644
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@ setup(
         "requests",
         "rich[jupyter]",
         "ruamel.yaml",
-        "sqlglot[rs]~=23.12.1",
+        "sqlglot[rs]~=23.12.2",
     ],
     extras_require={
         "bigquery": [


Test patch:
diff --git a/tests/core/engine_adapter/docker-compose.yaml b/tests/core/engine_adapter/docker-compose.yaml
index 117a7b1e..dcba648e 100644
--- a/tests/core/engine_adapter/docker-compose.yaml
+++ b/tests/core/engine_adapter/docker-compose.yaml
@@ -34,7 +34,7 @@ services:
     environment:
       POSTGRES_PASSWORD: postgres
   mssql:
-    image: mcr.microsoft.com/mssql/server:2022-latest
+    image: mcr.microsoft.com/mssql/server:2019-latest
     ports:
       - '1433:1433'
     environment:
diff --git a/tests/core/engine_adapter/test_integration.py b/tests/core/engine_adapter/test_integration.py
index dbeedda9..6bbc746a 100644
--- a/tests/core/engine_adapter/test_integration.py
+++ b/tests/core/engine_adapter/test_integration.py
@@ -1163,7 +1163,7 @@ def test_merge(ctx: TestContext):
 
 
 def test_scd_type_2_by_time(ctx: TestContext):
-    time_type = "timestamp"
+    time_type = exp.DataType.build("timestamp")
 
     ctx.columns_to_types = {
         "id": "int",
@@ -1306,7 +1306,7 @@ def test_scd_type_2_by_time(ctx: TestContext):
 
 
 def test_scd_type_2_by_column(ctx: TestContext):
-    time_type = "datetime" if ctx.dialect == "bigquery" else "timestamp"
+    time_type = exp.DataType.build("timestamp")
 
     ctx.columns_to_types = {
         "id": "int",
diff --git a/tests/core/test_macros.py b/tests/core/test_macros.py
index 08d1106b..751483c1 100644
--- a/tests/core/test_macros.py
+++ b/tests/core/test_macros.py
@@ -529,6 +529,13 @@ def test_macro_coercion(macro_evaluator: MacroEvaluator, assert_exp_eq):
             strict=True,
         )
 
+    with pytest.raises(SQLMeshError):
+        _ = coerce(
+            exp.column("a", "b"),
+            str,
+            strict=True,
+        )
+
 
 def test_positional_follows_kwargs(macro_evaluator: MacroEvaluator):
     with pytest.raises(MacroEvalError, match="Positional argument cannot follow"):
diff --git a/tests/core/test_model.py b/tests/core/test_model.py
index e0e02a2d..7ae481f4 100644
--- a/tests/core/test_model.py
+++ b/tests/core/test_model.py
@@ -1255,7 +1255,7 @@ def test_render_query(assert_exp_eq, sushi_context):
         WITH "test_macros" AS (
           SELECT
             2 AS "lit_two",
-            "waiter_revenue_by_day"."revenue" > 0 AS "sql_exp",
+            "waiter_revenue_by_day"."revenue" * 2.0 AS "sql_exp",
             CAST("waiter_revenue_by_day"."revenue" AS TEXT) AS "sql_lit"
           FROM "memory"."sushi"."waiter_revenue_by_day" AS "waiter_revenue_by_day"
         )
@@ -3825,7 +3825,7 @@ def test_this_model() -> None:
         );
 
         JINJA_STATEMENT_BEGIN;
-        COPY {{ this_model }} TO 'a';
+        VACUUM {{ this_model }} TO 'a';
         JINJA_END;
 
         JINJA_QUERY_BEGIN;
@@ -3833,7 +3833,7 @@ def test_this_model() -> None:
         JINJA_END;
 
         JINJA_STATEMENT_BEGIN;
-        COPY {{ this_model }} TO 'b';
+        VACUUM {{ this_model }} TO 'b';
         JINJA_END;
         """
     )
@@ -3846,11 +3846,11 @@ def test_this_model() -> None:
 
     assert (
         model.render_pre_statements()[0].sql(dialect="bigquery")
-        == """COPY `project-1`.`table` TO 'a'"""
+        == """VACUUM `project-1`.`table` TO 'a'"""
     )
     assert (
         model.render_post_statements()[0].sql(dialect="bigquery")
-        == """COPY `project-1`.`table` TO 'b'"""
+        == """VACUUM `project-1`.`table` TO 'b'"""
     )
 
     snapshot = Snapshot.from_node(model, nodes={})
@@ -3870,7 +3870,7 @@ def test_this_model() -> None:
             start="2020-01-01",
             snapshots={snapshot.name: snapshot},
         ).sql(dialect="bigquery")
-        == "SELECT '`sqlmesh__project-1`.`project_1__table__1178373199`' AS `x`"
+        == f"SELECT '`sqlmesh__project-1`.`project_1__table__{snapshot.version}`' AS `x`"
     )
 
 
diff --git a/tests/integrations/jupyter/test_magics.py b/tests/integrations/jupyter/test_magics.py
index 99689b93..5ab862c8 100644
--- a/tests/integrations/jupyter/test_magics.py
+++ b/tests/integrations/jupyter/test_magics.py
@@ -160,8 +160,8 @@ def test_render(
     assert output.stdout == ""
     assert output.stderr == ""
     assert len(output.outputs) == 1
-    assert len(convert_all_html_output_to_text(output)[0]) == 2212
-    assert convert_all_html_output_to_tags(output) == [["pre"] + (["span"] * 153)]
+    assert len(convert_all_html_output_to_text(output)[0]) > 2200
+    assert len(convert_all_html_output_to_tags(output)[0]) > 150
 
 
 @pytest.mark.slow
@@ -174,8 +174,8 @@ def test_render_no_format(
     assert output.stdout == ""
     assert output.stderr == ""
     assert len(output.outputs) == 1
-    assert len(convert_all_html_output_to_text(output)[0]) == 698
-    assert convert_all_html_output_to_tags(output) == [["pre"] + (["span"] * 51)]
+    assert len(convert_all_html_output_to_text(output)[0]) >= 700
+    assert len(convert_all_html_output_to_tags(output)[0]) >= 50
 
 
 @pytest.mark.slow