You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pr...@apache.org on 2020/11/04 08:40:16 UTC

[arrow] branch master updated: ARROW-9897: [C++][Gandiva] Revert - to_date function

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 913cd76  ARROW-9897: [C++][Gandiva] Revert - to_date function
913cd76 is described below

commit 913cd7612aebd235eaa35bf8b344448e281b2cbe
Author: Sagnik Chakraborty <sa...@dremio.com>
AuthorDate: Wed Nov 4 14:09:22 2020 +0530

    ARROW-9897: [C++][Gandiva] Revert - to_date function
    
    This reverts commit f1f4001660a634c311a1580160823bc645806273.
    
    Closes #8555 from sagnikc-dremio/revert-to-date and squashes the following commits:
    
    5c9f75325 <Sagnik Chakraborty> ARROW-10429:  Revert "ARROW-9897:  Added to_date function"
    
    Authored-by: Sagnik Chakraborty <sa...@dremio.com>
    Signed-off-by: Praveen <pr...@dremio.com>
---
 cpp/src/gandiva/function_registry_datetime.cc |  7 ----
 cpp/src/gandiva/gdv_function_stubs.cc         | 25 --------------
 cpp/src/gandiva/tests/projector_test.cc       | 49 ++-------------------------
 cpp/src/gandiva/tests/test_util.h             |  2 --
 cpp/src/gandiva/to_date_holder.cc             | 35 ++++++++-----------
 5 files changed, 17 insertions(+), 101 deletions(-)

diff --git a/cpp/src/gandiva/function_registry_datetime.cc b/cpp/src/gandiva/function_registry_datetime.cc
index 0688970..cd4ae00 100644
--- a/cpp/src/gandiva/function_registry_datetime.cc
+++ b/cpp/src/gandiva/function_registry_datetime.cc
@@ -16,7 +16,6 @@
 // under the License.
 
 #include "gandiva/function_registry_datetime.h"
-
 #include "gandiva/function_registry_common.h"
 
 namespace gandiva {
@@ -57,12 +56,6 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
                      kResultNullIfNull, "castVARCHAR_timestamp_int64",
                      NativeFunction::kNeedsContext),
 
