You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/07/18 22:58:25 UTC

[GitHub] [iceberg] szehon-ho commented on a diff in pull request #5300: Core: Add base implementations for changelog tasks

szehon-ho commented on code in PR #5300:
URL: https://github.com/apache/iceberg/pull/5300#discussion_r923921920


##########
core/src/main/java/org/apache/iceberg/BaseAddedRowsScanTask.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+
+class BaseAddedRowsScanTask
+    extends BaseChangelogContentScanTask<AddedRowsScanTask, DataFile>
+    implements AddedRowsScanTask {
+
+  private final DeleteFile[] deletes;
+
+  BaseAddedRowsScanTask(int changeOrdinal, long commitSnapshotId, DataFile file, DeleteFile[] deletes,
+                        String schemaString, String specString, ResidualEvaluator residuals) {
+    super(changeOrdinal, commitSnapshotId, file, schemaString, specString, residuals);
+    this.deletes = deletes != null ? deletes : new DeleteFile[0];
+  }
+
+  @Override
+  protected AddedRowsScanTask self() {
+    return this;
+  }
+
+  @Override
+  public List<DeleteFile> deletes() {
+    return ImmutableList.copyOf(deletes);
+  }
+
+  @Override
+  protected Iterable<AddedRowsScanTask> splitUsingOffsets(List<Long> offsets) {
+    return () -> new OffsetsAwareSplitScanTaskIteratorImpl(this, offsets);
+  }
+
+  @Override
+  protected Iterable<AddedRowsScanTask> splitUsingFixedSize(long targetSplitSize) {
+    return () -> new FixedSizeSplitScanTaskIteratorImpl(this, targetSplitSize);
+  }
+
+  private static class SplitScanTaskImpl
+      extends SplitScanTask<SplitScanTaskImpl, AddedRowsScanTask, DataFile>
+      implements AddedRowsScanTask {
+
+    SplitScanTaskImpl(AddedRowsScanTask parentTask, long offset, long length) {
+      super(parentTask, offset, length);
+    }
+
+    @Override
+    public List<DeleteFile> deletes() {
+      return parentTask().deletes();
+    }
+
+    @Override
+    public SplitScanTaskImpl merge(ScanTask other) {
+      SplitScanTaskImpl that = (SplitScanTaskImpl) other;
+      return new SplitScanTaskImpl(parentTask(), start(), length() + that.length());

Review Comment:
   Is it possible in  parent class to have abstract construction method:      
   
   protected abstract ThisT newSplitScanTask(T parentTask, int start, int offset);
   
   and then push merge() to parent, using this construction method?  Then we get merge() and canMerge() in the same class. 



##########
core/src/main/java/org/apache/iceberg/BaseChangelogContentScanTask.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+abstract class BaseChangelogContentScanTask<ThisT, F extends ContentFile<F>>
+    extends BaseContentScanTask<ThisT, F>
+    implements ChangelogScanTask {
+
+  private final int changeOrdinal;
+  private final long commitSnapshotId;
+
+  BaseChangelogContentScanTask(int changeOrdinal, long commitSnapshotId, F file,
+                               String schemaString, String specString, ResidualEvaluator residuals) {
+    super(file, schemaString, specString, residuals);
+    this.changeOrdinal = changeOrdinal;
+    this.commitSnapshotId = commitSnapshotId;
+  }
+
+  @Override
+  public int changeOrdinal() {
+    return changeOrdinal;
+  }
+
+  @Override
+  public long commitSnapshotId() {
+    return commitSnapshotId;
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)
+        .add("change_ordinal", changeOrdinal)
+        .add("commit_snapshot_id", commitSnapshotId)
+        .add("file", file().path())
+        .add("partition_data", file().partition())
+        .add("residual", residual())
+        .toString();
+  }
+
+  abstract static class SplitScanTask<ThisT, T extends ContentScanTask<F> & ChangelogScanTask, F extends ContentFile<F>>

Review Comment:
   ThisT and T are a bit confusing, how about something like T => ParentT ?



##########
core/src/main/java/org/apache/iceberg/BaseChangelogContentScanTask.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+abstract class BaseChangelogContentScanTask<ThisT, F extends ContentFile<F>>
+    extends BaseContentScanTask<ThisT, F>
+    implements ChangelogScanTask {
+
+  private final int changeOrdinal;
+  private final long commitSnapshotId;
+
+  BaseChangelogContentScanTask(int changeOrdinal, long commitSnapshotId, F file,
+                               String schemaString, String specString, ResidualEvaluator residuals) {
+    super(file, schemaString, specString, residuals);
+    this.changeOrdinal = changeOrdinal;
+    this.commitSnapshotId = commitSnapshotId;
+  }
+
+  @Override
+  public int changeOrdinal() {
+    return changeOrdinal;
+  }
+
+  @Override
+  public long commitSnapshotId() {
+    return commitSnapshotId;
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)
+        .add("change_ordinal", changeOrdinal)
+        .add("commit_snapshot_id", commitSnapshotId)
+        .add("file", file().path())

Review Comment:
   There seems to be some ways to have a method toStringHelper() at each level and use it for inheritance, do you think its worth it?  https://github.com/google/guava/issues/1239



##########
core/src/main/java/org/apache/iceberg/BaseChangelogContentScanTask.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+abstract class BaseChangelogContentScanTask<ThisT, F extends ContentFile<F>>
+    extends BaseContentScanTask<ThisT, F>
+    implements ChangelogScanTask {
+
+  private final int changeOrdinal;
+  private final long commitSnapshotId;
+
+  BaseChangelogContentScanTask(int changeOrdinal, long commitSnapshotId, F file,
+                               String schemaString, String specString, ResidualEvaluator residuals) {
+    super(file, schemaString, specString, residuals);
+    this.changeOrdinal = changeOrdinal;
+    this.commitSnapshotId = commitSnapshotId;
+  }
+
+  @Override
+  public int changeOrdinal() {
+    return changeOrdinal;
+  }
+
+  @Override
+  public long commitSnapshotId() {
+    return commitSnapshotId;
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)
+        .add("change_ordinal", changeOrdinal)
+        .add("commit_snapshot_id", commitSnapshotId)
+        .add("file", file().path())
+        .add("partition_data", file().partition())
+        .add("residual", residual())
+        .toString();
+  }
+
+  abstract static class SplitScanTask<ThisT, T extends ContentScanTask<F> & ChangelogScanTask, F extends ContentFile<F>>

Review Comment:
   Nit: I realize it gets long, but can we make these "SplitScanTask" classes have unique names?  There seems now 4 new SplitScanTask classes, which makes navigation very hard (finding a specific class on IDE).  I also got initially confused that it's extending SplitScanTask from BaseFileScanTask, so that's actually a fifth unrelated one.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org