Dandandan commented on code in PR #9755:
URL: https://github.com/apache/arrow-rs/pull/9755#discussion_r3101332653
##########
arrow-select/src/coalesce/primitive.rs:
##########
@@ -94,6 +97,99 @@ impl<T: ArrowPrimitiveType + Debug> InProgressArray for
InProgressPrimitiveArray
Ok(())
}
+ fn copy_rows_by_filter(&mut self, filter: &FilterPredicate) -> Result<(),
ArrowError> {
+ self.ensure_capacity();
+
+ let s = self
+ .source
+ .as_ref()
+ .ok_or_else(|| {
+ ArrowError::InvalidArgumentError(
+ "Internal Error: InProgressPrimitiveArray: source not
set".to_string(),
+ )
+ })?
+ .as_primitive::<T>();
+
+ match filter.strategy() {
+ IterationStrategy::None => return Ok(()),
+ IterationStrategy::All => return self.copy_rows(0, filter.count()),
+ IterationStrategy::Slices(slices) => {
+ for &(start, end) in slices {
+ self.copy_rows(start, end - start)?;
+ }
+ return Ok(());
+ }
+ IterationStrategy::SlicesIterator => {
+ for (start, end) in SlicesIterator::new(filter.filter_array())
{
+ self.copy_rows(start, end - start)?;
+ }
+ return Ok(());
+ }
+ IterationStrategy::Indices(_) | IterationStrategy::IndexIterator
=> {}
+ }
+
+ if let Some((null_count, nulls)) = filter_null_mask(s.nulls(), filter)
{
+ let nulls = unsafe {
+ NullBuffer::new_unchecked(BooleanBuffer::new(nulls, 0,
filter.count()), null_count)
+ };
+ self.nulls.append_buffer(&nulls);
+ } else {
+ self.nulls.append_n_non_nulls(filter.count());
+ }
+
+ let values = s.values();
+ self.current.reserve(filter.count());
+
+ match filter.strategy() {
+ IterationStrategy::Indices(indices) => {
+ for &idx in indices {
+ self.current.push(values[idx]);
+ }
+ }
+ IterationStrategy::IndexIterator => {
+ for idx in IndexIterator::new(filter.filter_array(),
filter.count()) {
+ self.current.push(values[idx]);
+ }
+ }
+ IterationStrategy::None
+ | IterationStrategy::All
+ | IterationStrategy::Slices(_)
+ | IterationStrategy::SlicesIterator => unreachable!(),
+ }
+
+ Ok(())
+ }
+
+ fn copy_rows_by_indices(&mut self, indices: &[usize]) -> Result<(),
ArrowError> {
+ self.ensure_capacity();
+
+ let s = self
+ .source
+ .as_ref()
+ .ok_or_else(|| {
+ ArrowError::InvalidArgumentError(
+ "Internal Error: InProgressPrimitiveArray: source not
set".to_string(),
+ )
+ })?
+ .as_primitive::<T>();
+
+ if let Some(nulls) = s.nulls().filter(|nulls| nulls.null_count() > 0) {
+ for &idx in indices {
+ self.nulls.append(nulls.is_valid(idx));
+ }
+ } else {
+ self.nulls.append_n_non_nulls(indices.len());
+ }
+
+ let values = s.values();
+ self.current.reserve(indices.len());
+ for &idx in indices {
Review Comment:
can use `extend` instead of `reserve` + `push` here
##########
arrow-select/src/coalesce/primitive.rs:
##########
@@ -94,6 +97,99 @@ impl<T: ArrowPrimitiveType + Debug> InProgressArray for
InProgressPrimitiveArray
Ok(())
}
+ fn copy_rows_by_filter(&mut self, filter: &FilterPredicate) -> Result<(),
ArrowError> {
+ self.ensure_capacity();
+
+ let s = self
+ .source
+ .as_ref()
+ .ok_or_else(|| {
+ ArrowError::InvalidArgumentError(
+ "Internal Error: InProgressPrimitiveArray: source not
set".to_string(),
+ )
+ })?
+ .as_primitive::<T>();
+
+ match filter.strategy() {
+ IterationStrategy::None => return Ok(()),
+ IterationStrategy::All => return self.copy_rows(0, filter.count()),
+ IterationStrategy::Slices(slices) => {
+ for &(start, end) in slices {
+ self.copy_rows(start, end - start)?;
+ }
+ return Ok(());
+ }
+ IterationStrategy::SlicesIterator => {
+ for (start, end) in SlicesIterator::new(filter.filter_array())
{
+ self.copy_rows(start, end - start)?;
+ }
+ return Ok(());
+ }
+ IterationStrategy::Indices(_) | IterationStrategy::IndexIterator
=> {}
+ }
+
+ if let Some((null_count, nulls)) = filter_null_mask(s.nulls(), filter)
{
+ let nulls = unsafe {
+ NullBuffer::new_unchecked(BooleanBuffer::new(nulls, 0,
filter.count()), null_count)
+ };
+ self.nulls.append_buffer(&nulls);
+ } else {
+ self.nulls.append_n_non_nulls(filter.count());
+ }
+
+ let values = s.values();
+ self.current.reserve(filter.count());
+
+ match filter.strategy() {
+ IterationStrategy::Indices(indices) => {
+ for &idx in indices {
+ self.current.push(values[idx]);
+ }
+ }
+ IterationStrategy::IndexIterator => {
+ for idx in IndexIterator::new(filter.filter_array(),
filter.count()) {
+ self.current.push(values[idx]);
+ }
+ }
+ IterationStrategy::None
+ | IterationStrategy::All
+ | IterationStrategy::Slices(_)
+ | IterationStrategy::SlicesIterator => unreachable!(),
+ }
+
+ Ok(())
+ }
+
+ fn copy_rows_by_indices(&mut self, indices: &[usize]) -> Result<(),
ArrowError> {
+ self.ensure_capacity();
+
+ let s = self
+ .source
+ .as_ref()
+ .ok_or_else(|| {
+ ArrowError::InvalidArgumentError(
+ "Internal Error: InProgressPrimitiveArray: source not
set".to_string(),
+ )
+ })?
+ .as_primitive::<T>();
+
+ if let Some(nulls) = s.nulls().filter(|nulls| nulls.null_count() > 0) {
+ for &idx in indices {
+ self.nulls.append(nulls.is_valid(idx));
+ }
+ } else {
+ self.nulls.append_n_non_nulls(indices.len());
+ }
+
+ let values = s.values();
+ self.current.reserve(indices.len());
+ for &idx in indices {
Review Comment:
can use `extend` instead of `reserve` + `push` here (it's faster)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]