Apache Ignite: list of all tables and all caches

Is there a way to list all tables present in a particular cache and specify all caches present on Apache Ignite Server?

---------------------------------- UPDATED ------------ --- ----------- Hello, I am running the following code to find out the name of the cache and a list of all tables present in my cache. This list of programs displays all the cache name present on the server. However, the table listing is printed as an empty collection. In the meantime, the SQL query provided in the example works fine.

public static void main(String[] args) throws Exception {
        System.out.println("Run Spring example!!");
        Ignition.setClientMode(true);
        IgniteConfiguration cfg = new IgniteConfiguration();
        cfg.setIncludeEventTypes( EVTS_CACHE);
        cfg.setPeerClassLoadingEnabled(true);
        TcpDiscoveryMulticastIpFinder discoveryMulticastIpFinder = new TcpDiscoveryMulticastIpFinder();
        Set<String> set = new HashSet<>();

        set.add("hostname:47500..47509");

        discoveryMulticastIpFinder.setAddresses(set);

        TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
        discoverySpi.setIpFinder(discoveryMulticastIpFinder);

        cfg.setDiscoverySpi(discoverySpi);

        cfg.setPeerClassLoadingEnabled(true);
        cfg.setIncludeEventTypes(EVTS_CACHE);
        Ignite ignite = Ignition.start(cfg);

        System.out.println("All Available Cache on server : "+ignite.cacheNames());

        CacheConfiguration<String, BinaryObject> cacheConfiguration = new CacheConfiguration<>(CACHE_NAME);

        Collection<QueryEntity> entities = cacheConfiguration.getQueryEntities();
        System.out.println("All available tables in cache : "+entities);

        cacheConfiguration.setIndexedTypes(String.class, BinaryObject.class);
        //cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);

        IgniteCache<String, BinaryObject> cache = ignite.getOrCreateCache(cacheConfiguration).withKeepBinary();

        System.out.println();





            QueryCursor<List<?>> query = cache.query(new SqlFieldsQuery("select Field1 from table1 where Field1='TEST'"));
            List<List<?>> all = query.getAll();
            for (List<?> l : all) {
                System.out.println(l);
            }

    }

      

+3


source to share


2 answers


Get all the names of the caches: Ignite.cacheNames()

. Then use Ignite.cache(String)

to get the cache instance.

Get SQL tables:



CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
Collection<QueryEntity> entities = ccfg.getQueryEntities();

      

Each query object represents a table.

+5


source


You can get all cache names with Ignite.cacheNames()

. To get all the table names you can use the command SHOW TABLES

:

QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SHOW TABLES FROM \""+CACHE_NAME+"\""));
for (List<?> row : cursor) {
    System.out.println(row.get(0));
}

      



SHOW

You can find more details about the command here: http://www.h2database.com/html/grammar.html#show

0


source







All Articles