doanduyhai / Achilles

An advanced Java Object Mapper/Query DSL generator for Cassandra
http://achilles.archinnov.info
Apache License 2.0
241 stars 92 forks source link

How to use minTimeuuid() and maxTimeuuid() with entity manager with achilles #342

Closed ronakthakrar closed 6 years ago

ronakthakrar commented 6 years ago

Hi,

I have an entity where I have a column as timeuuuid, also I tagged it using @TimeUUID annotation as well. Now I am looking for querying on that field using minTimeuuid() and maxTimeuuid() functions - how do i do it with achilles based entity manager created.

I am trying to fetch the data between the time range using minTimeuuid() and maxTimeuuid() functions.

Following is my entity:

test_schedule( cust uuid, //primary key nextschedule timeuuid //clustering key 1

......other fields

)

I have inserted data manually in this entity and was able to run following CQL Statement - which returns the correct data also: select * from test_schedule WHERE cust = c056a271-928e-43e1-974e-75e9ba1310b2 and nextschedule > maxTimeuuid('2018-06-29 15:50') AND nextschedule < minTimeuuid('2018-06-29 16:30');

BUT In the code while using entity manager the records are not returned.

Populating the Entity: I am populating the above entity using entity manager generated and provided by achilles and setting the timeuuid from the long timestamp using UUIDs.startOf(long timestamp)

    UUID timeUUID = UUIDs.startOf(nextSchedule);
    testScheduleEntity.setNextSchedue(timeUUID);

While fetching - I am using the Long startTime = DateTime.now().getMillis(); UUID startTimeUUID = UUIDs.startOf(startTime); Long lookupEndTime = new DateTime(startTime).plusHours(24).getMillis(); UUID endTimeUUID = UUIDs.endOf(lookupEndTime);

testScheduleEntityManager.dsl().select() .allColumns_FromBaseTable().where().cust().Eq(custUUID) .nextSchedule().Gte_And_Lte(startTimeUUID, endTimeUUID).getList();

Is this correct way to find out the records which are between the time range based on a time uuid field? Can you please guide here.

doanduyhai commented 6 years ago

Hello

So currently it is not possible to use function in the WHERE clause in source code generated by Achilles. I can certainly enhance the code to support this feature but there is no big use cases for the moment.

What you can do is to craft your query using the native QueryBuilder from the Java driver to create a statement and then use the Type Query API to do the object mapping for you

ronakthakrar commented 6 years ago

@doanduyhai ,

Thanks for the update, I am actually trying in an entity using achilles and seems there are Gte(>=) and Let(<=) functions being generated for that field. Also I am using UUIDs.startOf and UUIDs.endOfand using the entity manager and above function, it seems its working fine. I will test further and update.

Thanks