From 85739004b0be51d0c19b9d403502825c5ecab345 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Sun, 21 Jan 2024 07:41:42 -0800 Subject: [PATCH] add no-op writer --- .../connect/data/IcebergWriterFactory.java | 2 +- .../iceberg/connect/data/NoOpWriter.java | 40 +++++++++++++++++++ .../iceberg/connect/data/RecordWriter.java | 9 ++--- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/NoOpWriter.java diff --git a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java index 7e479e136f07..0548393d07dd 100644 --- a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java +++ b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java @@ -56,7 +56,7 @@ public RecordWriter createWriter( if (config.autoCreateEnabled()) { table = autoCreateTable(tableName, sample); } else if (ignoreMissingTable) { - return new RecordWriter() {}; + return new NoOpWriter(); } else { throw nst; } diff --git a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/NoOpWriter.java b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/NoOpWriter.java new file mode 100644 index 000000000000..31abe09cf1a4 --- /dev/null +++ b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/NoOpWriter.java @@ -0,0 +1,40 @@ +/* + * 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.iceberg.connect.data; + +import java.util.List; +import org.apache.kafka.connect.sink.SinkRecord; + +public class NoOpWriter implements RecordWriter { + @Override + public void write(SinkRecord record) { + // NO-OP + } + + @Override + public List complete() { + // NO-OP + return null; + } + + @Override + public void close() { + // NO-OP + } +} diff --git a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordWriter.java b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordWriter.java index 6dc2d4561c59..0b4d7566eab7 100644 --- a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordWriter.java +++ b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordWriter.java @@ -19,16 +19,13 @@ package org.apache.iceberg.connect.data; import java.util.List; -import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; import org.apache.kafka.connect.sink.SinkRecord; public interface RecordWriter extends Cloneable { - default void write(SinkRecord record) {} + void write(SinkRecord record); - default List complete() { - return ImmutableList.of(); - } + List complete(); - default void close() {} + void close(); }