Skip to content

Commit 64d7eb0

Browse files
refacto validate_emit
1 parent 927afb9 commit 64d7eb0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

exasol_udf_mock_python/column.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ def __init__(self, name, type, sql_type, precision=None, scale=None, length=None
88
self.length = length
99

1010
def __repr__(self):
11-
return str(self.__class__) + ": " + str(self.__dict__)
11+
return str(self.__class__) + ": " + str(self.__dict__)
12+
13+
def __str__(self):
14+
return f"{self.name}:{self.type.__name__}"

exasol_udf_mock_python/mock_context.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ def validate_emit(row: Tuple, columns: List[Column]):
3535
:param row: Data row
3636
:param columns: Column definition.
3737
"""
38-
if len(row) != len(columns):
39-
raise ValueError(f"row {row} has not the same number of values as columns are defined")
38+
if (expected_len := len(columns)) != (actual_len := len(row)):
39+
raise ValueError(
40+
f"Row length missmatch: got {actual_len} values but {expected_len} columns are defined.\n"
41+
f" Expected columns: {[str(c) for c in columns]}. Actual values: {row}\n"
42+
)
43+
errors = []
4044
for i, column in enumerate(columns):
4145
if row[i] is not None and not isinstance(row[i], column.type):
42-
raise TypeError(f"Value {row[i]} ({type(row[i])}) at position {i} is not a {column.type}")
46+
errors.append(
47+
f"Type missmatch at column '{column.name}' (index {i})\n"
48+
f" Expected type: {column.type.__name__}. Actual type {type(row[i]).__name__} with Value: {row[i]}.\n"
49+
)
50+
if errors:
51+
raise TypeError("\n".join(errors))
4352

4453

4554
class MockContext(UDFContext):

0 commit comments

Comments
 (0)