mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-31 13:18:12 +00:00
MINOR: Fix mariadb profiling with Time datatype (#20376)
This commit is contained in:
parent
b35ee783b2
commit
71927cc30b
@ -20,6 +20,7 @@ from metadata.generated.schema.entity.services.databaseService import (
|
||||
from metadata.profiler.orm.converter.azuresql.converter import AzureSqlMapTypes
|
||||
from metadata.profiler.orm.converter.bigquery.converter import BigqueryMapTypes
|
||||
from metadata.profiler.orm.converter.common import CommonMapTypes
|
||||
from metadata.profiler.orm.converter.mariadb.converter import MariaDBMapTypes
|
||||
from metadata.profiler.orm.converter.mssql.converter import MssqlMapTypes
|
||||
from metadata.profiler.orm.converter.redshift.converter import RedshiftMapTypes
|
||||
from metadata.profiler.orm.converter.snowflake.converter import SnowflakeMapTypes
|
||||
@ -30,3 +31,4 @@ converter_registry[DatabaseServiceType.Snowflake] = SnowflakeMapTypes
|
||||
converter_registry[DatabaseServiceType.Redshift] = RedshiftMapTypes
|
||||
converter_registry[DatabaseServiceType.Mssql] = MssqlMapTypes
|
||||
converter_registry[DatabaseServiceType.AzureSQL] = AzureSqlMapTypes
|
||||
converter_registry[DatabaseServiceType.MariaDB] = MariaDBMapTypes
|
||||
|
@ -0,0 +1,28 @@
|
||||
# Copyright 2025 Collate
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Converter logic to transform an OpenMetadata Table Entity for MariaDB
|
||||
to an SQLAlchemy ORM class.
|
||||
"""
|
||||
|
||||
from metadata.generated.schema.entity.data.table import DataType
|
||||
from metadata.profiler.orm.converter.common import CommonMapTypes
|
||||
from metadata.profiler.orm.registry import CustomTypes
|
||||
|
||||
|
||||
class MariaDBMapTypes(CommonMapTypes):
|
||||
def __init__(self) -> None:
|
||||
self._TYPE_MAP.update(
|
||||
{
|
||||
DataType.TIME: CustomTypes.TIME.value,
|
||||
}
|
||||
)
|
@ -28,6 +28,7 @@ from metadata.profiler.orm.types.custom_datetimerange import CustomDateTimeRange
|
||||
from metadata.profiler.orm.types.custom_hex_byte_string import HexByteString
|
||||
from metadata.profiler.orm.types.custom_image import CustomImage
|
||||
from metadata.profiler.orm.types.custom_ip import CustomIP
|
||||
from metadata.profiler.orm.types.custom_time import CustomTime
|
||||
from metadata.profiler.orm.types.custom_timestamp import CustomTimestamp
|
||||
from metadata.profiler.orm.types.undetermined_type import UndeterminedType
|
||||
from metadata.profiler.orm.types.uuid import UUIDString
|
||||
@ -44,6 +45,7 @@ class CustomTypes(TypeRegistry):
|
||||
IP = CustomIP
|
||||
SQADATETIMERANGE = CustomDateTimeRange
|
||||
UNDETERMINED = UndeterminedType
|
||||
TIME = CustomTime
|
||||
|
||||
|
||||
class PythonDialects(Enum):
|
||||
|
54
ingestion/src/metadata/profiler/orm/types/custom_time.py
Normal file
54
ingestion/src/metadata/profiler/orm/types/custom_time.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2025 Collate
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# 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.
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
"""
|
||||
Expand sqlalchemy types to map them to OpenMetadata DataType
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from sqlalchemy.sql.sqltypes import TIME, TypeDecorator
|
||||
|
||||
from metadata.utils.logger import profiler_logger
|
||||
|
||||
logger = profiler_logger()
|
||||
|
||||
|
||||
class CustomTime(TypeDecorator):
|
||||
"""
|
||||
Convert int time to timedelta object
|
||||
"""
|
||||
|
||||
__visit_name__ = "TIME"
|
||||
impl = TIME
|
||||
cache_ok = True
|
||||
|
||||
def result_processor(self, dialect, coltype):
|
||||
time = datetime.time
|
||||
|
||||
def process(value):
|
||||
# convert from a timedelta value
|
||||
if value is not None:
|
||||
if isinstance(value, int):
|
||||
value = datetime.timedelta(seconds=value)
|
||||
microseconds = value.microseconds
|
||||
seconds = value.seconds
|
||||
minutes = seconds // 60
|
||||
return time(
|
||||
minutes // 60,
|
||||
minutes % 60,
|
||||
seconds - minutes * 60,
|
||||
microsecond=microseconds,
|
||||
)
|
||||
return None
|
||||
|
||||
return process
|
Loading…
x
Reference in New Issue
Block a user