diff --git a/velox/docs/functions/spark/string.rst b/velox/docs/functions/spark/string.rst index 197bf4e5dd1d..282dacf9c039 100644 --- a/velox/docs/functions/spark/string.rst +++ b/velox/docs/functions/spark/string.rst @@ -125,10 +125,10 @@ Unless specified otherwise, all functions return NULL if at least one of the arg Returns a masked version of the input ``string``. ``string``: string value to mask. - ``upperChar``: A single character STRING literal used to substitute upper case characters. The default is 'X'. If NULL, upper case characters remain unmasked. - ``lowerChar``: A single character STRING literal used to substitute lower case characters. The default is 'x'. If NULL, lower case characters remain unmasked. - ``digitChar``: A single character STRING literal used to substitute digits. The default is 'n'. If NULL, digits remain unmasked. - ``otherChar``: A single character STRING literal used to substitute any other character. The default is NULL, which leaves these characters unmasked. :: + ``upperChar``: A single character STRING used to substitute upper case characters. The default is 'X'. If NULL, upper case characters remain unmasked. + ``lowerChar``: A single character STRING used to substitute lower case characters. The default is 'x'. If NULL, lower case characters remain unmasked. + ``digitChar``: A single character STRING used to substitute digits. The default is 'n'. If NULL, digits remain unmasked. + ``otherChar``: A single character STRING used to substitute any other character. The default is NULL, which leaves these characters unmasked. :: SELECT mask('abcd-EFGH-8765-4321'); -- "xxxx-XXXX-nnnn-nnnn" SELECT mask('abcd-EFGH-8765-4321', 'Q'); -- "xxxx-QQQQ-nnnn-nnnn" diff --git a/velox/functions/sparksql/Mask.cpp b/velox/functions/sparksql/Mask.cpp index a3bc1775851d..45ad94307553 100644 --- a/velox/functions/sparksql/Mask.cpp +++ b/velox/functions/sparksql/Mask.cpp @@ -23,6 +23,40 @@ namespace facebook::velox::functions::sparksql { namespace { +/** + * Masks the characters of the given string value with the provided specific + * characters respectively. + * + * mask(string) -> string + * replaces upper-case characters with 'X', lower-case characters with 'x', + * and numbers with 'n'. + * + * mask(string, upperChar) -> string + * replaces upper-case characters with provided `upperChar`, lower-case + * characters with 'x', and numbers with 'n'. + * Upper case characters remain unmasked if provided `upperChar` is NULL. + * + * mask(string, upperChar, lowerChar) -> string + * replaces upper-case characters with provided `upperChar`, lower-case + * characters with provided `lowerChar` and numbers with 'n'. + * Upper case characters or lower-case characters would remain unmasked if + * provided `upperChar` or `lowerChar` is NULL. + * + * mask(string, upperChar, lowerChar, digitChar) -> string + * replaces upper-case characters with provided `upperChar`, lower-case + * characters with provided `lowerChar` and numbers with provided `digitChar`. + * Upper case characters, lower-case characters and numbers would remain + * unmasked if provided `upperChar`, `lowerChar` or `digitChar` is NULL. + * + * mask(string, upperChar, lowerChar, digitChar, otherChar) -> string + * replaces upper-case characters with provided `upperChar`, lower-case + * characters with provided `lowerChar` and numbers with provided `digitChar` + * and all other characters with provided `otherChar`. + * Upper case characters remain unmasekd if provided `upperChar` is NULL. + * Lower case characters remain unmasekd if provided `lowerChar` is NULL. + * Numbers remain unmasekd if provided `digitChar` is NULL. + * All other characters remain unmasked if provided `otherChar` is NULL. + */ class MaskFunction final : public exec::VectorFunction { public: void apply(