2022-11-10 10:54:31 +01:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""Partition utility tests"""
|
|
|
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
from metadata.generated.schema.entity.data.table import (
|
2024-02-28 07:11:00 +01:00
|
|
|
PartitionColumnDetails,
|
|
|
|
PartitionIntervalTypes,
|
2022-11-10 10:54:31 +01:00
|
|
|
PartitionIntervalUnit,
|
|
|
|
PartitionProfilerConfig,
|
|
|
|
TablePartition,
|
|
|
|
TableProfilerConfig,
|
|
|
|
)
|
|
|
|
from metadata.generated.schema.entity.services.databaseService import (
|
|
|
|
DatabaseServiceType,
|
|
|
|
)
|
|
|
|
from metadata.utils.partition import get_partition_details
|
|
|
|
|
|
|
|
|
|
|
|
class MockTable(BaseModel):
|
|
|
|
tablePartition: Optional[TablePartition]
|
|
|
|
tableProfilerConfig: Optional[TableProfilerConfig]
|
|
|
|
serviceType = DatabaseServiceType.BigQuery
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
arbitrary_types_allowed = True
|
|
|
|
|
|
|
|
|
|
|
|
class MockRedshiftTable(BaseModel):
|
|
|
|
tablePartition: Optional[TablePartition]
|
|
|
|
tableProfilerConfig: Optional[TableProfilerConfig]
|
|
|
|
serviceType = DatabaseServiceType.Redshift
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
arbitrary_types_allowed = True
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_partition_details():
|
|
|
|
"""test get_partition_details function"""
|
|
|
|
table_entity = MockRedshiftTable(
|
|
|
|
tableProfilerConfig=TableProfilerConfig(
|
|
|
|
partitioning=PartitionProfilerConfig(
|
|
|
|
enablePartitioning=True,
|
|
|
|
partitionColumnName="order_date",
|
|
|
|
partitionIntervalType="TIME-UNIT",
|
|
|
|
partitionInterval=5,
|
|
|
|
partitionIntervalUnit="YEAR",
|
|
|
|
partitionValues=None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
partition = get_partition_details(table_entity)
|
|
|
|
|
|
|
|
assert partition.enablePartitioning == True
|
|
|
|
assert partition.partitionColumnName == "order_date"
|
2024-02-28 07:11:00 +01:00
|
|
|
assert partition.partitionIntervalType == PartitionIntervalTypes.TIME_UNIT
|
2022-11-10 10:54:31 +01:00
|
|
|
assert partition.partitionInterval == 5
|
|
|
|
assert partition.partitionIntervalUnit == PartitionIntervalUnit.YEAR
|
|
|
|
|
|
|
|
table_entity = MockTable(
|
|
|
|
tablePartition=TablePartition(
|
2024-02-28 07:11:00 +01:00
|
|
|
columns=[
|
|
|
|
PartitionColumnDetails(
|
|
|
|
columnName="e",
|
|
|
|
intervalType=PartitionIntervalTypes.INGESTION_TIME,
|
|
|
|
interval="HOUR",
|
|
|
|
)
|
|
|
|
]
|
2022-11-10 10:54:31 +01:00
|
|
|
),
|
|
|
|
tableProfilerConfig=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
partition = get_partition_details(table_entity)
|
|
|
|
|
|
|
|
assert partition.enablePartitioning == True
|
|
|
|
assert partition.partitionColumnName == "_PARTITIONTIME"
|
2024-02-28 07:11:00 +01:00
|
|
|
assert partition.partitionIntervalType == PartitionIntervalTypes.INGESTION_TIME
|
2023-12-27 19:13:44 +01:00
|
|
|
assert partition.partitionInterval == 1
|
2022-11-10 10:54:31 +01:00
|
|
|
assert partition.partitionIntervalUnit == PartitionIntervalUnit.HOUR
|
|
|
|
|
|
|
|
table_entity = MockTable(
|
|
|
|
tablePartition=TablePartition(
|
2024-02-28 07:11:00 +01:00
|
|
|
columns=[
|
|
|
|
PartitionColumnDetails(
|
|
|
|
columnName="e",
|
|
|
|
intervalType=PartitionIntervalTypes.INGESTION_TIME,
|
|
|
|
interval="DAY",
|
|
|
|
)
|
|
|
|
]
|
2022-11-10 10:54:31 +01:00
|
|
|
),
|
|
|
|
tableProfilerConfig=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
partition = get_partition_details(table_entity)
|
|
|
|
|
2024-02-28 07:11:00 +01:00
|
|
|
assert partition.enablePartitioning is True
|
2022-11-10 10:54:31 +01:00
|
|
|
assert partition.partitionColumnName == "_PARTITIONDATE"
|
2024-02-28 07:11:00 +01:00
|
|
|
assert partition.partitionIntervalType == PartitionIntervalTypes.INGESTION_TIME
|
2023-12-27 19:13:44 +01:00
|
|
|
assert partition.partitionInterval == 1
|
2022-11-10 10:54:31 +01:00
|
|
|
assert partition.partitionIntervalUnit == PartitionIntervalUnit.DAY
|