Improve the config class #544
delphisharp
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
in sqllineage/core/models.py: schema_unknown = "<default>"
class Schema:
"""
Data Class for Schema
"""
def __init__(self, name: str = schema_unknown):
"""
:param name: schema name
"""
if name == schema_unknown and SQLLineageConfig.DEFAULT_SCHEMA:
name = SQLLineageConfig.DEFAULT_SCHEMA
self.raw_name = escape_identifier_name(name)
def __str__(self):
return self.raw_name
def __repr__(self):
return "Schema: " + str(self)
def __eq__(self, other):
return isinstance(other, Schema) and str(self) == str(other)
def __hash__(self):
return hash(str(self))
def __bool__(self):
return str(self) != schema_unknown in sqllineage/config.py: import os
from dataclasses import dataclass
from typing import Any, Union
@dataclass
class SQLLineageConfigValue:
class_type: Any
value: Union[str, bool, None]
@dataclass
class SQLLineageConfigDef():
DIRECTORY: SQLLineageConfigValue
DEFAULT_SCHEMA: SQLLineageConfigValue
TSQL_NO_SEMICOLON: SQLLineageConfigValue
class _SQLLineageConfigLoader() :
"""
Load all configurable items from environment variable, otherwise fallback to default
"""
def __init__(self):
self._config = SQLLineageConfigDef(
DIRECTORY=SQLLineageConfigValue(
str, os.path.join(os.path.dirname(__file__), "data")
),
DEFAULT_SCHEMA=SQLLineageConfigValue(str, None),
TSQL_NO_SEMICOLON=SQLLineageConfigValue(bool, False),
)
@property
def DEFAULT_SCHEMA(self):
return self._config.DEFAULT_SCHEMA.value
@DEFAULT_SCHEMA.setter
def DEFAULT_SCHEMA(self, value):
if isinstance(value, self._config.DEFAULT_SCHEMA.class_type):
self._config.DEFAULT_SCHEMA.value = value
else:
raise ValueError(
f"DEFAULT_SCHEMA should be {self._config.DEFAULT_SCHEMA.class_type}"
)
@property
def DIRECTORY(self):
return self._config.DIRECTORY.value
@DIRECTORY.setter
def DIRECTORY(self, value):
if isinstance(value, self._config.DEFAULT_SCHEMA.class_type):
self._config.DIRECTORY.value = value
else:
raise ValueError(f"DIRECTORY should be {self._config.DIRECTORY.class_type}")
@property
def TSQL_NO_SEMICOLON(self):
return self._config.TSQL_NO_SEMICOLON.value
@TSQL_NO_SEMICOLON.setter
def TSQL_NO_SEMICOLON(self, value):
if isinstance(value, self._config.TSQL_NO_SEMICOLON.class_type):
self._config.TSQL_NO_SEMICOLON.value = value
else:
raise ValueError(
f"TSQL_NO_SEMICOLON should be {self._config.TSQL_NO_SEMICOLON.class_type}"
)
SQLLineageConfig = _SQLLineageConfigLoader()
if __name__ == "__main__":
SQLLineageConfig.DIRECTORY = "xxx"
SQLLineageConfig.DEFAULT_SCHEMA = "ods"
SQLLineageConfig.TSQL_NO_SEMICOLON = "xxx"
print(SQLLineageConfig.DIRECTORY)
print(SQLLineageConfig.DEFAULT_SCHEMA)
print(SQLLineageConfig.TSQL_NO_SEMICOLON) self._dialect = dialect
self._metadata_provider = metadata_provider
self._silent_mode = silent_mode
SQLLineageConfig.DEFAULT_SCHEMA = default_schema
SQLLineageConfig.TSQL_NO_SEMICOLON = tsql_no_semicolon 修改 unknown 设置为 单元变量, 通过 config 直接赋值 |
Beta Was this translation helpful? Give feedback.
1 reply
-
but SQLLineageConfig = _SQLLineageConfigLoader() (onlysqlineage) liuzhou@liuzhou sqllineage % mypy
sqllineage/config.py:71: error: Call to untyped function "_SQLLineageConfigLoader" in typed context [no-untyped-call]
Found 1 error in 1 file (checked 45 source files) Can you tell me how to solve this problem? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
我想我解决了变量传入的问题, 改动也很少。
肚子很饿,我晚点发代码上来,一起讨论下。
I think I have solved the problem of variable input and made very few changes.
I'm very hungry. I'll send the code later and discuss it together
Beta Was this translation helpful? Give feedback.
All reactions