コード例 #1
0
        public override int Visit(SqlStringLiteral sqlStringLiteral)
        {
            int hashCode = SqlStringLiteralHashCode;

            hashCode = CombineHashes(hashCode, SqlObjectHasher.Djb2(sqlStringLiteral.Value));
            return(hashCode);
        }
コード例 #2
0
 public override SqlObject Visit(SqlStringLiteral sqlStringLiteral)
 {
     return(SqlStringLiteral.Create(
                this.GetObfuscatedString(
                    sqlStringLiteral.Value,
                    "str",
                    ref this.stringSequenceNumber)));
 }
コード例 #3
0
        public override SqlObject VisitStringPathExpression([NotNull] sqlParser.StringPathExpressionContext context)
        {
            Contract.Requires(context != null);

            SqlPathExpression pathExpression = (SqlPathExpression)this.Visit(context.path_expression());
            SqlStringLiteral  stringIndex    = SqlStringLiteral.Create(CstToAstVisitor.GetStringValueFromNode(context.STRING_LITERAL()));

            return(SqlStringPathExpression.Create(pathExpression, stringIndex));
        }
コード例 #4
0
 public void UPPER()
 {
     // UPPER("\u00B5")
     // MICRO SIGN does not have an upper casing
     AssertEvaluation(
         expected: CosmosString.Create("\u00B5"),
         sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
             SqlFunctionCallScalarExpression.Identifiers.Upper,
             SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("\u00B5"))));
 }
コード例 #5
0
 public void CONTAINS()
 {
     // CONTAINS("hello", "")
     // -> all strings contain empty string.
     AssertEvaluation(
         expected: CosmosBoolean.Create(true),
         sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
             SqlFunctionCallScalarExpression.Identifiers.Contains,
             SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Hello")),
             SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(string.Empty))));
 }
コード例 #6
0
 public void REPLACE()
 {
     // REPLACE("Hello", "", "World")
     // replacing the empty string within a string is undefined behavior
     // SQL Server just returns the original string and that's the behavior the backend matches
     AssertEvaluation(
         expected: Undefined,
         sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
             SqlFunctionCallScalarExpression.Identifiers.Replace,
             hello,
             SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(string.Empty)),
             world));
 }
コード例 #7
0
        public void SqlObjectCreateScalarExpressionTest()
        {
            CosmosObject expected = CosmosObject.Create(new Dictionary <string, CosmosElement>
            {
                ["name"] = CosmosString.Create("John")
            });

            SqlObjectCreateScalarExpression john = SqlObjectCreateScalarExpression.Create(
                SqlObjectProperty.Create(SqlPropertyName.Create("name"),
                                         SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("John"))));

            AssertEvaluation(expected, john);
        }
コード例 #8
0
        public override SqlObject VisitLike_scalar_expression([NotNull] sqlParser.Like_scalar_expressionContext context)
        {
            Contract.Requires(context != null);

            SqlScalarExpression expression  = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[0]);
            SqlScalarExpression pattern     = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[1]);
            bool             not            = context.K_NOT() != null;
            SqlStringLiteral escapeSequence = (context.escape_expression() != null)
                                                ? (SqlStringLiteral)this.Visit(context.escape_expression())
                                                : null;

            return(SqlLikeScalarExpression.Create(expression, pattern, not, escapeSequence));
        }
コード例 #9
0
        public override bool Visit(SqlStringLiteral first, SqlObject secondAsObject)
        {
            if (!(secondAsObject is SqlStringLiteral second))
            {
                return(false);
            }

            if (first.Value != second.Value)
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public override SqlObject VisitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.ChildCount == 1);
            Contract.Requires(context.children[0].ChildCount == 1);

            TerminalNodeImpl terminalNode = (TerminalNodeImpl)(context.children[0].GetChild(0));

            SqlLiteralScalarExpression sqlLiteralScalarExpression;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(value));
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(number64));
                break;

            case sqlParser.K_TRUE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(true));
                break;

            case sqlParser.K_FALSE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(false));
                break;

            case sqlParser.K_NULL:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNullLiteral.Create());
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteralScalarExpression);
        }
