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);
        }
        public void SqlUnaryScalarExpressionTest()
        {
            SqlLiteralScalarExpression five        = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression trueBoolean = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.True);

            {
                SqlUnaryScalarExpression bitwiseNot = SqlUnaryScalarExpression.Create(SqlUnaryScalarOperatorKind.BitwiseNot, five);
                AssertEvaluation(CosmosNumber64.Create(~5), bitwiseNot);
            }

            {
                SqlLiteralScalarExpression largeNumber = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(130679749712577953));
                SqlUnaryScalarExpression   bitwiseNot  = SqlUnaryScalarExpression.Create(SqlUnaryScalarOperatorKind.BitwiseNot, largeNumber);
                AssertEvaluation(CosmosNumber64.Create(-1022657953), bitwiseNot);
            }

            {
                SqlUnaryScalarExpression not = SqlUnaryScalarExpression.Create(SqlUnaryScalarOperatorKind.Not, trueBoolean);
                AssertEvaluation(CosmosBoolean.Create(!true), not);
            }

            {
                SqlUnaryScalarExpression minus = SqlUnaryScalarExpression.Create(SqlUnaryScalarOperatorKind.Minus, five);
                AssertEvaluation(CosmosNumber64.Create(-5), minus);
            }

            {
                SqlUnaryScalarExpression plus = SqlUnaryScalarExpression.Create(SqlUnaryScalarOperatorKind.Plus, five);
                AssertEvaluation(CosmosNumber64.Create(5), plus);
            }
        }
        public void SqlBetweenScalarExpressionTest()
        {
            SqlBetweenScalarExpression threeBetweenFourAndFive = SqlBetweenScalarExpression.Create(
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(4)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5)),
                not: false);

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

            SqlBetweenScalarExpression threeNotBetweenFourAndFive = SqlBetweenScalarExpression.Create(
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(4)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5)),
                not: true);

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

            SqlBetweenScalarExpression trueBetweenTrueAndTrueNested = SqlBetweenScalarExpression.Create(
                SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(true)),
                threeBetweenFourAndFive,
                threeBetweenFourAndFive,
                not: false);

            AssertEvaluation(CosmosBoolean.Create(true), trueBetweenTrueAndTrueNested);
        }
        public void SqlArrayCreateScalarExpressionTest()
        {
            SqlArrayCreateScalarExpression inner = SqlArrayCreateScalarExpression.Create(
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)),
                SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)));

            AssertEvaluation(
                CosmosArray.Create(
                    new List <CosmosElement>()
            {
                CosmosNumber64.Create(1),
                CosmosNumber64.Create(2),
                CosmosNumber64.Create(3),
            }),
                inner);

            SqlArrayCreateScalarExpression outer = SqlArrayCreateScalarExpression.Create(inner);

            AssertEvaluation(
                CosmosArray.Create(
                    new List <CosmosElement>()
            {
                CosmosArray.Create(
                    new List <CosmosElement>()
                {
                    CosmosNumber64.Create(1),
                    CosmosNumber64.Create(2),
                    CosmosNumber64.Create(3),
                })
            }),
                outer);
        }
        public override int Visit(SqlLiteralScalarExpression sqlLiteralScalarExpression)
        {
            int hashCode = SqlLiteralScalarExpressionHashCode;

            hashCode = CombineHashes(hashCode, sqlLiteralScalarExpression.Literal.Accept(this));
            return(hashCode);
        }
Example #6
0
        public void LEFT()
        {
            // LEFT("Hello", -3)
            AssertEvaluation(
                expected: CosmosString.Empty,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Left,
                    hello,
                    negativeThree));

            // LEFT("Hello", 0)
            AssertEvaluation(
                expected: CosmosString.Empty,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Left,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(0))));

            // LEFT("Hello", 2)
            AssertEvaluation(
                expected: CosmosString.Create("He"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Left,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2))));

            // LEFT("Hello", 6)
            AssertEvaluation(
                expected: CosmosString.Create("Hello"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Left,
                    hello,
                    six));
        }
        public override SqlObject VisitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context)
        {
            Contract.Requires(context != null);

            SqlLiteral sqlLiteral = (SqlLiteral)this.Visit(context.literal());

            return(SqlLiteralScalarExpression.Create(sqlLiteral));
        }
        public override bool Visit(SqlLiteralScalarExpression first, SqlObject secondAsObject)
        {
            if (!(secondAsObject is SqlLiteralScalarExpression second))
            {
                return(false);
            }

            return(Equals(first.Literal, second.Literal));
        }
