Have a dataframe, which has a query as a value in one of the column, I am trying to extract the value between one/two parentheses in the first group using regex.
My Input the regex is:
select nvl(sum(field1),0), field2, field3 from tableName1 where partition_date='2018-03-13'
Output should be:
field1
Spark Code what I used to extract the value is:
target_query = "select nvl(sum(field1),0), field2, field3 from tableName1 where partition_date='2018-03-13'"
val df1 = df.withColumn("Extract_field", regexp_extract(df("target_query"),"(?<=\\().*?(?=\\))",0))
But I'm getting
sum(field1
Please let me know how to extract only the field1. I may get sum(field1) instead of nvl(sum(field1),0) as well. Is it possible to use same regex to handle both the cases?