示例#1
0
        /// <summary>
        /// Create a FROM clause from a set of FROM parameter bindings.
        /// </summary>
        /// <returns>The created FROM clause.</returns>
        private SqlFromClause CreateFrom()
        {
            SqlCollectionExpression input = null;

            foreach (var paramDef in this.fromParameters.GetBindings())
            {
                var parameter    = paramDef.Parameter;
                var paramBinding = paramDef.ParameterDefinition;

                var ident = new SqlIdentifier(parameter.Name);
                SqlCollectionExpression collExpr;
                if (!paramDef.IsInCollection)
                {
                    var newInput = new SqlInputPathCollection(ident, null);
                    collExpr = new SqlAliasedCollectionExpression(newInput, null);
                }
                else
                {
                    collExpr = new SqlArrayIteratorCollectionExpression(ident, paramBinding);
                }

                if (input != null)
                {
                    input = new SqlJoinCollectionExpression(input, collExpr);
                }
                else
                {
                    input = collExpr;
                }
            }
            var fromClause = new SqlFromClause(input);

            return(fromClause);
        }
        public override int Visit(SqlArrayIteratorCollectionExpression sqlArrayIteratorCollectionExpression)
        {
            int hashCode = SqlArrayIteratorCollectionExpressionHashCode;

            hashCode = CombineHashes(hashCode, sqlArrayIteratorCollectionExpression.Identifier.Accept(this));
            hashCode = CombineHashes(hashCode, sqlArrayIteratorCollectionExpression.Collection.Accept(this));
            return(hashCode);
        }
        public override SqlObject VisitArrayIteratorCollectionExpression([NotNull] sqlParser.ArrayIteratorCollectionExpressionContext context)
        {
            Contract.Requires(context != null);

            SqlCollection sqlCollection = (SqlCollection)this.Visit(context.collection());
            SqlIdentifier identifier    = SqlIdentifier.Create(context.IDENTIFIER().GetText());

            return(SqlArrayIteratorCollectionExpression.Create(identifier, sqlCollection));
        }
        /// <summary>
        /// Visits a SqlArrayIteratorCollectionExpression and transforms the documents accordingly.
        /// </summary>
        /// <param name="collectionExpression">The collection expression to visit.</param>
        /// <param name="documents">The documents to transform.</param>
        /// <returns>The transformed documents according to the collection expression.</returns>
        public override IEnumerable <CosmosElement> Visit(SqlArrayIteratorCollectionExpression collectionExpression, IEnumerable <CosmosElement> documents)
        {
            //If the query was:

            //SELECT p
            //FROM p in c.parents

            //and the document was
            //{
            //    "parents" : [{"name" : "John"}, {"name" : "Sally"}]
            //}

            //then the results would be:

            //{ "p" : {"name" : "John"} }

            //and

            //{ "p" : {"name" : "Sally"} }

            //Notice that the result set is larger than the input
            //This is because we emitted one document for each parent in the original document
            //and wrapped it in the provided alias.

            // throw away the identifer since we always have an alias
            CollectionEvaluationResult collectionEvaluationResult = collectionExpression.Collection.Accept(
                SqlInterpreterCollectionVisitor.Singleton,
                documents);

            // Wrap the collection in the alias so it's easier to bind later
            foreach (Tuple <CosmosElement, string> subDocumentAndRid in collectionEvaluationResult.SubDocumentsAndRids)
            {
                CosmosElement document = subDocumentAndRid.Item1;
                string        rid      = subDocumentAndRid.Item2;
                if (document is CosmosArray array)
                {
                    foreach (CosmosElement item in array)
                    {
                        Dictionary <string, CosmosElement> wrappedDocument = new Dictionary <string, CosmosElement>
                        {
                            [collectionExpression.Identifier.Value] = item,

                            //// Add the _rid so that we can break ties for sort later
                            ["_rid"] = CosmosString.Create(rid),
                        };
                        yield return(CosmosObject.Create(wrappedDocument));
                    }
                }
            }
        }
        public void SqlArrayScalarExpressionTest()
        {
            CosmosObject tag = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["name"] = CosmosString.Create("asdf")
            });

            CosmosObject tags = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["tags"] = CosmosArray.Create(new List <CosmosElement>()
                {
                    tag
                }),
                ["_rid"] = CosmosString.Create("AYIMAMmFOw8YAAAAAAAAAA==")
            });

            CosmosObject tagsWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["c"]    = tags,
                ["_rid"] = CosmosString.Create("AYIMAMmFOw8YAAAAAAAAAA==")
            });

            // ARRAY(SELECT VALUE t.name FROM t in c.tags)
            SqlArrayScalarExpression arrayScalarExpression = SqlArrayScalarExpression.Create(
                SqlQuery.Create(
                    SqlSelectClause.Create(
                        SqlSelectValueSpec.Create(
                            TestUtils.CreatePathExpression("t", "name"))),
                    SqlFromClause.Create(
                        SqlArrayIteratorCollectionExpression.Create(
                            SqlIdentifier.Create("t"),
                            SqlInputPathCollection.Create(
                                SqlIdentifier.Create("c"),
                                SqlStringPathExpression.Create(
                                    null,
                                    SqlStringLiteral.Create("tags"))))),
                    whereClause: null,
                    groupByClause: null,
                    orderByClause: null,
                    offsetLimitClause: null));

            CosmosArray tagNames = CosmosArray.Create(new List <CosmosElement>()
            {
                CosmosString.Create("asdf")
            });

            AssertEvaluation(tagNames, arrayScalarExpression, tagsWrapped);
        }
