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 2019/08/14 18:21:31 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #377: Add FindFiles helper API

rdblue commented on a change in pull request #377: Add FindFiles helper API
URL: https://github.com/apache/incubator-iceberg/pull/377#discussion_r314017383
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/FindFiles.java
 ##########
 @@ -0,0 +1,195 @@
+/*
+ * 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 com.google.common.base.Preconditions;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.CloseableIterable;
+
+public class FindFiles {
+  private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+
+  public static Builder in(Table table) {
+    return new Builder(table);
+  }
+
+  public static class Builder {
+    private final Table table;
+    private final TableOperations ops;
+    private boolean caseSensitive = true;
+    private Long snapshotId = null;
+    private Expression rowFilter = Expressions.alwaysTrue();
+    private Expression fileFilter = Expressions.alwaysTrue();
+    private Expression partitionFilter = Expressions.alwaysTrue();
+
+    public Builder(Table table) {
+      this.table = table;
+      this.ops = ((HasTableOperations) table).operations();
+    }
+
+    public Builder caseInsensitive() {
+      this.caseSensitive = false;
+      return this;
+    }
+
+    public Builder caseSensitive(boolean caseSensitive) {
+      this.caseSensitive = caseSensitive;
+      return this;
+    }
+
+    /**
+     * Base results on the given snapshot.
+     *
+     * @param snapshotId a snapshot ID
+     * @return this for method chaining
+     */
+    public Builder inSnapshot(long snapshotId) {
+      Preconditions.checkArgument(this.snapshotId == null,
+          "Cannot set snapshot multiple times, already set to id=%s", snapshotId);
+      Preconditions.checkArgument(table.snapshot(snapshotId) != null,
+          "Cannot find snapshot for id=%s", snapshotId);
+      this.snapshotId = snapshotId;
+      return this;
+    }
+
+    /**
+     * Base results on files in the snapshot that was current as of a timestamp.
+     *
+     * @param timestampMillis a timestamp in milliseconds
+     * @return this for method chaining
+     */
+    public Builder asOfTime(long timestampMillis) {
+      Preconditions.checkArgument(this.snapshotId == null,
+          "Cannot set snapshot multiple times, already set to id=%s", snapshotId);
+
+      Long lastSnapshotId = null;
+      for (HistoryEntry logEntry : ops.current().snapshotLog()) {
+        if (logEntry.timestampMillis() <= timestampMillis) {
+          lastSnapshotId = logEntry.snapshotId();
+        }
 
 Review comment:
   Done, and I added a test for `asOfTime`.
   
   The log is in ascending order and that is validated here: https://github.com/apache/incubator-iceberg/blob/master/core/src/main/java/org/apache/iceberg/TableMetadata.java#L178-L185

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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