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

POJO fields of java wrapper type are not retaining null values from Cassandra persistent store, while using ignite's CassandraCacheStoreFactory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.1
    • 2.7
    • cassandra

    Description

      While using ignite's CassandraCacheStoreFactory(part of ignite-cassandra-store.jar) as cacheStoreFactory for a cache, if a POJO field is of wrapper class type, and the column value mapped in Cassandra persistent store is null then the POJO field is getting set to default primitive type instead of null.

      For Example: Assume a table 'person' in a Cassandra persistent store with the following structure and data.
      table person:
      column person_no(int) phno(text) address(text) age(int) name(text)
      data 1 12353 null null yash
      person_no is the PRIMARY_KEY.

      This table is mapped to person POJO for ignite cache.
      public class person{
      private int person_no;
      private String name;
      private Integer age=null;
      private String phno;
      private String address;
      .....getters and setters etc......
      }

      Now we load the row from Cassandra into ignite cache using cache.get(1) or cache.load(..) And we are using ignite's CassandraCacheStoreFactory for this cache.
      Let person p1 = cache.get(1);
      now p1.getName returns "yash", p1.getAddress returns null.
      But p1.getAge returns 0 instead of null. It is expected null value since the value is null in Cassandra persistent store.
      Hence if the value is 0 for the age field there is no way differentiate if it was null or it was actually 0. The similar problem exists for other wrapper types -> Long, Float, Double, Boolean.

      This problem cause is as follows.
      In org.apache.ignite.cache.store.cassandra.persistence.PojoField.setValueFromRow(..) method first the Cassandra field value is obtained by using the method PropertyMappingHelper.getCassandraColumnValue(..). This method calls DataStax Driver methods Row.getInt() or Row.getFloat() or Row.getDouble() etc.. depending upon the column. This value obtained from this method is then set to the respective POJO field. But According to Datastax documentation getInt returns 0 if column value is null and similarly getLong returns 0L , getDouble return 0.0 etc. Hence PropertyMappingHelper. getCassandraColumnValue returns 0 or 0L or 0.0 or false even if the value is null. And then this value is set to the wrapper type POJO fields. The problem only persists with the primitive data types in Cassandra mapped to wrapper type fields in POJO. For other types like String , Date etc.. the null values are retained in the POJO fields.

      Attachments

        Issue Links

          Activity

            People

              kotamrajuyashasvi Yashasvi Kotamraju
              kotamrajuyashasvi Yashasvi Kotamraju
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: