spark-redshift icon indicating copy to clipboard operation
spark-redshift copied to clipboard

Fix executing empty sql statement in preactions and postactions

Open meetchandan opened this issue 5 years ago • 5 comments

Say for example: you need to execute preactions/postactions

val preactions = "update table1 set col1=2; update table2 set col2 = 2; " Looks nothing wrong, correct?

Only when you try to execute it, you will get weird error:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0

This is because of Line 248 and Line 260 in Parameters.scala def preActions: Array[String] = parameters("preactions").split(";")

def postActions: Array[String] = parameters("postactions").split(";")

the above functions are called in RedshiftWriter.scala LN: 132 and LN: 195 parameters("preactions").split(";") -- this returns an array of 3 items, with the 3rd item being empty string (only spaces) - see trailing spaces in val preactions = "update table1 set col1=2; update table2 set col2 = 2; "

and then it tries to execute sql query which is essentially just "spaces"

The fix is to just trim preactions and postactions so that the trailing spaces are not considered as query to be executed

meetchandan avatar Aug 15 '19 12:08 meetchandan

I am working on the fix and will soon raise a PR

meetchandan avatar Aug 15 '19 12:08 meetchandan

Link to PR: https://github.com/databricks/spark-redshift/pull/440

meetchandan avatar Aug 15 '19 13:08 meetchandan

@JoshRosen @marmbrus @brkyvz Please take a look

meetchandan avatar Aug 15 '19 13:08 meetchandan

Having the same issue, your fix would help a lot.

aleksandr-bogdanov avatar Sep 11 '19 11:09 aleksandr-bogdanov

can we merge this please @JoshRosen

meetchandan avatar Jan 06 '23 14:01 meetchandan