4

I have the data schema of LinkeIn account as shown below. I need to query the skills which is in the for of array, where array may contains either JAVA OR java OR Java or JAVA developer OR Java developer.

Linkedin dataschema

Dataset<Row> sqlDF = spark.sql("SELECT * FROM people"
            + " WHERE ARRAY_CONTAINS(skills,'Java') "
            + " OR ARRAY_CONTAINS(skills,'JAVA')"
            + " OR ARRAY_CONTAINS(skills,'Java developer') "
            + "AND ARRAY_CONTAINS(experience['description'],'Java developer')"  );

The above query is what i have tried and please suggest any better way.and also how to use case-insentive query ?

1 Answer 1

2
df.printschema()

root
 |-- skills: array (nullable = true)
 |    |-- element: string (containsNull = true)


df.show()

+--------------------+
|              skills|
+--------------------+
|        [Java, java]|
|[Java Developer, ...|
|               [dev]|
+--------------------+

Now lets register it as a temp table:

>>> df.registerTempTable("t")

Now, we will explode the array, convert each element as lower case and query using LIKE operator:

>>> res = sqlContext.sql("select skills, lower(skill) as skill from (select skills, explode(skills) skill from t) a where lower(skill) like '%java%'")
>>> res.show()
+--------------------+--------------+
|              skills|         skill|
+--------------------+--------------+
|        [Java, java]|          java|
|        [Java, java]|          java|
|[Java Developer, ...|java developer|
|[Java Developer, ...|      java dev|
+--------------------+--------------+

Now, you can do a distinct on skills field.

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

4 Comments

can you help me more ?
please post your question, will help as far as I can :)
Ayan Guha . please have a look at this link . i wan unable to pos uqestion from this account so i have done it with another question . stackoverflow.com/questions/39634284/…
can you vote up my question @Ayan Gupta .. i am unable to post other questions due to 0 vote in my question

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.