diff --git a/exasol_udf_mock_python/column.py b/exasol_udf_mock_python/column.py index 4198a5e..251377b 100644 --- a/exasol_udf_mock_python/column.py +++ b/exasol_udf_mock_python/column.py @@ -8,4 +8,7 @@ def __init__(self, name, type, sql_type, precision=None, scale=None, length=None self.length = length def __repr__(self): - return str(self.__class__) + ": " + str(self.__dict__) \ No newline at end of file + return str(self.__class__) + ": " + str(self.__dict__) + + def __str__(self): + return f"{self.name}:{self.type.__name__}" diff --git a/exasol_udf_mock_python/mock_context.py b/exasol_udf_mock_python/mock_context.py index 29c0ff2..c7d1be9 100644 --- a/exasol_udf_mock_python/mock_context.py +++ b/exasol_udf_mock_python/mock_context.py @@ -35,11 +35,20 @@ def validate_emit(row: Tuple, columns: List[Column]): :param row: Data row :param columns: Column definition. """ - if len(row) != len(columns): - raise ValueError(f"row {row} has not the same number of values as columns are defined") + if (expected_len := len(columns)) != (actual_len := len(row)): + raise ValueError( + f"Row length missmatch: got {actual_len} values but {expected_len} columns are defined.\n" + f" Expected columns: {[str(c) for c in columns]}. Actual values: {row}\n" + ) + errors = [] for i, column in enumerate(columns): if row[i] is not None and not isinstance(row[i], column.type): - raise TypeError(f"Value {row[i]} ({type(row[i])}) at position {i} is not a {column.type}") + errors.append( + f"Type missmatch at column '{column.name}' (index {i})\n" + f" Expected type: {column.type.__name__}. Actual type {type(row[i]).__name__} with Value: {row[i]}.\n" + ) + if errors: + raise TypeError("\n".join(errors)) class MockContext(UDFContext):