SteNicholas commented on code in PR #376:
URL: https://github.com/apache/paimon-cpp/pull/376#discussion_r4111457051


##########
src/paimon/format/vortex/vortex_format_writer.cpp:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.
+ */
+
+#include "paimon/format/vortex/vortex_format_writer.h"
+
+#include <utility>
+
+#include "arrow/c/bridge.h"
+#include "arrow/memory_pool.h"
+#include "arrow/type.h"
+#include "paimon/common/metrics/metrics_impl.h"
+#include "paimon/common/utils/arrow/arrow_utils.h"
+#include "paimon/common/utils/arrow/status_utils.h"
+#include "paimon/format/vortex/vortex_ffi_util.h"
+#include "paimon/fs/file_system.h"
+
+namespace paimon::vortex {
+
+VortexFormatWriter::VortexFormatWriter(std::shared_ptr<OutputStream> output,
+                                       std::shared_ptr<arrow::Schema> schema, 
VxSessionPtr session,
+                                       std::shared_ptr<VortexOutputContext> 
output_context,
+                                       vx_callback_sink* sink,
+                                       std::shared_ptr<arrow::MemoryPool> 
arrow_pool)
+    : output_(std::move(output)),
+      schema_(std::move(schema)),
+      arrow_pool_(std::move(arrow_pool)),
+      session_(std::move(session)),
+      output_context_(std::move(output_context)),
+      sink_(sink),
+      metrics_(std::make_shared<MetricsImpl>()) {}
+
+Result<std::unique_ptr<VortexFormatWriter>> VortexFormatWriter::Create(
+    const std::shared_ptr<OutputStream>& output, const 
std::shared_ptr<arrow::Schema>& schema,
+    const std::shared_ptr<arrow::MemoryPool>& arrow_pool) {
+    if (output == nullptr || schema == nullptr || arrow_pool == nullptr) {
+        return Status::Invalid("Vortex writer requires non-null output, schema 
and arrow pool");
+    }
+    VxSessionPtr session(vx_session_new(), vx_session_free);
+    if (session == nullptr) {
+        return Status::IOError("failed to create Vortex session");
+    }
+    ::ArrowSchema ffi_schema = {};
+    PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*schema, &ffi_schema));
+    vx_error* error = nullptr;
+    // vx_dtype_from_arrow_schema consumes ffi_schema on both success and 
failure.
+    VxDtypePtr dtype(vx_dtype_from_arrow_schema(&ffi_schema, &error), 
vx_dtype_free);

Review Comment:
   **Validate unsupported types at the public writer boundary**. Callers can 
construct writers through the public 
`FileFormat::CreateWriterBuilder(...)->Build(...)` API without running 
`SchemaValidation::ValidateTableSchema`. A MAP schema then reaches 
`vx_dtype_from_arrow_schema`, whose Vortex 0.75 `DType::from_arrow` 
implementation uses `unimplemented!` for MAP. The FFI `try_or_default` only 
handles `Result` errors and does not catch panics, so this can terminate the 
process instead of returning `Status`. Please validate supported schema types 
recursively at this boundary before entering Rust. I reproduced the MAP 
dtype-conversion panic using Vortex 0.75.



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