gengliangwang commented on code in PR #59520: URL: https://github.com/apache/spark/pull/59520#discussion_r4543256277
########## sql/native/rust/src/write.rs: ########## @@ -0,0 +1,290 @@ +// 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. + +//! Driver write coordination and task-local writers restored from serialized state, for batch +//! writes and for the writes of micro-batches. + +use std::ffi::c_void; + +use arrow_array::{ffi, Array, RecordBatch, StructArray}; +use arrow_schema::{DataType, SchemaRef}; +use serde::Serialize; + +use crate::abi::{self, ArrowArray, SparkDsTaskContext}; +use crate::bridge::stream::validate_schema; +use crate::bridge::{decode, describe, drop_provider, encode, provider_call}; +use crate::{ + BatchWrite, DataWriter, DataWriterFactory, PartitionWriter, Result, StreamingWrite, + TaskContext, WriterContext, +}; + +/// A batch write, which a driver writer drives as a streaming write whose epoch ID is always +/// -1 and is ignored. +pub struct Batch<W>(pub W); + +impl<W: BatchWrite> StreamingWrite for Batch<W> { + type Factory = W::Factory; + type Message = W::Message; + + fn writer_factory(&self) -> Result<W::Factory> { + self.0.writer_factory() + } + + fn commit(&mut self, _: i64, messages: Vec<W::Message>) -> Result<()> { + self.0.commit(messages) + } + + fn abort(&mut self, _: i64, messages: Vec<Option<W::Message>>) -> Result<()> { + self.0.abort(messages) + } +} + +/// A driver writer that decodes its own commit messages, so that one handle type holds the +/// driver writers of batch writes and of the writes of micro-batches, which share the writer +/// handles of the ABI. +pub trait DriverWrite: Send { + fn commit(&mut self, epoch_id: i64, messages: &[Option<&[u8]>]) -> Result<()>; + + fn abort(&mut self, epoch_id: i64, messages: &[Option<&[u8]>]) -> Result<()>; +} + +/// The driver keeps this coordinator until a successful commit or an abort, after which Spark Review Comment: Done in 3a405036b142: Since SPARK-61284, `DriverWriter` drops the coordinator at close again, as I planned. I removed the early drop, updated the `DriverWriter`, `BatchWrite` and `StreamingWrite` docs and the README, and the tests now close each writer right after its commit or abort, as Spark does, before the next `create_writer`. ########## .github/workflows/build_and_test.yml: ########## @@ -1425,3 +1428,33 @@ jobs: cd ui-test npm install --save-dev node --experimental-vm-modules node_modules/.bin/jest + + rust-sdk: + needs: [precondition] + if: fromJson(needs.precondition.outputs.required).rust-sdk == 'true' Review Comment: Done in 3a405036b142: Added `"rust-sdk": "true"` to the explicit jobs list in build_main.yml, so upstream builds that run the full job matrix also run the rust-sdk job. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
