| 29 | namespace gandiva { |
| 30 | |
| 31 | Result<std::shared_ptr<ToDateHolder>> ToDateHolder::Make(const FunctionNode& node) { |
| 32 | if (node.children().size() != 2 && node.children().size() != 3) { |
| 33 | return Status::Invalid("'to_date' function requires two or three parameters"); |
| 34 | } |
| 35 | |
| 36 | auto literal_pattern = dynamic_cast<LiteralNode*>(node.children().at(1).get()); |
| 37 | if (literal_pattern == nullptr) { |
| 38 | return Status::Invalid( |
| 39 | "'to_date' function requires a literal as the second parameter"); |
| 40 | } |
| 41 | |
| 42 | auto literal_type = literal_pattern->return_type()->id(); |
| 43 | if (literal_type != arrow::Type::STRING && literal_type != arrow::Type::BINARY) { |
| 44 | return Status::Invalid( |
| 45 | "'to_date' function requires a string literal as the second parameter"); |
| 46 | } |
| 47 | auto pattern = std::get<std::string>(literal_pattern->holder()); |
| 48 | |
| 49 | int suppress_errors = 0; |
| 50 | if (node.children().size() == 3) { |
| 51 | auto literal_suppress_errors = |
| 52 | dynamic_cast<LiteralNode*>(node.children().at(2).get()); |
| 53 | if (literal_suppress_errors == nullptr) { |
| 54 | return Status::Invalid( |
| 55 | "The (optional) third parameter to 'to_date' function needs to an integer " |
| 56 | "literal to indicate whether to suppress the error"); |
| 57 | } |
| 58 | |
| 59 | literal_type = literal_suppress_errors->return_type()->id(); |
| 60 | if (literal_type != arrow::Type::INT32) { |
| 61 | return Status::Invalid( |
| 62 | "The (optional) third parameter to 'to_date' function needs to an integer " |
| 63 | "literal to indicate whether to suppress the error"); |
| 64 | } |
| 65 | suppress_errors = std::get<int>(literal_suppress_errors->holder()); |
| 66 | } |
| 67 | |
| 68 | return Make(pattern, suppress_errors); |
| 69 | } |
| 70 | |
| 71 | Result<std::shared_ptr<ToDateHolder>> ToDateHolder::Make(const std::string& sql_pattern, |
| 72 | int32_t suppress_errors) { |