Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-4249

SUBSTR with starting location less than 1

    Details

      Description

      select ?sub ?sub2 ?sub3 WHERE

      { BIND ( SUBSTR('123', -1, 2) as ?sub ). BIND ( SUBSTR('123', 0, 2) as ?sub2 ). BIND ( SUBSTR('123', 1, 2) as ?sub3 ). }

      returns

      sub sub2 sub3
      12 12 12

      where XPath implementations return '', '1'and '12' cfr Xalan and Saxon.

      See also https://www.w3.org/TR/xpath/
      where specification gives as an example: substring("12345", 0, 3) returns "12"

        Activity

        Hide
        beebs Brad Bebee added a comment -

        igorkim Could you please take a look at this one?

        Show
        beebs Brad Bebee added a comment - igorkim Could you please take a look at this one?
        Hide
        igorkim igorkim added a comment -

        There is a check for negative values for starting position in com.bigdata.rdf.internal.constraints.SubstrBOp.get(IBindingSet), it overrides negative values with value 1.

                // Negative values and zero are treated as ONE.
                final int start = Math.max(1,
                        (int) Math.round(asLiteral(startArg).doubleValue()));
        

        xpath definition of substr function differs from java lang substiring which does not allow negative starting points, but SubstrBOp could be changed to follow xpath definition.
        I'll provide a PR for that.

        Show
        igorkim igorkim added a comment - There is a check for negative values for starting position in com.bigdata.rdf.internal.constraints.SubstrBOp.get(IBindingSet), it overrides negative values with value 1. // Negative values and zero are treated as ONE. final int start = Math .max(1, ( int ) Math .round(asLiteral(startArg).doubleValue())); xpath definition of substr function differs from java lang substiring which does not allow negative starting points, but SubstrBOp could be changed to follow xpath definition. I'll provide a PR for that.
        Hide
        natan.cox Natan Cox added a comment -

        Sounds like a great plan!

        For reference "The substr function corresponds to the XPath fn:substring function and returns a literal of the same kind (simple literal, literal with language tag, xsd:string typed literal) as the source input parameter but with a lexical form formed from the substring of the lexcial form of the source." (from https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr)

        Show
        natan.cox Natan Cox added a comment - Sounds like a great plan! For reference "The substr function corresponds to the XPath fn:substring function and returns a literal of the same kind (simple literal, literal with language tag, xsd:string typed literal) as the source input parameter but with a lexical form formed from the substring of the lexcial form of the source." (from https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr )
        Hide
        igorkim igorkim added a comment -

        Fixed SubstrBOp.
        PR: https://github.com/blazegraph/database/pull/36

        Brad Bebee, please, review and run CI tests at your convenience.

        Show
        igorkim igorkim added a comment - Fixed SubstrBOp. PR: https://github.com/blazegraph/database/pull/36 Brad Bebee , please, review and run CI tests at your convenience.

          People

          • Assignee:
            igorkim igorkim
            Reporter:
            natan.cox Natan Cox
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: