shyjsarah commented on code in PR #749:
URL: https://github.com/apache/paimon-rust/pull/749#discussion_r3870969674
##########
crates/paimon/src/io/file_io.rs:
##########
@@ -223,23 +225,38 @@ impl FileIO {
/// List all files recursively under the given directory path.
pub async fn list_status_recursive(&self, path: &str) ->
Result<Vec<FileStatus>> {
+ self.list_status_recursive_with_limit(path, None).await
+ }
+
+ pub(crate) async fn list_status_recursive_with_limit(
+ &self,
+ path: &str,
+ limit: Option<usize>,
+ ) -> Result<Vec<FileStatus>> {
+ if limit == Some(0) {
+ return Ok(Vec::new());
+ }
+
let (op, relative_path) = self.create(path).await?;
// See `list_status`: `relative_path` is a byte-suffix of `path` except
// for Windows local paths, where it only swaps separators (same
length).
let base_path = &path[..path.len() - relative_path.len()];
let list_path = normalize_root(relative_path.as_ref());
- let entries =
- op.list_with(&list_path)
+ let mut entries =
+ op.lister_with(&list_path)
.recursive(true)
.await
.context(IoUnexpectedSnafu {
message: format!("Failed to list files recursively in
'{path}'"),
})?;
let mut statuses = Vec::new();
+ let mut smallest = limit.map(|limit|
BinaryHeap::with_capacity(limit.saturating_add(1)));
Review Comment:
Fixed in fc31528. Limited recursive listing no longer allocates from the SQL
LIMIT at all: the bounded heap was removed, entries are appended as the lister
yields them, and polling stops once K files have been collected. A regression
with `usize::MAX` on an empty location verifies that no capacity allocation or
panic occurs.
##########
crates/integrations/datafusion/src/table/object.rs:
##########
@@ -0,0 +1,153 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use datafusion::arrow::array::{
+ new_null_array, ArrayRef, Int64Array, RecordBatch, StringViewArray,
+};
+use datafusion::arrow::datatypes::SchemaRef;
+use datafusion::catalog::Session;
+use datafusion::datasource::memory::MemorySourceConfig;
+use datafusion::datasource::{TableProvider, TableType};
+use datafusion::error::{DataFusionError, Result as DFResult};
+use datafusion::logical_expr::dml::InsertOp;
+use datafusion::logical_expr::Expr;
+use datafusion::physical_plan::ExecutionPlan;
+use paimon::table::ObjectTable;
+
+use crate::error::to_datafusion_error;
+
+use super::datafusion_arrow_schema;
+
+/// DataFusion provider for a native read-only Paimon object table.
+#[derive(Debug, Clone)]
+pub(crate) struct ObjectTableProvider {
+ table: ObjectTable,
+ schema: SchemaRef,
+}
+
+impl ObjectTableProvider {
+ pub(crate) fn try_new(table: ObjectTable, schema_force_view_types: bool)
-> DFResult<Self> {
+ let schema = datafusion_arrow_schema(&ObjectTable::fields(),
schema_force_view_types)?;
+ Ok(Self { table, schema })
+ }
+}
+
+#[async_trait]
+impl TableProvider for ObjectTableProvider {
+ fn schema(&self) -> SchemaRef {
+ Arc::clone(&self.schema)
+ }
+
+ fn table_type(&self) -> TableType {
+ TableType::Base
+ }
+
+ async fn scan(
+ &self,
+ _state: &dyn Session,
+ projection: Option<&Vec<usize>>,
+ _filters: &[Expr],
+ limit: Option<usize>,
+ ) -> DFResult<Arc<dyn ExecutionPlan>> {
+ let mut entries = self
+ .table
+ .list_objects()
Review Comment:
Addressed in fc31528. For a pushed `LIMIT K` without `ORDER BY`, the
recursive OpenDAL lister now stops after K files instead of draining to EOF;
only those K entries are sorted before materialization. Unlimited scans still
traverse the full namespace. I also added an instrumented lister regression
proving it is not polled past K, plus an `ORDER BY path LIMIT 1` regression to
preserve ordered-query correctness.
--
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]