jerry-024 commented on code in PR #749: URL: https://github.com/apache/paimon-rust/pull/749#discussion_r3870780685
########## 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: The update bounds retained memory to O(K) and reduces sorting to O(N log K), but the recursive lister is still drained to EOF. As a result, `LIMIT 1` still performs O(N) remote listing work and waits for the entire namespace. Because SQL `LIMIT` without `ORDER BY` does not require the globally smallest paths, this path can stop after K files and optionally sort only those K results. A global traversal should be reserved for an explicit ordering requirement. ########## crates/paimon/src/catalog/mod.rs: ########## @@ -263,14 +263,16 @@ use async_trait::async_trait; use crate::api::PagedList; use crate::spec::{Partition, Schema, SchemaChange, TableType}; -use crate::table::Table; +use crate::table::{ObjectTable, Table}; /// Outcome of [`Catalog::load_table`]. #[derive(Debug)] pub enum LoadedTable { /// A constructed Paimon table (boxed: far larger than the other variant). Paimon(Box<Table>), - /// A table this reader cannot construct. + /// A native read-only object table. + Object(ObjectTable), + /// A table that needs a registered external engine. Review Comment: Retraction after checking the published API history: `LoadedTable` is not present in the released v0.3.0 API and currently exists only on the unreleased 0.4.0 development line. Adding `Object` before the enum’s first release does not break released consumers, and `#[non_exhaustive]` prevents the same issue for future variants. This is not a compatibility blocker; please disregard my original finding. -- 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]
