Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed format
  • Loading branch information
bogao007 committed Aug 18, 2023
commit 334ee7c943861175ac07cbe8ecaeb8eb4ce96ab5
2 changes: 1 addition & 1 deletion python/pyspark/sql/connect/protobuf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.
#

"""Spark Connect Python Client - Protobuf Functions"""
"""Spark Connect Python Client - Protobuf Functions"""
42 changes: 15 additions & 27 deletions python/pyspark/sql/connect/protobuf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@


def from_protobuf(
data: "ColumnOrName",
messageName: str,
descFilePath: Optional[str] = None,
options: Optional[Dict[str, str]] = None,
binaryDescriptorSet: Optional[bytes] = None,
data: "ColumnOrName",
messageName: str,
descFilePath: Optional[str] = None,
options: Optional[Dict[str, str]] = None,
binaryDescriptorSet: Optional[bytes] = None,
) -> Column:
binary_proto = None
if binaryDescriptorSet is not None:
Expand All @@ -50,28 +50,22 @@ def from_protobuf(
if binary_proto is not None:
if options is None:
return _invoke_function(
"from_protobuf",
_to_col(data),
lit(messageName),
lit(binary_proto)
"from_protobuf", _to_col(data), lit(messageName), lit(binary_proto)
)
else:
return _invoke_function(
Copy link

@rangadi rangadi Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many calls to _invoke_function(). It will be much simpler if it allowed 'None' options and ignored it. @bogao007 could you include a comment about it?
cc: @LuciferYang, @HyukjinKwon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_invoke_function() doesn't seem to support None input. I will include a comment for it.

"from_protobuf",
_to_col(data),
lit(messageName),
lit(binary_proto),
_options_to_col(options)
_options_to_col(options),
)
else:
if options is None:
return _invoke_function("from_protobuf", _to_col(data), lit(messageName))
else:
return _invoke_function(
"from_protobuf",
_to_col(data),
lit(messageName),
_options_to_col(options)
"from_protobuf", _to_col(data), lit(messageName), _options_to_col(options)
)


Expand All @@ -94,28 +88,22 @@ def to_protobuf(
if binary_proto is not None:
if options is None:
return _invoke_function(
"to_protobuf",
_to_col(data),
lit(messageName),
lit(binary_proto)
"to_protobuf", _to_col(data), lit(messageName), lit(binary_proto)
)
else:
return _invoke_function(
"to_protobuf",
_to_col(data),
lit(messageName),
lit(binary_proto),
_options_to_col(options)
_options_to_col(options),
)
else:
if options is None:
return _invoke_function("to_protobuf", _to_col(data), lit(messageName))
else:
return _invoke_function(
"to_protobuf",
_to_col(data),
lit(messageName),
_options_to_col(options)
"to_protobuf", _to_col(data), lit(messageName), _options_to_col(options)
)


Expand Down Expand Up @@ -154,16 +142,16 @@ def _test() -> None:

globs["spark"] = (
PySparkSession.builder.appName("sql.protobuf.functions tests")
.remote("local[2]")
.getOrCreate()
.remote("local[2]")
.getOrCreate()
)

(failure_count, test_count) = doctest.testmod(
pyspark.sql.connect.protobuf.functions,
globs=globs,
optionflags=doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
| doctest.IGNORE_EXCEPTION_DETAIL,
| doctest.NORMALIZE_WHITESPACE
| doctest.IGNORE_EXCEPTION_DETAIL,
)

globs["spark"].stop()
Expand Down