コード例 #12
0
        private static SqlScalarExpression GenerateMemberIndexerScalarExpressionFromPath(Path path)
        {
            if (path.Length < 1)
            {
                throw new ArgumentException($"{nameof(path)} is too short.");
            }

            if (!(path.First() is StringPathToken rootToken))
            {
                throw new ArgumentException($"{nameof(path)} did not start with a string.");
            }

            SqlScalarExpression rootExpression = SqlPropertyRefScalarExpression.Create(
                member: null,
                identifier: SqlIdentifier.Create(rootToken.PropertyName));

            foreach (PathToken token in path.Skip(1))
            {
                SqlLiteralScalarExpression memberIndexer;
                switch (token)
                {
                case StringPathToken stringPathToken:
                    memberIndexer = SqlLiteralScalarExpression.Create(
                        SqlStringLiteral.Create(
                            stringPathToken.PropertyName));
                    break;

                case IntegerPathToken integerPathToken:
                    memberIndexer = SqlLiteralScalarExpression.Create(
                        SqlNumberLiteral.Create(
                            integerPathToken.Index));
                    break;

                default:
                    throw new ArgumentException($"Unknown token type: {token.GetType()}; {token}");
                }

                rootExpression = SqlMemberIndexerScalarExpression.Create(rootExpression, memberIndexer);
            }

            return(rootExpression);
        }
コード例 #13
0
        public override SqlObject VisitLiteral([NotNull] sqlParser.LiteralContext context)
        {
            TerminalNodeImpl terminalNode = (TerminalNodeImpl)context.children[0];

            SqlLiteral sqlLiteral;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteral = SqlStringLiteral.Create(value);
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteral = SqlNumberLiteral.Create(number64);
                break;

            case sqlParser.K_TRUE:
                sqlLiteral = SqlBooleanLiteral.Create(true);
                break;

            case sqlParser.K_FALSE:
                sqlLiteral = SqlBooleanLiteral.Create(false);
                break;

            case sqlParser.K_NULL:
                sqlLiteral = SqlNullLiteral.Create();
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteral = SqlUndefinedLiteral.Create();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteral);
        }
コード例 #14
0
        /// <summary>
        /// Constructs <see cref="SqlScalarExpression"/> from a geometry <see cref="JToken"/>.
        /// </summary>
        /// <param name="jToken">Json token.</param>
        /// <returns>Instance of <see cref="SqlScalarExpression"/>.</returns>
        private static SqlScalarExpression FromJToken(JToken jToken)
        {
            switch (jToken.Type)
            {
            case JTokenType.Array:
                return(new SqlArrayCreateScalarExpression(jToken.Select(FromJToken).ToArray()));

            case JTokenType.Boolean:
                SqlBooleanLiteral sqlBooleanLiteral = new SqlBooleanLiteral(jToken.Value <bool>());
                return(new SqlLiteralScalarExpression(sqlBooleanLiteral));

            case JTokenType.Null:
                return(new SqlLiteralScalarExpression(new SqlNullLiteral()));

            case JTokenType.String:
                SqlStringLiteral sqlStringLiteral = new SqlStringLiteral(jToken.Value <string>());
                return(new SqlLiteralScalarExpression(sqlStringLiteral));

            case JTokenType.Object:

                var properties =
                    ((JObject)jToken).Properties()
                    .Select(
                        p =>
                        new SqlObjectProperty(
                            new SqlPropertyName(p.Name),
                            FromJToken(p.Value)))
                    .ToArray();

                return(new SqlObjectCreateScalarExpression(properties));

            case JTokenType.Float:
            case JTokenType.Integer:
                SqlNumberLiteral sqlNumberLiteral = new SqlNumberLiteral(jToken.Value <double>());
                return(new SqlLiteralScalarExpression(sqlNumberLiteral));

            default:
                throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.UnexpectedTokenType, jToken.Type));
            }
        }
コード例 #15
0
        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);
        }
コード例 #16
0
 public override void Visit(SqlStringLiteral sqlStringLiteral)
 {
     this.writer.Write("\"");
     SqlObjectTextSerializer.WriteEscapedString(this.writer.GetStringBuilder(), sqlStringLiteral.Value.AsSpan());
     this.writer.Write("\"");
 }
コード例 #17
0
 public override CosmosElement Visit(SqlStringLiteral literal) => CosmosString.Create(literal.Value);
