Skip to content

Commit

Permalink
added a val func to check if location is provided if table does not e…
Browse files Browse the repository at this point in the history
…xist

Signed-off-by: Minura Punchihewa <minurapunchihewa17@gmail.com>
  • Loading branch information
MinuraPunchihewa committed Sep 8, 2024
1 parent 1734f44 commit b03bee8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions kedro-datasets/kedro_datasets/databricks/_base_table_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import pandas as pd
from kedro.io.core import (
AbstractVersionedDataset,
DatasetError,
Version,
VersionNotFoundError,
DatasetError
VersionNotFoundError
)
from pyspark.sql import DataFrame
from pyspark.sql.readwriter import DataFrameWriter
Expand Down Expand Up @@ -84,7 +84,7 @@ def _validate_table(self):
DatasetError: If the table name does not conform to naming constraints.
"""
if not re.fullmatch(self._NAMING_REGEX, self.table):
raise DatasetError("table does not conform to naming")
raise DatasetError("Table does not conform to naming")

def _validate_database(self):
"""Validates database name.
Expand All @@ -93,7 +93,7 @@ def _validate_database(self):
DatasetError: If the dataset name does not conform to naming constraints.
"""
if not re.fullmatch(self._NAMING_REGEX, self.database):
raise DatasetError("database does not conform to naming")
raise DatasetError("Database does not conform to naming")

def _validate_catalog(self):
"""Validates catalog name.
Expand All @@ -103,7 +103,7 @@ def _validate_catalog(self):
"""
if self.catalog:
if not re.fullmatch(self._NAMING_REGEX, self.catalog):
raise DatasetError("catalog does not conform to naming")
raise DatasetError("Catalog does not conform to naming")

def _validate_write_mode(self):
"""Validates the write mode.
Expand Down
16 changes: 16 additions & 0 deletions kedro-datasets/kedro_datasets/databricks/external_table_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from typing import Any

import pandas as pd
import pandas as pd
from kedro.io.core import (
DatasetError
)

from kedro_datasets.databricks._base_table_dataset import BaseTable, BaseTableDataset

Expand All @@ -19,6 +23,18 @@
class ExternalTable(BaseTable):
"""Stores the definition of an external table."""

def _validate_existence_of_table(self) -> None:
"""Validates that a location is provided if the table does not exist.
Raises:
DatasetError: If the table does not exist and no location is provided.
"""
if not self.exists() and not self.location:
raise DatasetError(
"If the external table does not exists, the `location` parameter must be provided. "
"This should be valid path in an external location that has already been created."
)


class ExternalTableDataset(BaseTableDataset):
"""``ExternalTableDataset`` loads and saves data into external tables in Databricks.
Expand Down

0 comments on commit b03bee8

Please sign in to comment.