Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Ignite : How to list all tables and all Caches

Tags:

java

ignite

Is there any way to list all tables present in a specific Cache and list all caches present on a Apache Ignite Server?

----------------------------------UPDATED-------------------------- Hi, I am running following code to know Cache name and list all tables present in my cache. This program list outs all cache name present on server. However table listing is printed as blank collection. Meanwhile SQL query present in example is working 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);
            }

    }
like image 467
Sushil Avatar asked Mar 27 '17 14:03

Sushil


People also ask

How do I clear Apache ignite cache?

To delete a cache from all cluster nodes, call the destroy() method. Ignite ignite = Ignition. ignite(); IgniteCache<Long, String> cache = ignite. cache("myCache"); cache.

What is Apache ignite cache?

In-memory cache is a storage layer placed between applications and databases. The cache keeps your hot data in memory to offload existing databases and accelerate applications.

Is Apache ignite a NoSQL database?

Is Ignite A NoSQL Database? Just like other NoSQL databases, Ignite is highly available and horizontally scalable. However, unlike other NoSQL databases, Ignite supports SQL and ACID transactions across multiple cluster nodes.


1 Answers

Get all cache names: 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 entity represents a table.

like image 143
Pavel Tupitsyn Avatar answered Sep 22 '22 04:09

Pavel Tupitsyn