openinx commented on a change in pull request #4132: URL: https://github.com/apache/iceberg/pull/4132#discussion_r816423019
########## File path: core/src/main/java/org/apache/iceberg/io/PartitioningWriterFactory.java ########## @@ -0,0 +1,87 @@ +/* + * 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.io; + +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.deletes.PositionDelete; +import org.apache.iceberg.io.DefaultPartitioningWriterFactory.Type; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public interface PartitioningWriterFactory<T> { Review comment: Why name it as `PartitioningWriterFactory` ? I don't see any partition info for those defined interface methods. ########## File path: core/src/main/java/org/apache/iceberg/io/PartitioningWriterFactory.java ########## @@ -0,0 +1,87 @@ +/* + * 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.io; + +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.deletes.PositionDelete; +import org.apache.iceberg.io.DefaultPartitioningWriterFactory.Type; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public interface PartitioningWriterFactory<T> { + PartitioningWriter<T, DataWriteResult> newDataWriter(); + + PartitioningWriter<T, DeleteWriteResult> newEqualityDeleteWriter(); + + PartitioningWriter<PositionDelete<T>, DeleteWriteResult> newPositionDeleteWriter(); + + static <T> Builder<T> builder(FileWriterFactory<T> writerFactory) { + return new Builder<>(writerFactory); + } + + class Builder<T> { + private final FileWriterFactory<T> writerFactory; + private OutputFileFactory fileFactory = null; + private FileIO io = null; + private FileFormat fileFormat = null; + private long targetFileSizeInBytes = 0; + + public Builder(FileWriterFactory<T> writerFactory) { + this.writerFactory = writerFactory; + } + + private void checkArguments() { + Preconditions.checkArgument(writerFactory != null, "writerFactory is required non-null"); + Preconditions.checkArgument(fileFactory != null, "fileFactory is required non-null"); + Preconditions.checkArgument(io != null, "io is required non-null"); Review comment: Nit: The `fileFormat` is also required to be not null, right ? ########## File path: core/src/main/java/org/apache/iceberg/io/PathOffset.java ########## @@ -0,0 +1,76 @@ +/* + * 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.io; + +import java.util.Objects; +import org.apache.iceberg.deletes.PositionDelete; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; + +public final class PathOffset { + private final CharSequence path; + private final long offset; + + private PathOffset(CharSequence path, long offset) { + this.path = path; + this.offset = offset; + } + + public static PathOffset of(CharSequence path, long offset) { + return new PathOffset(path, offset); + } + + public CharSequence path() { + return path; + } + + public long offset() { + return offset; + } + + public <T> PositionDelete<T> setTo(PositionDelete<T> positionDelete) { + return positionDelete.set(path, offset, null); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("path", path) + .add("offset", offset) + .toString(); + } + + @Override + public int hashCode() { + return Objects.hash(path, offset); Review comment: Please use `JavaHashes.hashCode(charseq)` to get the `CharSequence`'s hashCode. ########## File path: core/src/main/java/org/apache/iceberg/io/PartitioningWriterFactory.java ########## @@ -0,0 +1,87 @@ +/* + * 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.io; + +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.deletes.PositionDelete; +import org.apache.iceberg.io.DefaultPartitioningWriterFactory.Type; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public interface PartitioningWriterFactory<T> { + PartitioningWriter<T, DataWriteResult> newDataWriter(); + + PartitioningWriter<T, DeleteWriteResult> newEqualityDeleteWriter(); + + PartitioningWriter<PositionDelete<T>, DeleteWriteResult> newPositionDeleteWriter(); + + static <T> Builder<T> builder(FileWriterFactory<T> writerFactory) { + return new Builder<>(writerFactory); + } + + class Builder<T> { + private final FileWriterFactory<T> writerFactory; + private OutputFileFactory fileFactory = null; + private FileIO io = null; + private FileFormat fileFormat = null; + private long targetFileSizeInBytes = 0; + + public Builder(FileWriterFactory<T> writerFactory) { + this.writerFactory = writerFactory; + } + + private void checkArguments() { + Preconditions.checkArgument(writerFactory != null, "writerFactory is required non-null"); + Preconditions.checkArgument(fileFactory != null, "fileFactory is required non-null"); + Preconditions.checkArgument(io != null, "io is required non-null"); + } + + public PartitioningWriterFactory<T> buildForClusteredPartition() { + checkArguments(); + return new DefaultPartitioningWriterFactory<>(writerFactory, fileFactory, io, fileFormat, + targetFileSizeInBytes, Type.CLUSTERED); + } + + public PartitioningWriterFactory<T> buildForFanoutPartition() { + checkArguments(); + return new DefaultPartitioningWriterFactory<>(writerFactory, fileFactory, io, fileFormat, + targetFileSizeInBytes, Type.FANOUT); + } + + public Builder<T> fileFactory(OutputFileFactory newFileFactory) { + this.fileFactory = newFileFactory; + return this; + } + + public Builder<T> io(FileIO newIO) { Review comment: It's more clear to name this builder method as `fileIO` . ########## File path: core/src/main/java/org/apache/iceberg/io/PathOffset.java ########## @@ -0,0 +1,76 @@ +/* + * 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.io; + +import java.util.Objects; +import org.apache.iceberg.deletes.PositionDelete; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; + +public final class PathOffset { + private final CharSequence path; + private final long offset; + + private PathOffset(CharSequence path, long offset) { + this.path = path; + this.offset = offset; + } + + public static PathOffset of(CharSequence path, long offset) { + return new PathOffset(path, offset); + } + + public CharSequence path() { + return path; + } + + public long offset() { + return offset; + } + + public <T> PositionDelete<T> setTo(PositionDelete<T> positionDelete) { + return positionDelete.set(path, offset, null); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("path", path) + .add("offset", offset) + .toString(); + } + + @Override + public int hashCode() { + return Objects.hash(path, offset); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + PathOffset that = (PathOffset) o; + return this.offset == that.offset && this.path.equals(that.path); Review comment: Please use the `Comparators.charSequences().compare(a, b)` to compare two `CharSequence` because of this [comment](https://github.com/apache/iceberg/blob/90225d6c9413016d611e2ce5eff37db1bc1b4fc5/api/src/main/java/org/apache/iceberg/types/Comparators.java#L309-L316). There is a similar code path you can take a look. https://github.com/apache/iceberg/blob/90225d6c9413016d611e2ce5eff37db1bc1b4fc5/api/src/main/java/org/apache/iceberg/util/CharSequenceWrapper.java#L58 -- 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]
