adamreeve commented on code in PR #55665:
URL: https://github.com/apache/arrow/pull/55665#discussion_r4660630377


##########
cpp/src/arrow/dataset/dataset.cc:
##########
@@ -321,6 +322,129 @@ Result<FragmentIterator> 
UnionDataset::GetFragmentsImpl(compute::Expression pred
   return GetFragmentsFromDatasets(children_, predicate);
 }
 
+FilteredFragment::FilteredFragment(std::shared_ptr<Fragment> fragment,
+                                   compute::Expression filter)
+    : Fragment(fragment->partition_expression(), /*physical_schema=*/nullptr),
+      fragment_(std::move(fragment)),
+      filter_(std::move(filter)) {}
+
+Result<std::shared_ptr<Schema>> FilteredFragment::ReadPhysicalSchemaImpl() {
+  return fragment_->ReadPhysicalSchema();
+}
+
+Status FilteredFragment::ClearCachedMetadata() {
+  RETURN_NOT_OK(Fragment::ClearCachedMetadata());
+  return fragment_->ClearCachedMetadata();
+}
+
+std::string FilteredFragment::ToString() const {
+  // The scanner uses ToString() for the __filename augmented field, so this 
must
+  // match the wrapped fragment.
+  return fragment_->ToString();
+}
+
+Result<RecordBatchGenerator> FilteredFragment::ScanBatchesAsync(
+    const std::shared_ptr<ScanOptions>& options) {
+  const auto& dataset_schema = options->dataset_schema;
+  ARROW_ASSIGN_OR_RAISE(auto filter, filter_.Bind(*dataset_schema));
+  ARROW_ASSIGN_OR_RAISE(filter,
+                        SimplifyWithGuarantee(std::move(filter), 
partition_expression_));
+  if (!filter.IsSatisfiable()) {
+    return MakeEmptyGenerator<std::shared_ptr<RecordBatch>>();
+  }
+
+  // Combine any existing filter in the scan options with the fragment's 
filter,
+  // so the wrapped fragment can skip data that cannot match.
+  auto fragment_options = std::make_shared<ScanOptions>(*options);
+  ARROW_ASSIGN_OR_RAISE(fragment_options->filter,
+                        compute::and_(options->filter, 
filter).Bind(*dataset_schema));
+  ARROW_ASSIGN_OR_RAISE(auto batches, 
fragment_->ScanBatchesAsync(fragment_options));
+
+  // The filter might simplify to true if it only references partition fields,
+  // in which case we can skip filtering batches.
+  if (filter == compute::literal(true)) {
+    return batches;
+  }

Review Comment:
   Fixed in 336d281b70ec2dabf15e5015b3ae2c9da714734a, a null dataset schema 
returns `StatusInvalid`.



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

Reply via email to