question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty string is converted to null

See original GitHub issue

spark-redshift (v3.0.0-preview1) will convert an empty string '' into a null value when reading data from redshift:

spark.read
  .format("com.databricks.spark.redshift")
  .option("url", url)
  .option("aws_iam_role", iamRole)
  .option("tempdir", tmpDir)        
  .option("query", "select '' as foo, null as bar")
  .load()
  .show()

[info] +----+----+
[info] | foo| bar|
[info] +----+----+
[info] |null|null|
[info] +----+----+

In redshift, there is a distinction between null and '':

redshift-user=> select foo is null as foonull, bar is null as barnull from (select '' as foo, null as bar);
 foonull | barnull 
---------+---------
 f       | t
(1 row)

spark-sql also supports this distinction:

spark.sql("select '' as foo, null as bar").show()

[info] +---+----+
[info] |foo| bar|
[info] +---+----+
[info] |   |null|
[info] +---+----+

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
drewrobbcommented, Apr 18, 2018

Databricks has decided to close source new work on this project, so I don’t expect any update or any PR accepted here. Maybe a community fork will get going, I’m disappointed and will avoid Databricks open source projects going forward.

0reactions
Enigma-vcommented, Aug 18, 2022

I was wondering if you had an issue with Redshift that returns NULL in one database and on the same dataset but in different database it returns empty string. The data is the same on both of the databases?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting empty string into null - mysql - Stack Overflow
I have a form that POST value keeps coming as "" empty string into a unique SQL field. It has to be unique...
Read more >
Empty strings ("") converted to 'null' depending on database
When using the Oracle database platforms, empty strings are converted to 'null' values by the database.
Read more >
FAQ: Is there any property to convert an empty string to NULL ...
No, there is no custom property that converts empty strings to NULL values in the source in PowerCenter. However, some functions could be...
Read more >
21.2 Validating Null and Empty Strings
An empty string is represented as "" . It is a character sequence of zero characters. A null string is represented by null...
Read more >
Java Utililty Methods Null Value Convert - Java2s.com
Method ; String, convertNullToBlank(String s) convert Null To Blank return null == s ? "" : s; ; String, convertNullToEmptyStr(String inObj) convert Null...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found