示例#6
0
        /// <summary>
        /// Create a FROM clause from a set of FROM parameter bindings.
        /// </summary>
        /// <returns>The created FROM clause.</returns>
        private SqlFromClause CreateFrom(SqlCollectionExpression inputCollectionExpression)
        {
            bool first = true;

            foreach (Binding paramDef in this.fromParameters.GetBindings())
            {
                // If input collection expression is provided, the first binding,
                // which is the input paramter name, should be omitted.
                if (first)
                {
                    first = false;
                    if (inputCollectionExpression != null)
                    {
                        continue;
                    }
                }

                ParameterExpression parameter    = paramDef.Parameter;
                SqlCollection       paramBinding = paramDef.ParameterDefinition;

                SqlIdentifier           identifier = SqlIdentifier.Create(parameter.Name);
                SqlCollectionExpression collExpr;
                if (!paramDef.IsInCollection)
                {
                    SqlCollection collection = paramBinding ?? SqlInputPathCollection.Create(identifier, null);
                    SqlIdentifier alias      = paramBinding == null ? null : identifier;
                    collExpr = SqlAliasedCollectionExpression.Create(collection, alias);
                }
                else
                {
                    collExpr = SqlArrayIteratorCollectionExpression.Create(identifier, paramBinding);
                }

                if (inputCollectionExpression != null)
                {
                    inputCollectionExpression = SqlJoinCollectionExpression.Create(inputCollectionExpression, collExpr);
                }
                else
                {
                    inputCollectionExpression = collExpr;
                }
            }

            SqlFromClause fromClause = SqlFromClause.Create(inputCollectionExpression);

            return(fromClause);
        }
        public override bool Visit(SqlArrayIteratorCollectionExpression first, SqlObject secondAsObject)
        {
            if (!(secondAsObject is SqlArrayIteratorCollectionExpression second))
            {
                return(false);
            }

            if (!Equals(first.Identifier, second.Identifier))
            {
                return(false);
            }

            if (!Equals(first.Collection, second.Collection))
            {
                return(false);
            }

            return(true);
        }
        public void ArrayIteratorCollectionExpressionTest()
        {
            // FROM p in f.parents
            SqlArrayIteratorCollectionExpression fromPInFDotParents = SqlArrayIteratorCollectionExpression.Create(
                SqlIdentifier.Create("p"),
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("f"),
                    SqlStringPathExpression.Create(
                        null,
                        SqlStringLiteral.Create("parents"))));

            CosmosElement andersenParent1  = CosmosElement.Parse(@"{ ""p"" : { ""firstName"": ""Thomas"" }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAA==""}");
            CosmosElement andersenParent2  = CosmosElement.Parse(@"{ ""p"" : { ""firstName"": ""Mary Kay""}, ""_rid"": ""0fomAIxnukU1AQAAAAAAAA=="" }");
            CosmosElement wakeFieldParent1 = CosmosElement.Parse(@"{ ""p"" : { ""familyName"": ""Wakefield"", ""givenName"": ""Robin"" }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAB=="" }");
            CosmosElement wakeFieldParent2 = CosmosElement.Parse(@"{ ""p"" : { ""familyName"": ""Miller"", ""givenName"": ""Ben"" }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAB=="" }");

            AssertEvaluation(new CosmosElement[]
            {
                andersenParent1,
                andersenParent2,
                wakeFieldParent1,
                wakeFieldParent2,
            }, fromPInFDotParents, DataSource);
        }
