jerry-024 commented on code in PR #749: URL: https://github.com/apache/paimon-rust/pull/749#discussion_r3870089351
########## 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: <!-- dlf-review --> **[MAJOR]** `LIMIT` is applied only after `list_objects()` has recursively enumerated, materialized, and path-sorted the entire object namespace. Consequently, even `LIMIT 1` retains O(N) listing/memory work and O(N log N) sorting, which can cause high latency or exhaust memory on large object tables. Please pass the limit into the listing layer and consume the recursive lister incrementally, retaining at most the path-smallest K entries. Keep the full listing only when no limit is supplied. -- 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]
