1

I have a python variable (I am using pyspark) of date datatype: The variable value is 2016-10-31

print type(load_dt)

 >> <type 'datetime.date'>

I am having difficulty passing this to a sparksql query:

    hive_context.sql("select * from  tbl t1 where cast (substring(t1.dt,1,10) as date) ={0}".format(load_dt));

    Error:

    u"cannot resolve '(cast(substring(dt,1,10) as date) = ((2016 - 10) - 31))' due to data type mismatch: differing types in '(cast(substring(period_dt,1,10) as date) = ((2016 - 10) - 31))'
 (date and int)

1 Answer 1

2

Add quotes:

"select * from  tbl t1 where cast (substring(t1.dt,1,10) as date) = '{0}'"

otherwise date is converted to 2016-10-31 string and interpreted as arithmetic expression:

2016 - 10 - 31 
Sign up to request clarification or add additional context in comments.

Comments

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.