rymurr commented on a change in pull request #1587:
URL: https://github.com/apache/iceberg/pull/1587#discussion_r527722629



##########
File path: nessie/src/main/java/org/apache/iceberg/nessie/TableReference.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.nessie;
+
+import java.time.Instant;
+import org.apache.iceberg.catalog.TableIdentifier;
+
+public class TableReference {
+
+  private final TableIdentifier tableIdentifier;
+  private final Instant timestamp;
+  private final String reference;
+
+  /**
+   * Container class to specify a TableIdentifier on a specific Reference or 
at an Instant in time.
+   */
+  public TableReference(TableIdentifier tableIdentifier, Instant timestamp, 
String reference) {
+    this.tableIdentifier = tableIdentifier;
+    this.timestamp = timestamp;
+    this.reference = reference;
+  }
+
+  public TableIdentifier getTableIdentifier() {
+    return tableIdentifier;
+  }
+
+  public Instant getTimestamp() {
+    return timestamp;
+  }
+
+  public String getReference() {
+    return reference;
+  }
+
+  /**
+   * Convert dataset read/write options to a table and ref/hash.
+   */
+  public static TableReference parse(TableIdentifier path) {
+    TableReference pti = parse(path.name());
+    return new TableReference(TableIdentifier.of(path.namespace(), 
pti.getTableIdentifier().name()),
+        pti.getTimestamp(),
+        pti.getReference());
+  }
+
+  /**
+   * Convert dataset read/write options to a table and ref/hash.
+   */
+  public static TableReference parse(String path) {
+    // I am assuming tables can't have @ or # symbols
+    if (path.split("@").length > 2) {
+      throw new IllegalArgumentException(String.format("Can only reference one 
branch in %s", path));
+    }
+    if (path.split("#").length > 2) {
+      throw new IllegalArgumentException(String.format("Can only reference one 
timestamp in %s", path));
+    }
+
+    if (path.contains("@") && path.contains("#")) {
+      throw new IllegalArgumentException("Invalid table name:" +
+          " # is not allowed (reference by timestamp is not supported)");
+    }
+
+    if (path.contains("@")) {
+      String[] tableRef = path.split("@");
+      TableIdentifier identifier = TableIdentifier.parse(tableRef[0]);
+      return new TableReference(identifier, null, tableRef[1]);
+    }
+
+    if (path.contains("#")) {
+      throw new IllegalArgumentException("Invalid table name:" +
+          " # is not allowed (reference by timestamp is not supported)");
+    }

Review comment:
       If it doesn't matter much to you I would like to leave it in. I will be 
adding timestamp support here very soon.
   
   Happy to remove it till then if you prefer too.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to