Esempio n. 1
0
        public override CosmosElement Visit(SqlSubqueryScalarExpression scalarExpression, CosmosElement document)
        {
            // Only run on the current document since the subquery is always correlated.
            IEnumerable <CosmosElement> subqueryResults = SqlInterpreter.ExecuteQuery(
                new CosmosElement[] { document },
                scalarExpression.Query);

            CosmosElement result;
            int           cardinality = subqueryResults.Count();

            if (cardinality > 1)
            {
                throw new ArgumentException("The cardinality of a subquery can not exceed 1.");
            }
            else if (cardinality == 1)
            {
                result = subqueryResults.First();
            }
            else
            {
                // cardinality = 0
                result = Undefined;
            }

            return(result);
        }
Esempio n. 2
0
        public override CosmosElement Visit(SqlExistsScalarExpression scalarExpression, CosmosElement document)
        {
            // Only run on the current document since the subquery is always correlated.
            IEnumerable <CosmosElement> subqueryResults = SqlInterpreter.ExecuteQuery(
                new CosmosElement[] { document },
                scalarExpression.Subquery);

            return(CosmosBoolean.Create(subqueryResults.Any()));
        }
Esempio n. 3
0
        public override CosmosElement Visit(
            SqlArrayScalarExpression scalarExpression,
            CosmosElement document)
        {
            // Only run on the current document since the subquery is always correlated.
            IEnumerable <CosmosElement> subqueryResults = SqlInterpreter.ExecuteQuery(
                new CosmosElement[] { document },
                scalarExpression.SqlQuery);
            List <CosmosElement> arrayScalarResult = new List <CosmosElement>();

            foreach (CosmosElement subQueryResult in subqueryResults)
            {
                arrayScalarResult.Add(subQueryResult);
            }

            return(CosmosArray.Create(subqueryResults));
        }
            public override CollectionEvaluationResult Visit(SqlSubqueryCollection collection, IEnumerable <CosmosElement> input)
            {
                List <Tuple <CosmosElement, string> > subDocumentsAndRids = new List <Tuple <CosmosElement, string> >();

                foreach (CosmosObject document in input)
                {
                    string rid = ((CosmosString)document["_rid"]).Value;
                    IEnumerable <CosmosElement> subqueryResults = SqlInterpreter.ExecuteQuery(
                        new CosmosElement[] { document },
                        collection.Query);
                    foreach (CosmosElement subqueryResult in subqueryResults)
                    {
                        subDocumentsAndRids.Add(new Tuple <CosmosElement, string>(subqueryResult, rid));
                    }
                }

                return(new CollectionEvaluationResult(subDocumentsAndRids, null));
            }