项目文件夹

文件
wehub-resource-sync bf2343b7e4
Integration Tests - MySQL + Elasticsearch / Detect Changes (push) Has been cancelled
Integration Tests - MySQL + Elasticsearch / integration-tests-mysql-elasticsearch (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + Elasticsearch + Redis / integration-tests-postgres-elasticsearch-redis (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / Detect Changes (push) Has been cancelled
Integration Tests - PostgreSQL + OpenSearch / integration-tests-postgres-opensearch (push) Has been cancelled
Java Checkstyle / java-checkstyle (push) Has been cancelled
Maven Collate Tests / maven-collate-ci (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests-status (push) Has been cancelled
Publish Package to Maven Central Repository / publish-maven-packages (push) Has been cancelled
OpenMetadata Service Unit Tests / Detect Changes (push) Has been cancelled
OpenMetadata Service Unit Tests / openmetadata-service-unit-tests (push) Has been cancelled
OpenMetadata Service Unit Tests / k8s_operator-unit-tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:35:45 +08:00

60 行
2.1 KiB
Python

# Copyright 2025 Collate
# Licensed under the Collate Community License, Version 1.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
# 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.
"""
sqlalchemy utility tests
"""
import pytest
import sqlalchemy
from sqlalchemy import Column, text
from metadata.utils.sqa_utils import build_query_filter, dispatch_to_date_or_datetime
FILTER_TEST_DATA = [
(
[(Column("foo"), "eq", "foo"), (Column("bar"), "ne", "bar")],
"foo = 'foo' AND bar != 'bar'",
),
([(Column("foo"), "gt", 1), (Column("bar"), "lt", 2)], "foo > 1 AND bar < 2"),
([(Column("foo"), "in", [1, 2, 3, 4])], "foo IN (1, 2, 3, 4)"),
([(Column("foo"), "not_in", [1, 2, 3, 4])], "(foo NOT IN (1, 2, 3, 4))"),
]
DISPATCH_TEST_DATA = [
(1, "DAY", sqlalchemy.DATE(), "CAST(CURRENT_DATE - interval '1' DAY AS DATE)"),
(
1,
"HOUR",
sqlalchemy.DATETIME(),
"CAST(CURRENT_TIMESTAMP - interval '1' HOUR AS TIMESTAMP)",
),
]
@pytest.mark.parametrize("filters,expected", FILTER_TEST_DATA, ids=["eq", "gt_lt", "in", "not_in"])
def test_build_query_filter(filters, expected):
"""Test SQA query filter builder"""
filter_ = build_query_filter(filters, False)
assert filter_.compile(compile_kwargs={"literal_binds": True}).string == expected
@pytest.mark.parametrize(
"interval,interval_type,type_,expected",
DISPATCH_TEST_DATA,
ids=["date", "datetime"],
)
def test_dispatch_to_date_or_datetime(interval, interval_type, type_, expected):
"""Test dispatch function"""
fn = dispatch_to_date_or_datetime(interval, text(interval_type), type_)
assert fn.compile(compile_kwargs={"literal_binds": True}).string == expected