com.gemstone.gemfire.cache.query.Query Java Examples
The following examples show how to use
com.gemstone.gemfire.cache.query.Query.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParameterBindingTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBindMapInFromClause() throws Exception { Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM $1 "); Object params[] = new Object[1]; Map map = new HashMap(); Region region = CacheUtils.getRegion("/Portfolios"); Iterator iter = region.entries(false).iterator(); while(iter.hasNext()){ Region.Entry entry = (Region.Entry)iter.next(); map.put(entry.getKey(), entry.getValue()); } params[0] = map; Object result = query.execute(params); if(result instanceof Collection){ int resultSize = ((Collection)result).size(); if( resultSize != region.values().size()) fail("Results not as expected"); }else fail("Invalid result"); }
Example #2
Source File: StructMemberAcessTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBugNumber_32355() { String queries[] = { "select distinct positions.values.toArray[0], positions.values.toArray[0],status from /Portfolios",}; int i = 0; try { for (i = 0; i < queries.length; i++) { Query q = CacheUtils.getQueryService().newQuery(queries[i]); Object r = q.execute(); System.out.println(Utils.printResult(r)); StructType type = ((StructType) ((SelectResults) r).getCollectionType() .getElementType()); String fieldNames[] = type.getFieldNames(); for (i = 0; i < fieldNames.length; ++i) { String name = fieldNames[i]; System.out.println("Struct Field name = " + name); } } } catch (Exception e) { e.printStackTrace(); fail(queries[i]); } }
Example #3
Source File: DistinctResultsWithDupValuesInRegionTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Test on Local Region data */ public void testQueriesOnLocalRegion() { Cache cache = CacheUtils.getCache(); createLocalRegion(); assertNotNull(cache.getRegion(regionName)); assertEquals(numElem * 2, cache.getRegion(regionName).size()); QueryService queryService = cache.getQueryService(); Query query1 = null; try { for (String queryStr : queries) { query1 = queryService.newQuery(queryStr); SelectResults result1 = (SelectResults) query1.execute(); assertEquals(queryStr, numElem * 2, result1.size()); verifyDistinctResults(result1); } } catch (Exception e) { e.printStackTrace(); fail("Query " + query1 + " Execution Failed!"); } // Destroy current Region for other tests cache.getRegion(regionName).destroyRegion(); }
Example #4
Source File: QueryingFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
@Override public void execute(FunctionContext context) { // Get an existing cache Cache cache = CacheFactory.getAnyInstance(); // Get queryservice from cache QueryService queryService = cache.getQueryService(); // Get the query string passed as an argument to the function String qstr = (String) context.getArguments(); try { Query query = queryService.newQuery(qstr); // If function is executed on region, context is RegionFunctionContext RegionFunctionContext rContext = (RegionFunctionContext) context; // Execute the query cache.getLogger().info("Executing query: " + qstr); SelectResults results = (SelectResults) query.execute(rContext); cache.getLogger().info("Query returned " + results.size() + " results"); // Send the results to function caller node. context.getResultSender().sendResult((ArrayList) (results).asList()); context.getResultSender().lastResult(null); } catch (Exception e) { throw new FunctionException(e); } }
Example #5
Source File: PRQueryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testOrderByQuery() throws Exception { Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); String[] values = new String[100]; for (int j = 0; j < 100; j++) { values[j] = new String(""+ j); } try { populateData(region, values); String queryString = "Select distinct p from /" + region.getName() + " p order by p"; Query query = region.getCache().getQueryService().newQuery(queryString); SelectResults sr = (SelectResults)query.execute(); Assert.assertTrue(sr.size() == 100); } finally { region.close(); } }
Example #6
Source File: QueryTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static void readQueries() { Map<String,Pool> nameToPoolMap = PoolManager.getAll(); String poolName = TestConfig.tab().stringAt(PoolPrms.names, null); QueryService qs = CacheHelper.getCache().getQueryService(); if (poolName != null) { if (nameToPoolMap.get(poolName) != null) { qs = nameToPoolMap.get(poolName).getQueryService(); } } HydraVector hvQueries = TestConfig.tab() .vecAt(QueryPerfPrms.query, null); if (hvQueries != null) { queries = new Query[hvQueries.size()]; for (int i = 0; i < hvQueries.size(); i++) { queries[i] = qs.newQuery((String)(hvQueries.get(i))); } } queriesRead = true; }
Example #7
Source File: ComparisonOperatorsTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testCompareWithNULL() throws Exception{ String var ="P2"; Object value = null; QueryService qs = CacheUtils.getQueryService(); for(int i=0;i<operators.length;i++){ Query query = qs.newQuery("SELECT DISTINCT * FROM /Portfolios where "+var+operators[i]+value); Object result = query.execute(); if(result instanceof Collection){ Iterator iter = ((Collection)result).iterator(); while(iter.hasNext()){ boolean isPassed = false; Portfolio p = (Portfolio)iter.next(); switch(i){ case 0 : isPassed = (p.getP2() == value); break; default : isPassed = (p.getP2() != value); break; } if(!isPassed) fail(this.getName()+" failed for operator "+operators[i]); } }else{ fail(this.getName()+" failed for operator "+operators[i]); } } }
Example #8
Source File: QueryUsingFunctionContextDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
protected ArrayList runQueryOnServerLDS(String queryStr, Set filter) { Set buckets = getBucketsForFilter(filter); Region localDataSet = new LocalDataSet((PartitionedRegion)CacheFactory .getAnyInstance().getRegion(PartitionedRegionName1), buckets, null); QueryService qservice = CacheFactory.getAnyInstance().getQueryService(); Query query = qservice.newQuery(queryStr); SelectResults results; try { results = (SelectResults) ((LocalDataSet) localDataSet).executeQuery( (DefaultQuery) query, null, buckets); return (ArrayList)results.asList(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #9
Source File: SelectToDateJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void executeQueryTest(Cache cache, String[] queries, int[] expectedResults) { System.out.println("********Execute Query Test********"); QueryService queryService = cache.getQueryService(); Query query = null; String queryString = null; int numQueries = queries.length; try { for (int i = 0; i < numQueries; i++) { queryString = queries[0]; query = queryService.newQuery(queries[0]); SelectResults result = (SelectResults) query.execute(); assertEquals(queries[0], expectedResults[0], result.size()); } } catch (Exception e) { e.printStackTrace(); fail("Query " + queryString + ":" + query + " Execution Failed!"); } System.out.println("********Completed Executing Query Test********"); // Destroy current Region for other tests cache.getRegion(regionName).destroyRegion(); }
Example #10
Source File: IndexCreationTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creation of index on key path derived from Region.Entry object obtained * via keySet , fails as that function was not supported in the * QRegion & DummyQRegion * @author Asif */ public void testBug36590() { QueryService qs; qs = CacheUtils.getQueryService(); try{ qs.createIndex("keyIndex", IndexType.FUNCTIONAL, "keys","/portfolios.keySet keys"); Region rgn = CacheUtils.getRegion("/portfolios"); rgn.put("4",new Portfolio(4)); rgn.put("5",new Portfolio(5)); Query qr = qs.newQuery("Select distinct * from /portfolios.keySet keys where keys = '4'"); SelectResults sr = (SelectResults)qr.execute(); assertEquals(sr.size(),1); }catch(Exception e) { CacheUtils.getLogger().error(e); fail("Test failed because of exception. e="+e); } }
Example #11
Source File: IndexCreationTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Test the Index maiantenance as it may use the method keys() of QRegion * instead of DummyQRegion while running an IndexMaintenanceQuery * @author Asif */ public void testIMQFailureAsMethodKeysNAInDummyQRegion() { QueryService qs; qs = CacheUtils.getQueryService(); try{ Index i1 = qs.createIndex("keyIndex", IndexType.FUNCTIONAL, "ks.hashCode","/portfolios.keys() ks"); Region rgn = CacheUtils.getRegion("/portfolios"); rgn.put("4",new Portfolio(4)); rgn.put("5",new Portfolio(5)); System.out.println(((CompactRangeIndex)i1).dump()); Query qr = qs.newQuery("Select distinct keys.hashCode from /portfolios.keys() keys where keys.hashCode >= $1"); SelectResults sr = (SelectResults)qr.execute(new Object[]{new Integer(-1)}); assertEquals(6,sr.size()); }catch(Exception e) { CacheUtils.getLogger().error(e); fail("Test failed because of exception. e="+e); } }
Example #12
Source File: MiscTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBug40428_2() throws Exception { Object shortData1 = new Object() { public short shortField = 4; }; Object shortData2 = new Object() { public short shortField = 5; }; Region region = CacheUtils.createRegion("shortFieldTest", Object.class); region.put("0", shortData1); QueryService qs = CacheUtils.getQueryService(); String qry = "select * from /shortFieldTest.entries sf where sf.value.shortField < 10 "; qs.createIndex("shortIndex", IndexType.FUNCTIONAL, "value.shortField", "/shortFieldTest.entries"); region.put("1", shortData2); Query query = null; Object result = null; query = qs.newQuery(qry); SelectResults rs = (SelectResults)query.execute(); assertEquals(rs.size(), 2); }
Example #13
Source File: QueryDataFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void execute(FunctionContext context) { Cache cache = CacheFactory.getAnyInstance(); QueryService queryService = cache.getQueryService(); String qstr = (String) context.getArguments(); Region r = cache.getRegion(regionName); try { Query query = queryService.newQuery(qstr); if (r.getAttributes().getPartitionAttributes() != null && showMembers) { context.getResultSender().lastResult(query.execute((RegionFunctionContext) context)); } else { context.getResultSender().lastResult(query.execute()); } } catch (Exception e) { throw new FunctionException(e); } }
Example #14
Source File: IteratorTypeDefTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testIteratorDefSyntaxForObtainingResultBag() throws Exception { String queries[] = { "IMPORT com.gemstone.gemfire.cache.\"query\".data.Position;"+ "SELECT DISTINCT secId FROM /portfolios, (set<Position>)positions.values WHERE iD > 0", }; for (int i = 0; i < queries.length; i++) { Query q = null; try { q = CacheUtils.getQueryService().newQuery(queries[i]); Object r = q.execute(); System.out.println(Utils.printResult(r)); if (!(r instanceof SelectResults)) fail("testIteratorDefSyntaxForObtainingResultBag: Test failed as obtained Result Data not an instance of SelectResults. Query= "+ q.getQueryString()); if (((SelectResults)r).getCollectionType().allowsDuplicates()) fail("testIteratorDefSyntaxForObtainingResultBag: results of query should not allow duplicates, but says it does"); } catch (Exception e) { e.printStackTrace(); fail(q.getQueryString()); } } System.out.println("TestCase:testIteratorDefSyntaxForObtainingResultSet PASS"); }
Example #15
Source File: IteratorTypeDefTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testIteratorDefSyntax() throws Exception { String queries[] = { "IMPORT com.gemstone.gemfire.cache.\"query\".data.Position;" + "SELECT DISTINCT secId FROM /portfolios, positions.values pos TYPE Position WHERE iD > 0", "IMPORT com.gemstone.gemfire.cache.\"query\".data.Position;" + "SELECT DISTINCT secId FROM /portfolios, positions.values AS pos TYPE Position WHERE iD > 0", "IMPORT com.gemstone.gemfire.cache.\"query\".data.Position;" + "SELECT DISTINCT pos.secId FROM /portfolios, pos IN positions.values TYPE Position WHERE iD > 0", "SELECT DISTINCT pos.secId FROM /portfolios, positions.values AS pos WHERE iD > 0", "SELECT DISTINCT pos.secId FROM /portfolios, pos IN positions.values WHERE iD > 0",}; for (int i = 0; i < queries.length; i++) { Query q = null; try { q = CacheUtils.getQueryService().newQuery(queries[i]); Object r = q.execute(); System.out.println(Utils.printResult(r)); } catch (Exception e) { e.printStackTrace(); fail(q.getQueryString()); } } System.out.println("TestCase:testIteratorDefSyntax PASS"); }
Example #16
Source File: StructMemberAcessTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testUnsupportedQueries() throws Exception { String queries[] = { "SELECT DISTINCT * FROM" + " (SELECT DISTINCT * FROM /Portfolios ptf, positions pos)" + " WHERE value.secId = 'IBM'", "SELECT DISTINCT * FROM" + " (SELECT DISTINCT * FROM /Portfolios ptf, positions pos) p" + " WHERE p.get(1).value.secId = 'IBM'", "SELECT DISTINCT * FROM" + " (SELECT DISTINCT * FROM /Portfolios ptf, positions pos) p" + " WHERE p[1].value.secId = 'IBM'", "SELECT DISTINCT * FROM" + " (SELECT DISTINCT * FROM /Portfolios ptf, positions pos) p" + " WHERE p.value.secId = 'IBM'"}; for (int i = 0; i < queries.length; i++) { try { Query q = CacheUtils.getQueryService().newQuery(queries[i]); Object r = q.execute(); System.out.println(Utils.printResult(r)); fail(queries[i]); } catch (Exception e) { //e.printStackTrace(); } } }
Example #17
Source File: FunctionTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testIS_UNDEFINED() throws Exception { Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Portfolios where IS_UNDEFINED(P2.secId)"); Object result = query.execute(); if(result instanceof Collection){ Iterator iter = ((Collection)result).iterator(); while(iter.hasNext()){ Portfolio p = (Portfolio)iter.next(); if(p.getP2() != null) fail(query.getQueryString()); } } Object testData[][] ={ {"string", Boolean.FALSE}, {new Integer(0), Boolean.FALSE}, {QueryService.UNDEFINED, Boolean.TRUE}, {null, Boolean.FALSE} }; for(int i=0;i<testData.length;i++){ query = CacheUtils.getQueryService().newQuery("IS_UNDEFINED($1)"); result = query.execute(testData[i]); if(!result.equals(testData[i][1])) fail(query.getQueryString()+" for "+testData[i][0]); } }
Example #18
Source File: FunctionTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testIS_DEFINED() throws Exception { Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Portfolios where IS_DEFINED(P2.secId)"); Object result = query.execute(); if(result instanceof Collection){ Iterator iter = ((Collection)result).iterator(); while(iter.hasNext()){ Portfolio p = (Portfolio)iter.next(); if(p.getP2() == null) fail(query.getQueryString()); } } Object testData[][] ={ {"string", Boolean.TRUE}, {new Integer(0), Boolean.TRUE}, {QueryService.UNDEFINED, Boolean.FALSE}, {null, Boolean.TRUE} }; for(int i=0;i<testData.length;i++){ query = CacheUtils.getQueryService().newQuery("IS_DEFINED($1)"); result = query.execute(testData[i]); if(!result.equals(testData[i][1])) fail(query.getQueryString()+" for "+testData[i][0]); } }
Example #19
Source File: QueryObserverCallbackTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBeforeAndAfterMergeJoinOfDoubleIndexResults() { try { Region r3 = CacheUtils.createRegion("employees", Employee.class); Set add1 = new HashSet(); add1.add(new Address("411045", "Baner")); add1.add(new Address("411001", "DholePatilRd")); for (int i = 0; i < 4; i++) { r3.put(i + "", new Employee("empName", (20 + i), i, "Mr.", (5000 + i), add1)); } Query query = qs.newQuery("select distinct * from /portfolio p, p.positions,/employees e where p.ID = e.empId "); qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolio"); qs.createIndex("empidIndex", IndexType.FUNCTIONAL, "empId", "/employees"); MyQueryObserverImpl inst = new MyQueryObserverImpl(); QueryObserverHolder.setInstance(inst); query.execute(); assertTrue("beforeMergeJoinOfDoubleIndexResults callbak not received",inst.bfrMergeJoinOfDoubleIndexResults); assertTrue("afterMergeJoinOfDoubleIndexResults callbak not received",inst.aftMergeJoinOfDoubleIndexResults); }catch(Exception e) { e.printStackTrace(); fail(e.toString()); } }
Example #20
Source File: IndexUseTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testSizeEstimateGTInRangeIndexForNullMap() throws Exception { QueryService qs = CacheUtils.getQueryService(); LocalRegion testRgn = (LocalRegion)CacheUtils.createRegion("testRgn", null); //Create indexes Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "p.status", "/testRgn p, p.positions"); Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "p.ID", "/testRgn p, p.positions"); //put values testRgn.put(0, new Portfolio(0)); testRgn.put(1, new Portfolio(1)); //Set TestHook in RangeIndex TestHook hook = new RangeIndexTestHook(); RangeIndex.setTestHook(hook); // Execute Queries without Indexes Query q = CacheUtils.getQueryService().newQuery( "<trace> SELECT * FROM /testRgn p, p.positions where p.status = 'active' AND p.ID < 0 "); //Following should throw NullPointerException. SelectResults sr = (SelectResults)q.execute(); assertTrue("RangeIndexTestHook was not hooked for spot 1", ((RangeIndexTestHook)hook).isHooked(1)); RangeIndex.setTestHook(null); }
Example #21
Source File: MiscTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBug40428_1() throws Exception { Object shortData1 = new Object() { public short shortField = 4; }; Object shortData2 = new Object() { public short shortField = 5; }; Region region = CacheUtils.createRegion("shortFieldTest", Object.class); region.put("0", shortData1); QueryService qs = CacheUtils.getQueryService(); String qry = "select * from /shortFieldTest sf where sf.shortField < 10 "; qs.createIndex("shortIndex", IndexType.FUNCTIONAL, "shortField", "/shortFieldTest"); region.put("1", shortData2); Query query = null; Object result = null; query = qs.newQuery(qry); SelectResults rs = (SelectResults)query.execute(); assertEquals(rs.size(), 2); }
Example #22
Source File: MiscTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void xtestNestQueryInWhereClause() throws Exception { Region region = CacheUtils.createRegion("Portfolios", Portfolio.class); region.put("0", new Portfolio(0)); region.put("1", new Portfolio(1)); region.put("2", new Portfolio(2)); region.put("3", new Portfolio(3)); Query query = CacheUtils .getQueryService() .newQuery( "SELECT DISTINCT * FROM /Portfolios WHERE NOT (SELECT DISTINCT * FROM positions.values p WHERE p.secId = 'IBM').isEmpty"); Collection result = (Collection) query.execute(); Portfolio p = (Portfolio) (result.iterator().next()); if (!p.positions.containsKey("IBM")) fail(query.getQueryString()); //query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM // /Portfolios where status = ELEMENT(SELECT DISTINCT * FROM /Portfolios p // where p.ID = 0).status"); //result = (Collection)query.execute(); //System.out.println(result); //query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM // /Portfolios x where status = ELEMENT(SELECT DISTINCT * FROM /Portfolios // p where p.ID = x.ID).status"); //result = (Collection)query.execute(); //SELECT DISTINCT * FROM /Portfolios where status = ELEMENT(SELECT // DISTINCT * FROM /Portfolios where ID = 0).status //SELECT DISTINCT * FROM /Portfolios x where status = ELEMENT(SELECT // DISTINCT * FROM /Portfolios p where p.ID = x.ID).status }
Example #23
Source File: MiscTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testBug40441() throws Exception { CacheUtils.startCache(); final Cache cache = CacheUtils.getCache(); AttributesFactory attributesFactory = new AttributesFactory(); RegionAttributes ra = attributesFactory.create(); final Region region = cache.createRegion("new_pos", ra); String queryStr1 = " select distinct r.name, pVal, r.\"type\" " + " from /new_pos r , r.positions.values pVal where " + " ( r.undefinedTestField.toString = UNDEFINED OR false ) ";//AND pVal.mktValue = 1.00"; String queryStr2 = " select distinct r.name, pVal, r.\"type\" " + " from /new_pos r , r.positions.values pVal where " + " ( r.undefinedTestField.toString = UNDEFINED AND true ) AND pVal.mktValue = 1.00"; final QueryService qs = CacheUtils.getQueryService(); for (int i = 1; i < 100; ++i) { NewPortfolio pf = new NewPortfolio("name" + i, i); region.put("name" + i, pf); } Index indx1 = qs.createIndex("MarketValues", IndexType.FUNCTIONAL, "itr2.mktValue", "/new_pos itr1, itr1.positions.values itr2"); Index indx2 = qs.createIndex("Name", IndexType.FUNCTIONAL, "itr1.name", "/new_pos itr1"); Index indx3 = qs.createIndex("nameIndex", IndexType.PRIMARY_KEY, "name", "/new_pos"); Index indx4 = qs.createIndex("idIndex", IndexType.FUNCTIONAL, "id", "/new_pos"); Index indx5 = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/new_pos"); Index indx6 = qs.createIndex("undefinedFieldIndex", IndexType.FUNCTIONAL, "undefinedTestField.toString", "/new_pos"); final Query q1 = qs.newQuery(queryStr1); final Query q2 = qs.newQuery(queryStr2); try { SelectResults sr1 = (SelectResults)q1.execute(); SelectResults sr2 = (SelectResults)q2.execute(); }catch(Throwable e) { e.printStackTrace(); fail("Test failed due to = " +e.toString()); } }
Example #24
Source File: DistinctResultsWithDupValuesInRegionTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Test on Partitioned Region data */ public void testQueriesOnPartitionedRegion() { Cache cache = CacheUtils.getCache(); createPartitionedRegion(); assertNotNull(cache.getRegion(regionName)); assertEquals(numElem * 2, cache.getRegion(regionName).size()); QueryService queryService = cache.getQueryService(); Query query1 = null; try { for (String queryStr : queries) { query1 = queryService.newQuery(queryStr); SelectResults result1 = (SelectResults) query1.execute(); assertEquals(queryStr, numElem * 2, result1.size()); verifyDistinctResults(result1); } } catch (Exception e) { e.printStackTrace(); fail("Query " + query1 + " Execution Failed!"); } // Destroy current Region for other tests cache.getRegion(regionName).destroyRegion(); }
Example #25
Source File: QRegionInterfaceTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testGetValues() throws Exception{ Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.values where ID = 1"); Collection result = (Collection)query.execute(); Portfolio p = (Portfolio)result.iterator().next(); if(p.getID() != 1) fail(query.getQueryString()); }
Example #26
Source File: QueryObserverCallbackTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testBeforeAndAfterCutDownAndExpansionOfSingleIndexResult( ){ try { Query query = qs.newQuery("select distinct * from /portfolio p, p.positions where p.ID = 1 "); qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolio"); MyQueryObserverImpl inst = new MyQueryObserverImpl(); QueryObserverHolder.setInstance(inst); query.execute(); assertTrue("beforeCutDownAndExpansionOfSingleIndexResult callbak not received",inst.bfrCutDownAndExpansionOfSingleIndexResult); assertTrue("afterCutDownAndExpansionOfSingleIndexResult callbak not received",inst.aftCutDownAndExpansionOfSingleIndexResult); }catch(Exception e) { e.printStackTrace(); fail(e.toString()); } }
Example #27
Source File: IndexCreationTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Creation of index on a path derived from Region.Entry object obtained * via entrySet , fails as that function was not supported in the * QRegion & DummyQRegion * @author Asif */ public void testBug43519() { QueryService qs; qs = CacheUtils.getQueryService(); try{ Index index = qs.createIndex("shortIndex", IndexType.FUNCTIONAL, "p.shortID","/portfolios p"); Region rgn = CacheUtils.getRegion("/portfolios"); for (int i=1; i <= 10; i++) { String key ="" + i; Portfolio p = new Portfolio(i); p.shortID = new Short(key); // addToIndex rgn.put(key, p); // updateIndex rgn.put(key, p); if (i %2 == 0) { // destroy from index. rgn.destroy(key); } } Query qr = qs.newQuery("Select p.shortID from /portfolios p where p.shortID < 5"); SelectResults sr = (SelectResults)qr.execute(); assertEquals(sr.size(),2); }catch(Exception e) { CacheUtils.getLogger().error(e); fail("Test failed because of exception. e="+e); } }
Example #28
Source File: DistinctResultsWithDupValuesInRegionTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Test on Replicated Region data */ public void testQueriesOnReplicatedRegionWithIndex() { Cache cache = CacheUtils.getCache(); createReplicatedRegion(); assertNotNull(cache.getRegion(regionName)); assertEquals(numElem * 2, cache.getRegion(regionName).size()); QueryService queryService = cache.getQueryService(); Query query1 = null; try { queryService.createIndex("idIndex", "p.ID", "/" + regionName + " p"); for (String queryStr : queries) { query1 = queryService.newQuery(queryStr); SelectResults result1 = (SelectResults) query1.execute(); assertEquals(queryStr, numElem * 2, result1.size()); verifyDistinctResults(result1); } } catch (Exception e) { e.printStackTrace(); fail("Query " + query1 + " Execution Failed!"); } // Destroy current Region for other tests cache.getRegion(regionName).destroyRegion(); }
Example #29
Source File: MiscTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void xtestMiscQueries() throws Exception { String testData[] = { "NULL", "UNDEFINED"}; for (int i = 0; i < testData.length; i++) { Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM " + testData[i]); Object result = query.execute(); if (!result.equals(QueryService.UNDEFINED)) fail(query.getQueryString()); } }
Example #30
Source File: DistinctResultsWithDupValuesInRegionTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Test on Replicated Region data */ public void testQueriesOnReplicatedRegionWithNullProjAttr() { Cache cache = CacheUtils.getCache(); createLocalRegionWithNullValues(); assertNotNull(cache.getRegion(regionName)); assertEquals(numElem * 2, cache.getRegion(regionName).size()); QueryService queryService = cache.getQueryService(); Query query1 = null; try { for (String queryStr : moreQueries) { query1 = queryService.newQuery(queryStr); SelectResults result1 = (SelectResults) query1.execute(); cache.getLogger().fine(result1.asList().toString()); assertEquals(queryStr, numElem, result1.size()); verifyDistinctResults(result1); } } catch (Exception e) { e.printStackTrace(); fail("Query " + query1 + " Execution Failed!"); } // Destroy current Region for other tests cache.getRegion(regionName).destroyRegion(); }