Skip to content

Commit

Permalink
Added a new cross-join unit test taken from #2035
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Feb 8, 2018
1 parent da87ce4 commit cbd993f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
44 changes: 42 additions & 2 deletions Objective-C/Tests/QueryTest.m
Expand Up @@ -538,6 +538,46 @@ - (void) testCrossJoin {
}


- (void) testCrossJoin2 {
[self loadJSONResource:@"join"];
CBLQueryExpression* FIRSTNAME = [CBLQueryExpression property: @"firstname" from:@"employeeDS"];
CBLQueryExpression* LASTNAME = [CBLQueryExpression property: @"lastname" from:@"employeeDS"];
CBLQueryExpression* DEPTNAME = [CBLQueryExpression property: @"name" from:@"departmentDS"];

NSArray* results = @[[CBLQuerySelectResult expression: FIRSTNAME],
[CBLQuerySelectResult expression: LASTNAME],
[CBLQuerySelectResult expression: DEPTNAME]];


[CBLQuerySelectResult expression: [CBLQueryMeta idFrom: @"employeeDS"]];


CBLQueryExpression* expr1 = [[CBLQueryExpression property:@"type" from:@"employeeDS"] equalTo: [CBLQueryExpression string:@"employee"]];
CBLQueryExpression* expr2 = [[CBLQueryExpression property:@"type" from:@"departmentDS"] equalTo :[CBLQueryExpression string:@"department"]];

CBLQueryJoin* join = [CBLQueryJoin crossJoin:[CBLQueryDataSource database: self.db as: @"departmentDS"]];
CBLQuery* q = [CBLQueryBuilder select: results
from: [CBLQueryDataSource database: self.db as: @"employeeDS"]
join: @[join]
where:[expr1 andExpression:expr2]];


Assert(q);
NSError* error;

NSLog(@"%@",[q explain:nil]);

CBLQueryResultSet* rs = [q execute: &error];

NSUInteger i = 0;
NSArray* res = [rs allResults];
for (CBLQueryResult* r in res) {
NSLog(@" %@",[r toDictionary]);

i++;
}

}
- (void) testGroupBy {
NSArray* expectedStates = @[@"AL", @"CA", @"CO", @"FL", @"IA"];
NSArray* expectedCounts = @[@1, @6, @1, @1, @3];
Expand Down Expand Up @@ -1637,8 +1677,8 @@ - (void) testForumJoin {
CBLQueryJoin* join = [CBLQueryJoin join: [CBLQueryDataSource database: self.db as: @"itemDS"]
on: on];
CBLQuery* q = [CBLQueryBuilder select: @[ITEM_DOC_ID, CATEGORY_DOC_ID]
from: [CBLQueryDataSource database: self.db as: @"categoryDS"]
join: @[join]];
from: [CBLQueryDataSource database: self.db as: @"categoryDS"]
join: @[join]];
Assert(q);
NSError* error;

Expand Down
38 changes: 38 additions & 0 deletions Objective-C/Tests/Support/join.json
@@ -0,0 +1,38 @@
{ "type":"employee", "firstname":"John","lastname":"Smith","department":"1000","location":"101"}
{ "type":"employee", "firstname":"John","lastname":"Anderson","department":"2000","location":"101"}
{ "type":"employee","firstname":"Jane","lastname":"Doe","department":"1000","location":"101"}
{ "type":"employee","firstname":"Carman","lastname":"Hopscotch","department":"4000","location":"101"}
{ "type":"employee", "firstname":"Alex","lastname":"Pepe","department":"4000","location":"101"}
{ "type":"employee", "firstname":"Priya","lastname":"Rajagopal","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Donald","lastname":"Scotch","department":"2000","location":"102"}
{ "type":"employee", "firstname":"Alice","lastname":"Matt","department":"3000","location":"101"}
{ "type":"employee", "firstname":"Roslyn","lastname":"Aerni","department":"3000","location":"101"}
{ "type":"employee", "firstname":"Berneice","lastname":"Cefalu","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Patricia","lastname":"Shoji","department":"2000","location":"101"}
{ "type":"employee", "firstname":"Kenton","lastname":"Bagent","department":"3000","location":"101"}
{ "type":"employee", "firstname":"Elyse","lastname":"Leis","department":"4000","location":"101"}
{ "type":"employee", "firstname":"Maryjo","lastname":"Tariq","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Margaretta","lastname":"Ogwynn","department":"2000","location":"102"}
{ "type":"employee", "firstname":"Glory","lastname":"Mollenkopf","department":"2000","location":"102"}
{ "type":"employee", "firstname":"Janette","lastname":"Nicholes","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Brandon","lastname":"Laidlaw","department":"3000","location":"102"}
{ "type":"employee", "firstname":"Arturo","lastname":"Kinatyan","department":"3000","location":"101"}
{ "type":"employee", "firstname":"Eddie","lastname":"Colangelo","department":"3000","location":"102"}
{ "type":"employee", "firstname":"Margrett","lastname":"Heartz","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Verna","lastname":"Wigfield","department":"4000","location":"102"}
{ "type":"employee", "firstname":"Jarrod","lastname":"Litwiler","department":"4000","location":"101"}
{ "type":"employee", "firstname":"Kelley","lastname":"Wala","department":"1000","location":"101"}
{ "type":"employee", "firstname":"Shaunta","lastname":"Geringer","department":"1000","location":"102"}
{ "type":"employee", "firstname":"Ira","lastname":"Rechel","department":"1000","location":"102"}
{ "type":"employee", "firstname":"Rickie","lastname":"Bakaler","department":"2000","location":"102"}
{ "type":"employee", "firstname":"Georgetta","lastname":"Kolding","department":"2000","location":"101"}
{ "type":"employee", "firstname":"Concetta","lastname":"Rotondo","department":"1000","location":"102"}
{ "type":"employee", "firstname":"Chas","lastname":"Cefalu","department":"6000","location":"101"}
{ "type":"department", "name": "Engineering","code": "1000","head":{"firstname":"Ira","lastname":"Rechel"}}
{ "type":"department", "name": "Product Management","code": "2000","head":{"firstname":"Patricia","lastname":"Shoji"}}
{ "type":"department", "name": "Marketing","code": "3000","head":{"firstname":"Arturo","lastname":"Kinatyan"}}
{ "type":"department", "name": "Sales","code": "4000","head":{"firstname":"Alex","lastname":"Pepe"}}
{ "type":"department", "name": "HR","code": "5000"}
{ "type":"department", "name": "Quality","code": "7000"}
{ "type":"location", "name":"HQ","address": "1123 6th St. Melbourne, FL 32904 ","code": "101"}
{ "type":"location", "name": "Central HQ","address":"44 Shirley Ave. West Chicago, IL 60185","code": "102"}

0 comments on commit cbd993f

Please sign in to comment.