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

[GitHub] [arrow-datafusion] comphead opened a new pull request, #5377: Optimize count_distinct.size

comphead opened a new pull request, #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377

   # 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.
   -->
   
   Closes #5325 .
   
   # Rationale for this change
   Fixing performance drop for `.size` function. Drop was found during performance benchmarks
   During regression the query with `count(distinct )` took 100s in optimized build, now it takes 5s.
    
   <!--
    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.  
   -->
   
   # 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 these changes tested?
   Yes
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   No
   <!--
   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 `api 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-datafusion] alamb commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117941665


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   > are we missing this conditionall check in this PR? so we still have accurate size (slow for now) for variable data and accurate size (fast) for fixed lenth data
   
   This is the middle path I would suggest: keep the slow but accurate accounting for variable length data (aka strings) and add a fast path for fixed length sizes (what is in the benchmark)
   
   I believe the the additional overhead of doing accurate size accounting for string values is a relatively smaller amount of the overall time compared to fixed size types. Making `count distinct` with a large number of string values fast is likely going to take a more sophisticated approach to this query in general.



-- 
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-datafusion] comphead commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1119074644


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -149,6 +149,43 @@ impl DistinctCountAccumulator {
             self.update(&row_values)
         })
     }
+
+    // calculating the size approximately, taking first batch size * number of batches
+    // approx_size has some inaccuracy for variable length values, like strings.
+    fn approx_size(&self) -> usize {

Review Comment:
   Done



-- 
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-datafusion] alamb commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1119385689


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -149,6 +149,43 @@ impl DistinctCountAccumulator {
             self.update(&row_values)
         })
     }
+
+    // calculating the size for fixed length values, taking first batch size * number of batches
+    // This method is faster than .full_size(), however it is not suitable for variable length values like strings or complex types
+    fn fixed_size(&self) -> usize {
+        std::mem::size_of_val(self)
+            + (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity())
+            + self
+                .values
+                .iter()
+                .next()

Review Comment:
   👍  that is nice



##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +253,27 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
-        std::mem::size_of_val(self)
-            + (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity())
-            + self
-                .values
-                .iter()
-                .map(|vals| {
-                    ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0)
-                })
-                .sum::<usize>()
-            + (std::mem::size_of::<DataType>() * self.state_data_types.capacity())
-            + self
-                .state_data_types
-                .iter()
-                .map(|dt| dt.size() - std::mem::size_of_val(dt))
-                .sum::<usize>()
-            + self.count_data_type.size()
-            - std::mem::size_of_val(&self.count_data_type)
+        match &self.count_data_type {
+            DataType::Boolean
+            | DataType::Date32
+            | DataType::Date64
+            | DataType::Float16
+            | DataType::Float32
+            | DataType::Float64
+            | DataType::Int16
+            | DataType::Int32
+            | DataType::Int64
+            | DataType::Int8
+            | DataType::Time32(_)
+            | DataType::Time64(_)
+            | DataType::Null
+            | DataType::Timestamp(_, _)

Review Comment:
   I think this is missing some types like `Interval`  and `Duration`
   
   Perhaps you could check instead if `DataType::primitive_width` returned `Some(.)` 🤔 
   
   https://docs.rs/arrow/34.0.0/arrow/datatypes/enum.DataType.html#method.primitive_width



-- 
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-datafusion] comphead commented on pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#issuecomment-1442570098

   @alamb @crepererum please check this PR whenever you have time


-- 
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-datafusion] Dandandan commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1118543721


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -149,6 +149,43 @@ impl DistinctCountAccumulator {
             self.update(&row_values)
         })
     }
+
+    // calculating the size approximately, taking first batch size * number of batches
+    // approx_size has some inaccuracy for variable length values, like strings.
+    fn approx_size(&self) -> usize {

Review Comment:
   So we could change the name to e.g. `fixed_size`



-- 
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-datafusion] comphead commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117942298


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   @alamb @crepererum Let me remind you again another possible temp solution - The fastest and most painless fix to fix benchmark is to increase batch number, and .size function will be called less often. 
   



-- 
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-datafusion] alamb commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1120155054


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +253,11 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
-        std::mem::size_of_val(self)
-            + (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity())
-            + self
-                .values
-                .iter()
-                .map(|vals| {
-                    ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0)
-                })
-                .sum::<usize>()
-            + (std::mem::size_of::<DataType>() * self.state_data_types.capacity())
-            + self
-                .state_data_types
-                .iter()
-                .map(|dt| dt.size() - std::mem::size_of_val(dt))
-                .sum::<usize>()
-            + self.count_data_type.size()
-            - std::mem::size_of_val(&self.count_data_type)
+        if self.count_data_type.is_primitive() {

Review Comment:
   👍 



-- 
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-datafusion] comphead commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1119427473


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +253,27 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
-        std::mem::size_of_val(self)
-            + (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity())
-            + self
-                .values
-                .iter()
-                .map(|vals| {
-                    ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0)
-                })
-                .sum::<usize>()
-            + (std::mem::size_of::<DataType>() * self.state_data_types.capacity())
-            + self
-                .state_data_types
-                .iter()
-                .map(|dt| dt.size() - std::mem::size_of_val(dt))
-                .sum::<usize>()
-            + self.count_data_type.size()
-            - std::mem::size_of_val(&self.count_data_type)
+        match &self.count_data_type {
+            DataType::Boolean
+            | DataType::Date32
+            | DataType::Date64
+            | DataType::Float16
+            | DataType::Float32
+            | DataType::Float64
+            | DataType::Int16
+            | DataType::Int32
+            | DataType::Int64
+            | DataType::Int8
+            | DataType::Time32(_)
+            | DataType::Time64(_)
+            | DataType::Null
+            | DataType::Timestamp(_, _)

Review Comment:
   Done, seems in new arrow-rs @tustvold made some work for us, and introduced `Datatype::is_primitive`



-- 
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-datafusion] comphead commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117375837


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   Right, as we agreed in https://github.com/apache/arrow-datafusion/issues/5325#issuecomment-1441767680
   We need a fix the benchmark and later @alamb can think how to deal with variable length data. 
   



-- 
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-datafusion] ursabot commented on pull request #5377: Optimize count_distinct.size

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#issuecomment-1448307377

   Benchmark runs are scheduled for baseline = c477fc0ca991cfb84d8d6f082879e969761d9125 and contender = 20d08ab1fc960162c71d156935a7b29cc51ab4fb. 20d08ab1fc960162c71d156935a7b29cc51ab4fb is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/ecd37d3a08b34f64b027676d1d1dc31a...cd6234407d7c4d0ba6d15d5a182780b7/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/33155bb9810142ce9b9767ba60a716dd...b9ecb23e4b6c4588bb6e9e901394ad06/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/db228f0fe0ed4ff6a1df1ab52a75414b...7ee8dcd1c389466f9261e8140bdf2faa/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/28d3df49a8ed4f43b384c18b88954875...e9ba2e63040f4ebca2429bfdb3e4fb34/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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-datafusion] crepererum commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117926952


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   This is clearly a conflict of interests: you wanna fix the benchmark, I wanna have proper memory accounting. We likely can have both on the long run, but due to limited development resources, we cannot have the ideal solution right now. 
   
   I'll leave it to the project managers (e.g. @alamb) to decide what's more pressing.



-- 
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-datafusion] crepererum commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1116799043


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   This basically remove proper memory accounting for this operation and for strings will likely be very wrong. I would rather see a proper cached size accounting here.



-- 
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-datafusion] jychen7 commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "jychen7 (via GitHub)" <gi...@apache.org>.
jychen7 commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117930258


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   > Instead add some code that checks "if is ScalarType::Int8, UInt8, etc then size = size[0]*vec.len()"
   
   https://github.com/apache/arrow-datafusion/issues/5325#issuecomment-1435672826
   
   are we missing this conditionall check in this PR? so we still have accurate size (slow for now) for variable data and accurate size (fast) for fixed lenth data



-- 
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-datafusion] Dandandan commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1118542856


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -149,6 +149,43 @@ impl DistinctCountAccumulator {
             self.update(&row_values)
         })
     }
+
+    // calculating the size approximately, taking first batch size * number of batches
+    // approx_size has some inaccuracy for variable length values, like strings.
+    fn approx_size(&self) -> usize {

Review Comment:
   This shouldn't be approximate now, as we only do it for fixed types



-- 
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-datafusion] Dandandan commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117945872


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   The overhead for an accurate answer is still enormous for variable length types and gets worse with increasing table sizes, as the `size` gets slower with more distinct values in the aggregation, and is called for every update (so a `O(n^2)` operation).



-- 
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-datafusion] comphead commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1118166990


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   @alamb @crepererum @jychen7 @Dandandan Amended to get approx_size for primitives only



-- 
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-datafusion] alamb merged pull request #5377: Optimize count_distinct.size

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377


-- 
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-datafusion] jychen7 commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "jychen7 (via GitHub)" <gi...@apache.org>.
jychen7 commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117930258


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   > Instead add some code that checks "if is ScalarType::Int8, UInt8, etc then size = size[0]*vec.len()"
   
   https://github.com/apache/arrow-datafusion/issues/5325#issuecomment-1435672826
   
   are we missing this check in this PR? so we still have accurate size (slow for now) for variable data and accurate size (fast) for fixed lenth data



-- 
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-datafusion] jychen7 commented on a diff in pull request #5377: Optimize count_distinct.size

Posted by "jychen7 (via GitHub)" <gi...@apache.org>.
jychen7 commented on code in PR #5377:
URL: https://github.com/apache/arrow-datafusion/pull/5377#discussion_r1117930258


##########
datafusion/physical-expr/src/aggregate/count_distinct.rs:
##########
@@ -216,23 +216,19 @@ impl Accumulator for DistinctCountAccumulator {
     }
 
     fn size(&self) -> usize {
+        // temporarily calculating the size approximately, taking first batch size * number of batches
+        // such approach has some inaccuracy for variable length values, like strings.

Review Comment:
   > Instead add some code that checks "if is ScalarType::Int8, UInt8, etc then size = size[0]*vec.len()"
   
   https://github.com/apache/arrow-datafusion/issues/5325#issuecomment-1435672826
   
   are we missing this check in this PR?



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