/Users/andrewlamb/Software/datafusion/datafusion/expr/src/type_coercion/mod.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | //! Type coercion rules for DataFusion |
19 | | //! |
20 | | //! Coercion is performed automatically by DataFusion when the types |
21 | | //! of arguments passed to a function or needed by operators do not |
22 | | //! exactly match the types required by that function / operator. In |
23 | | //! this case, DataFusion will attempt to *coerce* the arguments to |
24 | | //! types accepted by the function by inserting CAST operations. |
25 | | //! |
26 | | //! CAST operations added by coercion are lossless and never discard |
27 | | //! information. |
28 | | //! |
29 | | //! For example coercion from i32 -> i64 might be |
30 | | //! performed because all valid i32 values can be represented using an |
31 | | //! i64. However, i64 -> i32 is never performed as there are i64 |
32 | | //! values which can not be represented by i32 values. |
33 | | |
34 | | pub mod aggregates { |
35 | | pub use datafusion_expr_common::type_coercion::aggregates::*; |
36 | | } |
37 | | pub mod functions; |
38 | | pub mod other; |
39 | | |
40 | | pub use datafusion_expr_common::type_coercion::binary; |
41 | | |
42 | | use arrow::datatypes::DataType; |
43 | | /// Determine whether the given data type `dt` represents signed numeric values. |
44 | 0 | pub fn is_signed_numeric(dt: &DataType) -> bool { |
45 | 0 | matches!( |
46 | 0 | dt, |
47 | | DataType::Int8 |
48 | | | DataType::Int16 |
49 | | | DataType::Int32 |
50 | | | DataType::Int64 |
51 | | | DataType::Float16 |
52 | | | DataType::Float32 |
53 | | | DataType::Float64 |
54 | | | DataType::Decimal128(_, _) |
55 | | | DataType::Decimal256(_, _), |
56 | | ) |
57 | 0 | } |
58 | | |
59 | | /// Determine whether the given data type `dt` is `Null`. |
60 | 0 | pub fn is_null(dt: &DataType) -> bool { |
61 | 0 | *dt == DataType::Null |
62 | 0 | } |
63 | | |
64 | | /// Determine whether the given data type `dt` is a `Timestamp`. |
65 | 0 | pub fn is_timestamp(dt: &DataType) -> bool { |
66 | 0 | matches!(dt, DataType::Timestamp(_, _)) |
67 | 0 | } |
68 | | |
69 | | /// Determine whether the given data type 'dt' is a `Interval`. |
70 | 0 | pub fn is_interval(dt: &DataType) -> bool { |
71 | 0 | matches!(dt, DataType::Interval(_)) |
72 | 0 | } |
73 | | |
74 | | /// Determine whether the given data type `dt` is a `Date` or `Timestamp`. |
75 | 0 | pub fn is_datetime(dt: &DataType) -> bool { |
76 | 0 | matches!( |
77 | 0 | dt, |
78 | | DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, _) |
79 | | ) |
80 | 0 | } |
81 | | |
82 | | /// Determine whether the given data type `dt` is a `Utf8` or `LargeUtf8`. |
83 | 0 | pub fn is_utf8_or_large_utf8(dt: &DataType) -> bool { |
84 | 0 | matches!(dt, DataType::Utf8 | DataType::LargeUtf8) |
85 | 0 | } |
86 | | |
87 | | /// Determine whether the given data type `dt` is a `Decimal`. |
88 | 0 | pub fn is_decimal(dt: &DataType) -> bool { |
89 | 0 | matches!(dt, DataType::Decimal128(_, _) | DataType::Decimal256(_, _)) |
90 | 0 | } |