From 729a06b5f02450a0cc73be6e2d3ef8e201e223a8 Mon Sep 17 00:00:00 2001 From: Imri Paran Date: Thu, 7 Nov 2024 11:42:03 +0100 Subject: [PATCH] fix: use enum.Enum instead of sqlalchemy enum (#18464) --- .../src/metadata/profiler/orm/registry.py | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ingestion/src/metadata/profiler/orm/registry.py b/ingestion/src/metadata/profiler/orm/registry.py index c1fc505a671..c1e42c5cdae 100644 --- a/ingestion/src/metadata/profiler/orm/registry.py +++ b/ingestion/src/metadata/profiler/orm/registry.py @@ -14,10 +14,11 @@ Custom types' registry for easy access without having an import mess """ import math +from enum import Enum import sqlalchemy from sqlalchemy import Date, DateTime, Integer, Numeric, Time -from sqlalchemy.sql.sqltypes import Concatenable, Enum +from sqlalchemy.sql.sqltypes import Concatenable from metadata.generated.schema.entity.data.table import DataType from metadata.ingestion.source import sqa_types @@ -45,7 +46,7 @@ class CustomTypes(TypeRegistry): UNDETERMINED = UndeterminedType -class Dialects(Enum): +class PythonDialects(Enum): """ Map the service types from DatabaseServiceType to the dialect scheme name used for ingesting @@ -54,6 +55,8 @@ class Dialects(Enum): Keep this alphabetically ordered """ + # pylint: disable=invalid-name + Athena = "awsathena" AzureSQL = "azuresql" BigQuery = "bigquery" @@ -83,6 +86,28 @@ class Dialects(Enum): Vertica = "vertica" +class EnumAdapter(type): + """A hack to use the Dialects string values can be accesses + without using the value attribute. + + Example: + Dialets.MySQL == "mysql" + + Instead of: + Dialects.MySQL.value == "mysql" + + We use this functionality when registring sqlalchemy custom functions. But we should + avoid using this pattern as it can be confusing. + """ + + def __getattr__(cls, item): + return PythonDialects[item].value + + +class Dialects(metaclass=EnumAdapter): + pass + + # Sometimes we want to skip certain types for computing metrics. # If the type is NULL, then we won't run the metric execution # in the profiler.