You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2023/02/23 23:20:49 UTC

[GitHub] [arrow-rs] viirya commented on a diff in pull request #3749: ArrayData Enumeration for Primitive, Binary and UTF8

viirya commented on code in PR #3749:
URL: https://github.com/apache/arrow-rs/pull/3749#discussion_r1116319209


##########
arrow-data/src/data/bytes.rs:
##########
@@ -0,0 +1,288 @@
+// 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.
+
+use crate::data::types::{BytesType, OffsetType};
+use arrow_buffer::buffer::{NullBuffer, ScalarBuffer};
+use arrow_buffer::{ArrowNativeType, Buffer};
+use arrow_schema::DataType;
+use std::marker::PhantomData;
+
+mod private {
+    use super::*;
+
+    pub trait BytesSealed {
+        /// Create from bytes without performing any validation
+        ///
+        /// # Safety
+        ///
+        /// If `str`, `b` must be a valid UTF-8 sequence
+        unsafe fn from_bytes_unchecked(b: &[u8]) -> &Self;
+
+        /// Downcast [`ArrayDataBytes`] to `[ArrayDataBytesOffset`]
+        fn downcast_ref(data: &ArrayDataBytes) -> Option<&ArrayDataBytesOffset<Self>>
+        where
+            Self: Bytes;
+
+        /// Downcast [`ArrayDataBytes`] to `[ArrayDataBytesOffset`]
+        fn downcast(data: ArrayDataBytes) -> Option<ArrayDataBytesOffset<Self>>
+        where
+            Self: Bytes;
+
+        /// Cast [`ArrayDataBytesOffset`] to [`ArrayDataBytes`]
+        fn upcast(v: ArrayDataBytesOffset<Self>) -> ArrayDataBytes
+        where
+            Self: Bytes;
+    }
+
+    pub trait BytesOffsetSealed {
+        /// Downcast [`ArrayDataBytesOffset`] to `[BytesArrayData`]
+        fn downcast_ref<B: Bytes + ?Sized>(
+            data: &ArrayDataBytesOffset<B>,
+        ) -> Option<&BytesArrayData<Self, B>>
+        where
+            Self: BytesOffset;
+
+        /// Downcast [`ArrayDataBytesOffset`] to `[BytesArrayData`]
+        fn downcast<B: Bytes + ?Sized>(
+            data: ArrayDataBytesOffset<B>,
+        ) -> Option<BytesArrayData<Self, B>>
+        where
+            Self: BytesOffset;
+
+        /// Cast [`BytesArrayData`] to [`ArrayDataBytesOffset`]
+        fn upcast<B: Bytes + ?Sized>(
+            v: BytesArrayData<Self, B>,

Review Comment:
   What difference between `ArrayDataBytes` and `BytesArrayData`? Seems `ArrayDataBytes` is the data of bytes types (binary and str). But `BytesArrayData`?



##########
arrow-data/src/data/bytes.rs:
##########
@@ -0,0 +1,288 @@
+// 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.
+
+use crate::data::types::{BytesType, OffsetType};
+use arrow_buffer::buffer::{NullBuffer, ScalarBuffer};
+use arrow_buffer::{ArrowNativeType, Buffer};
+use arrow_schema::DataType;
+use std::marker::PhantomData;
+
+mod private {
+    use super::*;
+
+    pub trait BytesSealed {
+        /// Create from bytes without performing any validation
+        ///
+        /// # Safety
+        ///
+        /// If `str`, `b` must be a valid UTF-8 sequence
+        unsafe fn from_bytes_unchecked(b: &[u8]) -> &Self;
+
+        /// Downcast [`ArrayDataBytes`] to `[ArrayDataBytesOffset`]
+        fn downcast_ref(data: &ArrayDataBytes) -> Option<&ArrayDataBytesOffset<Self>>
+        where
+            Self: Bytes;
+
+        /// Downcast [`ArrayDataBytes`] to `[ArrayDataBytesOffset`]
+        fn downcast(data: ArrayDataBytes) -> Option<ArrayDataBytesOffset<Self>>
+        where
+            Self: Bytes;
+
+        /// Cast [`ArrayDataBytesOffset`] to [`ArrayDataBytes`]
+        fn upcast(v: ArrayDataBytesOffset<Self>) -> ArrayDataBytes
+        where
+            Self: Bytes;
+    }
+
+    pub trait BytesOffsetSealed {
+        /// Downcast [`ArrayDataBytesOffset`] to `[BytesArrayData`]
+        fn downcast_ref<B: Bytes + ?Sized>(
+            data: &ArrayDataBytesOffset<B>,
+        ) -> Option<&BytesArrayData<Self, B>>
+        where
+            Self: BytesOffset;
+
+        /// Downcast [`ArrayDataBytesOffset`] to `[BytesArrayData`]
+        fn downcast<B: Bytes + ?Sized>(
+            data: ArrayDataBytesOffset<B>,
+        ) -> Option<BytesArrayData<Self, B>>
+        where
+            Self: BytesOffset;
+
+        /// Cast [`BytesArrayData`] to [`ArrayDataBytesOffset`]
+        fn upcast<B: Bytes + ?Sized>(
+            v: BytesArrayData<Self, B>,

Review Comment:
   I got it after reading the enums and struct `BytesArrayData` below. Maybe a descriptive comment at the top helpful.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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