1

I have tried this query to get required experience from linkedin data.

click here for my data

 Dataset<Row> filteredData = spark
                    .sql("select full_name ,experience from (select *, explode(experience['title']) exp from tempTable )"
                            + "  a where lower(exp) like '%developer%'");

But I got this error:

click here for error I got

and finally I tried but I got more rows with the same name .

Dataset<Row> filteredData = spark
                    .sql("select full_name ,explode(experience) from (select *, explode(experience['title']) exp from tempTable )"
                            + "  a where lower(exp) like '%developer%'");

Please give me hint, how to convert array of string to comma separated string in the same column.

3
  • 1
    can u share more information about the code and sample data Commented Sep 22, 2016 at 9:19
  • actually i am writing code in spark Commented Sep 23, 2016 at 8:30
  • thanks,but can u share ur sample code in json format Commented Sep 23, 2016 at 12:38

1 Answer 1

2

You can apply UDF for making a comma separate string

Create UDF like this

def mkString(value: WrappedArray[String]): String = value.mkString(",")

Register UDF in sparkSQL context

sqlContext.udf.register("mkstring", mkString _)

Apply it on SparkSQL query

sqlContext.sql(select mkstring(columnName) from tableName)

it will return comma separate value of array

Sign up to request clarification or add additional context in comments.

3 Comments

if the column has array of <String > use concat_ws(string delimiter, array<string>) else concat_ws(',',collect_set(cast(date as string)))
Thanks man you guided me . :) i did in a way how you suggest .. :)
@AshisParajuli if it is hlpful for u so plz accept the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.