You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/03/16 18:40:04 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3877: Rework Strongly Typed ArrayData Abstractions

tustvold opened a new pull request, #3877:
URL: https://github.com/apache/arrow-rs/pull/3877

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Part of #1799 
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   See https://github.com/apache/arrow-rs/issues/1799#issuecomment-1472437840
   
   In particular:
   
   * Moves `from_raw` to `From<ArrayData>`
   * Moves `layout` to `From<_> for ArrayData`
   * Removes `ArrayDataLayout`
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3877:
URL: https://github.com/apache/arrow-rs/pull/3877#discussion_r1139226257


##########
arrow-data/src/data/run.rs:
##########
@@ -83,87 +49,12 @@ run_end!(i16, Int16);
 run_end!(i32, Int32);
 run_end!(i64, Int64);
 
-/// Applies op to each variant of [`ArrayDataRun`]
-macro_rules! run_op {
-    ($array:ident, $op:block) => {
-        match $array {
-            ArrayDataRun::Int16($array) => $op
-            ArrayDataRun::Int32($array) => $op
-            ArrayDataRun::Int64($array) => $op
-        }
-    };
-}
-
-/// An enumeration of the types of [`RunArrayData`]
-#[derive(Debug, Clone)]
-pub enum ArrayDataRun {
-    Int16(RunArrayData<i16>),
-    Int32(RunArrayData<i32>),
-    Int64(RunArrayData<i64>),
-}
-
-impl ArrayDataRun {
-    /// Downcast this [`ArrayDataRun`] to the corresponding [`RunArrayData`]
-    pub fn downcast_ref<E: RunEnd>(&self) -> Option<&RunArrayData<E>> {
-        <E as private::RunEndSealed>::downcast_ref(self)
-    }
-
-    /// Downcast this [`ArrayDataRun`] to the corresponding [`RunArrayData`]
-    pub fn downcast<E: RunEnd>(self) -> Option<RunArrayData<E>> {
-        <E as private::RunEndSealed>::downcast(self)
-    }
-
-    /// Returns the values of this [`ArrayDataRun`]
-    #[inline]
-    pub fn values(&self) -> &ArrayData {
-        let s = self;
-        run_op!(s, { s.values() })
-    }
-
-    /// Returns a zero-copy slice of this array
-    pub fn slice(&self, offset: usize, len: usize) -> Self {
-        let s = self;
-        run_op!(s, { s.slice(offset, len).into() })
-    }
-
-    /// Returns an [`ArrayDataLayout`] representation of this
-    pub(crate) fn layout(&self) -> ArrayDataLayout<'_> {
-        let s = self;
-        run_op!(s, { s.layout() })
-    }
-
-    /// Creates a new [`ArrayDataRun`] from raw buffers
-    ///
-    /// # Safety
-    ///
-    /// See [`RunArrayData::new_unchecked`]
-    pub(crate) unsafe fn from_raw(builder: ArrayDataBuilder, run: RunEndType) -> Self {
-        use RunEndType::*;
-        match run {
-            Int16 => Self::Int16(RunArrayData::from_raw(builder)),
-            Int32 => Self::Int32(RunArrayData::from_raw(builder)),
-            Int64 => Self::Int64(RunArrayData::from_raw(builder)),
-        }
-    }
-}
-
-impl<E: RunEnd> From<RunArrayData<E>> for ArrayDataRun {
-    fn from(value: RunArrayData<E>) -> Self {
-        <E as private::RunEndSealed>::upcast(value)
-    }
-}
-
 /// ArrayData for [run-end encoded arrays](https://arrow.apache.org/docs/format/Columnar.html#run-end-encoded-layout)
 #[derive(Debug, Clone)]
 pub struct RunArrayData<E: RunEnd> {
     data_type: DataType,
     run_ends: RunEndBuffer<E>,
-    /// The children of this RunArrayData:
-    /// 1: the run ends
-    /// 2: the values
-    ///
-    /// We store an array so that a slice can be returned in [`RunArrayData::layout`]
-    children: Box<[ArrayData; 2]>,

Review Comment:
   We no longer need this hack :tada:



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


[GitHub] [arrow-rs] tustvold commented on pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #3877:
URL: https://github.com/apache/arrow-rs/pull/3877#issuecomment-1472892321

   Thinking about this a bit more, it is unclear what value add these abstractions have over the existing arrays... There may be more simplification possible... :thinking: 


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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3877:
URL: https://github.com/apache/arrow-rs/pull/3877#discussion_r1139226872


##########
arrow-data/src/data/dictionary.rs:
##########
@@ -86,100 +48,13 @@ dictionary!(u16, UInt16);
 dictionary!(u32, UInt32);
 dictionary!(u64, UInt64);
 
-/// Applies op to each variant of [`ArrayDataDictionary`]
-macro_rules! dictionary_op {
-    ($array:ident, $op:block) => {
-        match $array {
-            ArrayDataDictionary::Int8($array) => $op
-            ArrayDataDictionary::Int16($array) => $op
-            ArrayDataDictionary::Int32($array) => $op
-            ArrayDataDictionary::Int64($array) => $op
-            ArrayDataDictionary::UInt8($array) => $op
-            ArrayDataDictionary::UInt16($array) => $op
-            ArrayDataDictionary::UInt32($array) => $op
-            ArrayDataDictionary::UInt64($array) => $op
-        }
-    };
-}
-
-/// An enumeration of the types of [`DictionaryArrayData`]
-#[derive(Debug, Clone)]
-pub enum ArrayDataDictionary {
-    Int8(DictionaryArrayData<i8>),
-    Int16(DictionaryArrayData<i16>),
-    Int32(DictionaryArrayData<i32>),
-    Int64(DictionaryArrayData<i64>),
-    UInt8(DictionaryArrayData<u8>),
-    UInt16(DictionaryArrayData<u16>),
-    UInt32(DictionaryArrayData<u32>),
-    UInt64(DictionaryArrayData<u64>),
-}
-
-impl ArrayDataDictionary {
-    /// Downcast this [`ArrayDataDictionary`] to the corresponding [`DictionaryArrayData`]
-    pub fn downcast_ref<K: DictionaryKey>(&self) -> Option<&DictionaryArrayData<K>> {
-        K::downcast_ref(self)
-    }
-
-    /// Downcast this [`ArrayDataDictionary`] to the corresponding [`DictionaryArrayData`]
-    pub fn downcast<K: DictionaryKey>(self) -> Option<DictionaryArrayData<K>> {
-        K::downcast(self)
-    }
-
-    /// Returns the values of this dictionary
-    pub fn values(&self) -> &ArrayData {
-        let s = self;
-        dictionary_op!(s, { s.values() })
-    }
-
-    /// Returns a zero-copy slice of this array
-    pub fn slice(&self, offset: usize, len: usize) -> Self {
-        let s = self;
-        dictionary_op!(s, { s.slice(offset, len).into() })
-    }
-
-    /// Returns an [`ArrayDataLayout`] representation of this
-    pub(crate) fn layout(&self) -> ArrayDataLayout<'_> {
-        let s = self;
-        dictionary_op!(s, { s.layout() })
-    }
-
-    /// Creates a new [`ArrayDataDictionary`] from raw buffers
-    ///
-    /// # Safety
-    ///
-    /// See [`DictionaryArrayData::new_unchecked`]
-    pub(crate) unsafe fn from_raw(
-        builder: ArrayDataBuilder,
-        key: DictionaryKeyType,
-    ) -> Self {
-        use DictionaryKeyType::*;
-        match key {
-            Int8 => Self::Int8(DictionaryArrayData::from_raw(builder)),
-            Int16 => Self::Int16(DictionaryArrayData::from_raw(builder)),
-            Int32 => Self::Int32(DictionaryArrayData::from_raw(builder)),
-            Int64 => Self::Int64(DictionaryArrayData::from_raw(builder)),
-            UInt8 => Self::UInt8(DictionaryArrayData::from_raw(builder)),
-            UInt16 => Self::UInt16(DictionaryArrayData::from_raw(builder)),
-            UInt32 => Self::UInt32(DictionaryArrayData::from_raw(builder)),
-            UInt64 => Self::UInt64(DictionaryArrayData::from_raw(builder)),
-        }
-    }
-}
-
-impl<K: DictionaryKey> From<DictionaryArrayData<K>> for ArrayDataDictionary {
-    fn from(value: DictionaryArrayData<K>) -> Self {
-        K::upcast(value)
-    }
-}
-
 /// ArrayData for [dictionary arrays](https://arrow.apache.org/docs/format/Columnar.html#dictionary-encoded-layout)
 #[derive(Debug, Clone)]
 pub struct DictionaryArrayData<K: DictionaryKey> {
     data_type: DataType,
     nulls: Option<NullBuffer>,
     keys: ScalarBuffer<K>,
-    values: Box<ArrayData>,
+    values: ArrayData,

Review Comment:
   We no longer need to Box children, as not intending to use within an ArrayData enumeration



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


[GitHub] [arrow-rs] tustvold commented on pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #3877:
URL: https://github.com/apache/arrow-rs/pull/3877#issuecomment-1472786369

   Realised these need to check the DataType when converting from ArrayData, will fix tomorrow


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


[GitHub] [arrow-rs] tustvold commented on pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #3877:
URL: https://github.com/apache/arrow-rs/pull/3877#issuecomment-1474217111

   Closing in favor of #3880


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


[GitHub] [arrow-rs] tustvold closed pull request #3877: Rework Strongly Typed ArrayData Abstractions

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed pull request #3877: Rework Strongly Typed ArrayData Abstractions
URL: https://github.com/apache/arrow-rs/pull/3877


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