Example #9
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"))));
 }
Example #10
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))));
 }
Example #11
0
            public static SqlScalarExpression GetCaseInsensitiveExpression(Expression expression)
            {
                if (expression is ConstantExpression inputExpression &&
                    inputExpression.Value is StringComparison comparisonValue &&
                    IgnoreCaseComparisons.Contains(comparisonValue))
                {
                    SqlBooleanLiteral literal = SqlBooleanLiteral.Create(true);
                    return(SqlLiteralScalarExpression.Create(literal));
                }

                return(null);
            }
        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);
        }
Example #13
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));
 }
Example #14
0
        public void RIGHT()
        {
            // Right("Hello", -3)
            AssertEvaluation(
                expected: CosmosString.Empty,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    negativeThree));

            // Right("Hello", 1.5)
            AssertEvaluation(
                expected: Undefined,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    floatingPoint));

            // Right("Hello", 0)
            AssertEvaluation(
                expected: CosmosString.Empty,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(0))));

            // Right("Hello", 2)
            AssertEvaluation(
                expected: CosmosString.Create("lo"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2))));

            // Right("Hello", 6)
            AssertEvaluation(
                expected: CosmosString.Create("Hello"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    six));

            // Right("Hello", int.MaxValue + 1)
            AssertEvaluation(
                expected: CosmosString.Create("Hello"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Right,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create((long)int.MaxValue + 1))));
        }
Example #15
0
            public static SqlScalarExpression GetCaseSensitivityExpression(Expression expression)
            {
                if (expression is ConstantExpression inputExpression &&
                    inputExpression.Value is StringComparison comparisonValue)
                {
                    if (SensitiveCaseComparisons.Contains(comparisonValue))
                    {
                        return(SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(false)));
                    }
                    else if (IgnoreCaseComparisons.Contains(comparisonValue))
                    {
                        return(SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(true)));
                    }
                }

                return(null);
            }
Example #16
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);
        }
        public void SqlCoalesceScalarExpressionTest()
        {
            SqlLiteralScalarExpression nullLiteral      = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);
            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());
            SqlLiteralScalarExpression five             = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression three            = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));

            SqlCoalesceScalarExpression nullCoalesceFive = SqlCoalesceScalarExpression.Create(nullLiteral, five);

            AssertEvaluation(CosmosNull.Create(), nullCoalesceFive);

            SqlCoalesceScalarExpression undefinedCoalesceFive = SqlCoalesceScalarExpression.Create(undefinedLiteral, five);

            AssertEvaluation(CosmosNumber64.Create(5), undefinedCoalesceFive);

            SqlCoalesceScalarExpression threeCoalesceFive = SqlCoalesceScalarExpression.Create(three, five);

            AssertEvaluation(CosmosNumber64.Create(3), threeCoalesceFive);
        }
        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);
        }
        public void Unary()
        {
            List <SqlParserBaselineTestInput> inputs = new List <SqlParserBaselineTestInput>();

            // Positive
            foreach (SqlUnaryScalarOperatorKind unaryOperator in (SqlUnaryScalarOperatorKind[])Enum.GetValues(typeof(SqlUnaryScalarOperatorKind)))
            {
                inputs.Add(
                    CreateInput(
                        description: unaryOperator.ToString(),
                        scalarExpression: SqlUnaryScalarExpression.Create(
                            unaryOperator,
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))).ToString()));
            }

            // Negative
            inputs.Add(CreateInput(description: "unknown operator", scalarExpression: "$42"));

            this.ExecuteTestSuite(inputs);
        }
