I use gridgain Ignite community 8.8.31(it is same at apache ignite 2.15), and I made two tables using DDL.(Insert data with DML) When I try to cache.get() using C#/.NET, Person3 has error but Person4 is runs well. These two tables are exactly same except Primary Key name.
I wonder why this happen.
CREATE TABLE IF NOT EXISTS Person3 (
ID int,
CITY_ID int,
NAME varchar,
AGE int,
COMPANY varchar,
PRIMARY KEY (ID, CITY_ID)
) WITH "template=REPLICATED,CACHE_NAME=Person3,KEY_TYPE=test.PersonKey3,VALUE_TYPE=test.PersonValue3";
INSERT INTO Person3 VALUES (1,1,'1',1,'1');
CREATE TABLE IF NOT EXISTS Person4 (
CITY_ID int,
CITY_ID_2 int,
NAME varchar,
AGE int,
COMPANY varchar,
PRIMARY KEY (CITY_ID, CITY_ID_2)
) WITH "template=REPLICATED,CACHE_NAME=Person4,KEY_TYPE=test.PersonKey4,VALUE_TYPE=test.PersonValue4";
INSERT INTO Person4 VALUES (1,1,'1',1,'1');
My .NET code is below.
namespace test
{
class PersonKey3
{
[QuerySqlField]
public int ID, CITY_ID;
}
class PersonValue3 : PersonKey3
{
[QuerySqlField]
public string NAME, COMPANY;
[QuerySqlField]
public int AGE;
}
class PersonKey4
{
[QuerySqlField]
public int CITY_ID, CITY_ID_2;
}
class PersonValue4 : PersonKey4
{
[QuerySqlField]
public string NAME, COMPANY;
[QuerySqlField]
public int AGE;
}
class IgniteTest
{
public static void Main()
{
IgniteClientConfiguration cfg = new IgniteClientConfiguration
{
Endpoints = new[] { "127.0.0.1:10800" }
};
using (var client = Ignition.StartClient(cfg))
{
client.GetBinary().GetBinaryType(typeof(PersonKey3));
client.GetBinary().GetBinaryType(typeof(PersonValue3));
client.GetBinary().GetBinaryType(typeof(PersonKey4));
client.GetBinary().GetBinaryType(typeof(PersonValue4));
/*runs well*/
var cache4 = client.GetCache<PersonKey4, PersonValue4>("Person4");
PersonKey4 tableKey4 = new PersonKey4();
tableKey4.CITY_ID = 1;
tableKey4.CITY_ID_2 = 1;
Console.WriteLine(cache4.Get(tableKey4).COMPANY);
/*error!*/
var cache3 = client.GetCache<PersonKey3, PersonValue3>("Person3");
PersonKey3 tableKey3 = new PersonKey3();
tableKey3.ID = 1;
tableKey3.CITY_ID = 1;
Console.WriteLine(cache3.Get(tableKey3).COMPANY);
}
}
}
}
error message is below
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key was not present in the cache.
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.UnmarshalNotNull[T](ClientResponseContext ctx)
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.<Get>b__14_0(ClientResponseContext ctx)
at Apache.Ignite.Core.Impl.Client.ClientSocket.DecodeResponse[T](BinaryHeapStream stream, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.ClientSocket.DoOutInOp[T](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.DoOutInOpAffinity[T,TKey](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Int32 cacheId, TKey key, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.DoOutInOpAffinity[T](ClientOp opId, TK key, Func`2 readFunc)
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.Get(TK key)
at test.IgniteTest.Main() in E:\GHLee\dev\cs\GridgainTest\Program.cs:line 119
CREATE TABLE
should have key fields in alphabetical order. Put CITY_ID
before ID
to make it work:
CREATE TABLE IF NOT EXISTS Person3 (
CITY_ID int,
ID int,
NAME varchar,
...
Explanation:
Looks like a bug to me, I'll check if there is a ticket.