gabotechs commented on code in PR #124:
URL: 
https://github.com/apache/datafusion-iceberg/pull/124#discussion_r4736173527


##########
crates/datafusion/src/read/scan.rs:
##########
@@ -240,13 +243,31 @@ impl DataSource for IcebergDataSource {
                 task_context: &context,
             },
         )?;
-        let stream = self
+        let files_opened = MetricBuilder::new(&self.metrics)
+            .with_category(MetricCategory::Rows)
+            .counter("files_opened", partition);
+        let bytes_scanned = MetricBuilder::new(&self.metrics)
+            .with_type(MetricType::Summary)
+            .with_category(MetricCategory::Bytes)
+            .gauge("bytes_scanned", partition);

Review Comment:
   `bytes_scanned` must be a counter: aggregating it with DataFusion's Parquet 
`bytes_scanned` panics.
   
   `aggregate_by_name` groups by name only, and `MetricValue::aggregate` panics 
on `Gauge` vs `Count`.
   
   1. Put an Iceberg scan's and a Parquet scan's metrics in one `MetricsSet`.
   2. Call `aggregate_by_name()`.
   3. Panic: "Mismatched metric types".



##########
crates/datafusion/src/read/scan.rs:
##########
@@ -240,13 +243,31 @@ impl DataSource for IcebergDataSource {
                 task_context: &context,
             },
         )?;
-        let stream = self
+        let files_opened = MetricBuilder::new(&self.metrics)
+            .with_category(MetricCategory::Rows)
+            .counter("files_opened", partition);
+        let bytes_scanned = MetricBuilder::new(&self.metrics)
+            .with_type(MetricType::Summary)
+            .with_category(MetricCategory::Bytes)
+            .gauge("bytes_scanned", partition);
+
+        // Count files when the reader pulls their tasks, including read-ahead 
for LIMIT.
+        let tasks = tasks.inspect_ok(move |_| files_opened.add(1)).boxed();
+        let result = self
             .reader
             .clone()
             .read(tasks)
-            .map_err(to_datafusion_error)?
-            .stream()
-            .map_err(to_datafusion_error);
+            .map_err(to_datafusion_error)?;
+        // Reader bytes include data and delete files, but not manifest 
discovery.
+        let reader_metrics = result.metrics().clone();
+        let mut batches = result.stream().map_err(to_datafusion_error);
+        let stream = poll_fn(move |cx| {
+            let poll = batches.poll_next_unpin(cx);
+            if poll.is_ready() {

Review Comment:
   Bytes read before the stream is dropped mid-read never reach `bytes_scanned`.
   
   The total is only copied on a `Ready` poll. Updating it on drop would fix it.
   
   1. Eager provider with several partitions, one file each.
   2. `EXPLAIN ANALYZE SELECT * FROM t LIMIT 1`.
   3. The first partition to return a batch satisfies the limit.
   4. The other partitions are dropped while `Pending` and report fewer bytes 
than they read, often 0.



##########
crates/datafusion/src/read/scan.rs:
##########
@@ -240,13 +243,31 @@ impl DataSource for IcebergDataSource {
                 task_context: &context,
             },
         )?;
-        let stream = self
+        let files_opened = MetricBuilder::new(&self.metrics)
+            .with_category(MetricCategory::Rows)
+            .counter("files_opened", partition);
+        let bytes_scanned = MetricBuilder::new(&self.metrics)
+            .with_type(MetricType::Summary)
+            .with_category(MetricCategory::Bytes)
+            .gauge("bytes_scanned", partition);
+
+        // Count files when the reader pulls their tasks, including read-ahead 
for LIMIT.
+        let tasks = tasks.inspect_ok(move |_| files_opened.add(1)).boxed();

Review Comment:
   `files_opened` counts pulled tasks, not opened files.
   
   They only match because of `with_data_file_concurrency_limit(1)`. Worth a 
comment there, or a different name?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to