Skip to content

Commit 31a0099

Browse files
authored
Merge branch 'main' into lint-model-paths
2 parents 27057ae + ee57c61 commit 31a0099

11 files changed

Lines changed: 176 additions & 29 deletions

File tree

‎.devcontainer/devcontainer.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"postCreateCommand": "bash .devcontainer/post-create-command.sh",
1212
"customizations": {
1313
"vscode": {
14-
"extensions": [
15-
"ms-python.python",
16-
"ms-python.vscode-pylance"
17-
]
14+
"extensions": ["ms-python.python", "ms-python.vscode-pylance"]
1815
}
1916
},
2017
"remoteUser": "vscode"

‎.github/workflows/pr.yaml‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
outputs:
1717
python: ${{ steps.filter.outputs.python }}
1818
client: ${{ steps.filter.outputs.client }}
19+
vscode: ${{ steps.filter.outputs.vscode }}
1920
ci: ${{ steps.filter.outputs.ci }}
2021
steps:
2122
- uses: actions/checkout@v7
@@ -34,6 +35,8 @@ jobs:
3435
- 'pyproject.toml'
3536
client:
3637
- 'web/client/**'
38+
vscode:
39+
- 'vscode/**'
3740
ci:
3841
- '.github/**'
3942
- 'Makefile'
@@ -188,9 +191,10 @@ jobs:
188191

189192
ui-style:
190193
needs: [changes]
191-
if: false
192-
# needs.changes.outputs.client == 'true' || needs.changes.outputs.ci ==
193-
# 'true' || github.ref == 'refs/heads/main'
194+
if:
195+
needs.changes.outputs.client == 'true' || needs.changes.outputs.vscode ==
196+
'true' || needs.changes.outputs.ci == 'true' || github.ref ==
197+
'refs/heads/main'
194198
runs-on: ubuntu-latest
195199
steps:
196200
- uses: actions/checkout@v7
@@ -252,7 +256,17 @@ jobs:
252256
fail-fast: false
253257
matrix:
254258
engine:
255-
[duckdb, postgres, mysql, mssql, trino, spark, clickhouse, risingwave, starrocks]
259+
[
260+
duckdb,
261+
postgres,
262+
mysql,
263+
mssql,
264+
trino,
265+
spark,
266+
clickhouse,
267+
risingwave,
268+
starrocks,
269+
]
256270
env:
257271
PYTEST_XDIST_AUTO_NUM_WORKERS: 2
258272
SQLMESH__DISABLE_ANONYMIZED_ANALYTICS: '1'
@@ -393,10 +407,13 @@ jobs:
393407
retention-days: 7
394408

395409
test-vscode:
410+
needs: changes
411+
if:
412+
needs.changes.outputs.vscode == 'true' || needs.changes.outputs.ci ==
413+
'true' || github.ref == 'refs/heads/main'
396414
env:
397415
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
398416
runs-on: ubuntu-latest
399-
if: false
400417
steps:
401418
- uses: actions/checkout@v7
402419
- uses: actions/setup-node@v7
@@ -457,7 +474,19 @@ jobs:
457474
strategy:
458475
fail-fast: false
459476
matrix:
460-
dbt-version: ['1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10', '1.11', '1.12']
477+
dbt-version:
478+
[
479+
'1.3',
480+
'1.4',
481+
'1.5',
482+
'1.6',
483+
'1.7',
484+
'1.8',
485+
'1.9',
486+
'1.10',
487+
'1.11',
488+
'1.12',
489+
]
461490
steps:
462491
- uses: actions/checkout@v7
463492
- name: Set up Python

