schema_sentinel.metadata_manager.lookup.sql_data_type

  1from dataclasses import dataclass
  2
  3
  4@dataclass
  5class SqlDataTypeCategory:
  6    name: str
  7
  8
  9@dataclass
 10class SqlDataType:
 11    name: str
 12    category: SqlDataTypeCategory
 13    notes: str
 14
 15
 16def load_data_types() -> dict[str, SqlDataType]:
 17    """
 18    Function loads a dictionary of SQL Data Types
 19    :return: Dict[SqlDataType]
 20    """
 21    data_types: dict[str, SqlDataType] = {}
 22    for category in SQL_DATA_TYPE.keys():
 23        sql_data_type_category: SqlDataTypeCategory = SqlDataTypeCategory(category)
 24        data_types[category] = []
 25        for data_type in SQL_DATA_TYPE[category]:
 26            sql_data_type = SqlDataType(
 27                name=data_type["name"],
 28                category=sql_data_type_category,
 29                notes=data_type["notes"] if "notes" in data_type else None,
 30            )
 31            data_types[category].append(sql_data_type)
 32
 33
 34SQL_DATA_TYPE: dict = {
 35    "Numeric Data Types": [
 36        {"name": "NUMBER", "notes": "Default precision and scale are (38,0)."},
 37        {"name": "DECIMAL", "notes": "Synonymous with NUMBER. Default precision and scale are (38,0)."},
 38        {"name": "NUMERIC", "notes": "Synonymous with NUMBER. Default precision and scale are (38,0)."},
 39        {"name": "INT", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 40        {"name": "INTEGER", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 41        {"name": "BIGINT", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 42        {"name": "SMALLINT", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 43        {"name": "TINYINT", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 44        {"name": "BYTEINT", "notes": "Synonymous with NUMBER except precision and scale cannot be specified."},
 45        {
 46            "name": "FLOAT",
 47            "notes": "A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE",
 48        },
 49        {
 50            "name": "FLOAT4",
 51            "notes": "A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE",
 52        },
 53        {
 54            "name": "FLOAT8",
 55            "notes": "A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE",
 56        },
 57        {"name": "DOUBLE", "notes": "Synonymous with FLOAT."},
 58        {"name": "DOUBLE PRECISION", "notes": "Synonymous with FLOAT."},
 59        {"name": "REAL", "notes": "Synonymous with FLOAT."},
 60    ],
 61    "String & Binary Data Types": [
 62        {"name": "VARCHAR", "notes": "Default (and maximum) is 16,777,216 bytes."},
 63        {"name": "CHAR", "notes": "Synonymous with VARCHAR except default length is VARCHAR(1)."},
 64        {"name": "CHARACTER", "notes": "Synonymous with VARCHAR except default length is VARCHAR(1)."},
 65        {"name": "TEXT", "notes": "Synonymous with VARCHAR"},
 66        {"name": "BINARY"},
 67        {"name": "VARBINARY", "notes": "Synonymous with BINARY"},
 68    ],
 69    "Logical Data Types": [
 70        {"name": "BOOLEAN", "notes": "Currently only supported for accounts provisioned after January 25, 2016."}
 71    ],
 72    "Date & Time Data Types": [
 73        {
 74            "name": "DATE",
 75        },
 76        {"name": "DATETIME", "notes": "Alias for TIMESTAMP_NTZ"},
 77        {
 78            "name": "TIME",
 79        },
 80        {"name": "TIMESTAMP", "notes": "Alias for one of the TIMESTAMP variations (TIMESTAMP_NTZ by default)."},
 81        {"name": "TIMESTAMP_LTZ", "notes": "TIMESTAMP with local time zone; time zone, if provided, is not stored."},
 82        {"name": "TIMESTAMP_NTZ", "notes": "TIMESTAMP with no time zone; time zone, if provided, is not stored."},
 83        {"name": "TIMESTAMP_TZ", "notes": "TIMESTAMP with time zone."},
 84    ],
 85    "Semi-structured Data Types": [
 86        {
 87            "name": "VARIANT",
 88        },
 89        {
 90            "name": "OBJECT",
 91        },
 92        {
 93            "name": "ARRAY",
 94        },
 95    ],
 96    "Geospatial Data Types": [
 97        {
 98            "name": "GEOGRAPHY",
 99        },
100        {
101            "name": "GEOMETRY",
102        },
103    ],
104}
@dataclass
class SqlDataTypeCategory:
5@dataclass
6class SqlDataTypeCategory:
7    name: str
SqlDataTypeCategory(name: str)
name: str
@dataclass
class SqlDataType:
10@dataclass
11class SqlDataType:
12    name: str
13    category: SqlDataTypeCategory
14    notes: str
SqlDataType( name: str, category: SqlDataTypeCategory, notes: str)
name: str
notes: str
def load_data_types() -> dict[str, SqlDataType]:
17def load_data_types() -> dict[str, SqlDataType]:
18    """
19    Function loads a dictionary of SQL Data Types
20    :return: Dict[SqlDataType]
21    """
22    data_types: dict[str, SqlDataType] = {}
23    for category in SQL_DATA_TYPE.keys():
24        sql_data_type_category: SqlDataTypeCategory = SqlDataTypeCategory(category)
25        data_types[category] = []
26        for data_type in SQL_DATA_TYPE[category]:
27            sql_data_type = SqlDataType(
28                name=data_type["name"],
29                category=sql_data_type_category,
30                notes=data_type["notes"] if "notes" in data_type else None,
31            )
32            data_types[category].append(sql_data_type)

Function loads a dictionary of SQL Data Types

Returns

Dict[SqlDataType]

SQL_DATA_TYPE: dict = {'Numeric Data Types': [{'name': 'NUMBER', 'notes': 'Default precision and scale are (38,0).'}, {'name': 'DECIMAL', 'notes': 'Synonymous with NUMBER. Default precision and scale are (38,0).'}, {'name': 'NUMERIC', 'notes': 'Synonymous with NUMBER. Default precision and scale are (38,0).'}, {'name': 'INT', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'INTEGER', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'BIGINT', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'SMALLINT', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'TINYINT', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'BYTEINT', 'notes': 'Synonymous with NUMBER except precision and scale cannot be specified.'}, {'name': 'FLOAT', 'notes': 'A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE'}, {'name': 'FLOAT4', 'notes': 'A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE'}, {'name': 'FLOAT8', 'notes': 'A known issue in Snowflake displays FLOAT, FLOAT4, FLOAT8, REAL, DOUBLE, and DOUBLE PRECISION as FLOAT even though they are stored as DOUBLE'}, {'name': 'DOUBLE', 'notes': 'Synonymous with FLOAT.'}, {'name': 'DOUBLE PRECISION', 'notes': 'Synonymous with FLOAT.'}, {'name': 'REAL', 'notes': 'Synonymous with FLOAT.'}], 'String & Binary Data Types': [{'name': 'VARCHAR', 'notes': 'Default (and maximum) is 16,777,216 bytes.'}, {'name': 'CHAR', 'notes': 'Synonymous with VARCHAR except default length is VARCHAR(1).'}, {'name': 'CHARACTER', 'notes': 'Synonymous with VARCHAR except default length is VARCHAR(1).'}, {'name': 'TEXT', 'notes': 'Synonymous with VARCHAR'}, {'name': 'BINARY'}, {'name': 'VARBINARY', 'notes': 'Synonymous with BINARY'}], 'Logical Data Types': [{'name': 'BOOLEAN', 'notes': 'Currently only supported for accounts provisioned after January 25, 2016.'}], 'Date & Time Data Types': [{'name': 'DATE'}, {'name': 'DATETIME', 'notes': 'Alias for TIMESTAMP_NTZ'}, {'name': 'TIME'}, {'name': 'TIMESTAMP', 'notes': 'Alias for one of the TIMESTAMP variations (TIMESTAMP_NTZ by default).'}, {'name': 'TIMESTAMP_LTZ', 'notes': 'TIMESTAMP with local time zone; time zone, if provided, is not stored.'}, {'name': 'TIMESTAMP_NTZ', 'notes': 'TIMESTAMP with no time zone; time zone, if provided, is not stored.'}, {'name': 'TIMESTAMP_TZ', 'notes': 'TIMESTAMP with time zone.'}], 'Semi-structured Data Types': [{'name': 'VARIANT'}, {'name': 'OBJECT'}, {'name': 'ARRAY'}], 'Geospatial Data Types': [{'name': 'GEOGRAPHY'}, {'name': 'GEOMETRY'}]}