wchevreuil commented on code in PR #168: URL: https://github.com/apache/hbase-connectors/pull/168#discussion_r4104396803
########## spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBaseStreamingDataWriterFactory.scala: ########## @@ -0,0 +1,52 @@ +/* + * 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. + */ +package org.apache.hadoop.hbase.spark.datasources + +import org.apache.spark.sql.catalyst.InternalRow +import org.apache.spark.sql.connector.write.DataWriter +import org.apache.spark.sql.connector.write.streaming.StreamingDataWriterFactory +import org.apache.spark.sql.types.StructType +import org.apache.yetus.audience.InterfaceAudience + +/** + * This is a new class in the spark4 module. Implements StreamingDataWriterFactory for the DS V2 + * streaming write path. Serialized to executors. Creates one HBaseDataWriter per Spark partition + * per micro-batch epoch. The epochId is not used because HBase puts are idempotent — a retried + * epoch writes the same rows with the same row keys, producing no duplicates. + * + * @param schema + * @param properties + * @param catalog + * @param wrappedConf + */ [email protected] +class HBaseStreamingDataWriterFactory( + schema: StructType, + properties: Map[String, String], + catalog: HBaseTableCatalog, + wrappedConf: SerializableConfiguration) + extends StreamingDataWriterFactory + with Serializable { + + override def createWriter( + partitionId: Int, + taskId: Long, + epochId: Long): DataWriter[InternalRow] = { + new HBaseDataWriter(schema, properties, catalog, wrappedConf) Review Comment: Added four new streaming tests: 1. "streaming sink handles multiple micro-batches" — writes data in two separate epochs using the same checkpoint, verifies all rows from both batches are present. 2. "streaming sink preserves null columns" — streams rows with null non-key columns, verifies they round-trip correctly (mirrors the batch null test). 3. "streaming sink rejects null row key" — sends a row with a null key, verifies the query fails with an exception. 4. "streaming sink overwrites same row key across epochs" — writes a row in epoch 1, writes the same row key with updated values in epoch 2, verifies the latest-version read returns the updated values. This directly documents the at-least-once / latest-version-idempotent semantic that Copilot flagged. -- 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]