-      NativeFunction("to_date", {}, DataTypeVector{utf8(), utf8()}, date64(),
-                     kResultNullInternal, "gdv_fn_to_date_utf8_utf8",
-                     NativeFunction::kNeedsContext |
-                         NativeFunction::kNeedsFunctionHolder |
-                         NativeFunction::kCanReturnErrors),
-
       NativeFunction("to_date", {}, DataTypeVector{utf8(), utf8(), int32()}, date64(),
                      kResultNullInternal, "gdv_fn_to_date_utf8_utf8_int32",
                      NativeFunction::kNeedsContext |
diff --git a/cpp/src/gandiva/gdv_function_stubs.cc b/cpp/src/gandiva/gdv_function_stubs.cc
index 53253b0..71e6d72 100644
--- a/cpp/src/gandiva/gdv_function_stubs.cc
+++ b/cpp/src/gandiva/gdv_function_stubs.cc
@@ -50,16 +50,6 @@ double gdv_fn_random_with_seed(int64_t ptr, int32_t seed, bool seed_validity) {
   return (*holder)();
 }
 
-int64_t gdv_fn_to_date_utf8_utf8(int64_t context_ptr, int64_t holder_ptr,
-                                 const char* data, int data_len, bool in1_validity,
-                                 const char* pattern, int pattern_len, bool in2_validity,
-                                 bool* out_valid) {
-  gandiva::ExecutionContext* context =
-      reinterpret_cast<gandiva::ExecutionContext*>(context_ptr);
-  gandiva::ToDateHolder* holder = reinterpret_cast<gandiva::ToDateHolder*>(holder_ptr);
-  return (*holder)(context, data, data_len, in1_validity, out_valid);
-}
-
 int64_t gdv_fn_to_date_utf8_utf8_int32(int64_t context_ptr, int64_t holder_ptr,
                                        const char* data, int data_len, bool in1_validity,
                                        const char* pattern, int pattern_len,
@@ -229,21 +219,6 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
                                   types->i1_type() /*return_type*/, args,
                                   reinterpret_cast<void*>(gdv_fn_like_utf8_utf8));
 
-  // gdv_fn_to_date_utf8_utf8
-  args = {types->i64_type(),                   // int64_t execution_context
-          types->i64_type(),                   // int64_t holder_ptr
-          types->i8_ptr_type(),                // const char* data
-          types->i32_type(),                   // int data_len
-          types->i1_type(),                    // bool in1_validity
-          types->i8_ptr_type(),                // const char* pattern
-          types->i32_type(),                   // int pattern_len
-          types->i1_type(),                    // bool in2_validity
-          types->ptr_type(types->i8_type())};  // bool* out_valid
-
-  engine->AddGlobalMappingForFunc("gdv_fn_to_date_utf8_utf8",
-                                  types->i64_type() /*return_type*/, args,
-                                  reinterpret_cast<void*>(gdv_fn_to_date_utf8_utf8));
-
   // gdv_fn_to_date_utf8_utf8_int32
   args = {types->i64_type(),                   // int64_t execution_context
           types->i64_type(),                   // int64_t holder_ptr
diff --git a/cpp/src/gandiva/tests/projector_test.cc b/cpp/src/gandiva/tests/projector_test.cc
index 1ac04cd..b55093e 100644
--- a/cpp/src/gandiva/tests/projector_test.cc
+++ b/cpp/src/gandiva/tests/projector_test.cc
@@ -15,15 +15,13 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "gandiva/projector.h"
+#include <cmath>
 
 #include <gtest/gtest.h>
 
-#include <cmath>
-
 #include "arrow/memory_pool.h"
-#include "gandiva/literal_holder.h"
-#include "gandiva/node.h"
+
+#include "gandiva/projector.h"
 #include "gandiva/tests/test_util.h"
 #include "gandiva/tree_expr_builder.h"
 
@@ -768,45 +766,4 @@ TEST_F(TestProjector, TestOffset) {
   EXPECT_ARROW_ARRAY_EQUALS(exp_sum, outputs.at(0));
 }
 
-TEST_F(TestProjector, TestToDate) {
-  // schema for input fields
-  auto field0 = field("f0", arrow::utf8());
-  auto field_node = std::make_shared<FieldNode>(field0);
-  auto schema = arrow::schema({field0});
-
-  // output fields
-  auto field_result = field("res", arrow::date64());
-
-  auto pattern_node =
-      std::make_shared<LiteralNode>(arrow::utf8(), LiteralHolder("YYYY-MM-DD"), false);
-
-  // Build expression
-  auto fn_node = TreeExprBuilder::MakeFunction("to_date", {field_node, pattern_node},
-                                               arrow::date64());
-  auto expr = TreeExprBuilder::MakeExpression(fn_node, field_result);
-
-  // Build a projector for the expressions.
-  std::shared_ptr<Projector> projector;
-  auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector);
-  EXPECT_TRUE(status.ok());
-
-  // Create a row-batch with some sample data
-  int num_records = 3;
-  auto array0 =
-      MakeArrowArrayUtf8({"1986-12-01", "2012-12-01", "invalid"}, {true, true, false});
-  // expected output
-  auto exp = MakeArrowArrayDate64({533779200000, 1354320000000, 0}, {true, true, false});
-
-  // prepare input record batch
-  auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0});
-
-  // Evaluate expression
-  arrow::ArrayVector outputs;
-  status = projector->Evaluate(*in_batch, pool_, &outputs);
-  EXPECT_TRUE(status.ok());
-
-  // Validate results
-  EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0));
-}
-
 }  // namespace gandiva
