Skip to content

Commit 913cd76

Browse files
sgnkcpraveenbingo
authored andcommitted
ARROW-9897: [C++][Gandiva] Revert - to_date function
This reverts commit f1f4001. Closes #8555 from sagnikc-dremio/revert-to-date and squashes the following commits: 5c9f753 <Sagnik Chakraborty> ARROW-10429: Revert "ARROW-9897: Added to_date function" Authored-by: Sagnik Chakraborty <sagnikc@dremio.com> Signed-off-by: Praveen <praveen@dremio.com>
1 parent b4ddc96 commit 913cd76

5 files changed

Lines changed: 17 additions & 101 deletions

File tree

cpp/src/gandiva/function_registry_datetime.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717

1818
#include "gandiva/function_registry_datetime.h"
19-
2019
#include "gandiva/function_registry_common.h"
2120

2221
namespace gandiva {
@@ -57,12 +56,6 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
5756
kResultNullIfNull, "castVARCHAR_timestamp_int64",
5857
NativeFunction::kNeedsContext),
5958

60-
NativeFunction("to_date", {}, DataTypeVector{utf8(), utf8()}, date64(),
61-
kResultNullInternal, "gdv_fn_to_date_utf8_utf8",
62-
NativeFunction::kNeedsContext |
63-
NativeFunction::kNeedsFunctionHolder |
64-
NativeFunction::kCanReturnErrors),
65-
6659
NativeFunction("to_date", {}, DataTypeVector{utf8(), utf8(), int32()}, date64(),
6760
kResultNullInternal, "gdv_fn_to_date_utf8_utf8_int32",
6861
NativeFunction::kNeedsContext |

cpp/src/gandiva/gdv_function_stubs.cc

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ double gdv_fn_random_with_seed(int64_t ptr, int32_t seed, bool seed_validity) {
5050
return (*holder)();
5151
}
5252

53-
int64_t gdv_fn_to_date_utf8_utf8(int64_t context_ptr, int64_t holder_ptr,
54-
const char* data, int data_len, bool in1_validity,
55-
const char* pattern, int pattern_len, bool in2_validity,
56-
bool* out_valid) {
57-
gandiva::ExecutionContext* context =
58-
reinterpret_cast<gandiva::ExecutionContext*>(context_ptr);
59-
gandiva::ToDateHolder* holder = reinterpret_cast<gandiva::ToDateHolder*>(holder_ptr);
60-
return (*holder)(context, data, data_len, in1_validity, out_valid);
61-
}
62-
6353
int64_t gdv_fn_to_date_utf8_utf8_int32(int64_t context_ptr, int64_t holder_ptr,
6454
const char* data, int data_len, bool in1_validity,
6555
const char* pattern, int pattern_len,
@@ -229,21 +219,6 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
229219
types->i1_type() /*return_type*/, args,
230220
reinterpret_cast<void*>(gdv_fn_like_utf8_utf8));
231221

232-
// gdv_fn_to_date_utf8_utf8
233-
args = {types->i64_type(), // int64_t execution_context
234-
types->i64_type(), // int64_t holder_ptr
235-
types->i8_ptr_type(), // const char* data
236-
types->i32_type(), // int data_len
237-
types->i1_type(), // bool in1_validity
238-
types->i8_ptr_type(), // const char* pattern
239-
types->i32_type(), // int pattern_len
240-
types->i1_type(), // bool in2_validity
241-
types->ptr_type(types->i8_type())}; // bool* out_valid
242-
243-
engine->AddGlobalMappingForFunc("gdv_fn_to_date_utf8_utf8",
244-
types->i64_type() /*return_type*/, args,
245-
reinterpret_cast<void*>(gdv_fn_to_date_utf8_utf8));
246-
247222
// gdv_fn_to_date_utf8_utf8_int32
248223
args = {types->i64_type(), // int64_t execution_context
249224
types->i64_type(), // int64_t holder_ptr

cpp/src/gandiva/tests/projector_test.cc

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "gandiva/projector.h"
18+
#include <cmath>
1919

2020
#include <gtest/gtest.h>
2121

22-
#include <cmath>
23-
2422
#include "arrow/memory_pool.h"
25-
#include "gandiva/literal_holder.h"
26-
#include "gandiva/node.h"
23+
24+
#include "gandiva/projector.h"
2725
#include "gandiva/tests/test_util.h"
2826
#include "gandiva/tree_expr_builder.h"
2927

@@ -768,45 +766,4 @@ TEST_F(TestProjector, TestOffset) {
768766
EXPECT_ARROW_ARRAY_EQUALS(exp_sum, outputs.at(0));
769767
}
770768

771-
TEST_F(TestProjector, TestToDate) {
772-
// schema for input fields
773-
auto field0 = field("f0", arrow::utf8());
774-
auto field_node = std::make_shared<FieldNode>(field0);
775-
auto schema = arrow::schema({field0});
776-
777-
// output fields
778-
auto field_result = field("res", arrow::date64());
779-
780-
auto pattern_node =
781-
std::make_shared<LiteralNode>(arrow::utf8(), LiteralHolder("YYYY-MM-DD"), false);
782-
783-
// Build expression
784-
auto fn_node = TreeExprBuilder::MakeFunction("to_date", {field_node, pattern_node},
785-
arrow::date64());
786-
auto expr = TreeExprBuilder::MakeExpression(fn_node, field_result);
787-
788-
// Build a projector for the expressions.
789-
std::shared_ptr<Projector> projector;
790-
auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector);
791-
EXPECT_TRUE(status.ok());
792-
793-
// Create a row-batch with some sample data
794-
int num_records = 3;
795-
auto array0 =
796-
MakeArrowArrayUtf8({"1986-12-01", "2012-12-01", "invalid"}, {true, true, false});
797-
// expected output
798-
auto exp = MakeArrowArrayDate64({533779200000, 1354320000000, 0}, {true, true, false});
799-
800-
// prepare input record batch
801-
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0});
802-
803-
// Evaluate expression
804-
arrow::ArrayVector outputs;
805-
status = projector->Evaluate(*in_batch, pool_, &outputs);
806-
EXPECT_TRUE(status.ok());
807-
808-
// Validate results
809-
EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0));
810-
}
811-
812769
} // namespace gandiva

