0

I am using cassandra 2.2.3 and below is my table structure to store doj as date object.

Table structure:

class Emp{

String name
Date doj
}
empdata:

id                  name                          doj
1                   Test                         2010-01-01 00:00:00+0000
2                   Test1                        2011-01-01 00:00:00+0000

I have to use greater than or less than operator to select the employees between those dates.

From the json i get the following input to display the data.

{
"dateFrom":'1/1/2010'
}

//Modified the string to date using SimpleDateFormat

Date d1 = f.parse(dateFrom);
long milliseconds = d1.getTime(); 

//Query call to use the gte operator to fetch the data from Cassandra

Select selectQuery = QueryBuilder.select().all().from(tableName).allowFiltering()
Where selectWhere = selectQuery.where();
rangeClause(selectWhere,dateFrom,Tue Jan 01 00:00:00 PST 2010);
Statement s = selectWhere.limit(1)
println("st is:"+s); 

In the select statement i see the query as "SELECT * FROM emp WHERE doj>=1551427200000  LIMIT 1;


//Function Call

 def rangeClause(Where selectWhere, String columnName, Object columnValue) 
    {
    Clause whereClause = null
    whereClause= QueryBuilder.gte(columnName, columnValue.get("dateFrom"))
    selectWhere.and(whereClause)
    }
Studentlearner
  • 99
  • 2
  • 11

1 Answers1

1

dateFrom is a timestamp (long) which is 8 bytes and your passing it a String '2010-01-05' thats 10 bytes. You need to convert that date string into a epoc timestamp (long) or Date.

Chris Lohfink
  • 16,150
  • 1
  • 29
  • 38