I'm facing an issue with Apache Ignite SQL. Currently I'm using Ignite v2.6 but saw the same issue with previous version as well.
There is a cache defined like this:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="Tasks"/>
<property name="cacheMode" value="PARTITIONED" />
<property name="backups" value="1" />
<property name="storeKeepBinary" value="true" />
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="nodeFilter" ref="TaskNodeFilter" />
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.util.UUID"/>
<property name="valueType" value="Tasks" />
<property name="fields">
<map>
<entry key="id" value="java.util.UUID"/>
<entry key="created" value="java.lang.Long"/>
<entry key="jobId" value="java.util.UUID"/>
<entry key="exception" value="java.lang.Object"/>
<entry key="lastAction" value="java.lang.Long"/>
<entry key="jobId" value="java.util.UUID"/>
<entry key="masterId" value="java.util.UUID"/>
<entry key="identifier" value="java.lang.String"/>
<entry key="status" value="java.lang.Integer"/>
<entry key="nodeId" value="java.util.UUID"/>
<entry key="status" value="java.lang.Integer"/>
<entry key="progressMax" value="java.lang.Long"/>
<entry key="progressAt" value="java.lang.Long"/>
<entry key="actionType" value="java.lang.String"/>
</map>
</property>
<property name="indexes">
<list>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="jobId"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="status"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="actionType"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="created"/>
</bean>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="masterId"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
The entry "created" is the timestamp from System.currentTimeMillis(), so in Java it's a long value. So I set this field in cache config to "Java.lang.Long".
Now when I search using SQL I get different results depending on my query but always with the same range:
select COUNT(id) as ANZAHL
FROM "Tasks".Tasks
where created BETWEEN 1543705200000 AND 1545433200000;
returns 0 (wrong!)
select COUNT(id) as ANZAHL
FROM "Tasks".Tasks
where CAST(created AS BIGINT) BETWEEN 1543705200000 AND 1545433200000;
returns 1142 (this is the expected value)
select COUNT(*) as ANZAHL
FROM "Tasks".Tasks
where CAST(created AS BIGINT) BETWEEN 1543705200000 AND 1545433200000;
returns 0 (wrong!)
Am I'm doing something wrong? Why do I need to cast the value to BIGINT if its long value should be enough? Also, why is there a difference between COUNT(id) and COUNT(*)?
Thanks!
COUNT(*)
could return a smaller value thanCOUNT(id)
if that is the only difference in the query and the underlying data does not change. – Gordon Linoff