示例#9
0
 public abstract void Visit(SqlArrayIteratorCollectionExpression sqlObject);
        public void JoinCollectionExpressionTest()
        {
            // FROM f
            // JOIN c IN f.children
            // JOIN p in c.pets
            SqlAliasedCollectionExpression fromf = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("f"),
                    relativePath: null),
                alias: null);

            SqlArrayIteratorCollectionExpression cInFDotChildren = SqlArrayIteratorCollectionExpression.Create(
                SqlIdentifier.Create("c"),
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("f"),
                    SqlStringPathExpression.Create(
                        null,
                        SqlStringLiteral.Create("children"))));

            SqlJoinCollectionExpression joinFC = SqlJoinCollectionExpression.Create(
                fromf,
                cInFDotChildren);

            CosmosElement andersenChild1 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""AndersenFamily"",
                  ""lastName"": ""Andersen"",
                  ""parents"": [
                     { ""firstName"": ""Thomas"" },
                     { ""firstName"": ""Mary Kay""}
                  ],
                  ""children"": [
                     {
                         ""firstName"": ""Henriette Thaulow"",
                         ""gender"": ""female"",
                         ""grade"": 5,
                         ""pets"": [{ ""givenName"": ""Fluffy"" }]
                     }
                  ],
                  ""address"": { ""state"": ""WA"", ""county"": ""King"", ""city"": ""seattle"" },
                  ""creationDate"": 1431620472,
                  ""isRegistered"": true, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAA==""
                },
              ""c"": {
                         ""firstName"": ""Henriette Thaulow"",
                         ""gender"": ""female"",
                         ""grade"": 5,
                         ""pets"": [{ ""givenName"": ""Fluffy"" }]
                     }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAA==""
            }");

            CosmosElement wakeFieldChild1 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""WakefieldFamily"",
                  ""parents"": [
                      { ""familyName"": ""Wakefield"", ""givenName"": ""Robin"" },
                      { ""familyName"": ""Miller"", ""givenName"": ""Ben"" }
                  ],
                  ""children"": [
                      {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
                      { 
                        ""familyName"": ""Miller"", 
                         ""givenName"": ""Lisa"", 
                         ""gender"": ""female"", 
                         ""grade"": 8 }
                  ],
                  ""address"": { ""state"": ""NY"", ""county"": ""Manhattan"", ""city"": ""NY"" },
                  ""creationDate"": 1431620462,
                  ""isRegistered"": false, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
                },
              ""c"": {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
            }");

            CosmosElement wakeFieldChild2 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""WakefieldFamily"",
                  ""parents"": [
                      { ""familyName"": ""Wakefield"", ""givenName"": ""Robin"" },
                      { ""familyName"": ""Miller"", ""givenName"": ""Ben"" }
                  ],
                  ""children"": [
                      {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
                      { 
                        ""familyName"": ""Miller"", 
                         ""givenName"": ""Lisa"", 
                         ""gender"": ""female"", 
                         ""grade"": 8 }
                  ],
                  ""address"": { ""state"": ""NY"", ""county"": ""Manhattan"", ""city"": ""NY"" },
                  ""creationDate"": 1431620462,
                  ""isRegistered"": false, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
                },
              ""c"": { 
                        ""familyName"": ""Miller"", 
                         ""givenName"": ""Lisa"", 
                         ""gender"": ""female"", 
                         ""grade"": 8 }, ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
            }");

            AssertEvaluation(new CosmosElement[] { andersenChild1, wakeFieldChild1, wakeFieldChild2 }, joinFC, DataSource);

            SqlArrayIteratorCollectionExpression pInCDotPets = SqlArrayIteratorCollectionExpression.Create(
                SqlIdentifier.Create("p"),
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    SqlStringPathExpression.Create(
                        null,
                        SqlStringLiteral.Create("pets"))));

            SqlJoinCollectionExpression joinFCP = SqlJoinCollectionExpression.Create(
                SqlJoinCollectionExpression.Create(fromf, cInFDotChildren),
                pInCDotPets);

            CosmosElement andersenChild1Pet1 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""AndersenFamily"",
                  ""lastName"": ""Andersen"",
                  ""parents"": [
                     { ""firstName"": ""Thomas"" },
                     { ""firstName"": ""Mary Kay""}
                  ],
                  ""children"": [
                     {
                         ""firstName"": ""Henriette Thaulow"",
                         ""gender"": ""female"",
                         ""grade"": 5,
                         ""pets"": [{ ""givenName"": ""Fluffy"" }]
                     }
                  ],
                  ""address"": { ""state"": ""WA"", ""county"": ""King"", ""city"": ""seattle"" },
                  ""creationDate"": 1431620472,
                  ""isRegistered"": true, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAA==""
                },
              ""c"": {
                         ""firstName"": ""Henriette Thaulow"",
                         ""gender"": ""female"",
                         ""grade"": 5,
                         ""pets"": [{ ""givenName"": ""Fluffy"" }]
                     },
              ""p"": { ""givenName"": ""Fluffy"" }, 
              ""_rid"": ""0fomAIxnukU1AQAAAAAAAA==""
            }");

            CosmosElement wakeFieldChild1Pet1 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""WakefieldFamily"",
                  ""parents"": [
                      { ""familyName"": ""Wakefield"", ""givenName"": ""Robin"" },
                      { ""familyName"": ""Miller"", ""givenName"": ""Ben"" }
                  ],
                  ""children"": [
                      {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
                      { 
                        ""familyName"": ""Miller"", 
                         ""givenName"": ""Lisa"", 
                         ""gender"": ""female"", 
                         ""grade"": 8 }
                  ],
                  ""address"": { ""state"": ""NY"", ""county"": ""Manhattan"", ""city"": ""NY"" },
                  ""creationDate"": 1431620462,
                  ""isRegistered"": false, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
                },
              ""c"": {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
              ""p"": { ""givenName"": ""Goofy"" }, 
              ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
            }");

            CosmosElement wakeFieldChild1Pet2 = CosmosElement.Parse(@"
            {
              ""f"": {
                  ""id"": ""WakefieldFamily"",
                  ""parents"": [
                      { ""familyName"": ""Wakefield"", ""givenName"": ""Robin"" },
                      { ""familyName"": ""Miller"", ""givenName"": ""Ben"" }
                  ],
                  ""children"": [
                      {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
                      { 
                        ""familyName"": ""Miller"", 
                         ""givenName"": ""Lisa"", 
                         ""gender"": ""female"", 
                         ""grade"": 8 }
                  ],
                  ""address"": { ""state"": ""NY"", ""county"": ""Manhattan"", ""city"": ""NY"" },
                  ""creationDate"": 1431620462,
                  ""isRegistered"": false, 
                  ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
                },
              ""c"": {
                        ""familyName"": ""Merriam"",
                        ""givenName"": ""Jesse"",
                        ""gender"": ""female"", ""grade"": 1,
                        ""pets"": [
                            { ""givenName"": ""Goofy"" },
                            { ""givenName"": ""Shadow"" }
                        ]
                      },
              ""p"": { ""givenName"": ""Shadow"" }, 
              ""_rid"": ""0fomAIxnukU1AQAAAAAAAB==""
            }");

            AssertEvaluation(new CosmosElement[] { andersenChild1Pet1, wakeFieldChild1Pet1, wakeFieldChild1Pet2 }, joinFCP, DataSource);

            // SELECT c.id
            // FROM c
            // JOIN c.nonExistent

            SqlAliasedCollectionExpression c = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    relativePath: null),
                alias: null);

            SqlAliasedCollectionExpression cDotNonExistent = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    SqlStringPathExpression.Create(
                        null,
                        SqlStringLiteral.Create("nonExistent"))),
                alias: null);

            SqlJoinCollectionExpression joinCAndCDotNonExistent = SqlJoinCollectionExpression.Create(
                c,
                cDotNonExistent);

            AssertEvaluation(new CosmosElement[] { }, joinCAndCDotNonExistent, DataSource);
        }
 public override void Visit(SqlArrayIteratorCollectionExpression sqlArrayIteratorCollectionExpression)
 {
     sqlArrayIteratorCollectionExpression.Identifier.Accept(this);
     this.writer.Write(" IN ");
     sqlArrayIteratorCollectionExpression.Collection.Accept(this);
 }
 public override SqlObject Visit(SqlArrayIteratorCollectionExpression sqlArrayIteratorCollectionExpression)
 {
     return(SqlArrayIteratorCollectionExpression.Create(
                sqlArrayIteratorCollectionExpression.Identifier.Accept(this) as SqlIdentifier,
                sqlArrayIteratorCollectionExpression.Collection.Accept(this) as SqlCollection));
 }
 public abstract TResult Visit(SqlArrayIteratorCollectionExpression collectionExpression, TArg input);
