Search in sources :

Example 1 with CalciteAssert

use of org.apache.calcite.test.CalciteAssert in project calcite by apache.

the class GeodeZipsTest method testWhereWithOrForLargeValueList.

@Test
void testWhereWithOrForLargeValueList() throws Exception {
    Cache cache = POLICY.cache();
    QueryService queryService = cache.getQueryService();
    Query query = queryService.newQuery("select state as state from /zips");
    SelectResults results = (SelectResults) query.execute();
    Set<String> stateList = (Set<String>) results.stream().map(s -> {
        StructImpl struct = (StructImpl) s;
        return struct.get("state");
    }).collect(Collectors.toCollection(TreeSet::new));
    String stateListPredicate = stateList.stream().map(s -> String.format(Locale.ROOT, "state = '%s'", s)).collect(Collectors.joining(" OR "));
    String stateListStr = "'" + String.join("', '", stateList) + "'";
    String queryToBeExecuted = "SELECT state as state FROM view WHERE " + stateListPredicate;
    String expectedQuery = "SELECT state AS state FROM /zips WHERE state " + "IN SET(" + stateListStr + ")";
    calciteAssert().query(queryToBeExecuted).returnsCount(149).queryContains(GeodeAssertions.query(expectedQuery));
}
Also used : Arrays(java.util.Arrays) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Connection(java.sql.Connection) Query(org.apache.geode.cache.query.Query) StructImpl(org.apache.geode.cache.query.internal.StructImpl) Set(java.util.Set) CalciteAssert(org.apache.calcite.test.CalciteAssert) ViewTable(org.apache.calcite.schema.impl.ViewTable) QueryService(org.apache.geode.cache.query.QueryService) Disabled(org.junit.jupiter.api.Disabled) Collectors(java.util.stream.Collectors) TreeSet(java.util.TreeSet) Test(org.junit.jupiter.api.Test) Cache(org.apache.geode.cache.Cache) SQLException(java.sql.SQLException) SelectResults(org.apache.geode.cache.query.SelectResults) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) BeforeAll(org.junit.jupiter.api.BeforeAll) Region(org.apache.geode.cache.Region) Locale(java.util.Locale) Collections(java.util.Collections) DriverManager(java.sql.DriverManager) SelectResults(org.apache.geode.cache.query.SelectResults) Set(java.util.Set) TreeSet(java.util.TreeSet) StructImpl(org.apache.geode.cache.query.internal.StructImpl) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) TreeSet(java.util.TreeSet) Cache(org.apache.geode.cache.Cache) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (java.sql.Connection)1 DriverManager (java.sql.DriverManager)1 SQLException (java.sql.SQLException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Locale (java.util.Locale)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 ViewTable (org.apache.calcite.schema.impl.ViewTable)1 CalciteAssert (org.apache.calcite.test.CalciteAssert)1 Cache (org.apache.geode.cache.Cache)1 Region (org.apache.geode.cache.Region)1 Query (org.apache.geode.cache.query.Query)1 QueryService (org.apache.geode.cache.query.QueryService)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 StructImpl (org.apache.geode.cache.query.internal.StructImpl)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1