QuestionQ192

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

A Spark developer wants to improve the performance of an existing PySpark UDF that executes a hash function unavailable in the standard Spark functions library.

The existing UDF code is:

Question Image

The developer wants to replace the existing UDF with a Pandas UDF to improve performance.

The developer changes the definition of shake_256_udf to:

shake_256_udf = sf.pandas_udf(shake_256, StringType())

However, the developer receives this error:

[UNSUPPORTED_SIGNATURE] Unsupported signature: (raw: str) –> str.

To fix this error, what should the signature of the shake_256() function be changed to?

Explanation

A scalar Pandas UDF receives input data in pandas.Series batches and must return a pandas.Series of the same length. Thus the hash implementation must be vectorized over the input series, using the pandas.Series -> pandas.Series signature. PySpark pandas_udf documentation

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!