Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-15871

when use affinity_key and two fields as primary key, key-value api can't get the data of sql insert ,and binary write data can't get primary key fields value with sql

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 2.10
    • None
    • binary, cache, sql
    • None
    • Docs Required, Release Notes Required

    Description

      1. I use sql create table like this;  
        CREATE TABLE IF NOT EXISTS Person (
          id int,
          name varchar,
          test int,
          test2 varchar,
          companyId Long,
          PRIMARY KEY (id, companyId)
        ) WITH "template=partitioned,backups=1,affinity_key=companyId,KEY_TYPE=AffinityKey,VALUE_TYPE=Person";
        

         

      1. insert data with sql;
        insert into Public.Person(id,companyId,test,test2,name) values(1,1,1,'test11','test1');
        insert into Public.Person(id,companyId,test,test2,name) values(2,1,1,'test1','test');
        insert into Public.Person(id,companyId,test,test2,name) values(3,1,1,'test3','test3');
        
      1. now Binary_metadata view like this :
      2. then I use key-value api add data and query data:
      3. code like this:
        Ignite ignite = Ignition.ignite();
        IgniteCache<AffinityKey, Person> personCache = ignite.getOrCreateCache("SQL_PUBLIC_PERSON");
        IgniteCache<AffinityKey, BinaryObject> binaryCache = ignite.cache("SQL_PUBLIC_PERSON").withKeepBinary();
        IgniteCache<AffinityKey, Object> objCache = ignite.cache("SQL_PUBLIC_PERSON");
        var akey= new AffinityKey<Integer>(7,1L);
        IgniteBinary binary = ignite.binary();
        BinaryObjectBuilder bldr = binary.builder("Person");
        bldr.setField("ID",7,Integer.class);
        bldr.setField("COMPANYID",1L );
        bldr.setField("TEST",1 );
        bldr.setField("TEST2","test21");
        bldr.setField("NAME","test7");
        //   Person p3=new Person(5,1L,"test3");
        binaryCache.put(akey, bldr.build());
        if(personCache.containsKey(akey))
        {
            BinaryObject bo=binaryCache.get(akey);
            System.out.println("id:"+bo.field("id"));
            System.out.println("companyId:"+bo.field("COMPANYID"));
        }
        akey= new AffinityKey(1, 1L);
        if(personCache.containsKey(akey))
        {
            System.out.println("ok2");
        }
        if(binaryCache.containsKey(akey))
        {
            System.out.println(" binaryCache ok");
        }
        if(objCache.containsKey(akey))
        {
            System.out.println("objCache ok");
        }
        

        but can't find the row of ( id=1 and companyId=1 )
        and binaryCache.put(akey, bldr.build()); with sql query like this:
        now view of binary_metadata:

      Attachments

        Activity

          People

            Unassigned Unassigned
            wangwei.njcn w w
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: