You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2016/11/30 23:31:41 UTC

[1/3] incubator-trafodion git commit: Implement LOG() function for any base

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 833f8a904 -> c1fadffc6


Implement LOG() function for any base


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/1f9071ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/1f9071ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/1f9071ae

Branch: refs/heads/master
Commit: 1f9071ae82ee63e6f16bddd091d3fcce1057583f
Parents: 664a2bb
Author: ryzuo <jo...@gmail.com>
Authored: Fri Nov 25 18:30:26 2016 +0000
Committer: ryzuo <jo...@gmail.com>
Committed: Mon Nov 28 08:41:08 2016 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_math_func.cpp | 19 +++++++++++++++++--
 core/sql/parser/sqlparser.y    | 13 +++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1f9071ae/core/sql/exp/exp_math_func.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_math_func.cpp b/core/sql/exp/exp_math_func.cpp
index c5209fd..c477c53 100644
--- a/core/sql/exp/exp_math_func.cpp
+++ b/core/sql/exp/exp_math_func.cpp
@@ -51,6 +51,7 @@
 #define MathLog(op, err) log(op)
 #define MathLog10(op, err) log10(op)
 #define MathLog2(op, err) log2(op)
+#define MathLogX(op1, op2, err) (log(op2)/log(op1))
 #define MathModf(op, err) modf(op)
 #define MathPow(op1, op2, err) pow(op1, op2)
 //extern double MathPow(double Base, double Power, short &err);
@@ -337,8 +338,22 @@ ex_expr::exp_return_type ExFunctionMath::eval(char *op_data[],
 	  **diagsArea << DgString0("LOG");
 	  return ex_expr::EXPR_ERROR;
 	}
-      
-      *(double *)op_data[0] = MathLog(*(double *)op_data[1], err);
+
+      if(3 == getNumOperands())
+    {
+        double power = *(double *)op_data[2];
+        double radix = *(double *)op_data[1];
+        if(power <= 0 || 1 == radix)
+        {
+            ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+            **diagsArea << DgString0("LOG");
+            return ex_expr::EXPR_ERROR;
+        }
+        
+        *(double *)op_data[0] = MathLogX(radix, power, err);
+    }
+    else  
+        *(double *)op_data[0] = MathLog(*(double *)op_data[1], err);
       break;
 
     case ITM_LOG10:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1f9071ae/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 11f3067..2ce9f76 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -9600,6 +9600,16 @@ math_function :
 	   $$ = new (PARSERHEAP()) BitOperFunc(ITM_BITEXTRACT, $3, $5, $7);
 	 }
 
+       | TOK_LOG '(' value_expression ')'
+         {
+	   $$ = new (PARSERHEAP()) MathFunc(ITM_LOG, $3);
+	 }
+
+       | TOK_LOG '(' value_expression ',' value_expression ')'
+         {
+	   $$ = new (PARSERHEAP()) MathFunc(ITM_LOG, $3, $5);
+	 }
+
        | math_func_0_operand '(' ')'
          {
 	   $$ = new (PARSERHEAP()) MathFunc($1);
@@ -9631,7 +9641,6 @@ math_func_1_operand :
            |  TOK_DEGREES {$$ = ITM_DEGREES;}
            |  TOK_EXP {$$ = ITM_EXP;}
            |  TOK_FLOOR {$$ = ITM_FLOOR;}
-           |  TOK_LOG {$$ = ITM_LOG;}
            |  TOK_LOG10 {$$ = ITM_LOG10;}
            |  TOK_LOG2 {$$ = ITM_LOG2;}
            |  TOK_RADIANS {$$ = ITM_RADIANS;}
@@ -9645,7 +9654,7 @@ math_func_1_operand :
 /* type operator_type */
 math_func_2_operands :
               TOK_ATAN2 {$$ = ITM_ATAN2;}
-	   |  TOK_POWER {$$ = ITM_POWER;}
+           |  TOK_POWER {$$ = ITM_POWER;}
 //           |  TOK_TRUNCATE {$$ = ITM_SCALE_TRUNC;}
 
 


[3/3] incubator-trafodion git commit: Merge Fix for [TRAFODION - 2345] Support LOG() function of any base

Posted by li...@apache.org.
Merge Fix for [TRAFODION - 2345] Support LOG() function of any base


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/c1fadffc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/c1fadffc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/c1fadffc

Branch: refs/heads/master
Commit: c1fadffc628518295edb8d5aef35eb6e3de5395f
Parents: 833f8a9 df1f430
Author: Liu Ming <li...@apache.org>
Authored: Wed Nov 30 23:31:15 2016 +0000
Committer: Liu Ming <li...@apache.org>
Committed: Wed Nov 30 23:31:15 2016 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_math_func.cpp              | 19 +++++++++--
 core/sql/parser/sqlparser.y                 | 13 ++++++--
 core/sql/regress/compGeneral/EXPECTED006.SB | 42 ++++++++++++++++++++++++
 core/sql/regress/compGeneral/TEST006        |  7 ++++
 4 files changed, 77 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c1fadffc/core/sql/parser/sqlparser.y
----------------------------------------------------------------------


[2/3] incubator-trafodion git commit: Add tests for builtin function LOG() of any base

Posted by li...@apache.org.
Add tests for builtin function LOG() of any base


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/df1f430a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/df1f430a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/df1f430a

Branch: refs/heads/master
Commit: df1f430ae2aaaa22fda7931b938be267096bebba
Parents: 1f9071a
Author: ryzuo <jo...@gmail.com>
Authored: Mon Nov 28 08:39:45 2016 +0000
Committer: ryzuo <jo...@gmail.com>
Committed: Tue Nov 29 05:25:56 2016 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_math_func.cpp              | 18 +++++-----
 core/sql/regress/compGeneral/EXPECTED006.SB | 42 ++++++++++++++++++++++++
 core/sql/regress/compGeneral/TEST006        |  7 ++++
 3 files changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/df1f430a/core/sql/exp/exp_math_func.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_math_func.cpp b/core/sql/exp/exp_math_func.cpp
index c477c53..6978430 100644
--- a/core/sql/exp/exp_math_func.cpp
+++ b/core/sql/exp/exp_math_func.cpp
@@ -340,19 +340,19 @@ ex_expr::exp_return_type ExFunctionMath::eval(char *op_data[],
 	}
 
       if(3 == getNumOperands())
-    {
-        double power = *(double *)op_data[2];
-        double radix = *(double *)op_data[1];
-        if(power <= 0 || 1 == radix)
-        {
+	{
+          double power = *(double *)op_data[2];
+          double radix = *(double *)op_data[1];
+          if(power <= 0 || radix <= 0 || 1 == radix)
+          {
             ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
             **diagsArea << DgString0("LOG");
             return ex_expr::EXPR_ERROR;
+          }
+
+          *(double *)op_data[0] = MathLogX(radix, power, err);
         }
-        
-        *(double *)op_data[0] = MathLogX(radix, power, err);
-    }
-    else  
+      else
         *(double *)op_data[0] = MathLog(*(double *)op_data[1], err);
       break;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/df1f430a/core/sql/regress/compGeneral/EXPECTED006.SB
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/EXPECTED006.SB b/core/sql/regress/compGeneral/EXPECTED006.SB
index 741b6dc..58bfdfe 100644
--- a/core/sql/regress/compGeneral/EXPECTED006.SB
+++ b/core/sql/regress/compGeneral/EXPECTED006.SB
@@ -1825,4 +1825,46 @@ bc0050f3ff7a540c74a42664c53a7f9fd485622374a43eb4a62cd84e48f483237bed50f6562f8c6e
 18091a172d94aae1ae530ced02bde7f022229f446348f5d3b36989c2e6fd59f5252c7a7f8ecb71a74cb724448243ff71651f87aed155aee7340fad1b02567b60
 
 --- 1 row(s) selected.
+>>
+>>-- Test LOG() for any radix with 2 parameters
+>>select log(2,8) from dual;
+
+(EXPR)                   
+-------------------------
+
+ 3.00000000000000000E+000
+
+--- 1 row(s) selected.
+>>select log(5,10) from dual;
+
+(EXPR)                   
+-------------------------
+
+ 1.43067655807339328E+000
+
+--- 1 row(s) selected.
+>>select log(10,100) from dual;
+
+(EXPR)                   
+-------------------------
+
+ 2.00000000000000000E+000
+
+--- 1 row(s) selected.
+>>select log(2) from dual;
+
+(EXPR)                   
+-------------------------
+
+ 6.93147180559945344E-001
+
+--- 1 row(s) selected.
+>>select log(2.71828) from dual;
+
+(EXPR)                   
+-------------------------
+
+ 9.99999327347282176E-001
+
+--- 1 row(s) selected.
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/df1f430a/core/sql/regress/compGeneral/TEST006
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/TEST006 b/core/sql/regress/compGeneral/TEST006
index edee936..2c9e2d1 100644
--- a/core/sql/regress/compGeneral/TEST006
+++ b/core/sql/regress/compGeneral/TEST006
@@ -679,3 +679,10 @@ select sha2('the original data', 224) from dual;
 select sha2('the original data', 256) from dual;
 select sha2('the original data', 384) from dual;
 select sha2('the original data', 512) from dual;
+
+-- Test LOG() for any radix with 2 parameters
+select log(2,8) from dual;
+select log(5,10) from dual;
+select log(10,100) from dual;
+select log(2) from dual;
+select log(2.71828) from dual;