Skip to content

Commit

Permalink
[SPARK-43057][FOLLOWUP][CONNECT][PYTHON] Add & refine errors
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This is follow-up for apache#40694 to redeem some errors.

### Why are the changes needed?

To make errors clear

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

The existing CI should pass

Closes apache#41032 from itholic/connect_followup.

Authored-by: itholic <haejoon.lee@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
itholic authored and LuciferYang committed May 10, 2023
1 parent 4013cfa commit bb683b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions python/pyspark/errors/error_classes.py
Expand Up @@ -34,6 +34,11 @@
"Attribute `<attr_name>` in provided object `<obj_name>` is not callable."
]
},
"ATTRIBUTE_NOT_SUPPORTED" : {
"message" : [
"Attribute `<attr_name>` is not supported."
]
},
"BROADCAST_VARIABLE_NOT_LOADED": {
"message": [
"Broadcast variable `<variable>` not loaded."
Expand Down
10 changes: 6 additions & 4 deletions python/pyspark/sql/connect/column.py
Expand Up @@ -138,9 +138,9 @@ def __init__(self, expr: "Expression") -> None:

# container operators
def __contains__(self, item: Any) -> None:
raise ValueError(
"Cannot apply 'in' operator against a column: please use 'contains' "
"in a string column or 'array_contains' function for an array column."
raise PySparkValueError(
error_class="CANNOT_APPLY_IN_FOR_COLUMN",
message_parameters={},
)

# bitwise operators
Expand Down Expand Up @@ -438,7 +438,9 @@ def __getattr__(self, item: Any) -> "Column":
error_class="JVM_ATTRIBUTE_NOT_SUPPORTED", message_parameters={"attr_name": "_jc"}
)
if item.startswith("__"):
raise AttributeError(item)
raise PySparkAttributeError(
error_class="ATTRIBUTE_NOT_SUPPORTED", message_parameters={"attr_name": item}
)
return self[item]

def __getitem__(self, k: Any) -> "Column":
Expand Down

0 comments on commit bb683b4

Please sign in to comment.