From 18e58cde4f16692dbe23667ba9f9f8e348faef02 Mon Sep 17 00:00:00 2001 From: Alexandre Dutra Date: Thu, 28 Sep 2023 16:20:14 +0200 Subject: [PATCH] Allow relative hashes in table references --- CHANGELOG.md | 2 ++ .../projectnessie/model/TableReference.java | 2 +- .../model/TestTableReference.java | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9106b870db2..6101a2e1d89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ as necessary. Empty sections will not end in the release notes. - Introduces sizing of the Nessie object cache using a relative value of the max Java heap size. The defaults have been changed to 70% of the Java max heap size (from the previous default of 64MB). If a fixed cache size setting has been explicitly configured, consider to change it to the fraction based one. +- Relative hashes are now supported in table references, thus allowing SQL queries to specify a relative hash + in the `FROM` clause, e.g. `FROM table1@main#1234^1`. ### Deprecations diff --git a/api/model/src/main/java/org/projectnessie/model/TableReference.java b/api/model/src/main/java/org/projectnessie/model/TableReference.java index dcdd7837b05..2576cc60a38 100644 --- a/api/model/src/main/java/org/projectnessie/model/TableReference.java +++ b/api/model/src/main/java/org/projectnessie/model/TableReference.java @@ -127,7 +127,7 @@ public static TableReference parse(String tableReference) { b.reference(refName); } if (hashOrTimestamp != null) { - if (Validation.isValidHash(hashOrTimestamp)) { + if (Validation.isValidHashOrRelativeSpec(hashOrTimestamp)) { b.hash(hashOrTimestamp); } else { b.timestamp(hashOrTimestamp); diff --git a/api/model/src/test/java/org/projectnessie/model/TestTableReference.java b/api/model/src/test/java/org/projectnessie/model/TestTableReference.java index 8070edc0a53..c9d24ce8516 100644 --- a/api/model/src/test/java/org/projectnessie/model/TestTableReference.java +++ b/api/model/src/test/java/org/projectnessie/model/TestTableReference.java @@ -45,6 +45,37 @@ static List fromContentKeyTestCases() { "12345678abcdef12345678abcdef", null }, + // relative hashes - unambiguous + new Object[] { + "`simple_name@ref#12345678abcdef12345678abcdef~1^2*2023-09-28T12:34:56.789Z`", + "simple_name", + "ref", + "12345678abcdef12345678abcdef~1^2*2023-09-28T12:34:56.789Z", + null + }, + new Object[] { + "`simple_name#12345678abcdef12345678abcdef~1^2*2023-09-28T12:34:56.789Z`", + "simple_name", + null, + "12345678abcdef12345678abcdef~1^2*2023-09-28T12:34:56.789Z", + null + }, + // relative hashes - ambiguous + new Object[] { + "`simple_name@ref#~1^2*2023-09-28T12:34:56.789Z`", + "simple_name", + "ref", + "~1^2*2023-09-28T12:34:56.789Z", + null + }, + new Object[] { + "`simple_name#~1^2*2023-09-28T12:34:56.789Z`", + "simple_name", + null, + "~1^2*2023-09-28T12:34:56.789Z", + null + }, + // timestamps new Object[] {"`simple_name#2020-12-24`", "simple_name", null, null, "2020-12-24"}, new Object[] {"`simple_name@ref#2020-12-24`", "simple_name", "ref", null, "2020-12-24"}); }