Example #20
0
        public void ROUND()
        {
            // ROUND(4.84090499760142E+15)
            // offline engine has double precision errors
            AssertEvaluation(
                expected: CosmosNumber64.Create(4.84090499760142E+15),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Round,
                    SqlLiteralScalarExpression.Create(
                        SqlNumberLiteral.Create(
                            JToken.Parse("4840904997601420").Value <double>()))));

            // ROUND(0.5, 1)
            // -> should round up
            AssertEvaluation(
                expected: CosmosNumber64.Create(1),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Round,
                    SqlLiteralScalarExpression.Create(
                        SqlNumberLiteral.Create(0.5))));
        }
        public void SqlInScalarExpressionTest()
        {
            SqlLiteralScalarExpression one   = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1));
            SqlLiteralScalarExpression two   = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2));
            SqlLiteralScalarExpression three = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));

            SqlInScalarExpression oneInOneTwoThree = SqlInScalarExpression.Create(one, false, one, two, three);

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

            SqlInScalarExpression oneNotInOneTwoThree = SqlInScalarExpression.Create(one, true, one, two, three);

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

            SqlInScalarExpression oneInTwoThree = SqlInScalarExpression.Create(one, false, two, three);

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

            SqlInScalarExpression oneNotInTwoThree = SqlInScalarExpression.Create(one, true, two, three);

            AssertEvaluation(CosmosBoolean.Create(true), oneNotInTwoThree);
        }
        public void SqlSubqueryScalarExpressionTest()
        {
            SqlLiteralScalarExpression five  = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression three = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));

            // (SELECT VALUE 5 + 3)
            SqlSubqueryScalarExpression subqueryScalarExpression = SqlSubqueryScalarExpression.Create(
                SqlQuery.Create(
                    SqlSelectClause.Create(
                        SqlSelectValueSpec.Create(
                            SqlBinaryScalarExpression.Create(
                                SqlBinaryScalarOperatorKind.Add,
                                five,
                                three))),
                    fromClause: null,
                    whereClause: null,
                    groupByClause: null,
                    orderByClause: null,
                    offsetLimitClause: null));

            AssertEvaluation(CosmosNumber64.Create(5 + 3), subqueryScalarExpression);
        }
Example #23
0
        public void REPLICATE()
        {
            // REPLICATE("Hello", -1)
            // -> undefined
            AssertEvaluation(
                expected: Undefined,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Replicate,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(-1))));

            // REPLICATE("Hello", 1.5)
            // -> REPLICATE("Hello", 1) due to truncation
            AssertEvaluation(
                expected: CosmosString.Create("Hello"),
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Replicate,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1.5))));

            // REPLICATE("Hello", 10000)
            // -> undefined due to 10kb string cap
            AssertEvaluation(
                expected: Undefined,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Replicate,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(10000))));

            // REPLICATE("Hello", EXP(400))
            // -> undefined due to 10kb string cap
            AssertEvaluation(
                expected: Undefined,
                sqlScalarExpression: SqlFunctionCallScalarExpression.CreateBuiltin(
                    SqlFunctionCallScalarExpression.Identifiers.Replicate,
                    hello,
                    SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(Math.Exp(400)))));
        }
Example #24
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(SqlArrayCreateScalarExpression.Create(jToken.Select(FromJToken).ToArray()));

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

            case JTokenType.Null:
                return(SqlLiteralScalarExpression.SqlNullLiteralScalarExpression);

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

            case JTokenType.Object:

                SqlObjectProperty[] properties =
                    ((JObject)jToken).Properties()
                    .Select(
                        p =>
                        SqlObjectProperty.Create(
                            SqlPropertyName.Create(p.Name),
                            FromJToken(p.Value)))
                    .ToArray();

                return(SqlObjectCreateScalarExpression.Create(properties));

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

            default:
                throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.UnexpectedTokenType, jToken.Type));
            }
        }
