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-07-12 17:02:32 +02:00
|
|
|
Interface for sampler
|
2022-11-15 20:31:10 +05:30
|
|
|
"""
|
2023-07-12 17:02:32 +02:00
|
|
|
|
|
|
|
from abc import ABC, abstractmethod
|
2023-10-12 14:51:38 +02:00
|
|
|
from typing import Dict, List, Optional, Union
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
2022-11-15 20:31:10 +05:30
|
|
|
|
2023-04-11 20:58:31 +05:30
|
|
|
from metadata.generated.schema.entity.data.table import TableData
|
2023-03-01 08:20:38 +01:00
|
|
|
from metadata.profiler.api.models import ProfileSampleConfig
|
2023-10-12 14:51:38 +02:00
|
|
|
from metadata.utils.sqa_like_column import SQALikeColumn
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
|
2023-07-12 17:02:32 +02:00
|
|
|
class SamplerInterface(ABC):
|
|
|
|
"""Sampler interface"""
|
2022-11-15 20:31:10 +05:30
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2023-07-12 17:02:32 +02:00
|
|
|
client,
|
2022-11-15 20:31:10 +05:30
|
|
|
table,
|
2023-01-16 22:17:46 +05:30
|
|
|
profile_sample_config: Optional[ProfileSampleConfig] = None,
|
2023-07-12 17:02:32 +02:00
|
|
|
partition_details: Optional[Dict] = None,
|
2022-11-15 20:31:10 +05:30
|
|
|
profile_sample_query: Optional[str] = None,
|
|
|
|
):
|
2023-01-16 22:17:46 +05:30
|
|
|
self.profile_sample = None
|
|
|
|
self.profile_sample_type = None
|
|
|
|
if profile_sample_config:
|
|
|
|
self.profile_sample = profile_sample_config.profile_sample
|
|
|
|
self.profile_sample_type = profile_sample_config.profile_sample_type
|
2023-07-12 17:02:32 +02:00
|
|
|
self.client = client
|
2022-11-15 20:31:10 +05:30
|
|
|
self.table = table
|
|
|
|
self._profile_sample_query = profile_sample_query
|
|
|
|
self.sample_limit = 100
|
|
|
|
self._sample_rows = None
|
2023-07-12 17:02:32 +02:00
|
|
|
self._partition_details = partition_details
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def _rdn_sample_from_user_query(self):
|
|
|
|
"""Get random sample from user query"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def _fetch_sample_data_from_user_query(self) -> TableData:
|
|
|
|
"""Fetch sample data from user query"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def random_sample(self):
|
|
|
|
"""Get random sample"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-10-12 14:51:38 +02:00
|
|
|
def fetch_sample_data(
|
|
|
|
self, columns: Optional[Union[List[Column], List[SQALikeColumn]]]
|
|
|
|
) -> TableData:
|
|
|
|
"""Fetch sample data
|
|
|
|
|
|
|
|
Args:
|
|
|
|
columns (Optional[List]): List of columns to fetch
|
|
|
|
"""
|
2023-07-12 17:02:32 +02:00
|
|
|
raise NotImplementedError
|