Пример #1
0
        public QsiExpressionNode VisitInPredicate(InPredicate inPredicate)
        {
            var binaryNode = TreeHelper.Create <QsiBinaryExpressionNode>(n =>
            {
                n.Left.SetValue(VisitScalarExpression(inPredicate.Expression));

                if (inPredicate.Subquery != null)
                {
                    n.Right.SetValue(VisitScalarSubquery(inPredicate.Subquery));
                }
                else
                {
                    n.Right.SetValue(TreeHelper.Create <QsiMultipleExpressionNode>(mn =>
                    {
                        mn.Elements.AddRange(inPredicate.Values.Select(VisitScalarExpression));
                    }));
                }
            });

            if (!inPredicate.NotDefined)
            {
                return(binaryNode);
            }

            return(TreeHelper.CreateUnary(SqlServerKnownOperator.Not, binaryNode));
        }
        public override void ExitInPredicate(MiniSqlParserParser.InPredicateContext context)
        {
            var comments = this.GetComments(context);

            Exprs  exprs = null;
            IQuery query = null;

            if (context.exprs() != null)
            {
                exprs = (Exprs)_stack.Pop();
            }
            else if (context.query() != null)
            {
                query = (IQuery)_stack.Pop();
            }
            else
            {
                exprs = new Exprs();
            }
            var operand = (Expr)_stack.Pop();
            var not     = context.K_NOT() != null;

            var node = new InPredicate(operand, not, exprs, query, comments);

            _stack.Push(node);
        }
Пример #3
0
        public QsiExpressionNode VisitInPredicate(InPredicate inPredicate)
        {
            QsiExpressionNode node = TreeHelper.Create <QsiBinaryExpressionNode>(n =>
            {
                n.Operator = "IN";
                n.Left.SetValue(VisitScalarExpression(inPredicate.Expression));

                if (inPredicate.Subquery != null)
                {
                    n.Right.SetValue(VisitScalarSubquery(inPredicate.Subquery));
                }
                else
                {
                    n.Right.SetValue(TreeHelper.Create <QsiMultipleExpressionNode>(mn =>
                    {
                        mn.Elements.AddRange(inPredicate.Values.Select(VisitScalarExpression));
                    }));
                }
            });

            if (inPredicate.NotDefined)
            {
                node = TreeHelper.CreateUnary(SqlServerKnownOperator.Not, node);
            }

            SqlServerTree.PutFragmentSpan(node, inPredicate);

            return(node);
        }
Пример #4
0
        private void DropNAs <TDst>(ref VBuffer <TDst> src, ref VBuffer <TDst> dst, InPredicate <TDst> isNA)
        {
            Host.AssertValue(isNA);

            var srcValues = src.GetValues();
            int newCount  = 0;

            for (int i = 0; i < srcValues.Length; i++)
            {
                if (!isNA(in srcValues[i]))
                {
                    newCount++;
                }
            }
            Host.Assert(newCount <= srcValues.Length);

            if (newCount == 0)
            {
                VBufferUtils.Resize(ref dst, src.Length - srcValues.Length, 0);
                return;
            }

            if (newCount == srcValues.Length)
            {
                Utils.Swap(ref src, ref dst);
                return;
            }

            int iDst = 0;

            if (src.IsDense)
            {
                var editor = VBufferEditor.Create(ref dst, newCount);
                for (int i = 0; i < srcValues.Length; i++)
                {
                    if (!isNA(in srcValues[i]))
                    {
                        editor.Values[iDst] = srcValues[i];
                        iDst++;
                    }
                }
                Host.Assert(iDst == newCount);
                dst = editor.Commit();
            }
            else
            {
                var newLength = src.Length - srcValues.Length - newCount;
                var editor    = VBufferEditor.Create(ref dst, newLength, newCount);

                var srcIndices = src.GetIndices();
                int offset     = 0;
                for (int i = 0; i < srcValues.Length; i++)
                {
                    if (!isNA(in srcValues[i]))
                    {
                        editor.Values[iDst]  = srcValues[i];
                        editor.Indices[iDst] = srcIndices[i] - offset;
                        iDst++;
                    }
Пример #5
0
 protected TypedValue(Cursor cursor, ValueGetter <T> getSrc, InPredicate <T> hasBad)
     : base(cursor)
 {
     Contracts.AssertValue(getSrc);
     Contracts.AssertValue(hasBad);
     _getSrc = getSrc;
     _hasBad = hasBad;
 }
        public static IDataView Create <TSrc>(IHostEnvironment env, string name, IDataView input,
                                              string src, DataViewType typeSrc, InPredicate <TSrc> predicate)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckNonEmpty(name, nameof(name));
            env.CheckValue(input, nameof(input));
            env.CheckNonEmpty(src, nameof(src));
            env.CheckValue(typeSrc, nameof(typeSrc));
            env.CheckValue(predicate, nameof(predicate));

            if (typeSrc.RawType != typeof(TSrc))
            {
                throw env.ExceptParam(nameof(predicate),
                                      "The source column type '{0}' doesn't match the input type of the predicate", typeSrc);
            }

            int  colSrc;
            bool tmp = input.Schema.TryGetColumnIndex(src, out colSrc);

            if (!tmp)
            {
                throw env.ExceptParam(nameof(src), "The input data doesn't have a column named '{0}'", src);
            }
            var typeOrig = input.Schema[colSrc].Type;

            // REVIEW: Ideally this should support vector-type conversion. It currently doesn't.
            bool     ident;
            Delegate conv;

            if (typeOrig.SameSizeAndItemType(typeSrc))
            {
                ident = true;
                conv  = null;
            }
            else if (!Conversions.DefaultInstance.TryGetStandardConversion(typeOrig, typeSrc, out conv, out ident))
            {
                throw env.ExceptParam(nameof(predicate),
                                      "The type of column '{0}', '{1}', cannot be converted to the input type of the predicate '{2}'",
                                      src, typeOrig, typeSrc);
            }

            IDataView impl;

            if (ident)
            {
                impl = new Impl <TSrc, TSrc>(env, name, input, colSrc, predicate);
            }
            else
            {
                Func <IHostEnvironment, string, IDataView, int,
                      InPredicate <int>, ValueMapper <int, int>, Impl <int, int> > del = CreateImpl <int, int>;
                var meth = del.GetMethodInfo().GetGenericMethodDefinition()
                           .MakeGenericMethod(typeOrig.RawType, typeof(TSrc));
                impl = (IDataView)meth.Invoke(null, new object[] { env, name, input, colSrc, predicate, conv });
            }

            return(new OpaqueDataView(impl));
        }
Пример #7
0
        public override void Visit(InPredicate node)
        {
            base.Visit(node);

            if (node.Subquery != null)
            {
                InSubqueries.Add(node);
            }
        }
Пример #8
0
        public override void ExplicitVisit(InPredicate node)
        {
            base.ExplicitVisit(node);
            ReplaceExpression(node, n => n.Expression);

            for (var i = 0; i < node.Values.Count; i++)
            {
                node.Values[i] = ReplaceExpression(node.Values[i], out _);
            }
        }
 public override void EnterInPredicate(MySqlParser.InPredicateContext context)
 {
     if (_isOtherListener == 1)
     {
         InPredicate inPredicate =
             new InPredicate(context.SourceInterval, context, context.GetText());
         Rules.Remove(Rules[Rules.Count - 1]);
         Rules.Add(inPredicate);
     }
     _isOtherListener++;
 }
Пример #10
0
            public Impl(IHostEnvironment env, string name, IDataView input,
                        int colSrc, InPredicate <T2> pred, ValueMapper <T1, T2> conv = null)
                : base(env, name, input)
            {
                Host.AssertValue(pred);
                Host.Assert(conv != null | typeof(T1) == typeof(T2));
                Host.Assert(0 <= colSrc & colSrc < Source.Schema.Count);

                _colSrc = colSrc;
                _pred   = pred;
                _conv   = conv;
            }
            /// <summary>
            /// Adds all NAs (or non-NAs) to the indices List.  Whether NAs or non-NAs have been added is indicated by the bool sense.
            /// </summary>
            private void FindNAs <T>(ref VBuffer <T> src, InPredicate <T> isNA, bool defaultIsNA, List <int> indices, out bool sense)
            {
                Host.AssertValue(isNA);
                Host.AssertValue(indices);

                // Find the indices of all of the NAs.
                indices.Clear();
                var srcValues = src.Values;
                var srcCount  = src.Count;

                if (src.IsDense)
                {
                    for (int i = 0; i < srcCount; i++)
                    {
                        if (isNA(in srcValues[i]))
                        {
                            indices.Add(i);
                        }
                    }
                    sense = true;
                }
                else if (!defaultIsNA)
                {
                    var srcIndices = src.Indices;
                    for (int ii = 0; ii < srcCount; ii++)
                    {
                        if (isNA(in srcValues[ii]))
                        {
                            indices.Add(srcIndices[ii]);
                        }
                    }
                    sense = true;
                }
                else
                {
                    // Note that this adds non-NAs to indices -- this is indicated by sense being false.
                    var srcIndices = src.Indices;
                    for (int ii = 0; ii < srcCount; ii++)
                    {
                        if (!isNA(in srcValues[ii]))
                        {
                            indices.Add(srcIndices[ii]);
                        }
                    }
                    sense = false;
                }
            }
Пример #12
0
        public override void ExplicitVisit(InPredicate node)
        {
            node.Expression.Accept(this);
            _buffer.Append(" in (");
            bool needComma = false;

            foreach (var value in node.Values)
            {
                if (needComma)
                {
                    _buffer.Append(", ");
                }
                value.Accept(this);
                needComma = true;
            }
            _buffer.Append(")");
        }
Пример #13
0
        public override void Visit(InPredicate exp)
        {
            if (exp.Expression is ColumnReferenceExpression)
            {
                RbacWhereClause aWhereClause = new RbacWhereClause();
                aWhereClause.Literal           = RbacWhereClauseLiterals.InExpression;
                aWhereClause.OnTableAlias      = ((ColumnReferenceExpression)exp.Expression).MultiPartIdentifier.Identifiers.First().Value;
                aWhereClause.OnColumn          = ((ColumnReferenceExpression)exp.Expression).MultiPartIdentifier.Identifiers.Last().Value;
                aWhereClause.WhereClauseString = Query.Substring(exp.StartOffset, exp.FragmentLength);

                foreach (var value in exp.Values)
                {
                    aWhereClause.ConditionValues.Add(((Literal)value).Value);
                }

                WhereClauses.Add(aWhereClause);
            }
        }
Пример #14
0
        private protected IDataView MapLabelsCore<T>(DataViewType type, InPredicate<T> equalsTarget, RoleMappedData data)
        {
            Host.AssertValue(type);
            Host.Assert(type.RawType == typeof(T));
            Host.AssertValue(equalsTarget);
            Host.AssertValue(data);
            Host.Assert(data.Schema.Label.HasValue);

            var label = data.Schema.Label.Value;
            IDataView dataView = data.Data;
            if (!Args.ImputeMissingLabelsAsNegative)
                dataView = new NAFilter(Host, data.Data, false, label.Name);

            return LambdaColumnMapper.Create(Host, "Label mapper", data.Data,
                label.Name, label.Name, type, BooleanDataViewType.Instance,
                (in T src, ref bool dst) =>
                    dst = equalsTarget(in src) ? true : false);
        }
Пример #15
0
        public override void ExplicitVisit(InPredicate node)
        {
            if (node.Values != null)
            {
                var count = node.Values.Count;
                if (count > 1)
                {
                    for (var i = count - 1; i > 0; i--)
                    {
                        if (node.Values[i] is Literal)
                        {
                            node.Values.RemoveAt(i);
                        }
                    }
                }
            }

            base.ExplicitVisit(node);
        }
Пример #16
0
        internal gsWhereTermBase GetWhereTerm(InPredicate inPredicate, bool isNotIn)
        {
            gsWhereTermIn whereTerm  = new gsWhereTermIn();
            string        subQryName = $"subQry{gsSelectQuery.GetNextID()}";

            whereTerm.InType = isNotIn ? gsInOrNotIn.NotIn : gsInOrNotIn.In;

            whereTerm.Expression = gsScalarExpressionParserFactory.CreateParser(inPredicate.Expression, null).Parse();

            if (inPredicate.Subquery != null)
            {
                gsSelectQuery subQry = new gsSelectQuery();
                whereTerm.QueryName = subQry.QryName = subQryName;

                QuerySpecification qrySpec = inPredicate.Subquery.QueryExpression as QuerySpecification;

                gsSelectQueryParser qryParser = new gsSelectQueryParser();
                qryParser.ProcessQuerySpecification(qrySpec, subQry);

                whereTerm.Sql = subQry.ToString();
            }
            else if (inPredicate.Values.Count > 0)
            {
                List <string> values = new List <string>();

                foreach (ScalarExpression val in inPredicate.Values)
                {
                    string valueStr = Convert.ToString(gsScalarExpressionParserFactory.CreateParser(val, null).Parse().Value);
                    values.Add(valueStr);
                }

                whereTerm.values = values;
            }
            else
            {
                throw new NotImplementedException("InPredicate type not supported");
            }

            return(whereTerm);
        }
Пример #17
0
 public Cursor(Impl <T1, T2> parent, DataViewRowCursor input, bool[] active)
     : base(parent.Host, input, parent.OutputSchema, active)
 {
     _getSrc = Input.GetGetter <T1>(Input.Schema[parent._colSrc]);
     if (parent._conv == null)
     {
         Ch.Assert(typeof(T1) == typeof(T2));
         _pred = (InPredicate <T1>)(Delegate) parent._pred;
     }
     else
     {
         T2  val  = default(T2);
         var pred = parent._pred;
         var conv = parent._conv;
         _pred =
             (in T1 src) =>
         {
             conv(in _src, ref val);
             return(pred(in val));
         };
     }
 }
Пример #18
0
        private protected IDataView MapLabelsCore<T>(ColumnType type, InPredicate<T> equalsTarget, RoleMappedData data)
        {
            Host.AssertValue(type);
            Host.Assert(type.RawType == typeof(T));
            Host.AssertValue(equalsTarget);
            Host.AssertValue(data);
            Host.Assert(data.Schema.Label.HasValue);

            var lab = data.Schema.Label.Value;

            InPredicate<T> isMissing;
            if (!Args.ImputeMissingLabelsAsNegative && Conversions.Instance.TryGetIsNAPredicate(type, out isMissing))
            {
                return LambdaColumnMapper.Create(Host, "Label mapper", data.Data,
                    lab.Name, lab.Name, type, NumberType.Float,
                    (in T src, ref float dst) =>
                        dst = equalsTarget(in src) ? 1 : (isMissing(in src) ? float.NaN : default(float)));
            }
            return LambdaColumnMapper.Create(Host, "Label mapper", data.Data,
                lab.Name, lab.Name, type, NumberType.Float,
                (in T src, ref float dst) =>
                    dst = equalsTarget(in src) ? 1 : default(float));
        }
 void IVisitor.Visit(InPredicate predicate, int offset)
 {
     this.ParentExists(predicate);
 }
 void IVisitor.VisitAfter(InPredicate predicate)
 {
     this.ParentExists(predicate);
 }
Пример #21
0
 private static Impl <T1, T2> CreateImpl <T1, T2>(
     IHostEnvironment env, string name, IDataView input, int colSrc,
     InPredicate <T2> pred, ValueMapper <T1, T2> conv)
 {
     return(new Impl <T1, T2>(env, name, input, colSrc, pred, conv));
 }
Пример #22
0
        private void DropNAsAndDefaults <TDst>(ref VBuffer <TDst> src, ref VBuffer <TDst> dst, InPredicate <TDst> isNA)
        {
            Host.AssertValue(isNA);

            int newCount = 0;

            for (int i = 0; i < src.Count; i++)
            {
                if (!isNA(in src.Values[i]))
                {
                    newCount++;
                }
            }
            Host.Assert(newCount <= src.Count);

            if (newCount == 0)
            {
                dst = new VBuffer <TDst>(0, dst.Values, dst.Indices);
                return;
            }

            if (newCount == src.Count)
            {
                Utils.Swap(ref src, ref dst);
                if (!dst.IsDense)
                {
                    Host.Assert(dst.Count == newCount);
                    dst = new VBuffer <TDst>(dst.Count, dst.Values, dst.Indices);
                }
                return;
            }

            int iDst   = 0;
            var values = dst.Values;

            if (Utils.Size(values) < newCount)
            {
                values = new TDst[newCount];
            }

            // Densifying sparse vectors since default value equals NA and hence should be dropped.
            for (int i = 0; i < src.Count; i++)
            {
                if (!isNA(in src.Values[i]))
                {
                    values[iDst++] = src.Values[i];
                }
            }
            Host.Assert(iDst == newCount);

            dst = new VBuffer <TDst>(newCount, values, dst.Indices);
        }
Пример #23
0
 public ValueVec(Cursor cursor, ValueGetter <VBuffer <T> > getSrc, InPredicate <VBuffer <T> > hasBad)
     : base(cursor, getSrc, hasBad)
 {
     _getter = GetValue;
 }
Пример #24
0
        private void DropNAs <TDst>(ref VBuffer <TDst> src, ref VBuffer <TDst> dst, InPredicate <TDst> isNA)
        {
            Host.AssertValue(isNA);

            int newCount = 0;

            for (int i = 0; i < src.Count; i++)
            {
                if (!isNA(in src.Values[i]))
                {
                    newCount++;
                }
            }
            Host.Assert(newCount <= src.Count);

            if (newCount == 0)
            {
                dst = new VBuffer <TDst>(src.Length - src.Count, 0, dst.Values, dst.Indices);
                return;
            }

            if (newCount == src.Count)
            {
                Utils.Swap(ref src, ref dst);
                return;
            }

            var values = dst.Values;

            if (Utils.Size(values) < newCount)
            {
                values = new TDst[newCount];
            }

            int iDst = 0;

            if (src.IsDense)
            {
                for (int i = 0; i < src.Count; i++)
                {
                    if (!isNA(in src.Values[i]))
                    {
                        values[iDst] = src.Values[i];
                        iDst++;
                    }
                }
                Host.Assert(iDst == newCount);
                dst = new VBuffer <TDst>(newCount, values, dst.Indices);
            }
            else
            {
                var indices = dst.Indices;
                if (Utils.Size(indices) < newCount)
                {
                    indices = new int[newCount];
                }

                int offset = 0;
                for (int i = 0; i < src.Count; i++)
                {
                    if (!isNA(in src.Values[i]))
                    {
                        values[iDst]  = src.Values[i];
                        indices[iDst] = src.Indices[i] - offset;
                        iDst++;
                    }
Пример #25
0
 public ValueOne(Cursor cursor, ValueGetter <T> getSrc, InPredicate <T> hasBad)
     : base(cursor, getSrc, hasBad)
 {
     _getter = GetValue;
 }
Пример #26
0
		public void Visit(InPredicate predicate)
		{
			predicate.Column.Accept(this);

			_Query.Append( " IN (");

			if(predicate.SubQueries[0] is SelectStatement)
				predicate.SubQueries[0].Accept(this);
			
			if(predicate.SubQueries[0] is ValueExpression)
			{
				foreach(ValueExpression val in predicate.SubQueries)
				{
					val.Accept(this);
					_Query.Append(" ,");
				}
			}

			if(_Query[_Query.Length - 1] == ',')
				_Query.Remove(_Query.Length - 1, 1);
			_Query.Append(" )");
		}
 public override void ExplicitVisit(InPredicate fragment)
 {
     _fragments.Add(fragment);
 }
Пример #28
0
 public override void Visit(InPredicate node) { this.action(node); }
 void IVisitor.VisitBefore(InPredicate predicate)
 {
     this.ParentExists(predicate);
 }
Пример #30
0
            private void DropNAsAndDefaults <TDst>(ref VBuffer <TDst> src, ref VBuffer <TDst> dst, InPredicate <TDst> isNA)
            {
                Host.AssertValue(isNA);

                var srcValues = src.GetValues();
                int newCount  = 0;

                for (int i = 0; i < srcValues.Length; i++)
                {
                    if (!isNA(in srcValues[i]))
                    {
                        newCount++;
                    }
                }
                Host.Assert(newCount <= srcValues.Length);

                if (newCount == 0)
                {
                    VBufferUtils.Resize(ref dst, 0);
                    return;
                }

                if (newCount == srcValues.Length)
                {
                    Utils.Swap(ref src, ref dst);
                    if (!dst.IsDense)
                    {
                        Host.Assert(dst.GetValues().Length == newCount);
                        VBufferUtils.Resize(ref dst, newCount);
                    }
                    return;
                }

                int iDst = 0;

                // Densifying sparse vectors since default value equals NA and hence should be dropped.
                var editor = VBufferEditor.Create(ref dst, newCount);

                for (int i = 0; i < srcValues.Length; i++)
                {
                    if (!isNA(in srcValues[i]))
                    {
                        editor.Values[iDst++] = srcValues[i];
                    }
                }
                Host.Assert(iDst == newCount);

                dst = editor.Commit();
            }
Пример #31
0
        /// <summary>
        /// Converts a FetchXML &lt;condition&gt; to a SQL condition
        /// </summary>
        /// <param name="metadata">The metadata cache to use for the conversion</param>
        /// <param name="condition">The FetchXML condition to convert</param>
        /// <param name="prefix">The alias or name of the table that the <paramref name="condition"/> applies to</param>
        /// <param name="aliasToLogicalName">The mapping of table alias to logical name</param>
        /// <returns>The SQL condition equivalent of the <paramref name="condition"/></returns>
        private static BooleanExpression GetCondition(IAttributeMetadataCache metadata, condition condition, string prefix, IDictionary <string, string> aliasToLogicalName)
        {
            // Start with the field reference
            var field = new ColumnReferenceExpression
            {
                MultiPartIdentifier = new MultiPartIdentifier
                {
                    Identifiers =
                    {
                        new Identifier {
                            Value = condition.entityname ?? prefix
                        },
                        new Identifier {
                            Value = condition.attribute
                        }
                    }
                }
            };

            // Get the metadata for the attribute
            BooleanComparisonType type;
            ScalarExpression      value;

            if (!aliasToLogicalName.TryGetValue(condition.entityname ?? prefix, out var logicalName))
            {
                logicalName = condition.entityname ?? prefix;
            }

            var meta = metadata[logicalName];
            var attr = meta.Attributes.SingleOrDefault(a => a.LogicalName == condition.attribute);

            // Get the literal value to compare to
            if (attr == null)
            {
                value = new StringLiteral {
                    Value = condition.value
                }
            }
            ;
            else if (attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.BigInt ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Integer ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Picklist ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.State ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Status)
            {
                value = new IntegerLiteral {
                    Value = condition.value
                }
            }
            ;
            else if (attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Boolean)
            {
                value = new BinaryLiteral {
                    Value = condition.value
                }
            }
            ;
            else if (attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Decimal ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Double)
            {
                value = new NumericLiteral {
                    Value = condition.value
                }
            }
            ;
            else if (attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Money)
            {
                value = new MoneyLiteral {
                    Value = condition.value
                }
            }
            ;
            else if (attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Lookup ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Owner ||
                     attr.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Customer)
            {
                value = new IdentifierLiteral {
                    Value = condition.value
                }
            }
            ;
            else
            {
                value = new StringLiteral {
                    Value = condition.value
                }
            };

            // Apply the appropriate conversion for the type of operator
            switch (condition.@operator)
            {
            case @operator.above:
            case @operator.containvalues:
            case @operator.eqbusinessid:
            case @operator.eqorabove:
            case @operator.eqorunder:
            case @operator.equserid:
            case @operator.equserlanguage:
            case @operator.equseroruserhierarchy:
            case @operator.equseroruserhierarchyandteams:
            case @operator.equseroruserteams:
            case @operator.equserteams:
            case @operator.infiscalperiod:
            case @operator.infiscalperiodandyear:
            case @operator.infiscalyear:
            case @operator.inorafterfiscalperiodandyear:
            case @operator.inorbeforefiscalperiodandyear:
            case @operator.lastfiscalperiod:
            case @operator.lastfiscalyear:
            case @operator.lastmonth:
            case @operator.lastsevendays:
            case @operator.lastweek:
            case @operator.lastxdays:
            case @operator.lastxfiscalperiods:
            case @operator.lastxfiscalyears:
            case @operator.lastxhours:
            case @operator.lastxmonths:
            case @operator.lastxweeks:
            case @operator.lastxyears:
            case @operator.lastyear:
            case @operator.nebusinessid:
            case @operator.neuserid:
            case @operator.nextfiscalperiod:
            case @operator.nextfiscalyear:
            case @operator.nextmonth:
            case @operator.nextsevendays:
            case @operator.nextweek:
            case @operator.nextxdays:
            case @operator.nextxfiscalperiods:
            case @operator.nextxfiscalyears:
            case @operator.nextxhours:
            case @operator.nextxmonths:
            case @operator.nextxweeks:
            case @operator.nextxyears:
            case @operator.nextyear:
            case @operator.notcontainvalues:
            case @operator.notunder:
            case @operator.olderthanxdays:
            case @operator.olderthanxhours:
            case @operator.olderthanxminutes:
            case @operator.olderthanxmonths:
            case @operator.olderthanxweeks:
            case @operator.olderthanxyears:
            case @operator.on:
            case @operator.onorafter:
            case @operator.onorbefore:
            case @operator.thisfiscalperiod:
            case @operator.thisfiscalyear:
            case @operator.thismonth:
            case @operator.thisweek:
            case @operator.thisyear:
            case @operator.today:
            case @operator.tomorrow:
            case @operator.under:
            case @operator.yesterday:

                // These FetchXML operators don't have a direct SQL equivalent, so convert to the format
                // field = function(arg)
                // so <condition attribute="createdon" operator="lastxdays" value="2" /> will be converted to
                // createdon = lastxdays(2)

                type  = BooleanComparisonType.Equals;
                value = new FunctionCall {
                    FunctionName = new Identifier {
                        Value = [email protected]()
                    }
                };

                if (condition.value != null)
                {
                    ((FunctionCall)value).Parameters.Add(new StringLiteral {
                        Value = condition.value
                    });
                }

                break;

            case @operator.beginswith:
            case @operator.notbeginwith:
                return(new LikePredicate {
                    FirstExpression = field, SecondExpression = new StringLiteral {
                        Value = condition.value + "%"
                    }, NotDefined = condition.@operator == @operator.notbeginwith
                });

            case @operator.between:
            case @operator.notbetween:
                return(new BooleanTernaryExpression {
                    FirstExpression = field, TernaryExpressionType = condition.@operator == @operator.between ? BooleanTernaryExpressionType.Between : BooleanTernaryExpressionType.NotBetween, SecondExpression = new StringLiteral {
                        Value = condition.Items[0].Value
                    }, ThirdExpression = new StringLiteral {
                        Value = condition.Items[1].Value
                    }
                });

            case @operator.endswith:
            case @operator.notendwith:
                return(new LikePredicate {
                    FirstExpression = field, SecondExpression = new StringLiteral {
                        Value = "%" + condition.value
                    }, NotDefined = condition.@operator == @operator.notendwith
                });

            case @operator.eq:
                type = BooleanComparisonType.Equals;
                break;

            case @operator.ge:
                type = BooleanComparisonType.GreaterThanOrEqualTo;
                break;

            case @operator.gt:
                type = BooleanComparisonType.GreaterThan;
                break;

            case @operator.@in:
            case @operator.notin:
                var @in = new InPredicate {
                    Expression = field, NotDefined = condition.@operator == @operator.notin
                };

                foreach (var val in condition.Items)
                {
                    @in.Values.Add(new StringLiteral {
                        Value = val.Value
                    });
                }

                return(@in);

            case @operator.le:
                type = BooleanComparisonType.LessThanOrEqualTo;
                break;

            case @operator.like:
            case @operator.notlike:
                return(new LikePredicate {
                    FirstExpression = field, SecondExpression = new StringLiteral {
                        Value = condition.value
                    }, NotDefined = condition.@operator == @operator.notlike
                });

            case @operator.lt:
                type = BooleanComparisonType.LessThan;
                break;

            case @operator.ne:
            case @operator.neq:
                type = BooleanComparisonType.NotEqualToBrackets;
                break;

            case @operator.@null:
            case @operator.notnull:
                return(new BooleanIsNullExpression {
                    Expression = field, IsNot = condition.@operator == @operator.notnull
                });

            default:
                throw new NotImplementedException();
            }

            var expression = new BooleanComparisonExpression
            {
                FirstExpression  = field,
                ComparisonType   = type,
                SecondExpression = value
            };

            return(expression);
        }