0

How get date part in cassandra and scala? Somebody can help me please?

e.g 2014-11-22 13:23 I want extract "yyyy" "MM" "DD"

e.g
SELECT EXTRACT(YEAR FROM OrderDate) EXTRACT(MONTH FROM OrderDate) EXTRACT(DAY FROM OrderDate)

expected result 2014 11 22

I want extract date part, i don't want convert date format. So, the How to convert TimeStamp to Date in Java?, not resolve my problem.

Community
  • 1
  • 1
Marisa Cruz
  • 75
  • 1
  • 2
  • 10

1 Answers1

1

I hope you found the anwser, but you try to do two things:

  1. In Cassandra: Create a function inside the kespace;

    cqlsh> use keyspace;

    cqlsh:keyspace> CREATE OR REPLACE FUNCTION Year(input DATE) RETURNS NULL ON NULL INPUT RETURNS TEXT LANGUAGE java AS 'return input.toString().substring(0,4);';

  2. In Spark: You can use the spark function Function

e.g

SELECT year(OrderDate), month(OrderDate), day(OrderDate) from ...
Luciana Oliveira
  • 822
  • 4
  • 14
  • 35