Troubleshooting

Expand all | Collapse all

Adding SQL Support to an Existing Cache

  • 1.  Adding SQL Support to an Existing Cache

     
    Posted 06-14-2019 03:03 PM
    I have a cache called Person which initially was created like so:

    personCache = igniteClient.getOrCreateCache<String, Person>("Person")

    and a Person is defined as:

    data class Person(
        val name: String,
        val age: Int,
        val city: String
    )

    I now want to be able to run SQL queries on this cache and based on the
    Ignite docs have added some setup code to allow for this. Basically what I
    did was I added the annotations on the fields of the Person class which I
    would like to run queries on like so:
           
    data class Person(
        @QuerySqlField
        val name: String,
        @QuerySqlField
        val age: Int,
        val city: String
    )
           
    and in addition to this I have created a CacheConfiguration which gets
    passed to my cache which sets the indexedTypes that match my Person cache
    like so:
           
    personCache = igniteClient.getOrCreateCache<String, Person>(
        CacheConfiguration<String, Person>("Person")
            .setIndexedTypes(String::class.java, Person::class.java)
        )

    The problem that I run into once doing all of this is upon the first time
    that I try to run a SQL query, like for example:

        val sqlString = "name=?"
        val sql: SqlQuery<String, Person> = SqlQuery(Person::class.java,
    sqlString)
        sql.setArgs("Jon Snow")

        personCache.query(sql)

    I get Ignite SQL exceptions that the table Person does not exist.

    Now after some research into this problem, it seems that if I destroy the
    cache first once it goes to create the Person cache again Ignite will now
    also create the Person table and the queries will now work.

    So after all of this my question is, is there any other way that I could add
    SQL support to an existing Cache that wouldn't require me to destroy the
    existing cache and lose all the data that is currently in it?

    Follow up questions:
    - If the answer to the above is no that you cannot add this support without
    destroying the cache, how do people deal with this and not lose the data
    that is in their caches?
    - If there is no way around this data loss, is there any downside then to
    just making every cache SQL enabled immediately even if you don't know that
    you will use it (i.e. memory or performance costs)?
    - Are there any DDL queries possible that would allow me to create the table
    for the existing cache with no data loss?

    ------------------------------
    Steve Bremmer
    Software engineer
    MCI
    ------------------------------


  • 2.  RE: Adding SQL Support to an Existing Cache

     
    Posted 06-17-2019 01:28 PM
    Edited by Phil Goodman 06-17-2019 01:40 PM
    Hi DBA Guy,

    I suggest using Data Definition Language (DDL) if you'd like to configure SQL dynamically. More info here: https://apacheignite-sql.readme.io/docs/ddl

    Also, this page shows how to use both SQL and key-value APIs:
    https://apacheignite-sql.readme.io/docs/sql-and-key-value-usage

    Hope that helps.



Would you attend a July Meetup?


Announcements

  • Welcome to the new GridGain Forums!

    Hello and welcome to the new GridGain Forums. This is the place to ask questions, get or give advice and connect with your peers. GridGain experts regularly monitor these posts and can also help solve your issues.