Example #25
0
 public abstract void Visit(SqlLiteralScalarExpression sqlObject);
        public void Binary()
        {
            // Positive
            List <SqlParserBaselineTestInput> inputs = new List <SqlParserBaselineTestInput>();

            foreach (SqlBinaryScalarOperatorKind binaryOperator in (SqlBinaryScalarOperatorKind[])Enum.GetValues(typeof(SqlBinaryScalarOperatorKind)))
            {
                inputs.Add(
                    CreateInput(
                        description: binaryOperator.ToString(),
                        scalarExpression: SqlBinaryScalarExpression.Create(
                            binaryOperator,
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42)),
                            SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1337))).ToString()));
            }

            // Order of operations
            inputs.Add(CreateInput(
                           description: "Multiplication, division, and remainder -> left to right",
                           scalarExpression: "1 / 2 * 3 % 4"));
            inputs.Add(CreateInput(
                           description: "Addition and subtraction -> left to right",
                           scalarExpression: "1 + 2 - 3 + 4"));
            inputs.Add(CreateInput(
                           description: "Relational operators -> left to right",
                           scalarExpression: "1 < 2 <= 3 > 4 >= 5"));
            inputs.Add(CreateInput(
                           description: "Equality operators -> left to right",
                           scalarExpression: "1 = 2 != 3 = 4"));
            inputs.Add(CreateInput(
                           description: "Bitwise AND > Bitwise XOR (exclusive or) > Bitwise OR (inclusive or)",
                           scalarExpression: "1 | 2 & 3 ^ 4"));
            inputs.Add(CreateInput(
                           description: "Logical AND > Logical OR",
                           scalarExpression: "1 AND 2 OR 3 AND 4"));
            inputs.Add(CreateInput(
                           description: "Conditional-expression Right to left",
                           scalarExpression: "1 ? 2 : 3 + 4"));
            inputs.Add(CreateInput(
                           description: "Multiplicative > Additive",
                           scalarExpression: "1 + 2 * 3 - 4 / 5"));
            inputs.Add(CreateInput(
                           description: "Additive > Relational",
                           scalarExpression: "1 + 2 < 2 + 3 <= 10 - 4 > 5 >= 3"));
            inputs.Add(CreateInput(
                           description: "Relational > Equality",
                           scalarExpression: "1 > 2 = false AND 1 > 2 != true"));
            inputs.Add(CreateInput(
                           description: "Equality > Bitwise AND",
                           scalarExpression: "1 = 2 & 3 != 4"));
            inputs.Add(CreateInput(
                           description: "Bitwise AND > Bitwise Exclusive OR",
                           scalarExpression: "1 ^ 2 & 3 ^ 4"));
            inputs.Add(CreateInput(
                           description: "Bitwise Exclusive OR > Bitwise Inclusive OR",
                           scalarExpression: "1 | 2 ^ 3 | 4"));
            inputs.Add(CreateInput(
                           description: "Bitwise Inclusive OR > Logical AND",
                           scalarExpression: "1 AND 2 | 3 AND 4"));
            inputs.Add(CreateInput(
                           description: "Logical AND > Logical OR",
                           scalarExpression: "1 OR 2 AND 3 OR 4"));
            inputs.Add(CreateInput(
                           description: "Logical OR > String Concat",
                           scalarExpression: "1 || 2 OR 3 || 4"));

            // Negative
            inputs.Add(CreateInput(description: "Missing Right", scalarExpression: "42 +"));
            inputs.Add(CreateInput(description: "Missing Left", scalarExpression: "AND 1337"));
            inputs.Add(CreateInput(description: "Unknown Operator", scalarExpression: "42 # 1337"));

            this.ExecuteTestSuite(inputs);
        }
 public override void Visit(SqlLiteralScalarExpression sqlLiteralScalarExpression)
 {
     sqlLiteralScalarExpression.Literal.Accept(this);
 }
Example #28
0
        public override CosmosElement Visit(SqlLiteralScalarExpression scalarExpression, CosmosElement document)
        {
            SqlLiteral sqlLiteral = scalarExpression.Literal;

            return(sqlLiteral.Accept(SqlLiteralToCosmosElement.Singleton));
        }
 public override SqlObject Visit(SqlLiteralScalarExpression sqlLiteralScalarExpression)
 {
     return(SqlLiteralScalarExpression.Create(sqlLiteralScalarExpression.Literal.Accept(this) as SqlLiteral));
 }
 public abstract void Visit(SqlLiteralScalarExpression scalarExpression);