SteNicholas commented on code in PR #1448:
URL: https://github.com/apache/paimon-rust/pull/1448#discussion_r4656684719


##########
crates/integrations/datafusion/src/sql_context/ctas.rs:
##########
@@ -0,0 +1,286 @@
+// 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.
+
+//! Persistent CREATE TABLE AS SELECT. Population failures retain the table
+//! because concurrent writers can use it as soon as creation succeeds.
+
+use std::ops::ControlFlow;
+use std::sync::Arc;
+
+use datafusion::arrow::datatypes::SchemaRef;
+use datafusion::error::{DataFusionError, Result as DFResult};
+use datafusion::execution::context::SQLOptions;
+use datafusion::execution::session_state::SessionState;
+use datafusion::execution::TaskContext;
+use datafusion::physical_plan::{execute_stream, ExecutionPlan};
+use datafusion::prelude::DataFrame;
+use datafusion::sql::planner::object_name_to_table_reference;
+use 
datafusion::sql::sqlparser::ast::helpers::stmt_create_table::CreateTableBuilder;
+use datafusion::sql::sqlparser::ast::{
+    CreateTable, CreateTableOptions, Query, Select, SqlOption, Statement, 
Visit, Visitor,
+};
+use futures::StreamExt;
+use paimon::spec::{CoreOptions, DataType as PaimonDataType, TableType};
+use paimon::table::Table;
+
+use super::{create_table_schema, extract_options, ok_result, SQLContext, 
TimeTravelSource};
+use crate::error::to_datafusion_error;
+use crate::physical_plan::cast_batch_to_schema;
+
+impl SQLContext {
+    pub(super) async fn handle_create_table_as(
+        &self,
+        ct: &CreateTable,
+        query: Box<Query>,
+        partition_keys: Vec<String>,
+        state: SessionState,
+        options: SQLOptions,
+        time_travel_sources: &[TimeTravelSource],
+    ) -> DFResult<DataFrame> {
+        validate_create_table_as(ct, &query)?;
+        Self::ensure_main_branch_base_table(&ct.name, "CREATE TABLE AS 
SELECT")?;
+        let enable_ident_normalization =
+            state.config_options().sql_parser.enable_ident_normalization;
+        let target = object_name_to_table_reference(ct.name.clone(), 
enable_ident_normalization)?;
+        let (catalog, catalog_name, identifier) =
+            self.resolve_table_reference(&target, 
&state.config_options().catalog)?;
+
+        // An external target can exist even when its table engine is 
unavailable.
+        match catalog.load_table(&identifier).await {

Review Comment:
   I reproduced the missing `fs.oss.endpoint` error with both filesystem and 
REST catalogs. CTAS now checks the stored schema or the REST table metadata 
before planning the source. `IF NOT EXISTS` skips the existing Object Table, 
and strict creation reports that the table already exists. All 20 CTAS tests 
passed, including the OSS regression and the catalog error cases. [Fix in 
e4871750](https://github.com/apache/paimon-rust/pull/1448/commits/e487175095e3b15a760133068352eb874d8553eb)
   



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