You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/05/06 18:06:12 UTC

[arrow-datafusion] branch master updated: fix 265, log should be log10, and add ln (#271)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new f7a7505  fix 265, log should be log10, and add ln (#271)
f7a7505 is described below

commit f7a7505e2ee52546fcb0ad6e5bf266fb6f0da033
Author: Jiayu Liu <Ji...@users.noreply.github.com>
AuthorDate: Fri May 7 02:06:03 2021 +0800

    fix 265, log should be log10, and add ln (#271)
---
 ballista/rust/core/proto/ballista.proto            | 23 +++++++++++-----------
 .../rust/core/src/serde/logical_plan/from_proto.rs |  5 +++--
 .../rust/core/src/serde/logical_plan/to_proto.rs   |  1 +
 datafusion/src/logical_plan/expr.rs                |  2 +-
 datafusion/src/physical_plan/functions.rs          |  9 +++++++--
 datafusion/src/physical_plan/math_expressions.rs   |  2 +-
 6 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/ballista/rust/core/proto/ballista.proto b/ballista/rust/core/proto/ballista.proto
index b6bc5d0..381221f 100644
--- a/ballista/rust/core/proto/ballista.proto
+++ b/ballista/rust/core/proto/ballista.proto
@@ -33,7 +33,7 @@ message LogicalExprNode {
   oneof ExprType {
     // column references
     string column_name = 1;
-    
+
     // alias
     AliasNode alias = 2;
 
@@ -42,15 +42,15 @@ message LogicalExprNode {
 
     // binary expressions
     BinaryExprNode binary_expr = 4;
-    
+
     // aggregate expressions
     AggregateExprNode aggregate_expr = 5;
-    
+
     // null checks
     IsNull is_null_expr = 6;
     IsNotNull is_not_null_expr = 7;
     Not not_expr = 8;
-    
+
     BetweenNode between = 9;
     CaseNode case_ = 10;
     CastNode cast = 11;
@@ -130,6 +130,7 @@ enum ScalarFunction {
   SHA256 = 30;
   SHA384 = 31;
   SHA512 = 32;
+  LN = 33;
 }
 
 message ScalarFunctionNode {
@@ -361,7 +362,7 @@ message CsvScanExecNode {
   bool has_header = 5;
   uint32 batch_size = 6;
   string delimiter = 7;
-  
+
   // partition filenames
   repeated string filename = 8;
 }
@@ -466,7 +467,7 @@ message Action {
     // Fetch a partition from an executor
     PartitionId fetch_partition = 3;
   }
-  
+
   // configuration settings
   repeated KeyValuePair settings = 100;
 }
@@ -742,10 +743,10 @@ message ScalarValue{
     }
 }
 
-// Contains all valid datafusion scalar type except for 
+// Contains all valid datafusion scalar type except for
 // List
 enum PrimitiveScalarType{
-    
+
     BOOL = 0;     // arrow::Type::BOOL
     UINT8 = 1;    // arrow::Type::UINT8
     INT8 = 2;     // arrow::Type::INT8
@@ -777,7 +778,7 @@ message ScalarListType{
     PrimitiveScalarType deepest_type = 2;
 }
 
-// Broke out into multiple message types so that type 
+// Broke out into multiple message types so that type
 // metadata did not need to be in separate message
 //All types that are of the empty message types contain no additional metadata
 // about the type
@@ -794,7 +795,7 @@ message ArrowType{
         EmptyMessage UINT64 =9;
         EmptyMessage INT64 =10 ;
         EmptyMessage FLOAT16 =11 ;
-        EmptyMessage FLOAT32 =12 ; 
+        EmptyMessage FLOAT32 =12 ;
         EmptyMessage FLOAT64 =13 ;
         EmptyMessage UTF8 =14 ;
         EmptyMessage LARGE_UTF8 = 32;
@@ -824,7 +825,7 @@ message ArrowType{
 
 //Useful for representing an empty enum variant in rust
 // E.G. enum example{One, Two(i32)}
-// maps to 
+// maps to
 // message example{
 //    oneof{
 //        EmptyMessage One = 1;
diff --git a/ballista/rust/core/src/serde/logical_plan/from_proto.rs b/ballista/rust/core/src/serde/logical_plan/from_proto.rs
index 18a85d2..ab7c55f 100644
--- a/ballista/rust/core/src/serde/logical_plan/from_proto.rs
+++ b/ballista/rust/core/src/serde/logical_plan/from_proto.rs
@@ -28,8 +28,8 @@ use crate::{convert_box_required, convert_required};
 
 use arrow::datatypes::{DataType, Field, Schema};
 use datafusion::logical_plan::{
-    abs, acos, asin, atan, ceil, cos, exp, floor, log10, log2, round, signum, sin, sqrt,
-    tan, trunc, Expr, JoinType, LogicalPlan, LogicalPlanBuilder, Operator,
+    abs, acos, asin, atan, ceil, cos, exp, floor, ln, log10, log2, round, signum, sin,
+    sqrt, tan, trunc, Expr, JoinType, LogicalPlan, LogicalPlanBuilder, Operator,
 };
 use datafusion::physical_plan::aggregates::AggregateFunction;
 use datafusion::physical_plan::csv::CsvReadOptions;
@@ -1013,6 +1013,7 @@ impl TryInto<Expr> for &protobuf::LogicalExprNode {
                     protobuf::ScalarFunction::Log2 => {
                         Ok(log2((&expr.expr[0]).try_into()?))
                     }
+                    protobuf::ScalarFunction::Ln => Ok(ln((&expr.expr[0]).try_into()?)),
                     protobuf::ScalarFunction::Log10 => {
                         Ok(log10((&expr.expr[0]).try_into()?))
                     }
diff --git a/ballista/rust/core/src/serde/logical_plan/to_proto.rs b/ballista/rust/core/src/serde/logical_plan/to_proto.rs
index 560578d..de4b86e 100644
--- a/ballista/rust/core/src/serde/logical_plan/to_proto.rs
+++ b/ballista/rust/core/src/serde/logical_plan/to_proto.rs
@@ -1200,6 +1200,7 @@ impl TryInto<protobuf::ScalarFunction> for &BuiltinScalarFunction {
             BuiltinScalarFunction::Atan => Ok(protobuf::ScalarFunction::Atan),
             BuiltinScalarFunction::Exp => Ok(protobuf::ScalarFunction::Exp),
             BuiltinScalarFunction::Log => Ok(protobuf::ScalarFunction::Log),
+            BuiltinScalarFunction::Ln => Ok(protobuf::ScalarFunction::Ln),
             BuiltinScalarFunction::Log10 => Ok(protobuf::ScalarFunction::Log10),
             BuiltinScalarFunction::Floor => Ok(protobuf::ScalarFunction::Floor),
             BuiltinScalarFunction::Ceil => Ok(protobuf::ScalarFunction::Ceil),
diff --git a/datafusion/src/logical_plan/expr.rs b/datafusion/src/logical_plan/expr.rs
index fa9b9e0..3365bf2 100644
--- a/datafusion/src/logical_plan/expr.rs
+++ b/datafusion/src/logical_plan/expr.rs
@@ -1086,9 +1086,9 @@ unary_scalar_expr!(Trunc, trunc);
 unary_scalar_expr!(Abs, abs);
 unary_scalar_expr!(Signum, signum);
 unary_scalar_expr!(Exp, exp);
-unary_scalar_expr!(Log, ln);
 unary_scalar_expr!(Log2, log2);
 unary_scalar_expr!(Log10, log10);
+unary_scalar_expr!(Ln, ln);
 
 // string functions
 unary_scalar_expr!(Ascii, ascii);
diff --git a/datafusion/src/physical_plan/functions.rs b/datafusion/src/physical_plan/functions.rs
index 56365fe..960d7c5 100644
--- a/datafusion/src/physical_plan/functions.rs
+++ b/datafusion/src/physical_plan/functions.rs
@@ -102,7 +102,9 @@ pub enum BuiltinScalarFunction {
     Exp,
     /// floor
     Floor,
-    /// log, also known as ln
+    /// ln, Natural logarithm
+    Ln,
+    /// log, same as log10
     Log,
     /// log10
     Log10,
@@ -222,6 +224,7 @@ impl FromStr for BuiltinScalarFunction {
             "cos" => BuiltinScalarFunction::Cos,
             "exp" => BuiltinScalarFunction::Exp,
             "floor" => BuiltinScalarFunction::Floor,
+            "ln" => BuiltinScalarFunction::Ln,
             "log" => BuiltinScalarFunction::Log,
             "log10" => BuiltinScalarFunction::Log10,
             "log2" => BuiltinScalarFunction::Log2,
@@ -633,6 +636,7 @@ pub fn return_type(
         | BuiltinScalarFunction::Exp
         | BuiltinScalarFunction::Floor
         | BuiltinScalarFunction::Log
+        | BuiltinScalarFunction::Ln
         | BuiltinScalarFunction::Log10
         | BuiltinScalarFunction::Log2
         | BuiltinScalarFunction::Round
@@ -721,7 +725,8 @@ pub fn create_physical_expr(
         BuiltinScalarFunction::Cos => math_expressions::cos,
         BuiltinScalarFunction::Exp => math_expressions::exp,
         BuiltinScalarFunction::Floor => math_expressions::floor,
-        BuiltinScalarFunction::Log => math_expressions::ln,
+        BuiltinScalarFunction::Log => math_expressions::log10,
+        BuiltinScalarFunction::Ln => math_expressions::ln,
         BuiltinScalarFunction::Log10 => math_expressions::log10,
         BuiltinScalarFunction::Log2 => math_expressions::log2,
         BuiltinScalarFunction::Round => math_expressions::round,
diff --git a/datafusion/src/physical_plan/math_expressions.rs b/datafusion/src/physical_plan/math_expressions.rs
index 382a15f..72b4f10 100644
--- a/datafusion/src/physical_plan/math_expressions.rs
+++ b/datafusion/src/physical_plan/math_expressions.rs
@@ -113,6 +113,6 @@ math_unary_function!("trunc", trunc);
 math_unary_function!("abs", abs);
 math_unary_function!("signum", signum);
 math_unary_function!("exp", exp);
-math_unary_function!("log", ln);
+math_unary_function!("ln", ln);
 math_unary_function!("log2", log2);
 math_unary_function!("log10", log10);