mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-07 05:53:46 +00:00
Fixing Snowflake Query and arrayDataType issue (#3174)
This commit is contained in:
parent
23b97f5fe1
commit
ce99d52cd7
@ -8,12 +8,14 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
import logging
|
||||||
|
import traceback
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from snowflake.sqlalchemy.custom_types import VARIANT
|
from snowflake.sqlalchemy.custom_types import VARIANT
|
||||||
from snowflake.sqlalchemy.snowdialect import ischema_names
|
from snowflake.sqlalchemy.snowdialect import ischema_names
|
||||||
|
|
||||||
|
from metadata.generated.schema.entity.data.table import TableData
|
||||||
from metadata.generated.schema.entity.services.databaseService import (
|
from metadata.generated.schema.entity.services.databaseService import (
|
||||||
DatabaseServiceType,
|
DatabaseServiceType,
|
||||||
)
|
)
|
||||||
@ -26,6 +28,8 @@ GEOGRAPHY = create_sqlalchemy_type("GEOGRAPHY")
|
|||||||
ischema_names["VARIANT"] = VARIANT
|
ischema_names["VARIANT"] = VARIANT
|
||||||
ischema_names["GEOGRAPHY"] = GEOGRAPHY
|
ischema_names["GEOGRAPHY"] = GEOGRAPHY
|
||||||
|
|
||||||
|
logger: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SnowflakeConfig(SQLConnectionConfig):
|
class SnowflakeConfig(SQLConnectionConfig):
|
||||||
scheme = "snowflake"
|
scheme = "snowflake"
|
||||||
@ -53,6 +57,25 @@ class SnowflakeSource(SQLSource):
|
|||||||
def __init__(self, config, metadata_config, ctx):
|
def __init__(self, config, metadata_config, ctx):
|
||||||
super().__init__(config, metadata_config, ctx)
|
super().__init__(config, metadata_config, ctx)
|
||||||
|
|
||||||
|
def fetch_sample_data(self, schema: str, table: str) -> Optional[TableData]:
|
||||||
|
resp_sample_data = super().fetch_sample_data(schema, table)
|
||||||
|
if not resp_sample_data:
|
||||||
|
try:
|
||||||
|
logger.info("Using Table Name with quotes to fetch the data")
|
||||||
|
query = self.config.query.format(schema, f'"{table}"')
|
||||||
|
logger.info(query)
|
||||||
|
results = self.connection.execute(query)
|
||||||
|
cols = []
|
||||||
|
for col in results.keys():
|
||||||
|
cols.append(col.replace(".", "_DOT_"))
|
||||||
|
rows = []
|
||||||
|
for res in results:
|
||||||
|
row = list(res)
|
||||||
|
rows.append(row)
|
||||||
|
return TableData(columns=cols, rows=rows)
|
||||||
|
except Exception as err:
|
||||||
|
logger.error(err)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, config_dict, metadata_config_dict, ctx):
|
def create(cls, config_dict, metadata_config_dict, ctx):
|
||||||
config = SnowflakeConfig.parse_obj(config_dict)
|
config = SnowflakeConfig.parse_obj(config_dict)
|
||||||
|
|||||||
@ -29,6 +29,7 @@ from metadata.generated.schema.entity.data.table import (
|
|||||||
Constraint,
|
Constraint,
|
||||||
ConstraintType,
|
ConstraintType,
|
||||||
DataModel,
|
DataModel,
|
||||||
|
DataType,
|
||||||
ModelType,
|
ModelType,
|
||||||
Table,
|
Table,
|
||||||
TableConstraint,
|
TableConstraint,
|
||||||
@ -397,6 +398,7 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
|
|||||||
)
|
)
|
||||||
model_fqdn = f"{schema}.{model_name}"
|
model_fqdn = f"{schema}.{model_name}"
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
logger.debug(traceback.print_exc())
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
self.data_models[model_fqdn] = model
|
self.data_models[model_fqdn] = model
|
||||||
|
|
||||||
@ -562,8 +564,8 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
|
|||||||
col_type, column["type"]
|
col_type, column["type"]
|
||||||
)
|
)
|
||||||
if col_type == "NULL" or col_type is None:
|
if col_type == "NULL" or col_type is None:
|
||||||
col_type = "VARCHAR"
|
col_type = DataType.VARCHAR.name
|
||||||
data_type_display = "varchar"
|
data_type_display = col_type.lower()
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Unknown type {} mapped to VARCHAR: {}".format(
|
"Unknown type {} mapped to VARCHAR: {}".format(
|
||||||
repr(column["type"]), column["name"]
|
repr(column["type"]), column["name"]
|
||||||
@ -579,10 +581,10 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
|
|||||||
col_data_length = (
|
col_data_length = (
|
||||||
1 if col_data_length is None else col_data_length
|
1 if col_data_length is None else col_data_length
|
||||||
)
|
)
|
||||||
if col_type == "ARRAY":
|
if col_type == "ARRAY" and arr_data_type is None:
|
||||||
if arr_data_type is None:
|
arr_data_type = DataType.VARCHAR.name
|
||||||
arr_data_type = "VARCHAR"
|
dataTypeDisplay = f"array<{arr_data_type}>"
|
||||||
dataTypeDisplay = col_type + "<" + arr_data_type + ">"
|
|
||||||
om_column = Column(
|
om_column = Column(
|
||||||
name=column["name"],
|
name=column["name"],
|
||||||
description=column.get("comment", None),
|
description=column.get("comment", None),
|
||||||
@ -640,7 +642,8 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
|
|||||||
]
|
]
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.debug(traceback.print_exc())
|
logger.debug(traceback.print_exc())
|
||||||
logger.debug(err)
|
logger.error(err)
|
||||||
|
|
||||||
om_column = col_dict
|
om_column = col_dict
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.debug(traceback.print_exc())
|
logger.debug(traceback.print_exc())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user