‎sqlmesh/core/test/definition.py‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,9 @@ def assert_equal(
263263
for col, value in object_sentinel_values.items():
264264
try:
265265
# can't use `isinstance()` here - https://stackoverflow.com/a/68743663/1707525
266-
if type(value) is datetime.date:
267-
expected[col] = pd.to_datetime(expected[col]).dt.date
268-
elif type(value) is datetime.time:
269-
expected[col] = pd.to_datetime(expected[col]).dt.time
270-
elif type(value) is datetime.datetime:
271-
expected[col] = pd.to_datetime(expected[col]).dt.to_pydatetime()
266+
value_type = type(value)
267+
if value_type in (datetime.date, datetime.time, datetime.datetime):
268+
expected[col] = _parse_expected_datetime_column(expected[col], value_type)
272269
except Exception as e:
273270
from sqlmesh.core.console import get_console
274271

@@ -1014,6 +1011,34 @@ def _raise_error(msg: str, path: Path | None = None) -> None:
10141011
raise TestError(f"Failed to run test:\n{msg}")
10151012

10161013

1014+
def _parse_expected_datetime_column(series: pd.Series, target_type: type) -> pd.Series:
1015+
"""Convert a series of expected values to python ``date``/``time``/``datetime``.
1016+
1017+
Falls back to microsecond resolution when pandas' default nanosecond
1018+
parsing overflows. SQL ``TIMESTAMP`` columns can carry values outside
1019+
pandas' default ``datetime64[ns]`` range (1677-09-21..2262-04-11), so
1020+
unit tests may compare against values like ``0001-01-01`` which are
1021+
valid in the database but overflow the default resolution.
1022+
"""
1023+
import pandas as pd
1024+
from pandas.errors import OutOfBoundsDatetime
1025+
1026+
try:
1027+
parsed = pd.to_datetime(series)
1028+
except OutOfBoundsDatetime:
1029+
parsed = series.astype("datetime64[us]")
1030+
1031+
if target_type is datetime.date:
1032+
return parsed.dt.date
1033+
if target_type is datetime.time:
1034+
return parsed.dt.time
1035+
# `Series.dt.to_pydatetime()` returns an `ndarray` in pandas 2.x. Wrap it in a
1036+
# Series with ``dtype=object`` so pandas does not coerce the values back to
1037+
# ``pd.Timestamp`` (which would reintroduce the nanosecond overflow this
1038+
# function exists to avoid).
1039+
return pd.Series(parsed.dt.to_pydatetime(), index=parsed.index, dtype="object")
1040+
1041+
10171042
def _normalize_df_value(value: t.Any) -> t.Any:
10181043
"""Normalize data in a pandas dataframe so ruamel and sqlglot can deal with it."""
10191044
import numpy as np

‎tests/core/engine_adapter/integration/docker/_common-hive.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ services:
1212

1313
# S3-style object storage
1414
minio:
15-
image: 'minio/minio:RELEASE.2022-05-26T05-48-41Z'
15+
image: 'cgr.dev/chainguard/minio:latest@sha256:039800e64ec7247d2fde7cff3697e964f6fe20b6d7d2c46aa7d82cc63355d512'
1616
ports:
1717
- '9000:9000'
1818
- '9001:9001'
1919
environment:
20-
MINIO_ACCESS_KEY: minio
21-
MINIO_SECRET_KEY: minio123
20+
MINIO_ROOT_USER: minio
21+
MINIO_ROOT_PASSWORD: minio123
2222
command: server /data --console-address ":9001"
2323

2424
# Set up minio with default buckets / paths
2525
mc-job:
26-
image: 'minio/mc:RELEASE.2022-05-09T04-08-26Z'
26+
image: 'cgr.dev/chainguard/minio-client:latest-dev@sha256:fb635b967f5f32424391150dac4985cc1aea78fb0a1ce031c01952cf661a13ec'
2727
entrypoint: |
2828
/bin/bash -c "
2929
sleep 5;
30-
/usr/bin/mc config --quiet host add myminio http://minio:9000 minio minio123;
30+
/usr/bin/mc alias --quiet set myminio http://minio:9000 minio minio123;
3131
/usr/bin/mc mb --quiet myminio/trino/datalake;
3232
/usr/bin/mc mb --quiet myminio/trino/datalake_iceberg;
3333
/usr/bin/mc mb --quiet myminio/trino/datalake_delta;
@@ -39,4 +39,4 @@ services:
3939
/usr/bin/mc mb --quiet myminio/nessie/warehouse;
4040
"
4141
depends_on:
42-
- minio
42+
- minio

‎tests/core/test_test.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,48 @@ def test_timestamp_normalization() -> None:
29312931
)
29322932

29332933