示例#14
0
 public abstract TOutput Visit(SqlArrayIteratorCollectionExpression sqlObject, TArg input);
示例#15
0
 public abstract void Visit(SqlArrayIteratorCollectionExpression collectionExpression);
        public void SqlExistsScalarExpressionTest()
        {
            CosmosObject tag = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["name"] = CosmosString.Create("asdf")
            });

            CosmosObject tags = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["tags"] = CosmosArray.Create(new List <CosmosElement>()
                {
                    tag
                }),
                ["_rid"] = CosmosString.Create("AYIMAMmFOw8YAAAAAAAAAA==")
            });

            CosmosObject tagsWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["c"]    = tags,
                ["_rid"] = CosmosString.Create("AYIMAMmFOw8YAAAAAAAAAA==")
            });

            // EXISTS(SELECT VALUE t.name FROM t in c.tags where t.name = "asdf")
            SqlExistsScalarExpression existsScalarExpressionMatched = SqlExistsScalarExpression.Create(
                SqlQuery.Create(
                    SqlSelectClause.Create(
                        SqlSelectValueSpec.Create(
                            TestUtils.CreatePathExpression("t", "name"))),
                    SqlFromClause.Create(
                        SqlArrayIteratorCollectionExpression.Create(
                            SqlIdentifier.Create("t"),
                            SqlInputPathCollection.Create(
                                SqlIdentifier.Create("c"),
                                SqlStringPathExpression.Create(
                                    null,
                                    SqlStringLiteral.Create("tags"))))),
                    SqlWhereClause.Create(
                        SqlBinaryScalarExpression.Create(
                            SqlBinaryScalarOperatorKind.Equal,
                            TestUtils.CreatePathExpression("t", "name"),
                            SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("asdf")))),
                    groupByClause: null,
                    orderByClause: null,
                    offsetLimitClause: null));

            AssertEvaluation(CosmosBoolean.Create(true), existsScalarExpressionMatched, tagsWrapped);

            SqlExistsScalarExpression existsScalarExpressionNotMatched = SqlExistsScalarExpression.Create(
                SqlQuery.Create(
                    SqlSelectClause.Create(
                        SqlSelectValueSpec.Create(
                            TestUtils.CreatePathExpression("t", "name"))),
                    SqlFromClause.Create(
                        SqlArrayIteratorCollectionExpression.Create(
                            SqlIdentifier.Create("t"),
                            SqlInputPathCollection.Create(
                                SqlIdentifier.Create("c"),
                                SqlStringPathExpression.Create(
                                    null,
                                    SqlStringLiteral.Create("tags"))))),
                    SqlWhereClause.Create(
                        SqlBinaryScalarExpression.Create(
                            SqlBinaryScalarOperatorKind.NotEqual,
                            TestUtils.CreatePathExpression("t", "name"),
                            SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("asdf")))),
                    groupByClause: null,
                    orderByClause: null,
                    offsetLimitClause: null));

            AssertEvaluation(CosmosBoolean.Create(false), existsScalarExpressionNotMatched, tagsWrapped);
        }
        public void AliasedCollectionExpressionTest()
        {
            // FROM c
            SqlAliasedCollectionExpression fromC = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    relativePath: null),
                alias: null);

            CosmosObject andersenWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["c"]    = AndersenFamily,
                ["_rid"] = AndersenFamily["_rid"]
            });

            CosmosObject wakeFieldWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["c"]    = WakefieldFamily,
                ["_rid"] = WakefieldFamily["_rid"]
            });

            AssertEvaluation(new CosmosElement[] { andersenWrapped, wakeFieldWrapped }, fromC, DataSource);

            // FROM c.id
            SqlAliasedCollectionExpression fromCDotId = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    SqlIdentifierPathExpression.Create(
                        null,
                        SqlIdentifier.Create("id"))),
                alias: null);

            CosmosObject andersenId = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["id"]   = CosmosString.Create("AndersenFamily"),
                ["_rid"] = AndersenFamily["_rid"]
            });

            CosmosObject wakefieldId = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["id"]   = CosmosString.Create("WakefieldFamily"),
                ["_rid"] = WakefieldFamily["_rid"]
            });

            AssertEvaluation(new CosmosElement[] { andersenId, wakefieldId }, fromCDotId, DataSource);

            // FROM c.id AS familyId
            SqlAliasedCollectionExpression fromCDotIdAsFamilyId = SqlAliasedCollectionExpression.Create(
                SqlInputPathCollection.Create(
                    SqlIdentifier.Create("c"),
                    SqlIdentifierPathExpression.Create(
                        null,
                        SqlIdentifier.Create("id"))),
                SqlIdentifier.Create("familyId"));

            CosmosObject andersenIdAsFamilyId = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["familyId"] = CosmosString.Create("AndersenFamily"),
                ["_rid"]     = AndersenFamily["_rid"]
            });

            CosmosObject wakefieldIdAsFamilyId = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["familyId"] = CosmosString.Create("WakefieldFamily"),
                ["_rid"]     = WakefieldFamily["_rid"]
            });

            AssertEvaluation(new CosmosElement[] { andersenIdAsFamilyId, wakefieldIdAsFamilyId }, fromCDotIdAsFamilyId, DataSource);

            // FROM (SELECT VALUE child["grade"] FROM child IN c.children) grade
            SqlAliasedCollectionExpression fromSubqueryGrades = SqlAliasedCollectionExpression.Create(
                SqlSubqueryCollection.Create(
                    SqlQuery.Create(
                        SqlSelectClause.Create(
                            SqlSelectValueSpec.Create(
                                TestUtils.CreatePathExpression("child", "grade"))),
                        SqlFromClause.Create(
                            SqlArrayIteratorCollectionExpression.Create(
                                SqlIdentifier.Create("child"),
                                SqlInputPathCollection.Create(
                                    SqlIdentifier.Create("c"),
                                    SqlStringPathExpression.Create(
                                        null,
                                        SqlStringLiteral.Create("children"))))),
                        whereClause: null,
                        groupByClause: null,
                        orderByClause: null,
                        offsetLimitClause: null)),
                SqlIdentifier.Create("grade"));

            CosmosObject henrietteWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["grade"] = CosmosNumber64.Create(5),
                ["_rid"]  = AndersenFamily["_rid"]
            });

            CosmosObject jesseWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["grade"] = CosmosNumber64.Create(1),
                ["_rid"]  = WakefieldFamily["_rid"]
            });

            CosmosObject lisaWrapped = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["grade"] = CosmosNumber64.Create(8),
                ["_rid"]  = WakefieldFamily["_rid"]
            });

            AssertEvaluation(
                new CosmosElement[]
            {
                henrietteWrapped,
                jesseWrapped,
                lisaWrapped
            },
                fromSubqueryGrades,
                DataSource);
        }