diff --git a/cpp/src/gandiva/tests/test_util.h b/cpp/src/gandiva/tests/test_util.h
index 5427043..da2cd69 100644
--- a/cpp/src/gandiva/tests/test_util.h
+++ b/cpp/src/gandiva/tests/test_util.h
@@ -19,7 +19,6 @@
 #include <memory>
 #include <utility>
 #include <vector>
-
 #include "arrow/testing/gtest_util.h"
 #include "gandiva/arrow.h"
 #include "gandiva/configuration.h"
@@ -77,7 +76,6 @@ static inline ArrayPtr MakeArrowTypeArray(const std::shared_ptr<arrow::DataType>
 #define MakeArrowArrayUint64 MakeArrowArray<arrow::UInt64Type, uint64_t>
 #define MakeArrowArrayFloat32 MakeArrowArray<arrow::FloatType, float>
 #define MakeArrowArrayFloat64 MakeArrowArray<arrow::DoubleType, double>
-#define MakeArrowArrayDate64 MakeArrowArray<arrow::Date64Type, int64_t>
 #define MakeArrowArrayUtf8 MakeArrowArray<arrow::StringType, std::string>
 #define MakeArrowArrayBinary MakeArrowArray<arrow::BinaryType, std::string>
 #define MakeArrowArrayDecimal MakeArrowArray<arrow::Decimal128Type, arrow::Decimal128>
diff --git a/cpp/src/gandiva/to_date_holder.cc b/cpp/src/gandiva/to_date_holder.cc
index 1b7e286..1a75f57 100644
--- a/cpp/src/gandiva/to_date_holder.cc
+++ b/cpp/src/gandiva/to_date_holder.cc
@@ -15,23 +15,23 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "gandiva/to_date_holder.h"
-
 #include <algorithm>
 #include <string>
 
 #include "arrow/util/value_parsing.h"
 #include "arrow/vendored/datetime.h"
+
 #include "gandiva/date_utils.h"
 #include "gandiva/execution_context.h"
 #include "gandiva/node.h"
+#include "gandiva/to_date_holder.h"
 
 namespace gandiva {
 
 Status ToDateHolder::Make(const FunctionNode& node,
                           std::shared_ptr<ToDateHolder>* holder) {
-  if (node.children().size() != 2 && node.children().size() != 3) {
-    return Status::Invalid("'to_date' function requires two or three parameters");
+  if (node.children().size() != 3) {
+    return Status::Invalid("'to_date' function requires three parameters");
   }
 
   auto literal_pattern = dynamic_cast<LiteralNode*>(node.children().at(1).get());
@@ -47,25 +47,18 @@ Status ToDateHolder::Make(const FunctionNode& node,
   }
   auto pattern = arrow::util::get<std::string>(literal_pattern->holder());
 
-  int suppress_errors = 0;
-  if (node.children().size() == 3) {
-    auto literal_suppress_errors =
-        dynamic_cast<LiteralNode*>(node.children().at(2).get());
-    if (literal_pattern == nullptr) {
-      return Status::Invalid(
-          "The (optional) third parameter to 'to_date' function needs to an integer "
-          "literal to indicate whether to suppress the error");
-    }
-
-    literal_type = literal_suppress_errors->return_type()->id();
-    if (literal_type != arrow::Type::INT32) {
-      return Status::Invalid(
-          "The (optional) third parameter to 'to_date' function needs to an integer "
-          "literal to indicate whether to suppress the error");
-    }
-    suppress_errors = arrow::util::get<int>(literal_suppress_errors->holder());
+  auto literal_suppress_errors = dynamic_cast<LiteralNode*>(node.children().at(2).get());
+  if (literal_pattern == nullptr) {
+    return Status::Invalid(
+        "'to_date' function requires a int literal as the third parameter");
   }
 
+  literal_type = literal_suppress_errors->return_type()->id();
+  if (literal_type != arrow::Type::INT32) {
+    return Status::Invalid(
+        "'to_date' function requires a int literal as the third parameter");
+  }
+  auto suppress_errors = arrow::util::get<int>(literal_suppress_errors->holder());
   return Make(pattern, suppress_errors, holder);
 }