pvignesh92
Honored Contributor

In Spark SQL, the CONTAINS function is not a built-in function.

As an alternative, you can use the below inbuilt functions

  • LIKE function can be used to check whether a string contains a specific substring. The syntax is as follows:

Sample Code

SELECT * FROM table_name
WHERE column_name LIKE '%substring%'

  • INSTR function can be used to find the position of a substring within a string. If the substring is not found, the function returns 0. The syntax is as follows:

SELECT * FROM table_name WHERE INSTR(column_name, 'substring') > 0

Or the good old Regex

SELECT * FROM table_name
WHERE column_name RLIKE 'regexp_pattern'

Please let me know if this helps.