Spark Data frame search column starting with a string

Viewed 26805

I have a requirement to filter a data frame based on a condition that a column value should starts with a predefined string.

I am trying following:

 val domainConfigJSON = sqlContext.read
    .jdbc(url, "CONFIG", prop)
    .select("DID", "CONF", "KEY").filter("key like 'config.*'")

And getting exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'KEY = 'config.*'' at line 1

Using spark: 1.6.1
2 Answers

I used the same function but I was getting errors then I checked what is the error?

actually, we need to use startsWith(literals: String) but the above function having lowercase startswith().

Ex : df.filter(col("ACCOUNT_NUMBER").startsWith("9"))

Related