0

I need to replace a null character in a spark sql string.

I can't find an equivalent of COLLATE in spark sql.

Can you help?

2
  • Do you mean coalesce? Commented Jan 29, 2020 at 15:37
  • 1
    show some sample data Commented Jan 29, 2020 at 16:03

1 Answer 1

0

If you are looking for a way to replace every NULL character in a string you can use regexp_replace. Depending on the encoding and programming language you use the NULL character can be different: \000, \x00, \z, or \u0000. [Wikipedia]

null_character = u'\u0000'
replacement = ' '
df = df.withColumn('e', F.regexp_replace(F.col('columnX'), null_character, replacement))

Related response: https://stackoverflow.com/a/41152572/14338716

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.