2934+
def test_out_of_bounds_nanosecond_timestamp_comparison(mocker: MockerFixture) -> None:
2935+
# https://github.com/TobikoData/sqlmesh/issues/5929
2936+
# Engines like Redshift may return a TIMESTAMP column as an object-dtype
2937+
# series of python `datetime.datetime` instances. Values outside pandas'
2938+
# default `datetime64[ns]` range (1677-09-21..2262-04-11) - which SQL
2939+
# `TIMESTAMP` fully supports - previously raised `OutOfBoundsDatetime`
2940+
# while parsing the expected values, producing a "Failed to convert
2941+
# expected value into `datetime`" warning and a false mismatch on values
2942+
# whose repr survives str-coercion (the values below happen to compare
2943+
# equal via `str()`, so the mismatch was silent).
2944+
test = _create_test(
2945+
body=load_yaml(
2946+
"""
2947+
test_foo:
2948+
model: sushi.foo
2949+
outputs:
2950+
query:
2951+
- ts_col: "0001-01-01 00:00:00"
2952+
- ts_col: "9999-12-31 23:59:59"
2953+
"""
2954+
),
2955+
test_name="test_foo",
2956+
model=_create_model("SELECT ts_col FROM raw"),
2957+
context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
2958+
)
2959+
actual = pd.DataFrame(
2960+
{
2961+
"ts_col": pd.Series(
2962+
[datetime.datetime(1, 1, 1), datetime.datetime(9999, 12, 31, 23, 59, 59)],
2963+
dtype=object,
2964+
)
2965+
}
2966+
)
2967+
# Use T separator so a string-only comparison (broken path) would mismatch
2968+
# against str(datetime.datetime(1, 1, 1)) == "0001-01-01 00:00:00".
2969+
expected = pd.DataFrame({"ts_col": ["0001-01-01T00:00:00", "9999-12-31T23:59:59"]})
2970+
log_warning = mocker.spy(get_console(), "log_warning")
2971+
test.assert_equal(expected=expected, actual=actual, sort=False)
2972+
for call_args in log_warning.call_args_list:
2973+
assert "Failed to convert expected value" not in call_args.args[0]
2974+
2975+
29342976
@use_terminal_console
29352977
def test_disable_test_logging_if_no_tests_found(mocker: MockerFixture, tmp_path: Path) -> None:
29362978
init_example_project(tmp_path, engine_type="duckdb")

‎tests/web/test_models.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from sqlmesh.core.context import Context
8+
from web.server.api.endpoints.models import get_models
9+
10+
pytestmark = pytest.mark.web
11+
12+
13+
def test_get_models_multi_repo() -> None:
14+
"""Models of every project are serialized, not just those of the first one.
15+
16+
`context.path` is the first configured project, so it is not an ancestor of the models
17+
defined in any of the others.
18+
"""
19+
context = Context(paths=["examples/multi/repo_1", "examples/multi/repo_2"], gateway="memory")
20+
21+
paths_by_name = {model.name: model.path for model in get_models(context)}
22+
23+
# Each model is reported relative to the project that defines it.
24+
assert paths_by_name["bronze.a"] == "models/a.sql"
25+
assert paths_by_name["silver.c"] == "models/c.sql"

‎vscode/extension/tests/fixtures.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ export const test = base.extend<
6060
],
6161
})
6262

63-
// Export expect and Page from Playwright for convenience
64-
export { expect, Page } from '@playwright/test'
63+
// Export expect and commonly used Playwright types for convenience
64+
export { expect, FrameLocator, Page } from '@playwright/test'

‎vscode/extension/tests/lineage_settings.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from './fixtures'
2-
import type { FrameLocator, Page } from '@playwright/test'
2+
import type { FrameLocator, Page } from './fixtures'
33
import fs from 'fs-extra'
44
import {
55
openLineageView,

‎web/client/src/library/components/graph/ModelNode.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ export default function ModelNode({
198198
style={{
199199
width: '100%',
200200
...(tagColor != null
201-
? { borderColor: tagColor, backgroundColor: tagColor, color: tagColor }
201+
? {
202+
borderColor: tagColor,
203+
backgroundColor: tagColor,
204+
color: tagColor,
205+
}
202206
: {}),
203207
}}
204208
>
@@ -246,7 +250,10 @@ export default function ModelNode({
246250
/>
247251
</div>
248252
{showColumns && (
249-
<div ref={columnsWrapperRef} style={{ height: '10rem', overflow: 'hidden' }}>
253+
<div
254+
ref={columnsWrapperRef}
255+
style={{ height: '10rem', overflow: 'hidden' }}
256+
>
250257
<ModelColumns
251258
className="nowheel rounded-b-lg bg-theme-lighter text-xs h-full"
252259
nodeId={id}

‎web/client/src/library/components/graph/help.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ function getNodeMap({
175175
const model = models.get(modelName)
176176
const tagsStr = model?.details?.tags
177177
const tags = tagsStr
178-
? tagsStr.split(',').map(t => t.trim()).filter(Boolean)
178+
? tagsStr
179+
.split(',')
180+
.map(t => t.trim())
181+
.filter(Boolean)
179182
: undefined
180183
const node = createGraphNode(modelName, {
181184
label: model?.displayName ?? modelName,

0 commit comments

Comments
 (0)