|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.gravitino.flink.connector.integration.test.iceberg; |
| 21 | + |
| 22 | +import com.google.common.collect.Maps; |
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.Map; |
| 25 | +import org.apache.flink.table.api.ResultKind; |
| 26 | +import org.apache.flink.types.Row; |
| 27 | +import org.apache.gravitino.Schema; |
| 28 | +import org.apache.gravitino.flink.connector.iceberg.IcebergPropertiesConstants; |
| 29 | +import org.apache.gravitino.flink.connector.integration.test.utils.TestUtils; |
| 30 | +import org.junit.jupiter.api.Assertions; |
| 31 | +import org.junit.jupiter.api.Tag; |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | +import org.junit.jupiter.api.condition.EnabledIf; |
| 34 | + |
| 35 | +@Tag("gravitino-docker-test") |
| 36 | +public class FlinkIcebergRestCatalogIT extends FlinkIcebergCatalogIT { |
| 37 | + |
| 38 | + @Override |
| 39 | + protected Map<String, String> getCatalogConfigs() { |
| 40 | + Map<String, String> catalogProperties = Maps.newHashMap(); |
| 41 | + catalogProperties.put( |
| 42 | + IcebergPropertiesConstants.GRAVITINO_ICEBERG_CATALOG_BACKEND, |
| 43 | + IcebergPropertiesConstants.ICEBERG_CATALOG_BACKEND_REST); |
| 44 | + catalogProperties.put( |
| 45 | + IcebergPropertiesConstants.GRAVITINO_ICEBERG_CATALOG_WAREHOUSE, warehouse); |
| 46 | + catalogProperties.put( |
| 47 | + IcebergPropertiesConstants.GRAVITINO_ICEBERG_CATALOG_URI, icebergRestServiceUri); |
| 48 | + return catalogProperties; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void testListSchema() { |
| 53 | + doWithCatalog( |
| 54 | + currentCatalog(), |
| 55 | + catalog -> { |
| 56 | + String schema = "test_list_schema"; |
| 57 | + String schema2 = "test_list_schema2"; |
| 58 | + String schema3 = "test_list_schema3"; |
| 59 | + |
| 60 | + try { |
| 61 | + TestUtils.assertTableResult( |
| 62 | + sql("CREATE DATABASE IF NOT EXISTS %s", schema), ResultKind.SUCCESS); |
| 63 | + TestUtils.assertTableResult( |
| 64 | + sql("CREATE DATABASE IF NOT EXISTS %s", schema2), ResultKind.SUCCESS); |
| 65 | + TestUtils.assertTableResult( |
| 66 | + sql("CREATE DATABASE IF NOT EXISTS %s", schema3), ResultKind.SUCCESS); |
| 67 | + TestUtils.assertTableResult( |
| 68 | + sql("SHOW DATABASES"), |
| 69 | + ResultKind.SUCCESS_WITH_CONTENT, |
| 70 | + Row.of("default"), |
| 71 | + Row.of(schema), |
| 72 | + Row.of(schema2), |
| 73 | + Row.of(schema3)); |
| 74 | + |
| 75 | + String[] schemas = catalog.asSchemas().listSchemas(); |
| 76 | + Arrays.sort(schemas); |
| 77 | + Assertions.assertEquals(4, schemas.length); |
| 78 | + Assertions.assertEquals("default", schemas[0]); |
| 79 | + Assertions.assertEquals(schema, schemas[1]); |
| 80 | + Assertions.assertEquals(schema2, schemas[2]); |
| 81 | + Assertions.assertEquals(schema3, schemas[3]); |
| 82 | + } finally { |
| 83 | + catalog.asSchemas().dropSchema(schema, supportDropCascade()); |
| 84 | + catalog.asSchemas().dropSchema(schema2, supportDropCascade()); |
| 85 | + catalog.asSchemas().dropSchema(schema3, supportDropCascade()); |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + @EnabledIf("supportSchemaOperationWithCommentAndOptions") |
| 92 | + public void testAlterSchemaWithCommentAndOptions() { |
| 93 | + doWithCatalog( |
| 94 | + currentCatalog(), |
| 95 | + catalog -> { |
| 96 | + String schema = "test_alter_schema"; |
| 97 | + try { |
| 98 | + TestUtils.assertTableResult( |
| 99 | + sql( |
| 100 | + "CREATE DATABASE IF NOT EXISTS %s " |
| 101 | + + "COMMENT 'test comment'" |
| 102 | + + "WITH ('key1' = 'value1', 'key2'='value2')", |
| 103 | + schema), |
| 104 | + ResultKind.SUCCESS); |
| 105 | + |
| 106 | + Schema loadedSchema = catalog.asSchemas().loadSchema(schema); |
| 107 | + Assertions.assertEquals(schema, loadedSchema.name()); |
| 108 | + Assertions.assertEquals("test comment", loadedSchema.comment()); |
| 109 | + Assertions.assertEquals("value1", loadedSchema.properties().get("key1")); |
| 110 | + Assertions.assertEquals("value2", loadedSchema.properties().get("key2")); |
| 111 | + |
| 112 | + TestUtils.assertTableResult( |
| 113 | + sql("ALTER DATABASE %s SET ('key1'='new-value', 'key3'='value3')", schema), |
| 114 | + ResultKind.SUCCESS); |
| 115 | + Schema reloadedSchema = catalog.asSchemas().loadSchema(schema); |
| 116 | + Assertions.assertEquals(schema, reloadedSchema.name()); |
| 117 | + Assertions.assertEquals("test comment", reloadedSchema.comment()); |
| 118 | + Assertions.assertEquals("new-value", reloadedSchema.properties().get("key1")); |
| 119 | + Assertions.assertEquals("value3", reloadedSchema.properties().get("key3")); |
| 120 | + } finally { |
| 121 | + catalog.asSchemas().dropSchema(schema, supportDropCascade()); |
| 122 | + } |
| 123 | + }); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + protected String getCatalogBackend() { |
| 128 | + return "rest"; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + protected String getUri() { |
| 133 | + return icebergRestServiceUri; |
| 134 | + } |
| 135 | +} |
0 commit comments