cpp/src/gandiva/tests/test_util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <memory>
2020
#include <utility>
2121
#include <vector>
22-
2322
#include "arrow/testing/gtest_util.h"
2423
#include "gandiva/arrow.h"
2524
#include "gandiva/configuration.h"
@@ -77,7 +76,6 @@ static inline ArrayPtr MakeArrowTypeArray(const std::shared_ptr<arrow::DataType>
7776
#define MakeArrowArrayUint64 MakeArrowArray<arrow::UInt64Type, uint64_t>
7877
#define MakeArrowArrayFloat32 MakeArrowArray<arrow::FloatType, float>
7978
#define MakeArrowArrayFloat64 MakeArrowArray<arrow::DoubleType, double>
80-
#define MakeArrowArrayDate64 MakeArrowArray<arrow::Date64Type, int64_t>
8179
#define MakeArrowArrayUtf8 MakeArrowArray<arrow::StringType, std::string>
8280
#define MakeArrowArrayBinary MakeArrowArray<arrow::BinaryType, std::string>
8381
#define MakeArrowArrayDecimal MakeArrowArray<arrow::Decimal128Type, arrow::Decimal128>

cpp/src/gandiva/to_date_holder.cc

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "gandiva/to_date_holder.h"
19-
2018
#include <algorithm>
2119
#include <string>
2220

2321
#include "arrow/util/value_parsing.h"
2422
#include "arrow/vendored/datetime.h"
23+
2524
#include "gandiva/date_utils.h"
2625
#include "gandiva/execution_context.h"
2726
#include "gandiva/node.h"
27+
#include "gandiva/to_date_holder.h"
2828

2929
namespace gandiva {
3030

3131
Status ToDateHolder::Make(const FunctionNode& node,
3232
std::shared_ptr<ToDateHolder>* holder) {
33-
if (node.children().size() != 2 && node.children().size() != 3) {
34-
return Status::Invalid("'to_date' function requires two or three parameters");
33+
if (node.children().size() != 3) {
34+
return Status::Invalid("'to_date' function requires three parameters");
3535
}
3636

3737
auto literal_pattern = dynamic_cast<LiteralNode*>(node.children().at(1).get());
@@ -47,25 +47,18 @@ Status ToDateHolder::Make(const FunctionNode& node,
4747
}
4848
auto pattern = arrow::util::get<std::string>(literal_pattern->holder());
4949

50-
int suppress_errors = 0;
51-
if (node.children().size() == 3) {
52-
auto literal_suppress_errors =
53-
dynamic_cast<LiteralNode*>(node.children().at(2).get());
54-
if (literal_pattern == nullptr) {
55-
return Status::Invalid(
56-
"The (optional) third parameter to 'to_date' function needs to an integer "
57-
"literal to indicate whether to suppress the error");
58-
}
59-
60-
literal_type = literal_suppress_errors->return_type()->id();
61-
if (literal_type != arrow::Type::INT32) {
62-
return Status::Invalid(
63-
"The (optional) third parameter to 'to_date' function needs to an integer "
64-
"literal to indicate whether to suppress the error");
65-
}
66-
suppress_errors = arrow::util::get<int>(literal_suppress_errors->holder());
50+
auto literal_suppress_errors = dynamic_cast<LiteralNode*>(node.children().at(2).get());
51+
if (literal_pattern == nullptr) {
52+
return Status::Invalid(
53+
"'to_date' function requires a int literal as the third parameter");
6754
}
6855

56+
literal_type = literal_suppress_errors->return_type()->id();
57+
if (literal_type != arrow::Type::INT32) {
58+
return Status::Invalid(
59+
"'to_date' function requires a int literal as the third parameter");
60+
}
61+
auto suppress_errors = arrow::util::get<int>(literal_suppress_errors->holder());
6962
return Make(pattern, suppress_errors, holder);
7063
}
7164

0 commit comments

Comments
 (0)