1212import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .EQ ;
1313import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .GT ;
1414import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .GTE ;
15+ import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .IN ;
1516import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .LTE ;
1617import static org .hypertrace .core .documentstore .expression .operators .RelationalOperator .NEQ ;
18+ import static org .hypertrace .core .documentstore .expression .operators .SortOrder .ASC ;
1719import static org .hypertrace .core .documentstore .expression .operators .SortOrder .DESC ;
1820import static org .hypertrace .core .documentstore .utils .CreateUpdateTestThread .FAILURE ;
1921import static org .hypertrace .core .documentstore .utils .CreateUpdateTestThread .SUCCESS ;
5456import org .hypertrace .core .documentstore .expression .impl .RelationalExpression ;
5557import org .hypertrace .core .documentstore .mongo .MongoDatastore ;
5658import org .hypertrace .core .documentstore .postgres .PostgresDatastore ;
59+ import org .hypertrace .core .documentstore .query .Pagination ;
60+ import org .hypertrace .core .documentstore .query .Selection ;
61+ import org .hypertrace .core .documentstore .query .SelectionSpec ;
62+ import org .hypertrace .core .documentstore .query .Sort ;
63+ import org .hypertrace .core .documentstore .query .SortingSpec ;
5764import org .hypertrace .core .documentstore .utils .CreateUpdateTestThread ;
5865import org .hypertrace .core .documentstore .utils .CreateUpdateTestThread .Operation ;
5966import org .hypertrace .core .documentstore .utils .Utils ;
@@ -1551,12 +1558,22 @@ public void testQueryV1FilterWithNestedFiled(String dataStoreName) throws IOExce
15511558 org .hypertrace .core .documentstore .query .Query query =
15521559 org .hypertrace .core .documentstore .query .Query .builder ()
15531560 .setFilter (
1554- RelationalExpression .of (
1555- IdentifierExpression .of ("quantity" ), NEQ , ConstantExpression .of (10 )))
1561+ LogicalExpression .builder ()
1562+ .operator (AND )
1563+ .operand (
1564+ RelationalExpression .of (
1565+ IdentifierExpression .of ("quantity" ), GT , ConstantExpression .of (5 )))
1566+ .operand (
1567+ RelationalExpression .of (
1568+ IdentifierExpression .of ("props.seller.address.city" ),
1569+ EQ ,
1570+ ConstantExpression .of ("Kolkata" )))
1571+ .build ())
15561572 .build ();
15571573
15581574 Iterator <Document > iterator = collection .aggregate (query );
1559- assertSizeAndDocsEqual (dataStoreName , iterator , 6 , "mongo/simple_filter_quantity_neq_10.json" );
1575+ assertSizeAndDocsEqual (
1576+ dataStoreName , iterator , 1 , "mongo/test_nest_field_filter_response.json" );
15601577 }
15611578
15621579 @ ParameterizedTest
@@ -1772,8 +1789,7 @@ public void testQueryV1AggregationFilterWithWhereClause(String dataStoreName) th
17721789
17731790 @ ParameterizedTest
17741791 @ MethodSource ("databaseContextProvider" )
1775- public void testQueryQ1AggregationFilterAlongWithNonAliasFields (String dataStoreName )
1776- throws IOException {
1792+ public void testQueryV1DistinctCountWithSortingSpecs (String dataStoreName ) throws IOException {
17771793 Map <Key , Document > documents = createDocumentsFromResource ("mongo/collection_data.json" );
17781794 Datastore datastore = datastoreMap .get (dataStoreName );
17791795 Collection collection = datastore .getCollection (COLLECTION_NAME );
@@ -1788,53 +1804,64 @@ public void testQueryQ1AggregationFilterAlongWithNonAliasFields(String dataStore
17881804 AggregateExpression .of (DISTINCT_COUNT , IdentifierExpression .of ("quantity" )),
17891805 "qty_count" )
17901806 .addSelection (IdentifierExpression .of ("item" ))
1791- .addSelection (IdentifierExpression .of ("price" ))
17921807 .addAggregation (IdentifierExpression .of ("item" ))
1793- .addAggregation (IdentifierExpression .of ("price" ))
17941808 .setAggregationFilter (
1795- LogicalExpression .builder ()
1796- .operator (AND )
1797- .operand (
1798- RelationalExpression .of (
1799- IdentifierExpression .of ("qty_count" ), LTE , ConstantExpression .of (10 )))
1800- .operand (
1801- RelationalExpression .of (
1802- IdentifierExpression .of ("price" ), GT , ConstantExpression .of (5 )))
1803- .build ())
1809+ RelationalExpression .of (
1810+ IdentifierExpression .of ("qty_count" ), LTE , ConstantExpression .of (1000 )))
1811+ .addSort (IdentifierExpression .of ("qty_count" ), DESC )
1812+ .addSort (IdentifierExpression .of ("item" ), DESC )
18041813 .build ();
18051814
18061815 Iterator <Document > resultDocs = collection .aggregate (query );
1807- assertSizeAndDocsEqual (
1808- dataStoreName , resultDocs , 4 , "mongo/test_aggr_alias_distinct_count_response.json" );
1816+ assertDocsAndSizeEqual (resultDocs , "mongo/distinct_count_response.json" , 4 );
18091817 }
18101818
18111819 @ ParameterizedTest
18121820 @ MethodSource ("databaseContextProvider" )
1813- public void testQueryV1DistinctCountWithSortingSpecs (String dataStoreName ) throws IOException {
1821+ public void testFindWithSortingAndPagination (String datastoreName ) throws IOException {
18141822 Map <Key , Document > documents = createDocumentsFromResource ("mongo/collection_data.json" );
1815- Datastore datastore = datastoreMap .get (dataStoreName );
1823+ Datastore datastore = datastoreMap .get (datastoreName );
18161824 Collection collection = datastore .getCollection (COLLECTION_NAME );
18171825
18181826 // add docs
18191827 boolean result = collection .bulkUpsert (documents );
18201828 Assertions .assertTrue (result );
1829+ List <SelectionSpec > selectionSpecs =
1830+ List .of (
1831+ SelectionSpec .of (IdentifierExpression .of ("item" )),
1832+ SelectionSpec .of (IdentifierExpression .of ("price" )),
1833+ SelectionSpec .of (IdentifierExpression .of ("quantity" )),
1834+ SelectionSpec .of (IdentifierExpression .of ("date" )));
1835+ Selection selection = Selection .builder ().selectionSpecs (selectionSpecs ).build ();
1836+
1837+ org .hypertrace .core .documentstore .query .Filter filter =
1838+ org .hypertrace .core .documentstore .query .Filter .builder ()
1839+ .expression (
1840+ RelationalExpression .of (
1841+ IdentifierExpression .of ("item" ),
1842+ IN ,
1843+ ConstantExpression .ofStrings (List .of ("Mirror" , "Comb" , "Shampoo" , "Bottle" ))))
1844+ .build ();
1845+
1846+ Sort sort =
1847+ Sort .builder ()
1848+ .sortingSpec (SortingSpec .of (IdentifierExpression .of ("quantity" ), DESC ))
1849+ .sortingSpec (SortingSpec .of (IdentifierExpression .of ("item" ), ASC ))
1850+ .build ();
1851+
1852+ Pagination pagination = Pagination .builder ().offset (1 ).limit (3 ).build ();
18211853
18221854 org .hypertrace .core .documentstore .query .Query query =
18231855 org .hypertrace .core .documentstore .query .Query .builder ()
1824- .addSelection (
1825- AggregateExpression .of (DISTINCT_COUNT , IdentifierExpression .of ("quantity" )),
1826- "qty_count" )
1827- .addSelection (IdentifierExpression .of ("item" ))
1828- .addAggregation (IdentifierExpression .of ("item" ))
1829- .setAggregationFilter (
1830- RelationalExpression .of (
1831- IdentifierExpression .of ("qty_count" ), LTE , ConstantExpression .of (1000 )))
1832- .addSort (IdentifierExpression .of ("qty_count" ), DESC )
1833- .addSort (IdentifierExpression .of ("item" ), DESC )
1856+ .setSelection (selection )
1857+ .setFilter (filter )
1858+ .setSort (sort )
1859+ .setPagination (pagination )
18341860 .build ();
18351861
1836- Iterator <Document > resultDocs = collection .aggregate (query );
1837- assertDocsAndSizeEqual (resultDocs , "mongo/distinct_count_response.json" , 4 );
1862+ Iterator <Document > resultDocs = collection .find (query );
1863+ Utils .assertDocsAndSizeEqual (
1864+ resultDocs , "mongo/filter_with_sorting_and_pagination_response.json" , 3 );
18381865 }
18391866
18401867 @ ParameterizedTest
0 commit comments