openinx commented on code in PR #110: URL: https://github.com/apache/flink-table-store/pull/110#discussion_r867334974
########## flink-table-store-core/src/main/java/org/apache/flink/table/store/file/writer/FileWriter.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.flink.table.store.file.writer; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Iterator; + +/** + * File writer to accept one record or a branch of records and generate metadata after closing it. + * + * @param <T> record type. + * @param <R> file result to collect. + */ +public interface FileWriter<T, R> extends Closeable { + + /** + * Write only one record to this file. + * + * @param record to write. + * @throws IOException if encounter any IO error. + */ + void write(T record) throws IOException; + + /** + * Add records from {@link Iterator} to this file writer. + * + * @param records to write + * @throws IOException if encounter any IO error. + */ + default void write(Iterator<T> records) throws IOException { + while (records.hasNext()) { + write(records.next()); + } + } + + /** + * Add records from {@link Iterable} to file writer. + * + * @param records to write. + * @throws IOException if encounter any IO error. + */ + default void write(Iterable<T> records) throws IOException { + for (T record : records) { + write(record); + } + } + + /** + * The total written record count. + * + * @return record count. + */ + long recordCount(); + + /** + * The estimated length of the current writer. + * + * @return the estimated length. + * @throws IOException if encounter any IO error. + */ + long length() throws IOException; + + /** + * Flush the buffered records into underlying file system. + * + * @throws IOException if encounter any IO error. + */ + void flush() throws IOException; Review Comment: > Is there a need for flush to exist? The current `RollingFileWriter` or `BaseFileWriter` should not use any `flush` or `sync` semantic from filesystem. The further writer to write `LogEntry` ( which is similar to the HBase's `HLog`) will rely on this interface, because once we write one transaction into the table store, we will need to make sure that all data are persisted in the filesystem. For now, I'm okay to remove this method in the current version. I guess there will be another version `Writer` API for the further table store service. ########## flink-table-store-core/src/main/java/org/apache/flink/table/store/file/writer/FileWriter.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.flink.table.store.file.writer; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Iterator; + +/** + * File writer to accept one record or a branch of records and generate metadata after closing it. + * + * @param <T> record type. + * @param <R> file result to collect. + */ +public interface FileWriter<T, R> extends Closeable { + + /** + * Write only one record to this file. + * + * @param record to write. + * @throws IOException if encounter any IO error. + */ + void write(T record) throws IOException; + + /** + * Add records from {@link Iterator} to this file writer. + * + * @param records to write + * @throws IOException if encounter any IO error. + */ + default void write(Iterator<T> records) throws IOException { + while (records.hasNext()) { + write(records.next()); + } + } + + /** + * Add records from {@link Iterable} to file writer. + * + * @param records to write. + * @throws IOException if encounter any IO error. + */ + default void write(Iterable<T> records) throws IOException { + for (T record : records) { + write(record); + } + } + + /** + * The total written record count. + * + * @return record count. + */ + long recordCount(); + + /** + * The estimated length of the current writer. + * + * @return the estimated length. + * @throws IOException if encounter any IO error. + */ + long length() throws IOException; + + /** + * Flush the buffered records into underlying file system. + * + * @throws IOException if encounter any IO error. + */ + void flush() throws IOException; + + /** Abort to clear orphan file(s) if encounter any error. */ + default void abort() {} Review Comment: Sounds good to me, let's remove the `default` modifier. ########## flink-table-store-core/src/main/java/org/apache/flink/table/store/file/writer/FileWriter.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.flink.table.store.file.writer; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Iterator; + +/** + * File writer to accept one record or a branch of records and generate metadata after closing it. + * + * @param <T> record type. + * @param <R> file result to collect. + */ +public interface FileWriter<T, R> extends Closeable { + + /** + * Write only one record to this file. + * + * @param record to write. + * @throws IOException if encounter any IO error. + */ + void write(T record) throws IOException; + + /** + * Add records from {@link Iterator} to this file writer. + * + * @param records to write + * @throws IOException if encounter any IO error. + */ + default void write(Iterator<T> records) throws IOException { + while (records.hasNext()) { + write(records.next()); + } + } + + /** + * Add records from {@link Iterable} to file writer. + * + * @param records to write. + * @throws IOException if encounter any IO error. + */ + default void write(Iterable<T> records) throws IOException { + for (T record : records) { + write(record); + } + } + + /** + * The total written record count. + * + * @return record count. + */ + long recordCount(); + + /** + * The estimated length of the current writer. + * + * @return the estimated length. + * @throws IOException if encounter any IO error. + */ + long length() throws IOException; + + /** + * Flush the buffered records into underlying file system. + * + * @throws IOException if encounter any IO error. + */ + void flush() throws IOException; Review Comment: > Is it possible to merge close and result, and return result directly when closing I will suggest to keep the current separate `close()` and `result()` approach. Because the `void close() throws IOException` is a standard `java.io.Closeable` ( which is extending `java.io.AutoCloseable` ). That means we can use `try (writer = ...) {}` (without any `finally` block) and `IOUtils.closeQuietly` to close the writer automatically. -- 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]
