World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1054][#1060] fix(core): Fix bugs about get catalog by prefix (#1064)
Qi Yu95a6467c8813
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.javaindex 5717bfa929..3c2c068f14 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java@@ -184,7 +184,7 @@ public class TransactionalKvBackendImpl implements TransactionalKvBackend {byte[] end = scanRange.getEnd();boolean endInclude = scanRange.isEndInclusive();if (endInclude) {- end = Bytes.increment(Bytes.wrap(end)).get();+ end = endOfKey(end);endInclude = false;}@@ -283,7 +283,7 @@ public class TransactionalKvBackendImpl implements TransactionalKvBackend {new KvRangeScan.KvRangeScanBuilder().start(key).startInclusive(false)- .end(Bytes.increment(Bytes.wrap(key)).get())+ .end(endOfKey(key)).endInclusive(false).predicate((k, v) -> {@@ -353,7 +353,13 @@ public class TransactionalKvBackendImpl implements TransactionalKvBackend {/** Get the end of transaction id, we use this key to scan all commit marks. */static byte[] endOfTransactionId() {- return Bytes.increment(Bytes.wrap(Bytes.concat(TRANSACTION_PREFIX, SEPARATOR))).get();+ // Why use 1? Because we use 1 to represent the smallest transaction id. The smaller id will+ // be larger than the bigger id when converting it to a byte array.+ return generateCommitKey(1L);+ }++ static byte[] endOfKey(byte[] key) {+ return generateKey(key, 1L);}static byte[] getRealKey(byte[] rawKey) {diff --git a/core/src/main/java/com/datastrato/gravitino/utils/Bytes.java b/core/src/main/java/com/datastrato/gravitino/utils/Bytes.javaindex bdeea5734d..f046222aec 100644--- a/core/src/main/java/com/datastrato/gravitino/utils/Bytes.java+++ b/core/src/main/java/com/datastrato/gravitino/utils/Bytes.java@@ -166,6 +166,9 @@ public class Bytes implements Comparable<byte[]> {*/public static Bytes increment(Bytes input) throws IndexOutOfBoundsException {byte[] inputArr = input.get();+ if (inputArr.length == 0) {+ throw new IndexOutOfBoundsException("The length of Key should be greater than 0");+ }byte[] ret = new byte[inputArr.length];int carry = 1;for (int i = inputArr.length - 1; i >= 0; i--) {diff --git a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestTransactionalKvBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestTransactionalKvBackend.javaindex ed1c6ae23b..728bee1d45 100644--- a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestTransactionalKvBackend.java+++ b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestTransactionalKvBackend.java@@ -21,6 +21,7 @@ import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;+import java.util.Random;import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.ThreadLocalRandom;import java.util.concurrent.ThreadPoolExecutor;@@ -421,4 +422,401 @@ class TestTransactionalKvBackend {threadPoolExecutor.awaitTermination(5, TimeUnit.SECONDS);LOGGER.info(String.format("%d thread write qps is: %d/s", threadNum, atomicLong.get() / 2));}++ @Test+ void testPrefixError() throws IOException, InterruptedException {+ Config config = getConfig();+ KvBackend kvBackend = getKvBackEnd(config);+ TransactionIdGenerator transactionIdGenerator =+ new TransactionIdGeneratorImpl(kvBackend, config);+ TransactionalKvBackend transactionalKvBackend =+ new TransactionalKvBackendImpl(kvBackend, transactionIdGenerator);++ transactionalKvBackend.begin();+ transactionalKvBackend.put(+ "abcefghi ".getBytes(StandardCharsets.UTF_8),+ "value1".getBytes(StandardCharsets.UTF_8),+ true);+ transactionalKvBackend.commit();++ // Start to read;+ transactionalKvBackend.begin();+ Assertions.assertEquals(+ "value1", new String(transactionalKvBackend.get("abcefghi ".getBytes())));+ Assertions.assertNull(transactionalKvBackend.get("abcefghi".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcefgh".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcefg".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcef".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abce".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abc".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("ab".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("a".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("_".getBytes(StandardCharsets.UTF_8)));++ transactionalKvBackend.begin();+ transactionalKvBackend.put(+ "abc".getBytes(StandardCharsets.UTF_8), "value1".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.commit();++ transactionalKvBackend.begin();+ Assertions.assertEquals("value1", new String(transactionalKvBackend.get("abc".getBytes())));+ Assertions.assertNull(transactionalKvBackend.get("ab".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("a".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abce".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcd".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcef".getBytes(StandardCharsets.UTF_8)));+ Assertions.assertNull(transactionalKvBackend.get("abcefg".getBytes(StandardCharsets.UTF_8)));+ transactionalKvBackend.commit();++ // Start to test scan+ // We randomly repeated insert some data and test the result+ int repeatedTimes = new Random().nextInt(10) + 1;+ for (int i = 0; i < repeatedTimes; i++) {+ transactionalKvBackend.begin();+ transactionalKvBackend.put(+ "m".getBytes(StandardCharsets.UTF_8), "value1".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "mb".getBytes(StandardCharsets.UTF_8), "value2".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "mbc".getBytes(StandardCharsets.UTF_8), "value3".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "mbcd".getBytes(StandardCharsets.UTF_8), "value4".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "mbcde".getBytes(StandardCharsets.UTF_8),+ "value5".getBytes(StandardCharsets.UTF_8),+ true);+ transactionalKvBackend.put(+ "mbcdf".getBytes(StandardCharsets.UTF_8),+ "value6".getBytes(StandardCharsets.UTF_8),+ true);+ transactionalKvBackend.put(+ "mbcdfg".getBytes(StandardCharsets.UTF_8),+ "value7".getBytes(StandardCharsets.UTF_8),+ true);+ transactionalKvBackend.commit();+ Thread.sleep(1);+ }++ transactionalKvBackend.begin();++ // start is 'mb' and end is 'mc'+ List<Pair<byte[], byte[]>> data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(6, data.size());++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("mbc", new String(data.get(0).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(6, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(6, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));++ // Start is 'mb' and end is 'mbcde'+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbcde".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(2, data.size());+ Assertions.assertEquals("mbcd", new String(data.get(1).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbcde".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(3, data.size());+ Assertions.assertEquals("mbcde", new String(data.get(2).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbcde".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());++ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("mbcde", new String(data.get(3).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbcde".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());++ Assertions.assertEquals(3, data.size());+ Assertions.assertEquals("mbcd", new String(data.get(2).getKey()));++ // Start is 'mb' and end is 'mbc'+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(1, data.size());+ Assertions.assertEquals("mbc", new String(data.get(0).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(0, data.size());++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(1, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mbc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(2, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));+ Assertions.assertEquals("mbc", new String(data.get(1).getKey()));++ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mb".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());++ Assertions.assertEquals(1, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));++ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("mb".getBytes(StandardCharsets.UTF_8))+ .end("mc".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());++ Assertions.assertEquals(1, data.size());+ Assertions.assertEquals("mb", new String(data.get(0).getKey()));++ repeatedTimes = new Random().nextInt(10) + 1;+ for (int i = 0; i < repeatedTimes; i++) {+ transactionalKvBackend.begin();+ transactionalKvBackend.put(+ "bc".getBytes(StandardCharsets.UTF_8), "value1".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "bcd".getBytes(StandardCharsets.UTF_8), "value2".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "bcde".getBytes(StandardCharsets.UTF_8), "value3".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "bce".getBytes(StandardCharsets.UTF_8), "value4".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "bcef".getBytes(StandardCharsets.UTF_8), "value5".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "bef".getBytes(StandardCharsets.UTF_8), "value6".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.put(+ "beg".getBytes(StandardCharsets.UTF_8), "value7".getBytes(StandardCharsets.UTF_8), true);+ transactionalKvBackend.commit();+ Thread.sleep(1);+ }++ transactionalKvBackend.begin();++ // Start is "bc" and end is "bcef"+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bcef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(3, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bce", new String(data.get(2).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bcef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(3).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bcef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(4).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bcef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bce", new String(data.get(3).getKey()));++ // Start is "bc" and end is "bef"+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(3).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bef", new String(data.get(4).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(6, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bef", new String(data.get(5).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(4).getKey()));++ // Start is "bc" and end is "be"+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("be".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(3).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("be".getBytes(StandardCharsets.UTF_8))+ .startInclusive(false)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(4, data.size());+ Assertions.assertEquals("bcd", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(3).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("be".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(true)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(4).getKey()));+ data =+ transactionalKvBackend.scan(+ KvRangeScan.builder()+ .start("bc".getBytes(StandardCharsets.UTF_8))+ .end("bef".getBytes(StandardCharsets.UTF_8))+ .startInclusive(true)+ .endInclusive(false)+ .build());+ Assertions.assertEquals(5, data.size());+ Assertions.assertEquals("bc", new String(data.get(0).getKey()));+ Assertions.assertEquals("bcef", new String(data.get(4).getKey()));+ }}diff --git a/docs/metrics.md b/docs/metrics.mdindex e3ddca31c0..257bd3302f 100644--- a/docs/metrics.md+++ b/docs/metrics.md@@ -3,7 +3,8 @@ title: Gravitino metricsslug: /metricskeywords:- metrics-license: Copyright 2023 Datastrato. This software is licensed under the Apache License version 2.+license: "Copyright 2023 Datastrato Pvt Ltd.+This software is licensed under the Apache License version 2."---## Introductiondiff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.javaindex c1b22f6d81..1e0fe8aa2c 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java@@ -27,6 +27,8 @@ import static org.apache.hadoop.hive.serde.serdeConstants.TINYINT_TYPE_NAME;import static org.junit.jupiter.api.Assertions.assertThrows;import com.datastrato.gravitino.Catalog;+import com.datastrato.gravitino.CatalogChange;+import com.datastrato.gravitino.MetalakeChange;import com.datastrato.gravitino.NameIdentifier;import com.datastrato.gravitino.catalog.hive.HiveClientPool;import com.datastrato.gravitino.catalog.hive.HiveSchemaPropertiesMetadata;@@ -38,6 +40,9 @@ import com.datastrato.gravitino.dto.rel.SortOrderDTO;import com.datastrato.gravitino.dto.rel.expressions.FieldReferenceDTO;import com.datastrato.gravitino.dto.rel.partitions.IdentityPartitioningDTO;import com.datastrato.gravitino.dto.rel.partitions.Partitioning;+import com.datastrato.gravitino.exceptions.NoSuchCatalogException;+import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;+import com.datastrato.gravitino.exceptions.NoSuchSchemaException;import com.datastrato.gravitino.exceptions.NoSuchTableException;import com.datastrato.gravitino.integration.test.container.ContainerSuite;import com.datastrato.gravitino.integration.test.container.HiveContainer;@@ -75,6 +80,7 @@ import org.junit.jupiter.api.AfterEach;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Tag;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.TestMethodOrder;@@ -878,4 +884,179 @@ public class CatalogHiveIT extends AbstractIT {Assertions.assertFalse(properties3.containsKey("key1"));Assertions.assertEquals("val2-alter", properties3.get("key2"));}++ @Test+ void testLoadEntityWithSamePrefix() {+ GravitinoMetaLake metalake = client.loadMetalake(NameIdentifier.of(metalakeName));+ Catalog catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));+ Assertions.assertNotNull(catalog);++ for (int i = 1; i < metalakeName.length(); i++) {+ // We can't get the metalake by prefix+ final int length = i;+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(metalakeName.substring(0, length))));+ }+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(metalakeName + "a")));++ for (int i = 1; i < catalogName.length(); i++) {+ // We can't get the catalog by prefix+ final int length = i;+ Assertions.assertThrows(+ NoSuchCatalogException.class,+ () ->+ metalake.loadCatalog(+ NameIdentifier.of(metalakeName, catalogName.substring(0, length))));+ }++ // We can't load the catalog.+ Assertions.assertThrows(+ NoSuchCatalogException.class,+ () -> metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName + "a")));++ for (int i = 1; i < schemaName.length(); i++) {+ // We can't get the schema by prefix+ final int length = i;+ Assertions.assertThrows(+ NoSuchSchemaException.class,+ () ->+ catalog+ .asSchemas()+ .loadSchema(+ NameIdentifier.of(+ metalakeName, catalogName, schemaName.substring(0, length))));+ }++ Assertions.assertThrows(+ NoSuchSchemaException.class,+ () ->+ catalog+ .asSchemas()+ .loadSchema(NameIdentifier.of(metalakeName, catalogName, schemaName + "a")));++ for (int i = 1; i < tableName.length(); i++) {+ // We can't get the table by prefix+ final int length = i;+ Assertions.assertThrows(+ NoSuchTableException.class,+ () ->+ catalog+ .asTableCatalog()+ .loadTable(+ NameIdentifier.of(+ metalakeName, catalogName, schemaName, tableName.substring(0, length))));+ }++ Assertions.assertThrows(+ NoSuchTableException.class,+ () ->+ catalog+ .asTableCatalog()+ .loadTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName + "a")));+ }++ @Test+ // Make sure it will be executed at last.+ @Order(Integer.MAX_VALUE)+ void testAlterEntityName() {+ final GravitinoMetaLake metalake = client.loadMetalake(NameIdentifier.of(metalakeName));+ String newMetalakeName = GravitinoITUtils.genRandomName("CatalogHiveIT_metalake_new");++ // Test rename metalake+ for (int i = 0; i < 2; i++) {+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(newMetalakeName)));+ client.alterMetalake(NameIdentifier.of(metalakeName), MetalakeChange.rename(newMetalakeName));+ client.loadMetalake(NameIdentifier.of(newMetalakeName));+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(metalakeName)));++ client.alterMetalake(NameIdentifier.of(newMetalakeName), MetalakeChange.rename(metalakeName));+ client.loadMetalake(NameIdentifier.of(metalakeName));+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(newMetalakeName)));+ }++ Catalog catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));+ // Test rename catalog+ String newCatalogName = GravitinoITUtils.genRandomName("CatalogHiveIT_catalog_new");+ for (int i = 0; i < 2; i++) {+ Assertions.assertThrows(+ NoSuchCatalogException.class,+ () -> metalake.loadCatalog(NameIdentifier.of(metalakeName, newMetalakeName)));+ metalake.alterCatalog(+ NameIdentifier.of(metalakeName, catalogName), CatalogChange.rename(newCatalogName));+ metalake.loadCatalog(NameIdentifier.of(metalakeName, newCatalogName));+ Assertions.assertThrows(+ NoSuchCatalogException.class,+ () -> metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName)));++ metalake.alterCatalog(+ NameIdentifier.of(metalakeName, newCatalogName), CatalogChange.rename(catalogName));+ catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));+ Assertions.assertThrows(+ NoSuchCatalogException.class,+ () -> metalake.loadCatalog(NameIdentifier.of(metalakeName, newMetalakeName)));+ }++ // Schema does not have the rename operation.++ ColumnDTO[] columns = createColumns();+ catalog+ .asTableCatalog()+ .createTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName),+ columns,+ TABLE_COMMENT,+ createProperties(),+ new Transform[0]);++ final Catalog cata = catalog;+ // Now try to rename table+ final String newTableName = GravitinoITUtils.genRandomName("CatalogHiveIT_table_new");+ for (int i = 0; i < 2; i++) {+ // The table to be renamed does not exist+ Assertions.assertThrows(+ NoSuchTableException.class,+ () ->+ cata.asTableCatalog()+ .loadTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, newTableName)));+ catalog+ .asTableCatalog()+ .alterTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName),+ TableChange.rename(newTableName));+ Table table =+ catalog+ .asTableCatalog()+ .loadTable(NameIdentifier.of(metalakeName, catalogName, schemaName, newTableName));+ Assertions.assertNotNull(table);++ // Old Table should not exist anymore.+ Assertions.assertThrows(+ NoSuchTableException.class,+ () ->+ cata.asTableCatalog()+ .loadTable(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName)));++ catalog+ .asTableCatalog()+ .alterTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, newTableName),+ TableChange.rename(tableName));+ table =+ catalog+ .asTableCatalog()+ .loadTable(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName));+ Assertions.assertNotNull(table);+ }+ }}