0

I have a particular question about indexing with Apache Ignite.

My need is to query the Cache without "knowing" the schema. Because I have no java class definition at some moments, so no annotation available. But Apache Ignite seems to need annotation to recognize fields.

Is there a way to define queryable fields at runtime?

I ask it because I'm building an technology agnostic application and I plug specialized class at runtime. Another problem for me is to extend classes for Apache Ignite and define fake fields just to make "the field" (assuming it's not the original field...) viewable from Apache Ignite.

Did someone had the same "problem"?

Original class Command :

public class Command {
    private String commandName;

    public void setCommandName(String commandName) {
        this.commandName = commandName;
    }
    public String getCommandName(){
        return this.commandName;
    }
}

Extended Command class for Ignite SQL uses :

public class IgniteCommand extends Command{
    @QuerySqlField (name="name", index = true)
    private String _commandName;

    @Override
    public void setCommandName(String commandName) {
        super.setCommandName(commandName);
        this._commandName = getCommandName();
    }
}

This above code works fine for me.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sirius B
  • 11
  • 6

1 Answers1

1

You can configure query entities at runtime but before cache started. See Spring XML configuration example in docs [1]. You can do the same programmatically.

You also can create indexes dynamically using DDL. See [2].

[1] https://apacheignite.readme.io/docs/indexes#queryentity-based-configuration [2] https://apacheignite.readme.io/docs/distributed-ddl#section-create-index

a_gura
  • 400
  • 1
  • 5
  • Thank you for your answer :) So, if I well understand, a call to "ignite.cache()" will refresh the schema declaration for all objects already stored? Or are you talking about the Ignite instance? Because I can't shutdown the cluster just for that... – Sirius B Jul 07 '17 at 13:54
  • `ignite.cache()` just returns proxy for cache operations. You should configure all indexes before cache creation. – a_gura Jul 07 '17 at 14:03
  • OK, I understand, it looked too beautyful. Unfortunately it's not the behaviour I'm looking for (especially for the "schemaless" part of my application). You may wonder why I don't use a document database like MongoDB : I want to know the "limits" of Ignite and I want to stay into the cluster / nodes most time I can before switching to another database to reduce communication costs. Thank you again for your quick answer! Best regards – Sirius B Jul 07 '17 at 14:26
  • I've updated answer because remembered that Ignite 2.0 has DDL. – a_gura Jul 07 '17 at 14:32
  • Yes, but if I well understand, Ignite doesn't support "alter table", but it's a good begining to permit index creation at runtime :) I'm impatient to discover the next version of Ignite! – Sirius B Jul 07 '17 at 14:37