I am trying to select all record recorded at Sunday through SparkSQL. I have the following try but in vain.
SELECT * FROM mytable WHERE DATEPART(WEEKDAY, cre
This works for me:
spark.sql("select dayofweek(time) as dow from some_table")
Where time
needs to be in date format
SPARK 1.5.0 has a date_format
function that accepts a format as an argument. This format returns a name of a week day from a timestamp:
select date_format(my_timestamp, 'EEEE') from ....
Result: e.g. 'Tuesday'
If the create_time is in the format of UTC, you can use the following to filter out specific days in SparkSQL. I used Spark 1.6.1:
select id, date_format(from_unixtime(created_utc), 'EEEE') from testTable where date_format(from_unixtime(created_utc), 'EEEE') == "Wednesday"
If you specify 'EEEE', the day of the week is spelled out completely. You can use 'E' to specify the shortened version, e.g. Wed. You can find more info here: http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.DataFrame http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html