Apache ignite throwing System.DateTime exception when executing the SqlFieldsQuery for Datetime column but same time ignite saves the data successfully. The entities are created via configuration file as below
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="TEST"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<!-- Configure type metadata to enable queries. -->
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Long"/>
<property name="valueType" value="TEST"/>
<property name="fields">
<map>
<entry key="ID" value="java.lang.Long"/>
<entry key="DATE" value="java.sql.Timestamp"/>
</map>
</property>
</bean>
</list>
</property>
</bean>
here is the C# code to upload the values and reading...
string cacheName = "TEST";
try
{
using (IIgnite ignite = Ignition.Start("RemoteDevServer.config"))
{
//ignite.GetBinary().GetBinaryType(cacheName);
var cache = ignite.GetCache<long, IBinaryObject>(cacheName).WithKeepBinary<long, IBinaryObject>();
var objectBuilder = ignite.GetBinary().GetBuilder(cacheName);
long Id = 100;
objectBuilder.SetField("ID", Id);
objectBuilder.SetField("DATE", DateTime.Now);
cache[Id] = objectBuilder.Build();
var sqlp = new SqlFieldsQuery("select ID, DATE from TEST ");
using (var cursor = cache.Query(sqlp))
{
foreach (var row in cursor) // throws exception
{
Console.WriteLine(row[0] + "---" + row[1]);
}
}
}
}
catch (Exception ex)
{
throw ex;
}
Here is the error details
Failed to execute map query on remote node [nodeId=fa1cb87b-7a6a-46f0-aa21-0e1f680f241e, errMsg=General error: "class org.apache.ignite.binary.BinaryInvalidTypeException: Failed to resolve .NET class 'System.DateTime' in Java [platformId=0, typeId=-1854586790]."; SQL statement:
SELECT
"__Z0"."ID" AS "__C0_0",
"__Z0"."DATE" AS "__C0_1"
FROM "TEST"."TEST" AS "__Z0" [50000-199]]
I tried a solution recommended here - Apache Ignite Linq over Sql Failed to resolve java class but didn't resolve the issue. According to the link here - https://www.gridgain.com/docs/latest/sql-reference/data-types java.sql.Timestamp should match with System.DateTime but unfortunately not. any help will be really appreciated.
Replace objectBuilder.SetField("DATE", DateTime.Now);
with objectBuilder.SetTimestampField("DATE", DateTime.UtcNow);
.
IBinaryObjectBuilder
, call SetTimestampField
instead SetField
.I would also recommend to enable ForceTimestamp
mode to catch those issues early:
var igniteCfg = new IgniteConfiguration
{
BinaryConfiguration = new BinaryConfiguration
{
ForceTimestamp = true
}
}