(&self, args: ScalarFunctionArgs)
| 130 | } |
| 131 | |
| 132 | fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> { |
| 133 | let args = args.args; |
| 134 | if args.is_empty() { |
| 135 | return exec_err!("to_date function requires 1 or more arguments, got 0"); |
| 136 | } |
| 137 | |
| 138 | // validate that any args after the first one are Utf8 |
| 139 | if args.len() > 1 { |
| 140 | validate_data_types(&args, "to_date")?; |
| 141 | } |
| 142 | |
| 143 | match args[0].data_type() { |
| 144 | Null | Int32 | Int64 | Date32 | Date64 | Timestamp(_, _) => { |
| 145 | args[0].cast_to(&Date32, None) |
| 146 | } |
| 147 | UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 => { |
| 148 | // Arrow cast doesn't support direct casting of these types to date32 |
| 149 | // as it only supports Int32 and Int64. To work around that limitation, |
| 150 | // use cast_with_options to cast to Int32 and then cast the result of |
| 151 | // that to Date32. |
| 152 | match &args[0] { |
| 153 | ColumnarValue::Array(array) => { |
| 154 | Ok(ColumnarValue::Array(cast_with_options( |
| 155 | &cast_with_options(&array, &Int32, &DEFAULT_CAST_OPTIONS)?, |
| 156 | &Date32, |
| 157 | &DEFAULT_CAST_OPTIONS, |
| 158 | )?)) |
| 159 | } |
| 160 | ColumnarValue::Scalar(scalar) => { |
| 161 | let sv = |
| 162 | scalar.cast_to_with_options(&Int32, &DEFAULT_CAST_OPTIONS)?; |
| 163 | Ok(ColumnarValue::Scalar( |
| 164 | sv.cast_to_with_options(&Date32, &DEFAULT_CAST_OPTIONS)?, |
| 165 | )) |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | Float16 |
| 170 | | Float32 |
| 171 | | Float64 |
| 172 | | Decimal32(_, _) |
| 173 | | Decimal64(_, _) |
| 174 | | Decimal128(_, _) |
| 175 | | Decimal256(_, _) => { |
| 176 | // The only way this makes sense is to get the Int64 value of the float |
| 177 | // or decimal and then cast that to Date32. |
| 178 | args[0].cast_to(&Int64, None)?.cast_to(&Date32, None) |
| 179 | } |
| 180 | Utf8View | LargeUtf8 | Utf8 => self.to_date(&args), |
| 181 | other => { |
| 182 | exec_err!("Unsupported data type {} for function to_date", other) |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | fn documentation(&self) -> Option<&Documentation> { |
| 188 | self.doc() |
no test coverage detected