Search code examples
ignite

Why Apache Ignite response is empty when using sql query


I am trying to create cache in Ignite using sql query

 CacheConfiguration<?, ?> cacheCfg = new CacheConfiguration<>(DUMMY_CACHE_NAME);
        IgniteCache<?, ?> cache = igniteInstance.getOrCreateCache(cacheCfg);

 cache.query(new SqlFieldsQuery(
         "CREATE TABLE IF NOT EXISTS MY_TABLE (id varchar, value varchar, PRIMARY KEY(id)) " +
                "WITH \"template=replicated\", \"DATA_REGION=" + IgniteCacheConfiguration.DEFAULT_REGION + "\""));

Then I am trying to put some data into the cache using key-value api

        IgniteCache<String, String> cache = ignite.cache("SQL_PUBLIC_MY_TABLE");

        cache.put("1","example");

I know the data is stored successfully, I can retrieve it, I see that cache size is correct but when I am trying to retrieve the data with SQL

SELECT * FROM "PUBLIC".MY_TABLE

for example using DBeaver I am getting empty result

Do you know if it is how Ignite works or there is some additional configuration needed ?


Solution

  • By default, it wraps the kay and values in a class. You can tell it not to do that with the wrap_key and wrap_value parameter like this:

    create table MY_TABLE (id varchar, value varchar, PRIMARY KEY(id)) with "wrap_key=false,wrap_value=false" ;