You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/10/08 16:24:00 UTC

[GitHub] [arrow] nevi-me commented on a change in pull request #8400: ARROW-10236: [Rust][DataFusion] Unify type casting logic in DataFusion

nevi-me commented on a change in pull request #8400:
URL: https://github.com/apache/arrow/pull/8400#discussion_r501850814



##########
File path: rust/datafusion/src/physical_plan/type_casting.rs
##########
@@ -0,0 +1,218 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! This module provides a way of checking what type casts are
+//! supported at planning time for DataFusion. Since DataFusion uses
+//! the Arrow `cast` compute kernel, the supported casts are the same
+//! as the Arrow casts.
+//!
+//! The rules in this module are designed to be redundant with the
+//! rules in the Arrow `cast` kernel. The redundancy is needed so that
+//! DataFusion can generate an error at plan time rather than during
+//! execution (which could happen many hours after execution starts,
+//! when the query finally reaches that point)
+//!
+
+use arrow::datatypes::*;
+
+/// Return true if a value of type `from_type` can be cast into a
+/// value of `to_type`. Note that such as cast may be lossy. For
+/// lossless type conversions, see the `type_coercion` module
+///
+/// See the module level documentation for more detail on casting
+pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
+    use self::DataType::*;
+    if from_type == to_type {
+        return true;
+    }
+
+    // Note this is meant to mirror the structure in arrow/src/compute/kernels/cast.rs
+    match (from_type, to_type) {

Review comment:
       I was also going to suggest if we move `can_cast_types` to Arrow




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org