Esempio n. 1
0
        /// <summary>
        /// Gets the String representation of the Aggregate
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder output = new StringBuilder();

            output.Append("GROUP_CONCAT(");
            if (this._distinct)
            {
                output.Append("DISTINCT ");
            }
            if (this._expr is ConcatFunction)
            {
                ConcatFunction concatFunc = (ConcatFunction)this._expr;
                for (int i = 0; i < concatFunc.Arguments.Count(); i++)
                {
                    output.Append(concatFunc.Arguments.Skip(i).First().ToString());
                    if (i < concatFunc.Arguments.Count() - 1)
                    {
                        output.Append(", ");
                    }
                }
            }
            else
            {
                output.Append(this._expr.ToString());
            }
            if (this._customSeparator)
            {
                output.Append(" ; SEPARATOR = ");
                output.Append(this._sep.ToString());
            }
            output.Append(")");
            return(output.ToString());
        }
Esempio n. 2
0
        protected override string RenderConcatColumn(ConcatFunction concatColumn, bool renderAlias)
        {
            if (concatColumn == null)
            {
                throw new ArgumentNullException(nameof(concatColumn));
            }

            StringBuilder sbConcat = new StringBuilder();

            sbConcat = concatColumn.Columns
                       .Aggregate(sbConcat, (current, column) => current.Append($"{(current.Length > 0 ? ", " : string.Empty)}{RenderColumn(column, renderAlias: false)}"));

            sbConcat.Insert(0, "CONCAT(").Append(")");

            return(renderAlias && !string.IsNullOrWhiteSpace(concatColumn.Alias)
                ? RenderColumnnameWithAlias(sbConcat.ToString(), EscapeName(concatColumn.Alias))
                : sbConcat.ToString());
        }
