2025-04-03 10:39:47 +05:30
|
|
|
# Copyright 2025 Collate
|
|
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
2022-07-22 19:05:32 +02:00
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2025-04-03 10:39:47 +05:30
|
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
2022-07-22 19:05:32 +02:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Test ometa to orm converter
|
|
|
|
"""
|
|
|
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from pytest import mark
|
|
|
|
|
|
|
|
from metadata.generated.schema.entity.data.table import Column, DataType, Table
|
|
|
|
from metadata.generated.schema.entity.services.databaseService import (
|
|
|
|
DatabaseServiceType,
|
|
|
|
)
|
2023-07-20 13:34:35 +05:30
|
|
|
from metadata.profiler.orm.converter.base import ometa_to_sqa_orm
|
2022-07-22 19:05:32 +02:00
|
|
|
|
|
|
|
|
2023-07-20 13:34:35 +05:30
|
|
|
@patch("metadata.profiler.orm.converter.base.get_orm_schema", return_value="schema")
|
|
|
|
@patch("metadata.profiler.orm.converter.base.get_orm_database", return_value="database")
|
2022-07-22 19:05:32 +02:00
|
|
|
@mark.parametrize(
|
|
|
|
"column_definition, table_name",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"CaseSensitive",
|
|
|
|
DataType.STRING,
|
|
|
|
),
|
|
|
|
("UPPER_CASE", DataType.INT),
|
|
|
|
],
|
|
|
|
"table_1",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"all_lower_case",
|
|
|
|
DataType.STRING,
|
|
|
|
),
|
|
|
|
("lower_case", DataType.INT),
|
|
|
|
],
|
|
|
|
"table_2",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2022-09-12 18:05:36 +02:00
|
|
|
def test_snowflake_case_sensitive_orm(
|
|
|
|
mock_schema, mock_database, column_definition, table_name
|
|
|
|
):
|
2022-07-22 19:05:32 +02:00
|
|
|
"""Test that snowflake case sensitive orm table
|
|
|
|
are enforced correctly
|
|
|
|
"""
|
|
|
|
columns = [
|
|
|
|
Column(
|
|
|
|
name=name,
|
|
|
|
dataType=type,
|
|
|
|
)
|
|
|
|
for name, type in column_definition
|
|
|
|
]
|
|
|
|
|
|
|
|
table = Table(
|
|
|
|
id=UUID("1f8c1222-09a0-11ed-871b-ca4e864bb16a"),
|
|
|
|
name=table_name,
|
|
|
|
columns=columns,
|
|
|
|
serviceType=DatabaseServiceType.Snowflake,
|
|
|
|
)
|
|
|
|
|
2022-11-15 20:31:10 +05:30
|
|
|
orm_table = ometa_to_sqa_orm(table, None)
|
2022-07-22 19:05:32 +02:00
|
|
|
|
|
|
|
assert orm_table.__table_args__.get("quote")
|
|
|
|
assert [
|
|
|
|
name.lower() for name, _ in column_definition
|
|
|
|
] == orm_table.__table__.columns.keys()
|
|
|
|
assert orm_table.__tablename__ == table_name
|
|
|
|
assert orm_table.__table_args__["schema"] == "schema"
|
|
|
|
for name, _ in column_definition:
|
|
|
|
assert hasattr(orm_table, name)
|
|
|
|
|
|
|
|
|
2023-07-20 13:34:35 +05:30
|
|
|
@patch("metadata.profiler.orm.converter.base.get_orm_schema", return_value="schema")
|
|
|
|
@patch("metadata.profiler.orm.converter.base.get_orm_database", return_value="database")
|
2022-09-12 18:05:36 +02:00
|
|
|
def test_metadata_column(mock_schema, mock_database):
|
2022-07-22 19:05:32 +02:00
|
|
|
"""Test that snowflake case sensitive orm table
|
|
|
|
are enforced correctly
|
|
|
|
"""
|
|
|
|
table_name = "foo"
|
|
|
|
column_definition = [
|
|
|
|
(
|
|
|
|
"foo",
|
|
|
|
DataType.STRING,
|
|
|
|
),
|
|
|
|
("metadata", DataType.INT),
|
|
|
|
]
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
Column(
|
|
|
|
name=name,
|
|
|
|
dataType=type,
|
|
|
|
)
|
|
|
|
for name, type in column_definition
|
|
|
|
]
|
|
|
|
|
|
|
|
table = Table(
|
|
|
|
id=UUID("1f8c1222-09a0-11ed-871b-ca4e864bb16a"),
|
|
|
|
name=table_name,
|
|
|
|
columns=columns,
|
|
|
|
serviceType=DatabaseServiceType.BigQuery,
|
|
|
|
)
|
|
|
|
|
2022-11-15 20:31:10 +05:30
|
|
|
orm_table = ometa_to_sqa_orm(table, None)
|
2022-07-22 19:05:32 +02:00
|
|
|
|
|
|
|
assert not orm_table.__table_args__.get("quote")
|
|
|
|
assert [
|
|
|
|
name.lower() for name, _ in column_definition
|
|
|
|
] == orm_table.__table__.columns.keys()
|
|
|
|
assert orm_table.__tablename__ == table_name
|
|
|
|
assert orm_table.__table_args__["schema"] == "schema"
|
|
|
|
for name, _ in column_definition:
|
|
|
|
assert hasattr(orm_table, name)
|