You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by anu <an...@gmail.com> on 2015/03/02 10:37:50 UTC

Re: SparkSQL Timestamp query failure

Can you please post how did you overcome this issue.



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SparkSQL-Timestamp-query-failure-tp19502p21868.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org


Re: SparkSQL Timestamp query failure

Posted by anu <an...@gmail.com>.
Thank you Alessandro :)

On Tue, Mar 3, 2015 at 10:03 AM, whitebread [via Apache Spark User List] <
ml-node+s1001560n21884h2@n3.nabble.com> wrote:

> Anu,
>
> 1) I defined my class Header as it follows:
>
> case class Header(timestamp: java.sql.Timestamp, c_ip: String,
> cs_username: String, s_ip: String, s_port: String, cs_method: String,
> cs_uri_stem: String, cs_query: String, sc_status: Int, sc_bytes: Int,
> cs_bytes: Int, time_taken: Int, User_Agent: String, Referrer: String)
>
> 2) Defined a function to transform date to timestamp:
>
> implicit def date2timestamp(date: java.util.Date) = new
> java.sql.Timestamp(date.getTime)
>
> 3) Defined the format of my timestamp
>
> val formatTime = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
>
> 4) Finally, I was able to parse my data:
>
> val tableMod = toProcessLogs.map(_.split(" ")).map(p =>
> (Header(date2timestamp(formatTime3.parse(p(0)+" "+p(1))),p(2), p(3), p(4),
> p(5), p(6), p(7), p(8), p(9).trim.toInt, p(10).trim.toInt,
> p(11).trim.toInt, p(12).trim.toInt, p(13), p(14))))
>
> Hope this helps,
>
> Alessandro
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-spark-user-list.1001560.n3.nabble.com/SparkSQL-Timestamp-query-failure-tp19502p21884.html
>  To unsubscribe from SparkSQL Timestamp query failure, click here
> <http://apache-spark-user-list.1001560.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=19502&code=YW5hbWlrYS5ndW9wdGFAZ21haWwuY29tfDE5NTAyfDE1MjUxMDc5MQ==>
> .
> NAML
> <http://apache-spark-user-list.1001560.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SparkSQL-Timestamp-query-failure-tp19502p21885.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

Re: SparkSQL Timestamp query failure

Posted by anu <an...@gmail.com>.
Hi Alessandro

Could you specify which query were you able to run successfully?

1. sqlContext.sql("SELECT * FROM Logs as l where l.timestamp = '2012-10-08
16:10:36' ").collect 

OR

2. sqlContext.sql("SELECT * FROM Logs as l where cast(l.timestamp as string)
= '2012-10-08 16:10:36.0').collect 

I am able to run only the second query, i.e. the one with timestamp casted
to string. What is the use of even parsing my data to store timestamp values
when I can't do >= and <= comparisons on timestamp?? 

In the above query, I am ultimately doing string comparisons, while I
actually want to do comparison on timestamp values.

*My Spark version is 1.1.0*

Please somebody clarify why am I not able to perform queries like
Select * from table1 where endTime >= '2015-01-01 00:00:00' and endTime <=
'2015-01-10 00:00:00' 

without getting anything in the output.

Even, the following doesn't work
Select * from table1 where endTime >=  CAST('2015-01-01 00:00:00' as
timestamp) and endTime <= CAST('2015-01-10 00:00:00' as timestamp)

I get the this error :  *java.lang.RuntimeException: [1.99] failure:
``STRING'' expected but identifier timestamp found*

Thanks



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SparkSQL-Timestamp-query-failure-tp19502p22292.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org