pysparkdatabricksdatabricks-sql

How to use LIKE condition for an array of struct type in a Delta table


I have a delta table which I am accessing from Databricks. I have a column of type array of struct. If I want to see if a field in any element of the array contains a certain element, I could use the following.

array_contains(transform(ArrayCol, x -> x.f), 'something')

But now I don't want to do an exact match, but something similar to LIKE 'some%'. How can I achieve that? Basically, I want to return true if any element in the array has field f containing the pattern 'some%' here.


Solution

  • you almost got it.

    array_contains(transform(ArrayCol, x -> x LIKE 'some%'), true)