コード例 #18
0
        public void ARRAY_CONTAINS()
        {
            // ARRAY_CONTAINS(["apples", "strawberries", "bananas"], "apples")
            AssertEvaluation(
                expected: CosmosBoolean.Create(new string[] { "apples", "strawberries", "bananas" }.Contains("apples")),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray("apples", "strawberries", "bananas")),
                    SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("apples"))));

            // ARRAY_CONTAINS(["apples", "strawberries", "bananas"], "mangoes")
            AssertEvaluation(
                expected: CosmosBoolean.Create(new string[] { "apples", "strawberries", "bananas" }.Contains("mangoes")),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray("apples", "strawberries", "bananas")),
                    SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("mangoes"))));

            // ARRAY_CONTAINS([{"name": "apples", "fresh": true}, {"name": "strawberries", "fresh": true}], {"name": "apples"}, true)
            AssertEvaluation(
                expected: CosmosBoolean.Create(true),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray(
                                                            JObject.FromObject(new { name = "apples", fresh = true }),
                                                            JObject.FromObject(new { name = "strawberries", fresh = true }))),
                    JTokenToSqlScalarExpression.Convert(JObject.FromObject(new { name = "apples" })),
                    trueBoolean));

            // ARRAY_CONTAINS([{"name": "apples", "fresh": true}, {"name": "strawberries", "fresh": true}], {"name": "apples"}, undefined)
            AssertEvaluation(
                expected: CosmosBoolean.Create(false),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray(
                                                            JObject.FromObject(new { name = "apples", fresh = true }),
                                                            JObject.FromObject(new { name = "strawberries", fresh = true }))),
                    JTokenToSqlScalarExpression.Convert(JObject.FromObject(new { name = "apples" })),
                    SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create())));

            // ARRAY_CONTAINS([{"name": "apples", "fresh": true}, {"name": "strawberries", "fresh": true}], {"name": "apples"})
            AssertEvaluation(
                expected: CosmosBoolean.Create(false),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray(
                                                            JObject.FromObject(new { name = "apples", fresh = true }),
                                                            JObject.FromObject(new { name = "strawberries", fresh = true }))),
                    JTokenToSqlScalarExpression.Convert(JObject.FromObject(new { name = "apples" }))));

            // ARRAY_CONTAINS([{"name": "apples", "fresh": true}, {"name": "strawberries", "fresh": true}], {"name": "mangoes"}, true)
            AssertEvaluation(
                expected: CosmosBoolean.Create(false),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    JTokenToSqlScalarExpression.Convert(new JArray(
                                                            JObject.FromObject(new { name = "apples", fresh = true }),
                                                            JObject.FromObject(new { name = "strawberries", fresh = true }))),
                    JTokenToSqlScalarExpression.Convert(JObject.FromObject(new { name = "mangoes" })),
                    trueBoolean));

            // ARRAY_CONTAINS([SQUARE(2), POWER(2, 2)] 2)
            AssertEvaluation(
                expected: CosmosBoolean.Create(new double[] { 2 * 2, Math.Pow(2, 2) }.Contains(2)),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.ArrayContains,
                    SqlArrayCreateScalarExpression.Create(
                        SqlFunctionCallScalarExpression.CreateBuiltin(
                            SqlFunctionCallScalarExpression.Identifiers.Square,
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2))),
                        SqlFunctionCallScalarExpression.CreateBuiltin(
                            SqlFunctionCallScalarExpression.Identifiers.Power,
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)),
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)))),
                    JTokenToSqlScalarExpression.Convert(2)));
        }
コード例 #19
0
 public virtual void Visiting(SqlStringLiteral stringLiteral)
 {
     sqlBuilder.Append(EncapsulateString(FormatString(stringLiteral.StringValue)));
 }
コード例 #20
0
 public abstract void Visit(SqlStringLiteral literal);
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
 public abstract TResult Visit(SqlStringLiteral sqlObject);
コード例 #24
0
 public abstract TOutput Visit(SqlStringLiteral sqlObject, TArg input);
