Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyangxiaozhu committed Jul 1, 2024
1 parent 7deb242 commit 52f9465
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions velox/docs/functions/spark/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions velox/functions/sparksql/Mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 52f9465

Please sign in to comment.