2022-11-15 20:31:10 +05:30
|
|
|
# Copyright 2021 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.
|
2023-09-13 16:32:55 +02:00
|
|
|
# pylint: disable=arguments-differ
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Interfaces with database for all database engine
|
|
|
|
|
supporting sqlalchemy abstraction layer
|
|
|
|
|
"""
|
|
|
|
|
import traceback
|
|
|
|
|
from collections import defaultdict
|
2023-10-08 20:08:51 +05:30
|
|
|
from copy import deepcopy
|
2022-11-15 20:31:10 +05:30
|
|
|
from datetime import datetime, timezone
|
2023-10-08 20:08:51 +05:30
|
|
|
from typing import Dict, List, Optional
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
|
|
|
|
|
2023-11-17 17:51:39 +01:00
|
|
|
from metadata.generated.schema.entity.data.table import CustomMetricProfile, TableData
|
2023-03-01 08:20:38 +01:00
|
|
|
from metadata.generated.schema.entity.services.connections.database.datalakeConnection import (
|
|
|
|
|
DatalakeConnection,
|
|
|
|
|
)
|
2023-11-17 17:51:39 +01:00
|
|
|
from metadata.generated.schema.tests.customMetric import CustomMetric
|
2023-04-04 17:16:44 +02:00
|
|
|
from metadata.mixins.pandas.pandas_mixin import PandasInterfaceMixin
|
2023-11-17 17:51:39 +01:00
|
|
|
from metadata.profiler.api.models import ThreadPoolMetrics
|
2023-07-12 17:02:32 +02:00
|
|
|
from metadata.profiler.interface.profiler_interface import ProfilerInterface
|
2023-03-01 08:20:38 +01:00
|
|
|
from metadata.profiler.metrics.core import MetricTypes
|
|
|
|
|
from metadata.profiler.metrics.registry import Metrics
|
2023-08-09 12:37:16 +02:00
|
|
|
from metadata.readers.dataframe.models import DatalakeTableSchemaWrapper
|
2023-11-09 18:49:42 +05:30
|
|
|
from metadata.utils.constants import COMPLEX_COLUMN_SEPARATOR, SAMPLE_DATA_DEFAULT_COUNT
|
2024-02-01 09:02:52 +01:00
|
|
|
from metadata.utils.datalake.datalake_utils import (
|
|
|
|
|
GenericDataFrameColumnParser,
|
|
|
|
|
fetch_dataframe,
|
|
|
|
|
)
|
2022-11-15 20:31:10 +05:30
|
|
|
from metadata.utils.logger import profiler_interface_registry_logger
|
2023-09-13 15:15:49 +05:30
|
|
|
from metadata.utils.sqa_like_column import SQALikeColumn
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
logger = profiler_interface_registry_logger()
|
|
|
|
|
|
|
|
|
|
|
2023-07-12 17:02:32 +02:00
|
|
|
class PandasProfilerInterface(ProfilerInterface, PandasInterfaceMixin):
|
2022-11-15 20:31:10 +05:30
|
|
|
"""
|
|
|
|
|
Interface to interact with registry supporting
|
|
|
|
|
sqlalchemy.
|
|
|
|
|
"""
|
|
|
|
|
|
2023-06-22 12:51:56 +05:30
|
|
|
# pylint: disable=too-many-arguments
|
|
|
|
|
|
2023-03-01 08:20:38 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
service_connection_config,
|
|
|
|
|
ometa_client,
|
|
|
|
|
entity,
|
2023-11-09 18:49:42 +05:30
|
|
|
storage_config,
|
2023-03-01 08:20:38 +01:00
|
|
|
profile_sample_config,
|
2023-03-03 18:33:18 +05:30
|
|
|
source_config,
|
2023-03-01 08:20:38 +01:00
|
|
|
sample_query,
|
2023-07-12 17:02:32 +02:00
|
|
|
table_partition_config,
|
|
|
|
|
thread_count: int = 5,
|
|
|
|
|
timeout_seconds: int = 43200,
|
2023-11-09 18:49:42 +05:30
|
|
|
sample_data_count: int = SAMPLE_DATA_DEFAULT_COUNT,
|
2023-07-12 17:02:32 +02:00
|
|
|
**kwargs,
|
2023-03-01 08:20:38 +01:00
|
|
|
):
|
2023-07-12 17:02:32 +02:00
|
|
|
"""Instantiate Pandas Interface object"""
|
|
|
|
|
|
|
|
|
|
super().__init__(
|
|
|
|
|
service_connection_config,
|
|
|
|
|
ometa_client,
|
|
|
|
|
entity,
|
2023-11-09 18:49:42 +05:30
|
|
|
storage_config,
|
2023-07-12 17:02:32 +02:00
|
|
|
profile_sample_config,
|
|
|
|
|
source_config,
|
|
|
|
|
sample_query,
|
|
|
|
|
table_partition_config,
|
|
|
|
|
thread_count,
|
|
|
|
|
timeout_seconds,
|
2023-11-09 18:49:42 +05:30
|
|
|
sample_data_count,
|
2023-10-08 20:08:51 +05:30
|
|
|
**kwargs,
|
2023-07-12 17:02:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.client = self.connection.client
|
|
|
|
|
self.dfs = self._convert_table_to_list_of_dataframe_objects()
|
2023-10-08 20:08:51 +05:30
|
|
|
self.sampler = self._get_sampler()
|
|
|
|
|
self.complex_dataframe_sample = deepcopy(self.sampler.random_sample())
|
2023-07-12 17:02:32 +02:00
|
|
|
|
|
|
|
|
def _convert_table_to_list_of_dataframe_objects(self):
|
2023-08-09 12:37:16 +02:00
|
|
|
"""From a table entity, return the corresponding dataframe object
|
2023-07-12 17:02:32 +02:00
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List[DataFrame]
|
|
|
|
|
"""
|
|
|
|
|
data = fetch_dataframe(
|
|
|
|
|
config_source=self.service_connection_config.configSource,
|
|
|
|
|
client=self.client,
|
|
|
|
|
file_fqn=DatalakeTableSchemaWrapper(
|
|
|
|
|
key=self.table_entity.name.__root__,
|
|
|
|
|
bucket_name=self.table_entity.databaseSchema.name,
|
2023-09-13 15:15:49 +05:30
|
|
|
file_extension=self.table_entity.fileFormat,
|
2023-07-12 17:02:32 +02:00
|
|
|
),
|
2023-03-24 17:59:06 +01:00
|
|
|
)
|
2023-07-12 17:02:32 +02:00
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
|
raise TypeError(f"Couldn't fetch {self.table_entity.name.__root__}")
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
def _get_sampler(self):
|
|
|
|
|
"""Get dataframe sampler from config"""
|
2023-11-07 12:10:59 +05:30
|
|
|
from metadata.profiler.processor.sampler.sampler_factory import ( # pylint: disable=import-outside-toplevel
|
|
|
|
|
sampler_factory_,
|
|
|
|
|
)
|
|
|
|
|
|
2023-07-13 13:35:37 +02:00
|
|
|
return sampler_factory_.create(
|
2023-07-12 17:02:32 +02:00
|
|
|
DatalakeConnection.__name__,
|
2022-12-14 21:14:51 +05:30
|
|
|
client=self.client,
|
2023-07-12 17:02:32 +02:00
|
|
|
table=self.dfs,
|
2023-04-11 20:58:31 +05:30
|
|
|
profile_sample_config=self.profile_sample_config,
|
2023-07-12 17:02:32 +02:00
|
|
|
partition_details=self.partition_details,
|
|
|
|
|
profile_sample_query=self.profile_query,
|
2022-11-15 20:31:10 +05:30
|
|
|
)
|
|
|
|
|
|
2023-09-13 16:32:55 +02:00
|
|
|
def _compute_table_metrics(
|
2022-12-07 14:33:30 +01:00
|
|
|
self,
|
|
|
|
|
metrics: List[Metrics],
|
2023-09-13 16:32:55 +02:00
|
|
|
runner: List,
|
2022-12-07 14:33:30 +01:00
|
|
|
*args,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
|
|
|
|
"""Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
metrics: list of metrics to compute
|
|
|
|
|
Returns:
|
|
|
|
|
dictionnary of results
|
|
|
|
|
"""
|
|
|
|
|
import pandas as pd # pylint: disable=import-outside-toplevel
|
|
|
|
|
|
|
|
|
|
try:
|
2023-04-11 20:58:31 +05:30
|
|
|
row_dict = {}
|
2023-09-13 16:32:55 +02:00
|
|
|
df_list = [df.where(pd.notnull(df), None) for df in runner]
|
2022-12-07 14:33:30 +01:00
|
|
|
for metric in metrics:
|
2023-04-11 20:58:31 +05:30
|
|
|
row_dict[metric.name()] = metric().df_fn(df_list)
|
|
|
|
|
return row_dict
|
2022-12-07 14:33:30 +01:00
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug(traceback.format_exc())
|
|
|
|
|
logger.warning(f"Error trying to compute profile for {exc}")
|
|
|
|
|
raise RuntimeError(exc)
|
|
|
|
|
|
2023-09-13 16:32:55 +02:00
|
|
|
def _compute_static_metrics(
|
2022-12-07 14:33:30 +01:00
|
|
|
self,
|
|
|
|
|
metrics: List[Metrics],
|
2023-09-13 16:32:55 +02:00
|
|
|
runner: List,
|
2022-12-07 14:33:30 +01:00
|
|
|
column,
|
|
|
|
|
*args,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
|
|
|
|
"""Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
column: the column to compute the metrics against
|
|
|
|
|
metrics: list of metrics to compute
|
|
|
|
|
Returns:
|
|
|
|
|
dictionnary of results
|
|
|
|
|
"""
|
|
|
|
|
import pandas as pd # pylint: disable=import-outside-toplevel
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
row_dict = {}
|
2023-04-11 20:58:31 +05:30
|
|
|
for metric in metrics:
|
2023-09-13 16:32:55 +02:00
|
|
|
metric_resp = metric(column).df_fn(runner)
|
2023-04-11 20:58:31 +05:30
|
|
|
row_dict[metric.name()] = (
|
|
|
|
|
None if pd.isnull(metric_resp) else metric_resp
|
|
|
|
|
)
|
2022-12-07 14:33:30 +01:00
|
|
|
return row_dict
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug(
|
|
|
|
|
f"{traceback.format_exc()}\nError trying to compute profile for {exc}"
|
|
|
|
|
)
|
|
|
|
|
raise RuntimeError(exc)
|
|
|
|
|
|
2023-09-13 16:32:55 +02:00
|
|
|
def _compute_query_metrics(
|
2022-12-07 14:33:30 +01:00
|
|
|
self,
|
2023-09-13 16:32:55 +02:00
|
|
|
metric: Metrics,
|
|
|
|
|
runner: List,
|
2022-12-07 14:33:30 +01:00
|
|
|
column,
|
|
|
|
|
*args,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
|
|
|
|
"""Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
column: the column to compute the metrics against
|
|
|
|
|
metrics: list of metrics to compute
|
|
|
|
|
Returns:
|
|
|
|
|
dictionnary of results
|
|
|
|
|
"""
|
|
|
|
|
col_metric = None
|
2023-09-13 16:32:55 +02:00
|
|
|
col_metric = metric(column).df_fn(runner)
|
2022-12-07 14:33:30 +01:00
|
|
|
if not col_metric:
|
|
|
|
|
return None
|
2023-09-13 16:32:55 +02:00
|
|
|
return {metric.name(): col_metric}
|
2022-12-07 14:33:30 +01:00
|
|
|
|
2023-09-13 16:32:55 +02:00
|
|
|
def _compute_window_metrics(
|
2022-12-07 14:33:30 +01:00
|
|
|
self,
|
2023-09-13 16:32:55 +02:00
|
|
|
metrics: List[Metrics],
|
|
|
|
|
runner: List,
|
2023-03-03 21:56:32 +01:00
|
|
|
column,
|
2022-12-07 14:33:30 +01:00
|
|
|
*args,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
"""
|
2023-09-13 16:32:55 +02:00
|
|
|
|
2023-03-03 21:56:32 +01:00
|
|
|
try:
|
|
|
|
|
metric_values = {}
|
|
|
|
|
for metric in metrics:
|
2023-09-13 16:32:55 +02:00
|
|
|
metric_values[metric.name()] = metric(column).df_fn(runner)
|
2023-03-03 21:56:32 +01:00
|
|
|
return metric_values if metric_values else None
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug(traceback.format_exc())
|
|
|
|
|
logger.warning(f"Unexpected exception computing metrics: {exc}")
|
|
|
|
|
return None
|
2022-12-07 14:33:30 +01:00
|
|
|
|
2023-09-13 16:32:55 +02:00
|
|
|
def _compute_system_metrics(
|
2022-12-07 14:33:30 +01:00
|
|
|
self,
|
2023-09-13 16:32:55 +02:00
|
|
|
metrics: Metrics,
|
|
|
|
|
runner: List,
|
2022-12-07 14:33:30 +01:00
|
|
|
*args,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
"""
|
|
|
|
|
return None # to be implemented
|
|
|
|
|
|
2023-11-17 17:51:39 +01:00
|
|
|
def _compute_custom_metrics(
|
|
|
|
|
self, metrics: List[CustomMetric], runner, *args, **kwargs
|
|
|
|
|
):
|
|
|
|
|
"""Compute custom metrics. For pandas source we expect expression
|
|
|
|
|
to be a boolean value. We'll return the length of the dataframe
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
metrics (List[Metrics]): list of customMetrics
|
|
|
|
|
runner (_type_): runner
|
|
|
|
|
"""
|
|
|
|
|
if not metrics:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
custom_metrics = []
|
|
|
|
|
|
|
|
|
|
for metric in metrics:
|
|
|
|
|
try:
|
|
|
|
|
row = sum(
|
|
|
|
|
len(df.query(metric.expression).index)
|
|
|
|
|
for df in runner
|
|
|
|
|
if len(df.query(metric.expression).index)
|
|
|
|
|
)
|
|
|
|
|
custom_metrics.append(
|
|
|
|
|
CustomMetricProfile(name=metric.name.__root__, value=row)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
msg = f"Error trying to compute profile for custom metric: {exc}"
|
|
|
|
|
logger.debug(traceback.format_exc())
|
|
|
|
|
logger.warning(msg)
|
|
|
|
|
if custom_metrics:
|
|
|
|
|
return {"customMetrics": custom_metrics}
|
|
|
|
|
return None
|
|
|
|
|
|
2022-11-15 20:31:10 +05:30
|
|
|
def compute_metrics(
|
|
|
|
|
self,
|
2023-11-17 17:51:39 +01:00
|
|
|
metric_func: ThreadPoolMetrics,
|
2022-11-15 20:31:10 +05:30
|
|
|
):
|
|
|
|
|
"""Run metrics in processor worker"""
|
2023-11-17 17:51:39 +01:00
|
|
|
logger.debug(f"Running profiler for {metric_func.table}")
|
2022-11-15 20:31:10 +05:30
|
|
|
try:
|
2023-04-11 20:58:31 +05:30
|
|
|
row = None
|
2023-10-08 20:08:51 +05:30
|
|
|
if self.complex_dataframe_sample:
|
2023-11-17 17:51:39 +01:00
|
|
|
row = self._get_metric_fn[metric_func.metric_type.value](
|
|
|
|
|
metric_func.metrics,
|
2023-10-08 20:08:51 +05:30
|
|
|
self.complex_dataframe_sample,
|
2023-11-17 17:51:39 +01:00
|
|
|
column=metric_func.column,
|
2023-04-11 20:58:31 +05:30
|
|
|
)
|
2022-12-07 14:33:30 +01:00
|
|
|
except Exception as exc:
|
2023-11-17 17:51:39 +01:00
|
|
|
name = f"{metric_func.column if metric_func.column is not None else metric_func.table}"
|
2023-03-24 17:59:06 +01:00
|
|
|
error = f"{name} metric_type.value: {exc}"
|
|
|
|
|
logger.error(error)
|
2023-09-04 11:02:57 +02:00
|
|
|
self.status.failed_profiler(error, traceback.format_exc())
|
2022-11-15 20:31:10 +05:30
|
|
|
row = None
|
2023-11-17 17:51:39 +01:00
|
|
|
if metric_func.column is not None:
|
|
|
|
|
column = metric_func.column.name
|
|
|
|
|
self.status.scanned(f"{metric_func.table.name.__root__}.{column}")
|
2023-04-27 18:18:33 +02:00
|
|
|
else:
|
2023-11-17 17:51:39 +01:00
|
|
|
self.status.scanned(metric_func.table.name.__root__)
|
|
|
|
|
column = None
|
|
|
|
|
return row, column, metric_func.metric_type.value
|
2022-11-15 20:31:10 +05:30
|
|
|
|
2023-10-12 14:51:38 +02:00
|
|
|
def fetch_sample_data(self, table, columns: SQALikeColumn) -> TableData:
|
2022-11-15 20:31:10 +05:30
|
|
|
"""Fetch sample data from database
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
table: ORM declarative table
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
TableData: sample table data
|
|
|
|
|
"""
|
2023-10-12 14:51:38 +02:00
|
|
|
sampler = self._get_sampler()
|
|
|
|
|
return sampler.fetch_sample_data(columns)
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
def get_composed_metrics(
|
|
|
|
|
self, column: Column, metric: Metrics, column_results: Dict
|
|
|
|
|
):
|
|
|
|
|
"""Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
column: the column to compute the metrics against
|
2022-11-17 10:11:54 +01:00
|
|
|
metric: list of metrics to compute
|
|
|
|
|
column_results: computed values for the column
|
2022-11-15 20:31:10 +05:30
|
|
|
Returns:
|
|
|
|
|
dictionary of results
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
return metric(column).fn(column_results)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug(traceback.format_exc())
|
|
|
|
|
logger.warning(f"Unexpected exception computing metrics: {exc}")
|
|
|
|
|
return None
|
|
|
|
|
|
2023-03-03 21:56:32 +01:00
|
|
|
def get_hybrid_metrics(
|
|
|
|
|
self, column: Column, metric: Metrics, column_results: Dict, **kwargs
|
|
|
|
|
):
|
|
|
|
|
"""Given a list of metrics, compute the given results
|
|
|
|
|
and returns the values
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
column: the column to compute the metrics against
|
|
|
|
|
metric: list of metrics to compute
|
|
|
|
|
column_results: computed values for the column
|
|
|
|
|
Returns:
|
|
|
|
|
dictionary of results
|
|
|
|
|
"""
|
|
|
|
|
try:
|
2023-10-08 20:08:51 +05:30
|
|
|
return metric(column).df_fn(column_results, self.complex_dataframe_sample)
|
2023-03-03 21:56:32 +01:00
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug(traceback.format_exc())
|
|
|
|
|
logger.warning(f"Unexpected exception computing metrics: {exc}")
|
|
|
|
|
return None
|
|
|
|
|
|
2022-11-15 20:31:10 +05:30
|
|
|
def get_all_metrics(
|
|
|
|
|
self,
|
|
|
|
|
metric_funcs: list,
|
|
|
|
|
):
|
|
|
|
|
"""get all profiler metrics"""
|
|
|
|
|
|
|
|
|
|
profile_results = {"table": {}, "columns": defaultdict(dict)}
|
|
|
|
|
metric_list = [
|
2023-11-17 17:51:39 +01:00
|
|
|
self.compute_metrics(metric_func) for metric_func in metric_funcs
|
2022-11-15 20:31:10 +05:30
|
|
|
]
|
|
|
|
|
for metric_result in metric_list:
|
2022-12-07 14:33:30 +01:00
|
|
|
profile, column, metric_type = metric_result
|
2023-04-11 20:58:31 +05:30
|
|
|
if profile:
|
|
|
|
|
if metric_type == MetricTypes.Table.value:
|
|
|
|
|
profile_results["table"].update(profile)
|
|
|
|
|
if metric_type == MetricTypes.System.value:
|
|
|
|
|
profile_results["system"] = profile
|
2023-11-17 17:51:39 +01:00
|
|
|
elif metric_type == MetricTypes.Custom.value and column is None:
|
|
|
|
|
profile_results["table"].update(profile)
|
2023-04-11 20:58:31 +05:30
|
|
|
else:
|
|
|
|
|
if profile:
|
|
|
|
|
profile_results["columns"][column].update(
|
|
|
|
|
{
|
|
|
|
|
"name": column,
|
2023-08-25 08:47:16 +02:00
|
|
|
"timestamp": int(
|
|
|
|
|
datetime.now(tz=timezone.utc).timestamp() * 1000
|
|
|
|
|
),
|
2023-04-11 20:58:31 +05:30
|
|
|
**profile,
|
|
|
|
|
}
|
|
|
|
|
)
|
2022-11-15 20:31:10 +05:30
|
|
|
return profile_results
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def table(self):
|
|
|
|
|
"""OM Table entity"""
|
2023-10-08 20:08:51 +05:30
|
|
|
return self.table_entity
|
|
|
|
|
|
|
|
|
|
def get_columns(self) -> List[Optional[SQALikeColumn]]:
|
|
|
|
|
"""Get SQALikeColumns for datalake to be passed for metric computation"""
|
|
|
|
|
sqalike_columns = []
|
|
|
|
|
if self.complex_dataframe_sample:
|
|
|
|
|
for column_name in self.complex_dataframe_sample[0].columns:
|
|
|
|
|
complex_col_name = None
|
|
|
|
|
if COMPLEX_COLUMN_SEPARATOR in column_name:
|
|
|
|
|
complex_col_name = ".".join(
|
|
|
|
|
column_name.split(COMPLEX_COLUMN_SEPARATOR)[1:]
|
|
|
|
|
)
|
|
|
|
|
if complex_col_name:
|
|
|
|
|
for df in self.complex_dataframe_sample:
|
|
|
|
|
df.rename(
|
|
|
|
|
columns={column_name: complex_col_name}, inplace=True
|
|
|
|
|
)
|
|
|
|
|
column_name = complex_col_name or column_name
|
|
|
|
|
sqalike_columns.append(
|
|
|
|
|
SQALikeColumn(
|
|
|
|
|
column_name,
|
2024-02-01 09:02:52 +01:00
|
|
|
GenericDataFrameColumnParser.fetch_col_types(
|
|
|
|
|
self.complex_dataframe_sample[0], column_name
|
|
|
|
|
),
|
2023-10-08 20:08:51 +05:30
|
|
|
)
|
2023-02-22 09:42:34 +01:00
|
|
|
)
|
2023-10-08 20:08:51 +05:30
|
|
|
return sqalike_columns
|
2023-02-22 09:42:34 +01:00
|
|
|
return []
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
def close(self):
|
2023-03-01 08:20:38 +01:00
|
|
|
"""Nothing to close with pandas"""
|