You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "JingsongLi (via GitHub)" <gi...@apache.org> on 2023/05/04 06:55:16 UTC

[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1008: [core] add interface listPartitions and dropPartitions to paimon Catalog

JingsongLi commented on code in PR #1008:
URL: https://github.com/apache/incubator-paimon/pull/1008#discussion_r1184608211


##########
paimon-core/src/main/java/org/apache/paimon/manifest/SimpleManifestEntry.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.types.TinyIntType;
+import org.apache.paimon.utils.Preconditions;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.paimon.utils.SerializationUtils.newBytesType;
+import static org.apache.paimon.utils.SerializationUtils.newStringType;
+
+/** Partition Entry pojo read from manifest file. */
+public class SimpleManifestEntry {
+    private final FileKind kind;
+
+    private final BinaryRow partition;
+    private final int bucket;
+
+    private final String fileName;
+
+    public FileKind kind() {
+        return kind;
+    }
+
+    public BinaryRow partition() {
+        return partition;
+    }
+
+    public int bucket() {
+        return bucket;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public SimpleManifestEntry(FileKind kind, BinaryRow partition, int bucket, String fileName) {
+        this.kind = kind;
+        this.partition = partition;
+        this.bucket = bucket;
+        this.fileName = fileName;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof SimpleManifestEntry)) {
+            return false;
+        }
+        SimpleManifestEntry eobj = (SimpleManifestEntry) obj;
+
+        return Objects.equals(eobj.fileName, this.fileName)
+                && Objects.equals(eobj.partition, this.partition)
+                && Objects.equals(eobj.kind, this.kind);
+    }
+
+    public static RowType schema() {
+        List<DataField> fields = new ArrayList<>();
+        fields.add(new DataField(0, "_KIND", new TinyIntType(false)));
+        fields.add(new DataField(1, "_PARTITION", newBytesType(false)));
+        fields.add(new DataField(2, "_BUCKET", new IntType(false)));
+        fields.add(new DataField(3, "_FILE", schemaDataFileName()));
+        return new RowType(fields);
+    }
+
+    public static RowType schemaDataFileName() {
+        List<DataField> fields = new ArrayList<>();
+        fields.add(new DataField(0, "_FILE_NAME", newStringType(false)));
+        return new RowType(fields);
+    }
+
+    public static List<SimpleManifestEntry> mergePartitionEntries(

Review Comment:
   Can we unify this to `ManifestEntry.mergeEntries`?
   Maybe it can be:
   ```
   ManifestEntry {
       public static <T> Collection<T> mergeEntries(
               List<T> entries, Function<T, Identifier> extractIdentifier) {
               ..............
       }
   }
   ```



##########
paimon-core/src/main/java/org/apache/paimon/manifest/SimpleManifestReader.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.format.FormatReaderFactory;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.ObjectSerializer;
+import org.apache.paimon.utils.ObjectsFile;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.SegmentsCache;
+
+import javax.annotation.Nullable;
+
+/** This class read partitions from manifest file, only decode the partition related bytes. */
+public class SimpleManifestReader extends ObjectsFile<SimpleManifestEntry> {
+
+    private final RowType partitionType;
+
+    public SimpleManifestReader(
+            FileIO fileIO,
+            ObjectSerializer<SimpleManifestEntry> serializer,
+            RowType partitionType,
+            FormatReaderFactory readerFactory,
+            PathFactory pathFactory,
+            @Nullable SegmentsCache<String> cache) {
+        super(fileIO, serializer, readerFactory, pathFactory, cache);
+        this.partitionType = partitionType;
+    }
+
+    public RowType getPartitionType() {

Review Comment:
   ```
   @VisibleForTesting
   RowType getPartitionType() {...}
   ```



##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreScan.java:
##########
@@ -272,6 +274,36 @@ public List<ManifestEntry> files() {
         };
     }
 
+    // this method read partitions in Manifest File partition related bytes directly, reduce the
+    // usage of redundant deserialization
+    @Override
+    public List<SimpleManifestEntry> planPartitions() {
+        List<ManifestFileMeta> manifests = specifiedManifests;
+        Long snapshotId = specifiedSnapshotId;
+        if (manifests == null) {
+            if (snapshotId == null) {
+                snapshotId = snapshotManager.latestSnapshotId();
+            }
+            if (snapshotId == null) {
+                manifests = Collections.emptyList();
+            } else {
+                Snapshot snapshot = snapshotManager.snapshot(snapshotId);
+                manifests = readManifests(snapshot);
+            }
+        }
+
+        Iterable<SimpleManifestEntry> entries =
+                ParallellyExecuteUtils.parallelismBatchIterable(

Review Comment:
   `ParallellyExecuteUtils.parallelismBatchIterable` can be applied to `plan` too.



##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreScan.java:
##########
@@ -272,6 +274,36 @@ public List<ManifestEntry> files() {
         };
     }
 
+    // this method read partitions in Manifest File partition related bytes directly, reduce the
+    // usage of redundant deserialization
+    @Override
+    public List<SimpleManifestEntry> planPartitions() {

Review Comment:
   `planSimpleManifestEntry`?



##########
paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java:
##########
@@ -200,6 +200,19 @@ public void alterTable(
                                 .commitChanges(changes));
     }
 
+    @Override
+    public List<Partition> listPartitions(Identifier identifier) throws TableNotExistException {
+        checkNotSystemTable(identifier, "listPartitions");
+        return getTable(identifier).newReadBuilder().newScan().partitions();

Review Comment:
   Maybe we can have a default method in `Catalog`?



##########
paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFile.java:
##########
@@ -183,5 +183,20 @@ public ManifestFile create() {
                     suggestedFileSize,
                     cache);
         }
+
+        // this reader read simple manifest information which only contains partition, file kind and
+        // file name in a quick way.
+        public SimpleManifestReader createPartitionFileReader() {

Review Comment:
   `createSimpleManifestReader`?



##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreScan.java:
##########
@@ -272,6 +274,36 @@ public List<ManifestEntry> files() {
         };
     }
 
+    // this method read partitions in Manifest File partition related bytes directly, reduce the
+    // usage of redundant deserialization
+    @Override
+    public List<SimpleManifestEntry> planPartitions() {

Review Comment:
   Codes can be unified to `plan`? Extract some common methods?



-- 
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@paimon.apache.org

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