Uploaded image for project: 'Tajo'
  1. Tajo
  2. TAJO-342

Implement strpos(string, substring) function

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.8.0
    • Component/s: Function/UDF
    • Labels:
      None

      Description

      Function Definition

      int strpos(string text, substring text)
      

      Description

      This function finds the location of specified substring.

      • If string or substring is null, the result should be null.
      • If substring is '', the result should be 1.
      • If there is no matched substring, the result should be 0.
      • The result is one-based index.

      Example.

      hyunsik=> select strpos('tajo','jo');
       strpos 
      --------
            3
      (1 row)
      
      1. TAJO-342_2.patch
        9 kB
        Hyoungjun Kim
      2. TAJO-342.patch
        6 kB
        Hyoungjun Kim

        Activity

        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Tajo-trunk-postcommit #580 (See https://builds.apache.org/job/Tajo-trunk-postcommit/580/)
        TAJO-342: Implement strpos(string, substring) function. (hyoungjunkim via hyunsik) (hyunsik: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=e29b062d69315d24d75d121b53987e24e0451071)

        • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/StrPosb.java
        • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
        • CHANGES.txt
        • tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
        • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/StrPos.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Tajo-trunk-postcommit #580 (See https://builds.apache.org/job/Tajo-trunk-postcommit/580/ ) TAJO-342 : Implement strpos(string, substring) function. (hyoungjunkim via hyunsik) (hyunsik: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=e29b062d69315d24d75d121b53987e24e0451071 ) tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/StrPosb.java tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java CHANGES.txt tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/StrPos.java
        Hide
        hyunsik Hyunsik Choi added a comment -

        I've committed it to master. Thanks.

        Show
        hyunsik Hyunsik Choi added a comment - I've committed it to master. Thanks.
        Hide
        hjkim Hyoungjun Kim added a comment -

        In the new patch, Strpos function uses String.indexOf() method.
        And I added strposb() function which returns byte position.

        Show
        hjkim Hyoungjun Kim added a comment - In the new patch, Strpos function uses String.indexOf() method. And I added strposb() function which returns byte position.
        Hide
        hyunsik Hyunsik Choi added a comment -

        In many cases, dealing with characters as a binary array would be useful for users. So, I suggest you to rename the current function to strposb (with 'b' suffix) and to create a new function strpos that deals with data as characters.

        For other functions, we could use 'b' suffix for clearly specifying binary functions.

        Show
        hyunsik Hyunsik Choi added a comment - In many cases, dealing with characters as a binary array would be useful for users. So, I suggest you to rename the current function to strposb (with 'b' suffix) and to create a new function strpos that deals with data as characters. For other functions, we could use 'b' suffix for clearly specifying binary functions.
        Hide
        hyunsik Hyunsik Choi added a comment -

        The patch looks good for me.

        However, this implementation cannot evlauate multi-byte characters. For this, why don't you use just String::indexOf?

        Show
        hyunsik Hyunsik Choi added a comment - The patch looks good for me. However, this implementation cannot evlauate multi-byte characters. For this, why don't you use just String::indexOf?
        Hide
        hjkim Hyoungjun Kim added a comment -

        I implemented strpos.
        Please review this patch.

        Show
        hjkim Hyoungjun Kim added a comment - I implemented strpos. Please review this patch.

          People

          • Assignee:
            hjkim Hyoungjun Kim
            Reporter:
            hyunsik Hyunsik Choi
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development