Esempio n. 3
0
        private IDataReader GetRelatedTableReader(string table_name)
        {
            var metadata = (TMappingInfo)MappingFactory.GetMapping(typeof(TMappingInfo));
            var item     = metadata.Associations.Where(x => x.Name == table_name).FirstOrDefault();

            if (item == null)
            {
                return(null);
            }

            var omapping = MappingFactory.GetMapping(item.OtherMappingType);

            var qry = (new SelectStatement())
                      .Column(omapping.Columns.Where(x => x.Name == item.OtherKeys[0]).Single().ColumnName)
                      .From(omapping.TableName);

            var lblCount = item.OtherLabels.Count;

            if (lblCount == 0)
            {
                return(null);
            }
            else
            {
                if (lblCount == 1)
                {
                    qry.Column(omapping.Columns.Where(x => x.Name == item.OtherLabels[0]).Single().ColumnName);
                }
                else
                {
                    var lblConcat = new ConcatFunction(" | ");
                    foreach (var lbl in item.OtherLabels)
                    {
                        lblConcat.Append(new SqlColumnName(omapping.Columns.Where(x => x.Name == lbl).Single().ColumnName));
                    }
                    qry.Column(lblConcat);
                }
            }

            return(qry.ExecuteReader());
        }
        /// <summary>
        /// Tries to create an XPath Function expression if the function Uri correseponds to a supported XPath Function.
        /// </summary>
        /// <param name="u">Function Uri.</param>
        /// <param name="args">Function Arguments.</param>
        /// <param name="scalarArgs">Scalar Arguments.</param>
        /// <param name="expr">Generated Expression.</param>
        /// <returns>Whether an expression was successfully generated.</returns>
        public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <String, ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            // If any Scalar Arguments are present then can't possibly be an XPath Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return(false);
            }

            String func = u.AbsoluteUri;

            if (func.StartsWith(XPathFunctionsNamespace))
            {
                func = func.Substring(XPathFunctionsNamespace.Length);
                ISparqlExpression xpathFunc = null;

                switch (func)
                {
                case Absolute:
                    if (args.Count == 1)
                    {
                        xpathFunc = new AbsFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath abs() function");
                    }
                    break;

                case AdjustDateTimeToTimezone:
                    throw new NotSupportedException("XPath adjust-dateTime-to-timezone() function is not supported");

                case Boolean:
                    if (args.Count == 1)
                    {
                        xpathFunc = new BooleanFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath boolean() function");
                    }
                    throw new NotSupportedException("XPath boolean() function is not supported");

                case Ceiling:
                    if (args.Count == 1)
                    {
                        xpathFunc = new CeilingFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath ceiling() function");
                    }
                    break;

                case Compare:
                    if (args.Count == 2)
                    {
                        xpathFunc = new CompareFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath compare() function");
                    }
                    break;

                case Concat:
                    if (args.Count == 2)
                    {
                        xpathFunc = new ConcatFunction(args.First(), args.Last());
                    }
                    else if (args.Count > 2)
                    {
                        xpathFunc = new ConcatFunction(args);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath concat() function");
                    }
                    break;

                case Contains:
                    if (args.Count == 2)
                    {
                        xpathFunc = new ContainsFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath contains() function");
                    }
                    break;

                case DayFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new DayFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath day-from-dateTime() function");
                    }
                    break;

                case EncodeForURI:
                    if (args.Count == 1)
                    {
                        xpathFunc = new EncodeForUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath encode-for-uri() function");
                    }
                    break;

                case EndsWith:
                    if (args.Count == 2)
                    {
                        xpathFunc = new EndsWithFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath ends-with() function");
                    }
                    break;

                case EscapeHtmlURI:
                    if (args.Count == 1)
                    {
                        xpathFunc = new EscapeHtmlUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath escape-html-uri() function");
                    }
                    break;

                case False:
                    if (args.Count == 0)
                    {
                        xpathFunc = new ConstantTerm(new BooleanNode(null, false));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath false() function");
                    }
                    break;

                case Floor:
                    if (args.Count == 1)
                    {
                        xpathFunc = new FloorFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath floor() function");
                    }
                    break;

                case HoursFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new HoursFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath hours-from-dateTime() function");
                    }
                    break;

                case LowerCase:
                    if (args.Count == 1)
                    {
                        xpathFunc = new LowerCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath lower-case() function");
                    }
                    break;

                case Matches:
                    if (args.Count == 2)
                    {
                        xpathFunc = new Functions.Sparql.Boolean.RegexFunction(args.First(), args.Last());
                    }
                    else if (args.Count == 3)
                    {
                        xpathFunc = new Functions.Sparql.Boolean.RegexFunction(args.First(), args[1], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath matches() function");
                    }
                    break;

                case MinutesFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new MinutesFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath minutes-from-dateTime() function");
                    }
                    break;

                case MonthFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new MonthFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath month-from-dateTime() function");
                    }
                    break;

                case NormalizeSpace:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NormalizeSpaceFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                    }
                    break;

                case NormalizeUnicode:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NormalizeUnicodeFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new NormalizeUnicodeFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                    }
                    break;

                case Not:
                    if (args.Count == 1)
                    {
                        xpathFunc = new NotExpression(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath not() function");
                    }
                    break;

                case Replace:
                    if (args.Count == 3)
                    {
                        xpathFunc = new ReplaceFunction(args.First(), args[1], args.Last());
                    }
                    else if (args.Count == 4)
                    {
                        xpathFunc = new ReplaceFunction(args.First(), args[1], args[2], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath replace() function");
                    }
                    break;

                case Round:
                    if (args.Count == 1)
                    {
                        xpathFunc = new RoundFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath round() function");
                    }
                    break;

                case RoundHalfToEven:
                    if (args.Count == 1)
                    {
                        xpathFunc = new RoundHalfToEvenFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new RoundHalfToEvenFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath round-half-to-even() function");
                    }
                    break;

                case SecondsFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new SecondsFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath seconds-from-dateTime() function");
                    }
                    break;

                case StartsWith:
                    if (args.Count == 2)
                    {
                        xpathFunc = new StartsWithFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath starts-with() function");
                    }
                    break;

                case StringJoin:
                    if (args.Count == 1)
                    {
                        xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First()));
                    }
                    else if (args.Count == 2)
                    {
                        xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First(), args.Last()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath string-join() function");
                    }
                    break;

                case StringLength:
                    if (args.Count == 1)
                    {
                        xpathFunc = new StringLengthFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath string-length() function");
                    }
                    break;

                case Substring:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringFunction(args.First(), args.Last());
                    }
                    else if (args.Count == 3)
                    {
                        xpathFunc = new SubstringFunction(args.First(), args[1], args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring() function");
                    }
                    break;

                case SubstringAfter:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringAfterFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring-after() function");
                    }
                    break;

                case SubstringBefore:
                    if (args.Count == 2)
                    {
                        xpathFunc = new SubstringBeforeFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath substring-before() function");
                    }
                    break;

                case TimezoneFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new TimezoneFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath timezone-from-dateTime() function");
                    }
                    break;

                case Translate:
                    throw new NotSupportedException("XPath translate() function is not supported");

                case True:
                    if (args.Count == 0)
                    {
                        xpathFunc = new ConstantTerm(new BooleanNode(null, true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath true() function");
                    }
                    break;

                case UpperCase:
                    if (args.Count == 1)
                    {
                        xpathFunc = new UpperCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath upper-case() function");
                    }
                    break;

                case YearFromDateTime:
                    if (args.Count == 1)
                    {
                        xpathFunc = new YearFromDateTimeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the XPath year-from-dateTime() function");
                    }
                    break;
                }

                if (xpathFunc != null)
                {
                    expr = xpathFunc;
                    return(true);
                }
            }
            expr = null;
            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Tries to create a SPARQL Function expression if the function Uri correseponds to a supported SPARQL Function.
        /// </summary>
        /// <param name="u">Function Uri.</param>
        /// <param name="args">Function Arguments.</param>
        /// <param name="scalarArguments">Scalar Arguments.</param>
        /// <param name="expr">Generated Expression.</param>
        /// <returns>Whether an expression was successfully generated.</returns>
        public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <string, ISparqlExpression> scalarArguments, out ISparqlExpression expr)
        {
            String func = u.ToString();

            if (func.StartsWith(SparqlFunctionsNamespace))
            {
                func = func.Substring(SparqlFunctionsNamespace.Length);
                func = func.ToUpper();

                // If any Scalar Arguments are present then can't be a SPARQL Function UNLESS it is
                // a GROUP_CONCAT function and it has the SEPARATOR argument
                if (scalarArguments.Count > 0)
                {
                    if (func.Equals(SparqlSpecsHelper.SparqlKeywordGroupConcat) && scalarArguments.Count == 1 && scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator))
                    {
                        // OK
                    }
                    else
                    {
                        expr = null;
                        return(false);
                    }
                }

                // Q: Will there be special URIs for the DISTINCT modified forms of aggregates?

                ISparqlExpression sparqlFunc = null;
                switch (func)
                {
                case SparqlSpecsHelper.SparqlKeywordAbs:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AbsFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordAvg:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new AverageAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordBound:
                    if (args.Count == 1)
                    {
                        if (args[0] is VariableTerm)
                        {
                            sparqlFunc = new BoundFunction((VariableTerm)args[0]);
                        }
                        else
                        {
                            throw new RdfParseException("The SPARQL BOUND() function only operates over Variables");
                        }
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL BOUND() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordCeil:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new CeilFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL CEIL() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordCoalesce:
                    if (args.Count >= 1)
                    {
                        sparqlFunc = new CoalesceFunction(args);
                    }
                    else
                    {
                        throw new RdfParseException("The SPARQL COALESCE() function requires at least 1 argument");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordConcat:
                    if (args.Count >= 1)
                    {
                        sparqlFunc = new ConcatFunction(args);
                    }
                    else
                    {
                        throw new RdfParseException("The SPARQL CONCAT() function requires at least 1 argument");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordContains:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new ContainsFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL CONTAINS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordCount:
                    // Q: What will the URIs be for the special forms of COUNT?
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new CountAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL COUNT() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordDataType:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new DataTypeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL DATATYPE() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordDay:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new DayFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL DAY() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordEncodeForUri:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new EncodeForUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ENCODE_FOR_URI() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordFloor:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new FloorFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL FLOOR() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordGroupConcat:
                    if (args.Count == 1)
                    {
                        if (scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator))
                        {
                            sparqlFunc = new AggregateTerm(new GroupConcatAggregate(args.First(), scalarArguments[SparqlSpecsHelper.SparqlKeywordSeparator]));
                        }
                        else
                        {
                            sparqlFunc = new AggregateTerm(new GroupConcatAggregate(args.First()));
                        }
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL GROUP_CONCAT() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordHours:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new HoursFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL HOURS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIf:
                    if (args.Count == 3)
                    {
                        sparqlFunc = new IfElseFunction(args[0], args[1], args[2]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL IF() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIri:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL IRI() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIsBlank:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IsBlankFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ISBLANK() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIsIri:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IsIriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ISIRI() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIsLiteral:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IsLiteralFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ISLITERAL() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIsNumeric:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IsNumericFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ISNUMERIC() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordIsUri:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IsUriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ISURI() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordLang:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new LangFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL LANG() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordLangMatches:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new LangMatchesFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL LANGMATCHES() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordLCase:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new LCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL LCASE() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordMax:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new MaxAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL MAX() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordMD5:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new MD5HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL MD5() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordMin:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new MinAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL MIN() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordMinutes:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new MinutesFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL MINUTES() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordMonth:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new MonthFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL MONTH() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordNow:
                    if (args.Count == 0)
                    {
                        sparqlFunc = new NowFunction();
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordRegex:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new RegexFunction(args[0], args[1]);
                    }
                    else if (args.Count == 3)
                    {
                        sparqlFunc = new RegexFunction(args[0], args[1], args[2]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL REGEX() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordRound:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new RoundFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL ROUND() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSameTerm:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new SameTermFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SAMETERM() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSample:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new SampleAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSeconds:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new SecondsFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SECONDS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSha1:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new Sha1HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA1() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSha256:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new Sha256HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA256() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSha384:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new Sha384HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA384() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSha512:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new Sha512HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA512() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStr:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new StrFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STR() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStrDt:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new StrDtFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STRDT() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStrEnds:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new StrEndsFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STRENDS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStrLang:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new StrLangFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STRLANG() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStrLen:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new StrLenFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STRKEN() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordStrStarts:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new StrStartsFunction(args[0], args[1]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL STRSTARTS() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSubStr:
                    if (args.Count == 2)
                    {
                        sparqlFunc = new SubStrFunction(args[0], args[1]);
                    }
                    else if (args.Count == 3)
                    {
                        sparqlFunc = new SubStrFunction(args[0], args[1], args[2]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SUBSTR() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordSum:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new AggregateTerm(new SumAggregate(args.First()));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL SUM() aggregate");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordTimezone:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new TimezoneFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL TIMEZONE() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordTz:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new TZFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL TZ() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordUCase:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new UCaseFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL UCASE() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordUri:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new IriFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL URI() function");
                    }
                    break;

                case SparqlSpecsHelper.SparqlKeywordYear:
                    if (args.Count == 1)
                    {
                        sparqlFunc = new YearFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the SPARQL YEAR() function");
                    }
                    break;
                }

                if (sparqlFunc != null)
                {
                    expr = sparqlFunc;
                    return(true);
                }
            }
            expr = null;
            return(false);
        }
Esempio n. 6
0
        public void TestConcatRhsNotEmptyLhsNull()
        {
            var function = new ConcatFunction();

            Assert.That(function.Evaluate(null, "rhs"), Is.EqualTo("rhs"));
        }
Esempio n. 7
0
        public void TestConcatLhsNotEmptyRhsNull()
        {
            var function = new ConcatFunction();

            Assert.That(function.Evaluate("lhs", null), Is.EqualTo("lhs"));
        }
Esempio n. 8
0
        public void TestConcatBothNull()
        {
            var function = new ConcatFunction();

            Assert.That(function.Evaluate(null, null), Is.EqualTo(""));
        }
Esempio n. 9
0
        public void TestConcatBothEmpty()
        {
            var function = new ConcatFunction();

            Assert.That(function.Evaluate("", ""), Is.EqualTo(""));
        }
Esempio n. 10
0
        public void TesSomethingToConcat()
        {
            var function = new ConcatFunction();

            Assert.That(function.Evaluate("lhs", "rhs"), Is.EqualTo("lhsrhs"));
        }
Esempio n. 11
0
        private void AddDataTable(string table_name, string table_alias, IMapping mapping)
        {
            if (this.Tables.Contains(table_alias))
            {
                return;
            }

            var table = new DataTable(table_alias);
            var keys  = new List <DataColumn>();

            this.Tables.Add(table);
            var columns = table.Columns;
            var select  = (new SelectStatement()).From(table_name, "t0");

            table.ExtendedProperties["Storage"] = table_name;
            foreach (var item in mapping.Columns)
            {
                if (IgnoreMemoFields && item.IsMemo)
                {
                    continue;
                }

                var        pinfo = (PropertyInfo)item.Property;
                DataColumn column;
                if (pinfo.PropertyType.IsGenericType && pinfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    column = columns.Add(item.Name, pinfo.PropertyType.GetGenericArguments()[0]);
                }
                else if (pinfo.PropertyType.IsEnum)
                {
                    column = columns.Add(item.Name, typeof(string));
                }
                else
                {
                    column = columns.Add(item.Name, pinfo.PropertyType);
                }
                select.Column(new SqlColumnName("t0", item.ColumnName), item.Name);

                if (item.IsDbGenerated)
                {
                    column.AutoIncrement     = true;
                    column.AutoIncrementSeed = 1;
                    column.AutoIncrementStep = 1;
                    column.Unique            = true;
                }
                if (item.IsPrimaryKey)
                {
                    column.ExtendedProperties["PrimaryKey"] = true;
                    keys.Add(column);
                }
                column.AllowDBNull = item.IsNullable;
                //if (item.IsNullable && item.DefaultValue != null)
                //    column.DefaultValue = item.DefaultValue;

                if (!item.IsDbGenerated)
                {
                    if (item.DefaultFunctionValue == null)
                    {
                        column.DefaultValue = item.DefaultValue;
                    }
                    else
                    {
                        column.DefaultValue = item.DefaultFunctionValue();
                    }
                }

                column.ExtendedProperties["Storage"] = item.ColumnName;
                if (item.IsMemo)
                {
                    column.ExtendedProperties["Memo"] = true;
                }
            }
            table.ExtendedProperties["SelectStatement"] = select;

            if (keys.Count > 0)
            {
                table.PrimaryKey = keys.ToArray();
            }


            /* Procedimiento para añadir las columnas descriptivas de las columnas foreanas */
            var items = mapping.Associations.Where(x => x.GetType().Name == "MakeReferenceToMapping`2" || x.GetType().Name == "HasOneMapping`2");

            if (items.Count() == 0)
            {
                return;
            }

            //Debes poner las otras columnas con el nombre fisico alias el nombre de la propiedad
            int    t  = 1;
            string tp = "t" + t;

            foreach (var item in items)
            {
                var omapping = MappingFactory.GetMapping(item.OtherMappingType);

                // extra columns for criteria support
                for (var x = 0; x < omapping.Columns.Count; x++)
                {
                    var col = omapping.Columns[x];
                    select.Column(new SqlColumnName(tp, col.ColumnName), item.Name + "." + col.Name);
                }

                /* build joins */

                //for (var k = 0; k < item.ThisKeys.Count; k++ )
                //{
                var keyName      = item.ThisKeys[0];
                var otherKeyName = item.OtherKeys[0];
                var tcol         = mapping.Columns.Where(x => x.Name == keyName).Single();
                var ocol         = omapping.Columns.Where(x => x.Name == otherKeyName).Single();
                if (tcol.IsNullable || item.GetType().Name == "HasOneMapping`2")
                {
                    select.LeftJoin(omapping.TableName, tp, Condition.IsEqual(new SqlColumnName("t0", tcol.ColumnName), new SqlColumnName(tp, ocol.ColumnName)));
                }
                else
                {
                    select.InnerJoin(omapping.TableName, tp, Condition.IsEqual(new SqlColumnName("t0", tcol.ColumnName), new SqlColumnName(tp, ocol.ColumnName)));
                }
                //}
                /* build foreign row name */
                var lblCount = item.OtherLabels.Count;
                if (lblCount > 0)
                {
                    var lbl0 = item.OtherLabels[0];
                    //var colName = omapping.Columns.Where(x => x.Name == lbl0).Single().ColumnName;

                    ISqlExpression lblExpr;
                    if (lblCount == 1)
                    {
                        lblExpr = new SqlColumnName(item.Name + "." + item.OtherLabels[0]);
                    }
                    else
                    {
                        var lblConcat = new ConcatFunction(" | ");
                        foreach (var lbl in item.OtherLabels)
                        {
                            lblConcat.Append(new SqlColumnName(item.Name, lbl));
                        }
                        lblExpr = lblConcat;
                    }
                    var column = columns.Add(item.Name, typeof(string));
                    column.ExtendedProperties["SelectExpression"] = lblExpr;
                    column.ExtendedProperties["NonStorable"]      = true;
                }

                // Include OtherColumns in DataTable
                foreach (string ocn in item.OtherColumns)
                {
                    var column = columns.Add(omapping.EntityName + "." + ocn, typeof(string));
                    column.ExtendedProperties["NonStorable"] = true;
                }

                t++;
                tp = "t" + t;
            }
        }
Esempio n. 12
0
        private ISparqlExpression TryParseAggregateExpression(Queue<IToken> tokens)
        {
            if (this._syntax == SparqlQuerySyntax.Sparql_1_0) throw new RdfParseException("Aggregates are not permitted in SPARQL 1.0");

            IToken agg = tokens.Dequeue();
            ISparqlExpression aggExpr = null;
            bool distinct = false, all = false;
            bool scalarArgs = false;

            //Expect a Left Bracket next
            IToken next = tokens.Dequeue();
            if (next.TokenType != Token.LEFTBRACKET)
            {
                throw Error("Unexpected Token '" + next.GetType().ToString() + "', expected a Left Bracket after an Aggregate Keyword", next);
            }

            //Then a possible DISTINCT/ALL
            next = tokens.Peek();
            if (next.TokenType == Token.DISTINCT)
            {
                distinct = true;
                tokens.Dequeue();
            }
            next = tokens.Peek();
            if (next.TokenType == Token.ALL || next.TokenType == Token.MULTIPLY)
            {
                all = true;
                tokens.Dequeue();
            }
            next = tokens.Peek();

            //If we've seen an ALL then we need the closing bracket
            if (all && next.TokenType != Token.RIGHTBRACKET)
            {
                throw Error("Unexpected Token '" + next.GetType().ToString() + "', expected a Right Bracket after the * specifier in an aggregate to terminate the aggregate", next);
            }
            else if (all && agg.TokenType != Token.COUNT)
            {
                throw new RdfQueryException("Cannot use the * specifier in aggregates other than COUNT");
            }
            else if (!all)
            {
                //If it's not an all then we expect some expression(s)
                //Gather the Tokens and parse the Expression
                Queue<IToken> subtokens = new Queue<IToken>();

                int openBrackets = 1;
                List<ISparqlExpression> expressions = new List<ISparqlExpression>();

                while (openBrackets > 0)
                {
                    subtokens = new Queue<IToken>();
                    next = tokens.Dequeue();
                    do
                    {
                        if (next.TokenType == Token.LEFTBRACKET)
                        {
                            openBrackets++;
                        }
                        else if (next.TokenType == Token.RIGHTBRACKET)
                        {
                            openBrackets--;
                        }
                        else if (next.TokenType == Token.COMMA)
                        {
                            //If we see a comma when we only have 1 bracket open then it is separating argument expressions
                            if (openBrackets == 1)
                            {
                                break;
                            }
                        }
                        else if (next.TokenType == Token.SEMICOLON)
                        {
                            //If we see a semicolon when we only have 1 bracket open then this indicates we have scalar arguments in-use
                            if (openBrackets == 1)
                            {
                                scalarArgs = true;
                                break;
                            }
                        }

                        if (openBrackets > 0)
                        {
                            subtokens.Enqueue(next);
                            next = tokens.Dequeue();
                        }
                    } while (openBrackets > 0);

                    //Parse this expression and add to the list of expressions we're concatenating
                    expressions.Add(this.Parse(subtokens));

                    //Once we've hit the ; for the scalar arguments then we can stop looking for expressions
                    if (scalarArgs) break;

                    //If we've hit a , then openBrackets will still be one and we'll go around again looking for another expression
                    //Otherwise we've reached the end of the aggregate and there was no ; for scalar arguments
                }

                if (expressions.Count == 0) throw new RdfParseException("Aggregate must have at least one argument expression unless they are a COUNT(*)");
                if (agg.TokenType == Token.GROUPCONCAT)
                {
                    aggExpr = new ConcatFunction(expressions);
                }
                else
                {
                    if (expressions.Count > 1) throw new RdfParseException("The " + agg.Value + " aggregate does not support more than one argument expression");
                    aggExpr = expressions.First();
                }
            }
            else
            {
                tokens.Dequeue();
            }

            //If the aggregate uses scalar arguments then we'll parse them here
            Dictionary<String, ISparqlExpression> scalarArguments = new Dictionary<string, ISparqlExpression>();
            if (scalarArgs)
            {
                scalarArguments = this.TryParseScalarArguments(agg, tokens);
            }

            //Now we need to generate the actual expression
            switch (agg.TokenType)
            {
                case Token.AVG:
                    //AVG Aggregate
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new AverageAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new AverageAggregate(aggExpr, distinct));
                    }

                case Token.COUNT:
                    //COUNT Aggregate
                    if (all)
                    {
                        if (distinct)
                        {
                            return new AggregateTerm(new CountAllDistinctAggregate());
                        }
                        else
                        {
                            return new AggregateTerm(new CountAllAggregate());
                        }
                    }
                    else if (aggExpr is VariableTerm)
                    {
                        if (distinct)
                        {
                            return new AggregateTerm(new CountDistinctAggregate((VariableTerm)aggExpr));
                        }
                        else
                        {
                            return new AggregateTerm(new CountAggregate((VariableTerm)aggExpr));
                        }
                    }
                    else
                    {
                        if (distinct)
                        {
                            return new AggregateTerm(new CountDistinctAggregate(aggExpr));
                        }
                        else
                        {
                            return new AggregateTerm(new CountAggregate(aggExpr));
                        }
                    }
                case Token.GROUPCONCAT:
                    if (scalarArgs)
                    {
                        if (!scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator)) throw new RdfParseException("The GROUP_CONCAT aggregate has Scalar Arguments but does not have the expected SEPARATOR argument");
                        return new AggregateTerm(new GroupConcatAggregate(aggExpr, scalarArguments[SparqlSpecsHelper.SparqlKeywordSeparator], distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new GroupConcatAggregate(aggExpr, distinct));
                    }

                case Token.MAX:
                    //MAX Aggregate
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new MaxAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new MaxAggregate(aggExpr, distinct));
                    }

                case Token.MEDIAN:
                    //MEDIAN Aggregate
                    if (this._syntax != SparqlQuerySyntax.Extended) throw new RdfParseException("The MEDIAN aggregate is only supported when the Syntax is set to Extended.");
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new MedianAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new MedianAggregate(aggExpr, distinct));
                    }

                case Token.MIN:
                    //MIN Aggregate
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new MinAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new MinAggregate(aggExpr, distinct));
                    }

                case Token.MODE:
                    //MODE Aggregate
                    if (this._syntax != SparqlQuerySyntax.Extended) throw new RdfParseException("The MODE aggregate is only supported when the Syntax is set to Extended.");
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new ModeAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new ModeAggregate(aggExpr, distinct));
                    }

                case Token.NMAX:
                    //NMAX Aggregate
                    if (this._syntax != SparqlQuerySyntax.Extended) throw new RdfParseException("The NMAX (Numeric Maximum) aggregate is only supported when the Syntax is set to Extended.  To achieve an equivalent result in SPARQL 1.0/1.1 apply a FILTER to your query so the aggregated variable is only literals of the desired numeric type");
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new NumericMaxAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new NumericMaxAggregate(aggExpr, distinct));
                    }

                case Token.NMIN:
                    //NMIN Aggregate
                    if (this._syntax != SparqlQuerySyntax.Extended) throw new RdfParseException("The NMIN (Numeric Minimum) aggregate is only supported when the Syntax is set to Extended.  To achieve an equivalent result in SPARQL 1.0/1.1 apply a FILTER to your query so the aggregated variable is only literals of the desired numeric type");
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new NumericMinAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new NumericMinAggregate(aggExpr, distinct));
                    }

                case Token.SAMPLE:
                    //SAMPLE Aggregate
                    if (distinct) throw new RdfParseException("DISTINCT modifier is not valid for the SAMPLE aggregate");
                    return new AggregateTerm(new SampleAggregate(aggExpr));

                case Token.SUM:
                    //SUM Aggregate
                    if (aggExpr is VariableTerm)
                    {
                        return new AggregateTerm(new SumAggregate((VariableTerm)aggExpr, distinct));
                    }
                    else
                    {
                        return new AggregateTerm(new SumAggregate(aggExpr, distinct));
                    }

                default:
                    //Should have already handled this but have to have it to keep the compiler happy
                    throw Error("Cannot parse an Aggregate since '" + agg.GetType().ToString() + "' is not an Aggregate Keyword Token", agg);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Tries to create an XPath Function expression if the function Uri correseponds to a supported XPath Function
        /// </summary>
        /// <param name="u">Function Uri</param>
        /// <param name="args">Function Arguments</param>
        /// <param name="scalarArgs">Scalar Arguments</param>
        /// <param name="expr">Generated Expression</param>
        /// <returns>Whether an expression was successfully generated</returns>
        public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<String,ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            //If any Scalar Arguments are present then can't possibly be an XPath Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return false;
            }

            String func = u.ToString();
            if (func.StartsWith(XPathFunctionFactory.XPathFunctionsNamespace))
            {
                func = func.Substring(XPathFunctionFactory.XPathFunctionsNamespace.Length);
                ISparqlExpression xpathFunc = null;

                switch (func)
                {
                    case XPathFunctionFactory.Absolute:
                        if (args.Count == 1)
                        {
                            xpathFunc = new AbsFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath abs() function");
                        }
                        break;
                    case XPathFunctionFactory.AdjustDateTimeToTimezone:
                        throw new NotSupportedException("XPath adjust-dateTime-to-timezone() function is not supported");
                    case XPathFunctionFactory.Boolean:
                        if (args.Count == 1)
                        {
                            xpathFunc = new BooleanFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath boolean() function");
                        }
                        throw new NotSupportedException("XPath boolean() function is not supported");
                    case XPathFunctionFactory.Ceiling:
                        if (args.Count == 1)
                        {
                            xpathFunc = new CeilingFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath ceiling() function");
                        }
                        break;
                    case XPathFunctionFactory.Compare:
                        if (args.Count == 2)
                        {
                            xpathFunc = new CompareFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath compare() function");
                        }
                        break;
                    case XPathFunctionFactory.Concat:
                        if (args.Count == 2)
                        {
                            xpathFunc = new ConcatFunction(args.First(), args.Last());
                        }
                        else if (args.Count > 2)
                        {
                            xpathFunc = new ConcatFunction(args);
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath concat() function");
                        }
                        break;
                    case XPathFunctionFactory.Contains:
                        if (args.Count == 2)
                        {
                            xpathFunc = new ContainsFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath contains() function");
                        }
                        break;
                    case XPathFunctionFactory.DayFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new DayFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath day-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.EncodeForURI:
                        if (args.Count == 1)
                        {
                            xpathFunc = new EncodeForUriFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath encode-for-uri() function");
                        }
                        break;
                    case XPathFunctionFactory.EndsWith:
                        if (args.Count == 2)
                        {
                            xpathFunc = new EndsWithFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath ends-with() function");
                        }
                        break;
            #if !NO_WEB
                    case XPathFunctionFactory.EscapeHtmlURI:
                        if (args.Count == 1)
                        {
                            xpathFunc = new EscapeHtmlUriFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath escape-html-uri() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.False:
                        if (args.Count == 0)
                        {
                            xpathFunc = new ConstantTerm(new BooleanNode(null, false));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath false() function");
                        }
                        break;
                    case XPathFunctionFactory.Floor:
                        if (args.Count == 1)
                        {
                            xpathFunc = new FloorFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath floor() function");
                        }
                        break;
                    case XPathFunctionFactory.HoursFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new HoursFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath hours-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.LowerCase:
                        if (args.Count == 1)
                        {
                            xpathFunc = new LowerCaseFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath lower-case() function");
                        }
                        break;
                    case XPathFunctionFactory.Matches:
                        if (args.Count == 2)
                        {
                            xpathFunc = new VDS.RDF.Query.Expressions.Functions.Sparql.Boolean.RegexFunction(args.First(), args.Last());
                        }
                        else if (args.Count == 3)
                        {
                            xpathFunc = new VDS.RDF.Query.Expressions.Functions.Sparql.Boolean.RegexFunction(args.First(), args[1], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath matches() function");
                        }
                        break;
                    case XPathFunctionFactory.MinutesFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new MinutesFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath minutes-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.MonthFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new MonthFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath month-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.NormalizeSpace:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NormalizeSpaceFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                        }
                        break;
            #if !NO_NORM
                    case XPathFunctionFactory.NormalizeUnicode:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NormalizeUnicodeFunction(args.First());
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new NormalizeUnicodeFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.Not:
                        if (args.Count == 1)
                        {
                            xpathFunc = new NotExpression(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath not() function");
                        }
                        break;
                    case XPathFunctionFactory.Replace:
                        if (args.Count == 3)
                        {
                            xpathFunc = new ReplaceFunction(args.First(), args[1], args.Last());
                        }
                        else if (args.Count == 4)
                        {
                            xpathFunc = new ReplaceFunction(args.First(), args[1], args[2], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath replace() function");
                        }
                        break;
                    case XPathFunctionFactory.Round:
                        if (args.Count == 1)
                        {
                            xpathFunc = new RoundFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath round() function");
                        }
                        break;
            #if !SILVERLIGHT
                    case XPathFunctionFactory.RoundHalfToEven:
                        if (args.Count == 1)
                        {
                            xpathFunc = new RoundHalfToEvenFunction(args.First());
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new RoundHalfToEvenFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath round-half-to-even() function");
                        }
                        break;
            #endif
                    case XPathFunctionFactory.SecondsFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new SecondsFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath seconds-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.StartsWith:
                        if (args.Count == 2)
                        {
                            xpathFunc = new StartsWithFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath starts-with() function");
                        }
                        break;
                    case XPathFunctionFactory.StringJoin:
                        if (args.Count == 1)
                        {
                            xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First()));
                        }
                        else if (args.Count == 2)
                        {
                            xpathFunc = new AggregateTerm(new StringJoinAggregate(args.First(), args.Last()));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath string-join() function");
                        }
                        break;
                    case XPathFunctionFactory.StringLength:
                        if (args.Count == 1)
                        {
                            xpathFunc = new StringLengthFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath string-length() function");
                        }
                        break;
                    case XPathFunctionFactory.Substring:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringFunction(args.First(), args.Last());
                        }
                        else if (args.Count == 3)
                        {
                            xpathFunc = new SubstringFunction(args.First(), args[1], args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring() function");
                        }
                        break;
                    case XPathFunctionFactory.SubstringAfter:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringAfterFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring-after() function");
                        }
                        break;
                    case XPathFunctionFactory.SubstringBefore:
                        if (args.Count == 2)
                        {
                            xpathFunc = new SubstringBeforeFunction(args.First(), args.Last());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath substring-before() function");
                        }
                        break;
                    case XPathFunctionFactory.TimezoneFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new TimezoneFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath timezone-from-dateTime() function");
                        }
                        break;
                    case XPathFunctionFactory.Translate:
                        throw new NotSupportedException("XPath translate() function is not supported");
                    case XPathFunctionFactory.True:
                        if (args.Count == 0)
                        {
                            xpathFunc = new ConstantTerm(new BooleanNode(null, true));
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath true() function");
                        }
                        break;
                    case XPathFunctionFactory.UpperCase:
                        if (args.Count == 1)
                        {
                            xpathFunc = new UpperCaseFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath upper-case() function");
                        }
                        break;
                    case XPathFunctionFactory.YearFromDateTime:
                        if (args.Count == 1)
                        {
                            xpathFunc = new YearFromDateTimeFunction(args.First());
                        }
                        else
                        {
                            throw new RdfParseException("Incorrect number of arguments for the XPath year-from-dateTime() function");
                        }
                        break;
                }

                if (xpathFunc != null)
                {
                    expr = xpathFunc;
                    return true;
                }
            }
            expr = null;
            return false;
        }
        public object Evaluate(ConcatFunction funcExp, object data, IEnumerable <object> parameters = null)
        {
            var paramValues = _GetParameterValues(funcExp, data, parameters);

            return((object)paramValues.Aggregate((x, y) => (string)x + y));
        }
 public string ToSQL(ConcatFunction funcExp)
 {
     return(_FunctionToSQL(funcExp, "CONCAT"));
 }