コード例 #25
0
        public void SqlLiteralScalarExpressionTest()
        {
            SqlLiteralScalarExpression numberLiteral = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1));

            AssertEvaluation(CosmosNumber64.Create(1), numberLiteral);

            SqlLiteralScalarExpression stringLiteral = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Hello"));

            AssertEvaluation(CosmosString.Create("Hello"), stringLiteral);

            SqlLiteralScalarExpression trueLiteral = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.True);

            AssertEvaluation(CosmosBoolean.Create(true), trueLiteral);

            SqlLiteralScalarExpression falseLiteral = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.False);

            AssertEvaluation(CosmosBoolean.Create(false), falseLiteral);

            SqlLiteralScalarExpression nullLiteral = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);

            AssertEvaluation(CosmosNull.Create(), nullLiteral);

            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());

            AssertEvaluation(Undefined, undefinedLiteral);
        }
コード例 #26
0
 public virtual void Visited(SqlStringLiteral stringLiteral)
 {
 }
コード例 #27
0
        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);
        }
コード例 #28
0
        public void SqlBinaryScalarExpressionTest()
        {
            SqlLiteralScalarExpression five             = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression three            = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));
            SqlLiteralScalarExpression hello            = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Hello"));
            SqlLiteralScalarExpression world            = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("World"));
            SqlLiteralScalarExpression trueBoolean      = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.True);
            SqlLiteralScalarExpression falseBoolean     = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.False);
            SqlLiteralScalarExpression nullLiteral      = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);
            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());

            SqlArrayCreateScalarExpression  arrayCreateScalarExpresion1  = SqlArrayCreateScalarExpression.Create();
            SqlArrayCreateScalarExpression  arrayCreateScalarExpresion2  = SqlArrayCreateScalarExpression.Create(five);
            SqlObjectCreateScalarExpression objectCreateScalarExpression = SqlObjectCreateScalarExpression.Create();

            SqlBinaryScalarExpression fivePlusThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Add, five, three);

            AssertEvaluation(CosmosNumber64.Create(3 + 5), fivePlusThree);

            SqlBinaryScalarExpression trueAndFalse = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, trueBoolean, falseBoolean);

            AssertEvaluation(CosmosBoolean.Create(true && false), trueAndFalse);

            SqlBinaryScalarExpression falseAndUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, falseBoolean, undefinedLiteral);

            AssertEvaluation(CosmosBoolean.Create(false), falseAndUndefined);

            SqlBinaryScalarExpression trueAndUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, trueBoolean, undefinedLiteral);

            AssertEvaluation(Undefined, trueAndUndefined);

            try
            {
                SqlBinaryScalarExpression threeBitwiseAndFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseAnd, three, five);
                AssertEvaluation(CosmosNumber64.Create(1), threeBitwiseAndFive);
            }
            catch (Exception)
            {
            }

            try
            {
                SqlBinaryScalarExpression threeBitwiseOrFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseOr, three, five);
                AssertEvaluation(CosmosNumber64.Create(7), threeBitwiseOrFive);
            }
            catch (Exception)
            {
            }

            try
            {
                SqlBinaryScalarExpression threeBitwiseXorFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseXor, three, five);
                AssertEvaluation(CosmosNumber64.Create(7), threeBitwiseXorFive);
            }
            catch (Exception)
            {
            }

            SqlBinaryScalarExpression nullCoalesceFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Coalesce, nullLiteral, five);

            AssertEvaluation(CosmosNull.Create(), nullCoalesceFive);

            SqlBinaryScalarExpression fiveDivideFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Divide, five, five);

            AssertEvaluation(CosmosNumber64.Create(5 / 5), fiveDivideFive);

            SqlBinaryScalarExpression fiveEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Equal, five, five);

            AssertEvaluation(CosmosBoolean.Create(5 == 5), fiveEqualFive);

            SqlBinaryScalarExpression threeEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Equal, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 == 5), threeEqualFive);

            AssertEvaluation(
                CosmosBoolean.Create(true),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    arrayCreateScalarExpresion1));

            AssertEvaluation(
                CosmosBoolean.Create(false),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    arrayCreateScalarExpresion2));

            AssertEvaluation(
                CosmosBoolean.Create(false),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    objectCreateScalarExpression));

            SqlBinaryScalarExpression threeGreaterThanFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThan, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 > 5), threeGreaterThanFive);

            SqlBinaryScalarExpression fiveGreaterThanThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThan, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 > 3), fiveGreaterThanThree);

            SqlBinaryScalarExpression threeGreaterThanOrEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThanOrEqual, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 >= 5), threeGreaterThanOrEqualFive);

            SqlBinaryScalarExpression fiveGreaterThanOrEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThanOrEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 >= 3), fiveGreaterThanOrEqualThree);

            SqlBinaryScalarExpression threeLessThanFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThan, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 < 5), threeLessThanFive);

            SqlBinaryScalarExpression fiveLessThanThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThan, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 < 3), fiveLessThanThree);

            SqlBinaryScalarExpression threeLessThanOrEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThanOrEqual, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 <= 5), threeLessThanOrEqualFive);

            SqlBinaryScalarExpression fiveLessThanOrEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThanOrEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 <= 3), fiveLessThanOrEqualThree);

            SqlBinaryScalarExpression fiveModThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Modulo, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 % 3), fiveModThree);

            SqlBinaryScalarExpression fiveMultiplyThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Multiply, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 * 3), fiveMultiplyThree);

            SqlBinaryScalarExpression fiveNotEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.NotEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 != 3), fiveNotEqualThree);

            SqlBinaryScalarExpression fiveNotEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.NotEqual, five, five);

            AssertEvaluation(CosmosBoolean.Create(5 != 5), fiveNotEqualFive);

            SqlBinaryScalarExpression trueOrFalse = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, trueBoolean, falseBoolean);

            AssertEvaluation(CosmosBoolean.Create(true || false), trueOrFalse);

            SqlBinaryScalarExpression trueOrUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, trueBoolean, undefinedLiteral);

            AssertEvaluation(CosmosBoolean.Create(true), trueOrUndefined);

            SqlBinaryScalarExpression falseOrUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, falseBoolean, undefinedLiteral);

            AssertEvaluation(Undefined, falseOrUndefined);

            SqlBinaryScalarExpression helloConcatWorld = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.StringConcat, hello, world);

            AssertEvaluation(CosmosString.Create("Hello" + "World"), helloConcatWorld);

            SqlBinaryScalarExpression fiveSubtract3 = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Subtract, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 - 3), fiveSubtract3);
        }
