Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#411]feat(catalog-lakehouse): Add E2E test to Iceberg REST service (#448)

FANNG0f7380d184ab
diff --git a/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/utils/IcebergCatalogUtil.java b/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/utils/IcebergCatalogUtil.java
index 9273b5b228..c121f943de 100644
--- a/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/utils/IcebergCatalogUtil.java
+++ b/catalogs/catalog-lakehouse/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/utils/IcebergCatalogUtil.java
@@ -7,6 +7,7 @@ package com.datastrato.graviton.catalog.lakehouse.iceberg.utils;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.inmemory.InMemoryCatalog;
@@ -15,6 +16,7 @@ public class IcebergCatalogUtil {
private static InMemoryCatalog loadMemoryCatalog() {
InMemoryCatalog memoryCatalog = new InMemoryCatalog();
Map<String, String> properties = new HashMap<>();
+ properties.put(CatalogProperties.WAREHOUSE_LOCATION, "/tmp");
memoryCatalog.initialize("memory", properties);
return memoryCatalog;
diff --git a/conf/graviton.conf.template b/conf/graviton.conf.template
index e4a99421fb..e07413cb80 100644
--- a/conf/graviton.conf.template
+++ b/conf/graviton.conf.template
@@ -35,3 +35,9 @@ graviton.entity.store.kv.rocksdbPath = /tmp/graviton
# THE CONFIGURATION FOR GRAVITON CATALOG
# The interval in milliseconds to evict the catalog cache
graviton.catalog.cache.evictionIntervalMs = 3600000
+
+# THE CONFIGURATION FOR AUXILIARY SERVICE
+# Auxiliary service names, seperate by ','
+graviton.auxService.names = iceberg-rest
+# Iceberg REST service classpath
+graviton.auxService.iceberg-rest.classpath = catalogs/lakehouse/libs
\ No newline at end of file
diff --git a/core/src/main/java/com/datastrato/graviton/aux/AuxiliaryServiceManager.java b/core/src/main/java/com/datastrato/graviton/aux/AuxiliaryServiceManager.java
index e1954e45ce..0b0aec5884 100644
--- a/core/src/main/java/com/datastrato/graviton/aux/AuxiliaryServiceManager.java
+++ b/core/src/main/java/com/datastrato/graviton/aux/AuxiliaryServiceManager.java
@@ -32,8 +32,8 @@ import org.slf4j.LoggerFactory;
public class AuxiliaryServiceManager {
private static final Logger LOG = LoggerFactory.getLogger(AuxiliaryServiceManager.class);
public static final String GRAVITON_AUX_SERVICE_PREFIX = "graviton.auxService.";
- public static final String AUX_SERVICE_NAMES = "auxServiceNames";
- public static final String AUX_SERVICE_CLASSPATH = "auxServiceClasspath";
+ public static final String AUX_SERVICE_NAMES = "names";
+ public static final String AUX_SERVICE_CLASSPATH = "classpath";
private static final Splitter splitter = Splitter.on(",");
private static final Joiner DOT = Joiner.on(".");
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 19d1657d5d..85759def25 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -26,6 +26,7 @@ commons-collections4 = "4.4"
caffeine = "2.9.3"
rocksdbjni = "7.7.3"
iceberg = '1.3.1'
+spark = "3.3.3"
protobuf-plugin = "0.9.2"
spotless-plugin = '6.11.0'
@@ -80,6 +81,8 @@ caffeine = { group = "com.github.ben-manes.caffeine", name = "caffeine", version
rocksdbjni = { group = "org.rocksdb", name = "rocksdbjni", version.ref = "rocksdbjni" }
commons-collections4 = { group = "org.apache.commons", name = "commons-collections4", version.ref = "commons-collections4" }
iceberg-core = { group = "org.apache.iceberg", name = "iceberg-core", version.ref = "iceberg" }
+iceberg-spark-runtime = { group = "org.apache.iceberg", name = "iceberg-spark-runtime-3.3_2.13", version.ref = "iceberg" }
+spark-sql = { group = "org.apache.spark", name = "spark-sql_2.13", version.ref = "spark" }
[bundles]
log4j = ["slf4j-api", "log4j-slf4j2-impl", "log4j-api", "log4j-core", "log4j-12-api"]
@@ -93,4 +96,4 @@ spotless = { id = "com.diffplug.spotless", version.ref = "spotless-plugin" }
gradle-extensions = { id = "com.github.vlsi.gradle-extensions", version.ref = "gradle-extensions-plugin" }
publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "publish-plugin" }
rat = { id = "org.nosphere.apache.rat", version.ref = "rat-plugin" }
-shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow-plugin" }
\ No newline at end of file
+shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow-plugin" }
diff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.kts
index d2e3480ca9..71e91229d3 100644
--- a/integration-test/build.gradle.kts
+++ b/integration-test/build.gradle.kts
@@ -96,6 +96,9 @@ dependencies {
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(libs.mockito.core)
testImplementation(libs.bundles.log4j)
+ testImplementation(libs.iceberg.spark.runtime)
+ testImplementation(libs.spark.sql)
+ testImplementation(libs.slf4j.jdk14)
}
/* Optimizing integration test execution conditions */
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceBaseIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceBaseIT.java
new file mode 100644
index 0000000000..e80ea37aa9
--- /dev/null
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceBaseIT.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.graviton.integration.test.catalog.lakehouse.iceberg;
+
+import com.datastrato.graviton.Config;
+import com.datastrato.graviton.aux.AuxiliaryServiceManager;
+import com.datastrato.graviton.catalog.lakehouse.iceberg.IcebergRESTConfig;
+import com.datastrato.graviton.catalog.lakehouse.iceberg.IcebergRESTService;
+import com.datastrato.graviton.integration.test.util.AbstractIT;
+import com.datastrato.graviton.utils.MapUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.Assertions;
+
+/*
+ * <p>Referred from spark/v3.4/spark/src/test/java/org/apache/iceberg/spark/SparkTestBase.java
+ */
+public class TestIcebergRESTServiceBaseIT extends AbstractIT {
+ private SparkSession sparkSession;
+
+ public TestIcebergRESTServiceBaseIT() {
+ initSparkEnv();
+ }
+
+ private static IcebergRESTConfig buildIcebergRESTConfig(Config config) {
+ Map<String, String> m =
+ config.getConfigsWithPrefix(AuxiliaryServiceManager.GRAVITON_AUX_SERVICE_PREFIX);
+ m = MapUtils.getPrefixMap(m, IcebergRESTService.SERVICE_NAME + ".");
+ IcebergRESTConfig icebergRESTConfig = new IcebergRESTConfig();
+ icebergRESTConfig.loadFromMap(m, k -> true);
+ return icebergRESTConfig;
+ }
+
+ private void initSparkEnv() {
+ IcebergRESTConfig icebergRESTConfig = buildIcebergRESTConfig(serverConfig);
+ int port = icebergRESTConfig.get(IcebergRESTConfig.ICEBERG_REST_SERVER_HTTP_PORT);
+ LOG.info("Iceberg REST server port:{}", port);
+ String IcebergRESTUri = String.format("http://127.0.0.1:%d/iceberg/", port);
+ sparkSession =
+ SparkSession.builder()
+ .master("local[1]")
+ .config(
+ "spark.sql.extensions",
+ "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
+ .config("spark.sql.catalog.rest", "org.apache.iceberg.spark.SparkCatalog")
+ .config("spark.sql.catalog.rest.type", "rest")
+ .config("spark.sql.catalog.rest.uri", IcebergRESTUri)
+ .getOrCreate();
+
+ sparkSession.sparkContext().setLogLevel("WARN");
+ }
+
+ protected List<Object[]> sql(String query, Object... args) {
+ List<Row> rows = sparkSession.sql(String.format(query, args)).collectAsList();
+ if (rows.isEmpty()) {
+ return ImmutableList.of();
+ }
+ return rowsToJava(rows);
+ }
+
+ protected List<Object[]> rowsToJava(List<Row> rows) {
+ return rows.stream().map(this::toJava).collect(Collectors.toList());
+ }
+
+ private Object[] toJava(Row row) {
+ return IntStream.range(0, row.size())
+ .mapToObj(
+ pos -> {
+ if (row.isNullAt(pos)) {
+ return null;
+ }
+ Object value = row.get(pos);
+ if (value instanceof Row) {
+ return toJava((Row) value);
+ } else if (value instanceof scala.collection.Seq) {
+ return row.getList(pos);
+ } else if (value instanceof scala.collection.Map) {
+ return row.getJavaMap(pos);
+ }
+ return value;
+ })
+ .toArray(Object[]::new);
+ }
+
+ /** check whether all child map content is in parent map */
+ protected void checkMapContains(Map<String, String> child, Map<String, String> parent) {
+ child.forEach(
+ (k, v) -> {
+ Assertions.assertTrue(parent.containsKey(k));
+ Assertions.assertEquals(v, parent.get(k));
+ });
+ }
+
+ /** mainly used to debug */
+ protected void printObjects(List<Object[]> objects) {
+ objects.stream()
+ .forEach(
+ row -> {
+ String oneRow =
+ Arrays.stream(row).map(o -> String.valueOf(o)).collect(Collectors.joining(","));
+ LOG.warn(oneRow);
+ });
+ }
+
+ protected Map<String, String> getTableInfo(String tableName) {
+ return convertToStringMap(sql("desc table extended " + tableName));
+ }
+
+ protected List<String> getTableColumns(String tableName) {
+ List<Object[]> objects = sql("desc table extended " + tableName);
+ List<String> columns = new ArrayList<>();
+ objects.stream()
+ .anyMatch(
+ row -> {
+ String columName = (String) row[0];
+ if (StringUtils.isNoneBlank(columName)) {
+ columns.add(columName);
+ return false;
+ }
+ return true;
+ });
+ return columns;
+ }
+
+ protected Set<String> convertToStringSet(List<Object[]> objects, int index) {
+ return objects.stream().map(row -> String.valueOf(row[index])).collect(Collectors.toSet());
+ }
+
+ protected Map<String, String> convertToStringMap(List<Object[]> objects) {
+ return objects.stream()
+ .collect(
+ Collectors.toMap(
+ row -> String.valueOf(row[0]),
+ row -> String.valueOf(row[1]),
+ (oldValue, newValue) -> oldValue));
+ }
+}
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceIT.java
new file mode 100644
index 0000000000..98a970d067
--- /dev/null
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/lakehouse/iceberg/TestIcebergRESTServiceIT.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.graviton.integration.test.catalog.lakehouse.iceberg;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.exceptions.BadRequestException;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.spark.sql.AnalysisException;
+import org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class TestIcebergRESTServiceIT extends TestIcebergRESTServiceBaseIT {
+
+ @BeforeEach
+ void initEnv() {
+ // use rest catalog
+ sql("USE rest");
+ sql("CREATE DATABASE IF NOT EXISTS table_test");
+ }
+
+ @Test
+ void testCreateNamespace() {
+ sql(
+ "CREATE DATABASE db_create COMMENT 'This is customer database' WITH DBPROPERTIES (ID=001, Name='John')");
+ Map<String, String> databaseInfo =
+ convertToStringMap(sql("DESCRIBE DATABASE EXTENDED db_create"));
+ Assertions.assertEquals("This is customer database", databaseInfo.get("Comment"));
+ Assertions.assertEquals("db_create", databaseInfo.get("Namespace Name"));
+ Assertions.assertEquals("((ID,001), (Name,John))", databaseInfo.get("Properties"));
+
+ Assertions.assertThrowsExactly(
+ NamespaceAlreadyExistsException.class, () -> sql("CREATE DATABASE db_create"));
+ }
+
+ @Test
+ void testListNamespace() {
+ sql("CREATE DATABASE list_foo1");
+ sql("CREATE DATABASE list_foo2");
+ List<Object[]> databases = sql("SHOW DATABASES like 'list_foo*'");
+ Set<String> databasesString = convertToStringSet(databases, 0);
+ Assertions.assertEquals(ImmutableSet.of("list_foo1", "list_foo2"), databasesString);
+ }
+
+ @Test
+ void testDropNameSpace() {
+ sql("CREATE DATABASE IF NOT EXISTS drop_foo1");
+ sql("DESC DATABASE drop_foo1");
+ sql(
+ "CREATE TABLE IF NOT EXISTS drop_foo1.test (id bigint COMMENT 'unique id',data string) using iceberg");
+
+ // seems a bug in Iceberg REST client, should be NamespaceNotEmptyException
+ Assertions.assertThrowsExactly(BadRequestException.class, () -> sql("DROP DATABASE drop_foo1"));
+ sql("DROP TABLE drop_foo1.test");
+ sql("DROP DATABASE drop_foo1");
+
+ Assertions.assertThrowsExactly(
+ NoSuchNamespaceException.class, () -> sql("DESC DATABASE drop_foo1"));
+
+ Assertions.assertThrowsExactly(
+ NoSuchNamespaceException.class, () -> sql("DROP DATABASE drop_foo1"));
+ }
+
+ @Test
+ void testNameSpaceProperties() {
+ sql("DROP DATABASE if exists alter_foo1");
+ sql("CREATE DATABASE if not exists alter_foo1");
+ sql("ALTER DATABASE alter_foo1 SET PROPERTIES(id = 2)");
+ List<Object[]> datas = sql("DESC DATABASE EXTENDED alter_foo1");
+ Map<String, String> m = convertToStringMap(datas);
+ Assertions.assertEquals("((id,2))", m.getOrDefault("Properties", ""));
+ }
+
+ @Test
+ void testDML() {
+ sql("CREATE DATABASE IF NOT EXISTS dml");
+ sql("DROP TABLE IF EXISTS dml.test");
+ sql("CREATE TABLE dml.test (id bigint COMMENT 'unique id',data string) using iceberg");
+ sql(" INSERT INTO dml.test VALUES (1, 'a'), (2, 'b');");
+ sql(" INSERT INTO dml.test VALUES (3, 'c'), (4, 'd');");
+ Map<String, String> m = convertToStringMap(sql("SELECT * FROM dml.test"));
+ Assertions.assertEquals(m, ImmutableMap.of("1", "a", "2", "b", "3", "c", "4", "d"));
+ }
+
+ @Test
+ void testCreateTable() {
+ sql(
+ "CREATE TABLE table_test.create_foo1( id bigint, data string, ts timestamp)"
+ + "USING iceberg PARTITIONED BY (bucket(16, id), days(ts))");
+ Map<String, String> tableInfo = getTableInfo("table_test.create_foo1");
+ Map<String, String> m =
+ ImmutableMap.of(
+ "id", "bigint",
+ "data", "string",
+ "ts", "timestamp",
+ "Part 0", "bucket(16, id)",
+ "Part 1", "days(ts)");
+
+ checkMapContains(m, tableInfo);
+
+ Assertions.assertThrowsExactly(
+ TableAlreadyExistsException.class, () -> sql("CREATE TABLE table_test.create_foo1"));
+ }
+
+ @Test
+ void testDropTable() {
+ sql(
+ "CREATE TABLE table_test.drop_foo1(id bigint COMMENT 'unique id',data string) using iceberg");
+ sql("DROP TABLE table_test.drop_foo1");
+ Assertions.assertThrowsExactly(
+ AnalysisException.class, () -> sql("DESC TABLE table_test.drop_foo1"));
+
+ Assertions.assertThrowsExactly(
+ AnalysisException.class, () -> sql("DROP TABLE table_test.drop_foo1"));
+ }
+
+ @Test
+ void testListTable() {
+ sql("CREATE DATABASE if not exists list_db");
+ sql("CREATE TABLE list_db.list_foo1(id bigint COMMENT 'unique id',data string) using iceberg");
+ sql("CREATE TABLE list_db.list_foo2(id bigint COMMENT 'unique id',data string) using iceberg");
+
+ Set<String> tables = convertToStringSet(sql("show tables in list_db"), 1);
+ Assertions.assertEquals(ImmutableSet.of("list_foo1", "list_foo2"), tables);
+ }
+
+ @Test
+ void testRenameTable() {
+ sql(
+ "CREATE TABLE table_test.rename_foo1(id bigint COMMENT 'unique id',data string) using iceberg");
+ sql("ALTER TABLE table_test.rename_foo1 RENAME TO table_test.rename_foo2");
+ sql("desc table table_test.rename_foo2");
+ Assertions.assertThrowsExactly(
+ AnalysisException.class, () -> sql("desc table table_test.rename_foo1"));
+
+ sql(
+ "CREATE TABLE table_test.rename_foo1(id bigint COMMENT 'unique id',data string) using iceberg");
+ Assertions.assertThrowsExactly(
+ TableAlreadyExistsException.class,
+ () -> sql("ALTER TABLE table_test.rename_foo2 RENAME TO table_test.rename_foo1"));
+ }
+
+ @Test
+ void testSetTableProperties() {
+ sql(
+ "CREATE TABLE table_test.set_foo1 (id bigint COMMENT 'unique id',data string) using iceberg");
+ sql("ALTER TABLE table_test.set_foo1 SET TBLPROPERTIES ('read.split.target-size'='268435456')");
+ Map<String, String> m = getTableInfo("table_test.set_foo1");
+ Assertions.assertTrue(
+ m.getOrDefault("Table Properties", "").contains("read.split.target-size=268435456"));
+
+ sql("ALTER TABLE table_test.set_foo1 UNSET TBLPROPERTIES ('read.split.target-size')");
+ m = getTableInfo("table_test.set_foo1");
+ Assertions.assertFalse(
+ m.getOrDefault("Table Properties", "read.split.target-size")
+ .contains("read.split.target-size"));
+
+ sql("ALTER TABLE table_test.set_foo1 SET TBLPROPERTIES ('comment'='a')");
+ m = getTableInfo("table_test.set_foo1");
+ // comment is hidden
+ Assertions.assertFalse(m.getOrDefault("Table Properties", "").contains("comment=a"));
+ }
+
+ @Test
+ void testAddColumns() {
+ sql(
+ "CREATE TABLE table_test.add_foo1 (id bigint COMMENT 'unique id',data string) using iceberg");
+
+ Assertions.assertThrowsExactly(
+ AnalysisException.class,
+ () -> sql("ALTER TABLE table_test.add_foo1 ADD COLUMNS foo_after String After not_exits"));
+
+ sql("ALTER TABLE table_test.add_foo1 ADD COLUMNS foo_after String After id");
+ List<String> columns = getTableColumns("table_test.add_foo1");
+ Assertions.assertEquals(Arrays.asList("id", "foo_after", "data"), columns);
+
+ sql("ALTER TABLE table_test.add_foo1 ADD COLUMNS foo_last String");
+ columns = getTableColumns("table_test.add_foo1");
+ Assertions.assertEquals(Arrays.asList("id", "foo_after", "data", "foo_last"), columns);
+
+ sql("ALTER TABLE table_test.add_foo1 ADD COLUMNS foo_first String FIRST");
+ columns = getTableColumns("table_test.add_foo1");
+ Assertions.assertEquals(
+ Arrays.asList("foo_first", "id", "foo_after", "data", "foo_last"), columns);
+ }
+
+ @Test
+ void testRenameColumns() {
+ sql(
+ "CREATE TABLE table_test.renameC_foo1 (id bigint COMMENT 'unique id',data string) using iceberg");
+ sql("ALTER TABLE table_test.renameC_foo1 RENAME COLUMN data TO data1");
+
+ Map<String, String> tableInfo = getTableInfo("table_test.renameC_foo1");
+ Map<String, String> m =
+ ImmutableMap.of(
+ "id", "bigint",
+ "data1", "string");
+ checkMapContains(m, tableInfo);
+ Assertions.assertFalse(m.containsKey("data"));
+ }
+
+ @Test
+ void testDropColumns() {
+ sql(
+ "CREATE TABLE table_test.dropC_foo1 (id bigint COMMENT 'unique id',data string) using iceberg");
+
+ Assertions.assertThrowsExactly(
+ AnalysisException.class,
+ () -> sql("ALTER TABLE table_test.dropC_foo1 DROP COLUMNS not_exits"));
+
+ sql("ALTER TABLE table_test.dropC_foo1 DROP COLUMNS data");
+ Map<String, String> tableInfo = getTableInfo("table_test.dropC_foo1");
+ Map<String, String> m = ImmutableMap.of("id", "bigint");
+ checkMapContains(m, tableInfo);
+ Assertions.assertFalse(m.containsKey("data"));
+ }
+
+ @Test
+ void testUpdateColumnType() {
+ sql(
+ "CREATE TABLE table_test.updateC_foo1 (id int COMMENT 'unique id',data string) using iceberg");
+ Map<String, String> tableInfo = getTableInfo("table_test.updateC_foo1");
+ Map<String, String> m = ImmutableMap.of("id", "int");
+ checkMapContains(m, tableInfo);
+
+ sql("ALTER TABLE table_test.updateC_foo1 ALTER COLUMN id TYPE bigint");
+ tableInfo = getTableInfo("table_test.updateC_foo1");
+ m = ImmutableMap.of("id", "bigint");
+ checkMapContains(m, tableInfo);
+ }
+
+ @Test
+ void testUpdateColumnPosition() {
+ sql(
+ "CREATE TABLE table_test.updateP_foo1 (id int COMMENT 'unique id',data string) using iceberg");
+ List<String> columns = getTableColumns("table_test.updateP_foo1");
+ Assertions.assertEquals(Arrays.asList("id", "data"), columns);
+
+ sql("ALTER TABLE table_test.updateP_foo1 ALTER COLUMN id AFTER data");
+ columns = getTableColumns("table_test.updateP_foo1");
+ Assertions.assertEquals(Arrays.asList("data", "id"), columns);
+
+ sql("ALTER TABLE table_test.updateP_foo1 ALTER COLUMN id FIRST");
+ columns = getTableColumns("table_test.updateP_foo1");
+ Assertions.assertEquals(Arrays.asList("id", "data"), columns);
+ }
+
+ @Test
+ void testAlterPartitions() {
+ sql("CREATE TABLE table_test.part_foo1( id bigint, data string, ts timestamp) USING iceberg");
+ sql("ALTER TABLE table_test.part_foo1 ADD PARTITION FIELD bucket(16, id)");
+ sql("ALTER TABLE table_test.part_foo1 ADD PARTITION FIELD truncate(4, data)");
+ sql("ALTER TABLE table_test.part_foo1 ADD PARTITION FIELD years(ts)");
+
+ Map<String, String> tableInfo = getTableInfo("table_test.part_foo1");
+ Map<String, String> partitions =
+ ImmutableMap.of(
+ "Part 0", "bucket(16, id)",
+ "Part 1", "truncate(4, data)",
+ "Part 2", "years(ts)");
+ checkMapContains(partitions, tableInfo);
+ Assertions.assertFalse(tableInfo.containsKey("Part 3"));
+
+ Assertions.assertThrowsExactly(
+ IllegalArgumentException.class,
+ () -> sql("ALTER TABLE table_test.part_foo1 DROP PARTITION FIELD bucket(8, id)"));
+ sql("ALTER TABLE table_test.part_foo1 DROP PARTITION FIELD bucket(16, id)");
+ tableInfo = getTableInfo("table_test.part_foo1");
+ partitions =
+ ImmutableMap.of(
+ "Part 0", "truncate(4, data)",
+ "Part 1", "years(ts)");
+ checkMapContains(partitions, tableInfo);
+ Assertions.assertFalse(tableInfo.containsKey("Part 2"));
+
+ Assertions.assertThrowsExactly(
+ IllegalArgumentException.class,
+ () ->
+ sql(
+ "ALTER TABLE table_test.part_foo1 REPLACE PARTITION FIELD months(ts) WITH days(ts)"));
+ sql("ALTER TABLE table_test.part_foo1 REPLACE PARTITION FIELD years(ts) WITH days(ts)");
+ tableInfo = getTableInfo("table_test.part_foo1");
+ partitions =
+ ImmutableMap.of(
+ "Part 0", "truncate(4, data)",
+ "Part 1", "days(ts)");
+ checkMapContains(partitions, tableInfo);
+ Assertions.assertFalse(tableInfo.containsKey("Part 3"));
+ }
+
+ @Test
+ void testAlterSortBy() {
+ sql("CREATE TABLE table_test.sort_foo1( id bigint, data string, ts timestamp) USING iceberg");
+ Assertions.assertThrowsExactly(
+ ValidationException.class,
+ () -> sql("ALTER TABLE table_test.sort_foo1 WRITE ORDERED BY xx, id"));
+ sql(
+ "ALTER TABLE table_test.sort_foo1 WRITE ORDERED BY data ASC NULLS FIRST, id ASC NULLS FIRST");
+ Map<String, String> tableInfo = getTableInfo("table_test.sort_foo1");
+ Assertions.assertTrue(
+ tableInfo
+ .get("Table Properties")
+ .contains("sort-order=data ASC NULLS FIRST, id ASC NULLS FIRST,"));
+
+ // replace with new one
+ sql("ALTER TABLE table_test.sort_foo1 WRITE ORDERED BY ts ASC NULLS FIRST");
+ tableInfo = getTableInfo("table_test.sort_foo1");
+ Assertions.assertTrue(
+ tableInfo.get("Table Properties").contains("sort-order=ts ASC NULLS FIRST,"));
+ }
+
+ @Test
+ void testAlterPartitionBy() {
+ sql("CREATE TABLE table_test.partby_foo1( id bigint, data string, ts timestamp) USING iceberg");
+ sql("ALTER TABLE table_test.partby_foo1 WRITE DISTRIBUTED BY PARTITION");
+ Map<String, String> tableInfo = getTableInfo("table_test.partby_foo1");
+ Assertions.assertTrue(
+ tableInfo.get("Table Properties").contains("write.distribution-mode=hash"));
+ }
+
+ @Test
+ void testAlterIdentifier() {
+ sql(
+ "CREATE TABLE table_test.identifier_foo1( id bigint NOT NULL, data string, ts timestamp) USING iceberg");
+ sql("ALTER TABLE table_test.identifier_foo1 SET IDENTIFIER FIELDS id");
+ Map<String, String> tableInfo = getTableInfo("table_test.identifier_foo1");
+ Assertions.assertTrue(tableInfo.get("Table Properties").contains("identifier-fields=[id]"));
+
+ sql("ALTER TABLE table_test.identifier_foo1 DROP IDENTIFIER FIELDS id");
+ tableInfo = getTableInfo("table_test.identifier_foo1");
+ Assertions.assertFalse(tableInfo.get("Table Properties").contains("identifier-fields"));
+
+ // java.lang.IllegalArgumentException: Cannot add field id as an identifier field: not a
+ // required field
+ Assertions.assertThrowsExactly(
+ IllegalArgumentException.class,
+ () -> sql("ALTER TABLE table_test.identifier_foo1 SET IDENTIFIER FIELDS data"));
+ }
+
+ @Test
+ // todo: MemoryCatalog doesn't support snapshot operations, will be supported after hive catalog
+ // is merged
+ void testSnapshot() {
+ sql(
+ "CREATE TABLE table_test.snapshot_foo1 (id bigint COMMENT 'unique id',data string) using iceberg");
+ sql(" INSERT INTO table_test.snapshot_foo1 VALUES (1, 'a'), (2, 'b');");
+ sql(" INSERT INTO table_test.snapshot_foo1 VALUES (3, 'c'), (4, 'd');");
+ printObjects(sql("desc table_test.snapshot_foo1"));
+
+ // org.apache.iceberg.exceptions.NotFoundException: File does not exist:
+ // /tmp/table_test/snapshot_foo1/metadata/00002-c7516f8e-ef6b-406a-8d78-9dda825dd762.metadata.json
+ // printObjects(sql("SELECT * FROM table_test.snapshot_foo1.snapshots"));
+ }
+}
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java
index a8a4ab776e..9174b00f2f 100644
--- a/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java
+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/util/AbstractIT.java
@@ -29,6 +29,8 @@ public class AbstractIT {
private static final String TEST_MODE = "testMode";
private static final String EMBEDDED_TEST_MODE = "embedded";
+ protected static Config serverConfig;
+
static String testMode =
System.getProperty(TEST_MODE) == null ? EMBEDDED_TEST_MODE : System.getProperty(TEST_MODE);
@@ -36,7 +38,7 @@ public class AbstractIT {
public static void startIntegrationTest() throws Exception {
LOG.info("Running Graviton Server in {} mode", testMode);
- Config serverConfig = new ServerConfig();
+ serverConfig = new ServerConfig();
if (testMode != null && testMode.equals(EMBEDDED_TEST_MODE)) {
miniGraviton = new MiniGraviton();
miniGraviton.start();
diff --git a/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java b/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
index 5ba73feb57..22a21a54bf 100644
--- a/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
+++ b/server/src/test/java/com/datastrato/graviton/server/TestGravitonServer.java
@@ -7,6 +7,8 @@ package com.datastrato.graviton.server;
import static com.datastrato.graviton.Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import com.datastrato.graviton.aux.AuxiliaryServiceManager;
+import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
@@ -39,6 +41,11 @@ public class TestGravitonServer {
spyServerConfig = Mockito.spy(serverConfig);
Mockito.when(spyServerConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH))
.thenReturn(ROCKS_DB_STORE_PATH);
+
+ Mockito.when(
+ spyServerConfig.getConfigsWithPrefix(
+ AuxiliaryServiceManager.GRAVITON_AUX_SERVICE_PREFIX))
+ .thenReturn(ImmutableMap.of(AuxiliaryServiceManager.AUX_SERVICE_NAMES, ""));
}
@BeforeEach