Search in sources :

Example 1 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class MutateTask method selectGeneByChromsomeCriteria.

/**
 * method assumes ChromosomeCriteria is set.
 *
 * @param k Gene index in Chromosome.
 * @return Primary key of Gene
 */
private long selectGeneByChromsomeCriteria(int k) {
    List<Gene> genes = new ArrayList();
    StringBuffer sbSqlClause = new StringBuffer("_val like '");
    sbSqlClause.append("%");
    sbSqlClause.append(config.getChromosomeCriteria().getCriteria().get(k));
    sbSqlClause.append("%'");
    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
    SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
    try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
        for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
    }
    int idx = selectRandomIndex(genes.size());
    Gene gene = genes.get(idx);
    return gene.id();
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery) ArrayList(java.util.ArrayList)

Example 2 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class TruncateSelectionTask method getChromosome.

/**
 * Retrieve a chromosome
 *
 * @param key Primary key of chromosome
 * @return Chromosome
 */
private Chromosome getChromosome(Long key) {
    IgniteCache<Long, Chromosome> cache = ignite.cache(GAGridConstants.POPULATION_CACHE);
    StringBuffer sbSqlClause = new StringBuffer();
    sbSqlClause.append("_key IN (");
    sbSqlClause.append(key);
    sbSqlClause.append(")");
    Chromosome chromosome = null;
    SqlQuery sql = new SqlQuery(Chromosome.class, sbSqlClause.toString());
    try (QueryCursor<Entry<Long, Chromosome>> cursor = cache.query(sql)) {
        for (Entry<Long, Chromosome> e : cursor) chromosome = (e.getValue());
    }
    return chromosome;
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery)

Example 3 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class GAGridUtils method getGenesForChromosome.

/**
 * @param ignite Ignite
 * @param chromosome Chromosome
 * @return List of Genes
 */
public static List<Gene> getGenesForChromosome(Ignite ignite, Chromosome chromosome) {
    List<Gene> genes = new ArrayList();
    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
    StringBuffer sbSqlClause = new StringBuffer();
    sbSqlClause.append("_key IN ");
    String sqlInClause = Arrays.toString(chromosome.getGenes());
    sqlInClause = sqlInClause.replace("[", "(");
    sqlInClause = sqlInClause.replace("]", ")");
    sbSqlClause.append(sqlInClause);
    SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
    try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
        for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
    }
    return genes;
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Gene(org.apache.ignite.ml.genetic.Gene) ArrayList(java.util.ArrayList)

Example 4 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class GAGridUtils method getChromosomes.

/**
 * Retrieve chromosomes
 *
 * @param ignite Ignite
 * @param query Sql
 * @return List of Chromosomes
 */
public static List<Chromosome> getChromosomes(Ignite ignite, String query) {
    List<Chromosome> chromosomes = new ArrayList();
    IgniteCache<Long, Chromosome> populationCache = ignite.getOrCreateCache(PopulationCacheConfig.populationCache());
    SqlQuery sql = new SqlQuery(Chromosome.class, query);
    try (QueryCursor<Entry<Long, Chromosome>> cursor = populationCache.query(sql)) {
        for (Entry<Long, Chromosome> e : cursor) chromosomes.add(e.getValue());
    }
    return chromosomes;
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery) ArrayList(java.util.ArrayList) Chromosome(org.apache.ignite.ml.genetic.Chromosome)

Example 5 with Entry

use of javax.cache.Cache.Entry in project camel by apache.

the class IgniteCacheTest method testQuery.

@Test
public void testQuery() {
    IgniteCache<String, String> cache = ignite().getOrCreateCache("testcache1");
    Set<String> keys = new HashSet<>();
    for (int i = 0; i < 100; i++) {
        cache.put("k" + i, "v" + i);
        keys.add("k" + i);
    }
    Query<Entry<String, String>> query = new ScanQuery<String, String>(new IgniteBiPredicate<String, String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean apply(String key, String value) {
            return Integer.parseInt(key.replace("k", "")) >= 50;
        }
    });
    List results = template.requestBodyAndHeader("ignite:cache:testcache1?operation=QUERY", keys, IgniteConstants.IGNITE_CACHE_QUERY, query, List.class);
    assert_().that(results.size()).isEqualTo(50);
}
Also used : Entry(javax.cache.Cache.Entry) ScanQuery(org.apache.ignite.cache.query.ScanQuery) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Entry (javax.cache.Cache.Entry)8 SqlQuery (org.apache.ignite.cache.query.SqlQuery)6 ArrayList (java.util.ArrayList)5 Gene (org.apache.ignite.ml.genetic.Gene)2 HashSet (java.util.HashSet)1 List (java.util.List)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 CacheDataStore (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager.CacheDataStore)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 CacheDataRowStore (org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore)1 CacheDataTree (org.apache.ignite.internal.processors.cache.tree.CacheDataTree)1 SearchRow (org.apache.ignite.internal.processors.cache.tree.SearchRow)1 Chromosome (org.apache.ignite.ml.genetic.Chromosome)1 Test (org.junit.Test)1