コード例 #29
0
 public abstract void Visit(SqlStringLiteral sqlObject);
コード例 #30
0
        /// <summary>
        /// Converts a JToken to a semantically equivalent SqlScalarExpression.
        /// </summary>
        /// <param name="token">The JToken to convert.</param>
        /// <returns>The semantically equivalent SqlScalarExpression.</returns>
        public static SqlScalarExpression Convert(JToken token)
        {
            if (token == null)
            {
                return(Undefined);
            }

            switch (token.Type)
            {
            case JTokenType.Array:
            {
                List <SqlScalarExpression> items = new List <SqlScalarExpression>();
                foreach (JToken element in token)
                {
                    items.Add(JTokenToSqlScalarExpression.Convert(element));
                }

                return(SqlArrayCreateScalarExpression.Create(items.ToArray()));
            }

            case JTokenType.Boolean:
            {
                SqlBooleanLiteral literal = SqlBooleanLiteral.Create(token.ToObject <bool>());
                return(SqlLiteralScalarExpression.Create(literal));
            }

            case JTokenType.Null:
            {
                SqlNullLiteral literal = SqlNullLiteral.Singleton;
                return(SqlLiteralScalarExpression.Create(literal));
            }

            case JTokenType.Integer:
            case JTokenType.Float:
            {
                SqlNumberLiteral literal = SqlNumberLiteral.Create(token.ToObject <double>());
                return(SqlLiteralScalarExpression.Create(literal));
            }

            case JTokenType.Object:
            {
                List <SqlObjectProperty> properties = new List <SqlObjectProperty>();

                foreach (JProperty prop in (JToken)token)
                {
                    SqlPropertyName     name       = SqlPropertyName.Create(prop.Name);
                    JToken              value      = prop.Value;
                    SqlScalarExpression expression = JTokenToSqlScalarExpression.Convert(value);
                    SqlObjectProperty   property   = SqlObjectProperty.Create(name, expression);
                    properties.Add(property);
                }

                return(SqlObjectCreateScalarExpression.Create(properties.ToArray()));
            }

            case JTokenType.String:
            {
                SqlStringLiteral literal = SqlStringLiteral.Create(token.ToObject <string>());
                return(SqlLiteralScalarExpression.Create(literal));
            }

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, "Unsupported JsonType {0}", token.Type));
            }
        }