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

      text substr(string text, from int4 [, count int4])
      

      Description

      • It extracts substring (same as substring(string from from for count)).
      • If string is null, the result also should be null.
      • Note that from is one based index.
      • from can be negative integer.
      • count can be omitted. If then, all string after from will be returned.
      • count cannot be negative integer.
      • If count is 0, the result should be '' instead of null.

      Example and Sementic

      hyunsik=> select substr('abcdef', 3, 2);
       substr 
      --------
      cd
      
      (1 row)
      
      hyunsik=> select substr('abcdef',3) ;
       substr 
      --------
       cdef
      (1 row)
      
      hyunsik=> select substr('abcdef',1,1) ;
       substr 
      --------
       a
      
      (1 row)
      hyunsik=> select substr('abcdef',0,1) ;
       substr 
      --------
       
      (1 row)
      
      hyunsik=> select substr('abcdef',0,2) ;
       substr 
      --------
       a
      (1 row)
      
      
      1. TAJO-341.patch
        6 kB
        Hyoungjun Kim

        Issue Links

          Activity

          Hide
          hjkim Hyoungjun Kim added a comment -

          I implemented substr function and add testcase testSubstr() in TestStringOperatorsAndFunctions class.
          Please review this. Thank you.

          There is some issues.

          • TestStringOperatorsAndFunctions.testSubstr() has serval testcase which contains multi-bytes charset like korean.
          • If there is a minus value in function argument, next error occurred.
            select substr('abcdef', -1, 100) as col1
            org.apache.tajo.engine.parser.SQLSyntaxError: ERROR: syntax error at or near 'substr'
            LINE 1:7 select substr('abcdef', -1, 100) as col1
                                    ^^^^^^
            	at org.apache.tajo.engine.parser.SQLAnalyzer.parse(SQLAnalyzer.java:64)
            	at org.apache.tajo.engine.eval.ExprTestBase.getRawTargets(ExprTestBase.java:78)
            	at org.apache.tajo.engine.eval.ExprTestBase.testEval(ExprTestBase.java:123)
            	at org.apache.tajo.engine.eval.ExprTestBase.testSimpleEval(ExprTestBase.java:91)
            	at org.apache.tajo.engine.function.TestStringOperatorsAndFunctions.testSubstr(TestStringOperatorsAndFunctions.java:213)
            
          Show
          hjkim Hyoungjun Kim added a comment - I implemented substr function and add testcase testSubstr() in TestStringOperatorsAndFunctions class. Please review this. Thank you. There is some issues. TestStringOperatorsAndFunctions.testSubstr() has serval testcase which contains multi-bytes charset like korean. If there is a minus value in function argument, next error occurred. select substr('abcdef', -1, 100) as col1 org.apache.tajo.engine.parser.SQLSyntaxError: ERROR: syntax error at or near 'substr' LINE 1:7 select substr('abcdef', -1, 100) as col1 ^^^^^^ at org.apache.tajo.engine.parser.SQLAnalyzer.parse(SQLAnalyzer.java:64) at org.apache.tajo.engine.eval.ExprTestBase.getRawTargets(ExprTestBase.java:78) at org.apache.tajo.engine.eval.ExprTestBase.testEval(ExprTestBase.java:123) at org.apache.tajo.engine.eval.ExprTestBase.testSimpleEval(ExprTestBase.java:91) at org.apache.tajo.engine.function.TestStringOperatorsAndFunctions.testSubstr(TestStringOperatorsAndFunctions.java:213)
          Hide
          hyunsik Hyunsik Choi added a comment -

          +1 for this patch

          That error is caused by the parser problem. I'll create a separate issue for parse to deal negative integer and real values.

          Show
          hyunsik Hyunsik Choi added a comment - +1 for this patch That error is caused by the parser problem. I'll create a separate issue for parse to deal negative integer and real values.
          Hide
          hyunsik Hyunsik Choi added a comment -

          Now, I'll commit this patch. The error will be fixed after TAJO-344.

          Show
          hyunsik Hyunsik Choi added a comment - Now, I'll commit this patch. The error will be fixed after TAJO-344 .
          Hide
          hyunsik Hyunsik Choi added a comment -

          I've committed it to master branch. Thank you for your contributions.

          Show
          hyunsik Hyunsik Choi added a comment - I've committed it to master branch. Thank you for your contributions.
          Hide
          hudson Hudson added a comment -

          SUCCESS: Integrated in Tajo-trunk-postcommit #573 (See https://builds.apache.org/job/Tajo-trunk-postcommit/573/)
          TAJO-341: Implement substr function. (hyoungjunkim via hyunsik) (hyunsik: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=f9a6e9ca3dbfc7c518ad6f0d3b1c9fe3196b654e)

          • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Substr.java
          • tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
          • CHANGES.txt
          • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
          Show
          hudson Hudson added a comment - SUCCESS: Integrated in Tajo-trunk-postcommit #573 (See https://builds.apache.org/job/Tajo-trunk-postcommit/573/ ) TAJO-341 : Implement substr function. (hyoungjunkim via hyunsik) (hyunsik: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=f9a6e9ca3dbfc7c518ad6f0d3b1c9fe3196b654e ) tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Substr.java tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java CHANGES.txt tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java

            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