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

Implement sin( x ) - returns the sine of x (x is in radians)

    Details

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

      Description

      sin function returns the sine of x (x is in radians)

      double sin(double x)
      

      Only double type implementation is OK, or INT also needs?

      1. TAJO-339.patch
        4 kB
        Jae Young Lee

        Activity

        Hide
        hyunsik Hyunsik Choi added a comment -

        Only double type may be enough now. Tajo needs to support auto type casting mechanism for expressions and UDF system. sin(x:int) function will be supported with auto type casting mechanism.

        If you want to assign this issue to yourself, feel free to tell us.

        Show
        hyunsik Hyunsik Choi added a comment - Only double type may be enough now. Tajo needs to support auto type casting mechanism for expressions and UDF system. sin(x:int) function will be supported with auto type casting mechanism. If you want to assign this issue to yourself, feel free to tell us.
        Hide
        goodljy Jae Young Lee added a comment -

        Please assign it to me.

        Show
        goodljy Jae Young Lee added a comment - Please assign it to me.
        Hide
        hyunsik Hyunsik Choi added a comment -

        I just assigned this issue to you. Thank you for your participation.

        Show
        hyunsik Hyunsik Choi added a comment - I just assigned this issue to you. Thank you for your participation.
        Hide
        goodljy Jae Young Lee added a comment -

        Thanks a lot.

        Show
        goodljy Jae Young Lee added a comment - Thanks a lot.
        Hide
        goodljy Jae Young Lee added a comment -

        I've uploaded the patch for this issue.
        Please review.

        Show
        goodljy Jae Young Lee added a comment - I've uploaded the patch for this issue. Please review.
        Hide
        sirpkt Keuntae Park added a comment -

        This patch looks good to me.
        'mvn clean install' is successfully finished.

        However, there is commented code in TestMathFunctions.Java

          @Test
          public void testSin() throws IOException {
            testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"});
            testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.6442176781200616"});
            testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320391032457895"});
        //    testSimpleEval("select sin(-0.5) as col1 ", new String[]{"-0.479425538604203"});
        
            Schema schema = new Schema();
            schema.addColumn("col1", FLOAT8);
            schema.addColumn("col2", FLOAT8);
            schema.addColumn("col3", FLOAT8);
        
            testEval(schema, "table1", "1.0, 0.2, 0.1", "select sin(col1 + col2 + col3) from table1",
               new String[]{"0.963558185417193"});
        }
        

        And, when I removed the above comment and 'mvn clean install',
        I got following error during test:

        Test set: org.apache.tajo.engine.function.TestMathFunctions
        -------------------------------------------------------------------------------
        Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.12 sec <<< FAILURE!
        testSin(org.apache.tajo.engine.function.TestMathFunctions)  Time elapsed: 0.01 sec  <<< ERROR!
        org.apache.tajo.engine.parser.SQLSyntaxError: ERROR: syntax error at or near 'sin'
        LINE 1:7 select sin(-0.5) 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.TestMathFunctions.testSin(TestMathFunctions.java:89)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
            at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
            at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
            at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
            at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
            at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
            at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
            at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
            at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
            at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
            at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
            at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
            at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
            at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
            at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
            at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
            at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
        

        I'm not sure the exact reason but I think that SQL parser may not handle negative number properly in sin() function.

        Does anybody have an idea about the above error?

        Show
        sirpkt Keuntae Park added a comment - This patch looks good to me. 'mvn clean install' is successfully finished. However, there is commented code in TestMathFunctions.Java @Test public void testSin() throws IOException { testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"}); testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.6442176781200616"}); testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320391032457895"}); // testSimpleEval("select sin(-0.5) as col1 ", new String[]{"-0.479425538604203"}); Schema schema = new Schema(); schema.addColumn("col1", FLOAT8); schema.addColumn("col2", FLOAT8); schema.addColumn("col3", FLOAT8); testEval(schema, "table1", "1.0, 0.2, 0.1", "select sin(col1 + col2 + col3) from table1", new String[]{"0.963558185417193"}); } And, when I removed the above comment and 'mvn clean install', I got following error during test: Test set: org.apache.tajo.engine.function.TestMathFunctions ------------------------------------------------------------------------------- Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.12 sec <<< FAILURE! testSin(org.apache.tajo.engine.function.TestMathFunctions) Time elapsed: 0.01 sec <<< ERROR! org.apache.tajo.engine.parser.SQLSyntaxError: ERROR: syntax error at or near 'sin' LINE 1:7 select sin(-0.5) 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.TestMathFunctions.testSin(TestMathFunctions.java:89) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) I'm not sure the exact reason but I think that SQL parser may not handle negative number properly in sin() function. Does anybody have an idea about the above error?
        Hide
        charsyam DaeMyung Kang added a comment -

        This patch looks good to me.

        Keuntae Park it is because of minus value parsing problem of tajo.
        so you can just ignore it.

        Show
        charsyam DaeMyung Kang added a comment - This patch looks good to me. Keuntae Park it is because of minus value parsing problem of tajo. so you can just ignore it.
        Hide
        blrunner Jaehwa Jung added a comment -

        +1.
        I've committed it to the master branch.

        Show
        blrunner Jaehwa Jung added a comment - +1. I've committed it to the master branch.
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Tajo-trunk-postcommit #584 (See https://builds.apache.org/job/Tajo-trunk-postcommit/584/)
        TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee via jaehwa) (jhjung: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=2659cda4a88d074a7664babc39ac6ec1719778eb)

        • tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
        • tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.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 #584 (See https://builds.apache.org/job/Tajo-trunk-postcommit/584/ ) TAJO-339 : Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee via jaehwa) (jhjung: https://git-wip-us.apache.org/repos/asf?p=incubator-tajo.git&a=commit&h=2659cda4a88d074a7664babc39ac6ec1719778eb ) tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.java CHANGES.txt tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java

          People

          • Assignee:
            goodljy Jae Young Lee
            Reporter:
            goodljy Jae Young Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development