public static Portfolio[] createPortfoliosAndPositions(int count) { Position.cnt = 0; // reset Portfolio counter Portfolio[] portfolios = new Portfolio[count]; for (int i = 0; i < count; i++) { portfolios[i] = new Portfolio(i); } return portfolios; }
@Override public Object execute() { Region region = PerfQuery.this.cache.getRegion("/portfolios"); SelectResults results = new ResultsSet(); for (Iterator itr = region.values().iterator(); itr.hasNext();) { Portfolio ptflo = (Portfolio) itr.next(); if ("type1".equals(ptflo.getType())) { results.add(ptflo); } } return results; } };
private static void prepareDataForRegion(String regionPath) { InternalCache cache = ClusterStartupRule.getCache(); Region dataRegion = cache.getRegion(regionPath); for (int j = 0; j < 10; j++) { dataRegion.put(new Integer(j), new Portfolio(j)); } }
@Override public Object execute() { Region region = PerfQuery.this.cache.getRegion("/portfolios"); SelectResults results = new ResultsSet(); for (Iterator itr = region.values().iterator(); itr.hasNext();) { Portfolio ptflo = (Portfolio) itr.next(); if ("miss".equals(ptflo.getType())) { results.add(ptflo); } } return results; } };
/** * we are "indexed" on indexKey. Equality of portfolios is based on ID indexKeys are based on 0 -> * numEntries IDs are startID -> startID + numEntries * * @param numToCreate how many portfolios to create * @param startID the ID value to start incrementing from */ private Map<Integer, Portfolio> createPortfolioObjects(int numToCreate, int startID) { Map<Integer, Portfolio> portfoliosMap = new HashMap<>(); IntStream.range(0, numToCreate).forEach(e -> { Portfolio p = new Portfolio(e + startID); p.indexKey = e; portfoliosMap.put(p.indexKey, p); }); return portfoliosMap; }
@Override @Test public void testConvertibleGroupByQuery_refer_column() throws Exception { Region region = this.createRegion("portfolio", Portfolio.class); for (int i = 1; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); region.put("" + i, pf); } String queryStr = "select p.shortID from /portfolio p where p.ID >= 0 group by p.shortID "; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Short> results = (SelectResults<Short>) query.execute(); Iterator<Short> iter = results.asList().iterator(); int counter = 0; while (iter.hasNext()) { Short shortID = iter.next(); assertEquals(counter++, shortID.intValue()); } assertEquals(39, counter - 1); }
@Override @Test public void testConvertibleGroupByQuery_refer_column_alias_Bug520141() throws Exception { Region region = this.createRegion("portfolio", Portfolio.class); for (int i = 1; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); region.put("" + i, pf); } String queryStr = "select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id "; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Struct> results = (SelectResults<Struct>) query.execute(); Iterator<Struct> iter = results.asList().iterator(); int counter = 0; while (iter.hasNext()) { Struct str = iter.next(); assertEquals(counter++, ((Short) str.get("short_id")).intValue()); } assertEquals(39, counter - 1); }
@Test public void testOrderByWithColumnAlias_Bug52041_1() throws Exception { Region region = createRegion("portfolio", Portfolio.class); for (int i = 1; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); pf.status = "active"; region.put("" + i, pf); } String queryStr = "select distinct p.status, p.shortID as short_id from /portfolio p where p.ID >= 0 " + "order by short_id asc"; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Struct> results = (SelectResults<Struct>) query.execute(); Iterator<Struct> iter = results.asList().iterator(); int counter = 0; while (iter.hasNext()) { Struct str = iter.next(); assertEquals(counter, ((Short) str.get("short_id")).intValue()); ++counter; } assertEquals(39, counter - 1); CompiledSelect cs = ((DefaultQuery) query).getSimpleSelect(); List<CompiledSortCriterion> orderbyAtts = cs.getOrderByAttrs(); assertEquals(orderbyAtts.get(0).getColumnIndex(), 1); }
private void warmUpIndexCreation() throws CacheException, QueryException { System.out.println("Populating Cache with 1000 Portfolios"); if (this.region != null) { this.region.localDestroyRegion(); } this.region = cache.createRegion("portfolios", this.regionAttributes); for (int i = 0; i < 1000; i++) { this.region.put(String.valueOf(i), new Portfolio(i)); } System.out.println("Warming up index creation..."); for (int i = 0; i < 20000; i++) { Index index = this.qs.createIndex("portfolios", IndexType.FUNCTIONAL, "type", "/portfolios"); this.qs.removeIndex(index); } }
@Test public void testOrderByWithColumnAlias_Bug52041_2() throws Exception { Region region = createRegion("portfolio", Portfolio.class); for (int i = 0; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); pf.status = "active"; region.put("" + i, pf); } String queryStr = "select distinct p.ID as _id, p.shortID as short_id from /portfolio p where p.ID >= 0 " + "order by short_id asc, p.ID desc"; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Struct> results = (SelectResults<Struct>) query.execute(); Iterator<Struct> iter = results.asList().iterator(); int counter = 0; int k = 0; while (iter.hasNext()) { k = ((counter) / 5 + 1) * 5 - 1; Struct str = iter.next(); assertEquals(counter / 5, ((Short) str.get("short_id")).intValue()); assertEquals(k - (counter) % 5, ((Integer) str.get("_id")).intValue()); ++counter; } CompiledSelect cs = ((DefaultQuery) query).getSimpleSelect(); List<CompiledSortCriterion> orderbyAtts = cs.getOrderByAttrs(); assertEquals(orderbyAtts.get(0).getColumnIndex(), 1); assertEquals(orderbyAtts.get(1).getColumnIndex(), 0); }
private void populate(int numPortfolios, boolean indexed) throws CacheException, QueryException { System.out.println("Populating Cache with " + numPortfolios + " Portfolios"); if (this.region != null) { this.region.localDestroyRegion(); } this.region = cache.createRegion("portfolios", this.regionAttributes); for (int i = 0; i < numPortfolios; i++) { this.region.put(String.valueOf(i), new Portfolio(i)); } if (indexed) { System.out.println("Creating index..."); long startNanos = NanoTimer.getTime(); this.qs.createIndex("portfolios", IndexType.FUNCTIONAL, "type", "/portfolios"); float createTime = (NanoTimer.getTime() - startNanos) / 1e6f; System.out.println("Index created in " + createTime + " ms."); this.results[INDEX_CREATE].add(createTime); } }
Region region = this.createRegion("portfolio", Portfolio.class); for (int i = 1; i < 600; ++i) { Portfolio pf = new Portfolio(i); if (pf.status.equals("active")) { pf.shortID = (short) ((short) i % 5);
@Test public void testIndexWhenObjectNotInSetWhenPopulated() { int numEntries = 10; this.setupHashIndexSet(numEntries); assertEquals(-1, his.index(new Portfolio(numEntries + 1))); }
r1.put(i + "", new Portfolio(i));
r1.put(i + "", new Portfolio(i));
r1.put(i + "", new Portfolio(i));
r1.put(i + "", new Portfolio(i));
@Test public void testHashIndexContainsAllShouldReturnFalse() throws Exception { int numEntries = 100; setupHashIndexSet(numEntries); assertEquals(numEntries, his.size()); portfolioSet.add(new Portfolio(numEntries + 1)); assertFalse(his.containsAll(portfolioSet)); }
Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); r1.put("" + i, pf);
Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); r1.put("" + i, pf);