|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package io.trino.plugin.hive; |
| 15 | + |
| 16 | +import com.google.common.collect.ImmutableMap; |
| 17 | +import io.trino.Session; |
| 18 | +import io.trino.plugin.hive.containers.Hive3MinioDataLake; |
| 19 | +import io.trino.plugin.hive.containers.HiveMinioDataLake; |
| 20 | +import io.trino.plugin.hive.s3.S3HiveQueryRunner; |
| 21 | +import io.trino.spi.security.Identity; |
| 22 | +import io.trino.testing.AbstractTestQueryFramework; |
| 23 | +import io.trino.testing.QueryRunner; |
| 24 | +import io.trino.testing.sql.TestTable; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.junit.jupiter.api.TestInstance; |
| 27 | + |
| 28 | +import java.util.List; |
| 29 | + |
| 30 | +import static io.trino.plugin.hive.containers.HiveHadoop.HIVE3_IMAGE; |
| 31 | +import static io.trino.testing.TestingNames.randomNameSuffix; |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
| 33 | +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; |
| 34 | + |
| 35 | +@TestInstance(PER_CLASS) |
| 36 | +final class TestThriftMetastoreImpersonation |
| 37 | + extends AbstractTestQueryFramework |
| 38 | +{ |
| 39 | + @Override |
| 40 | + protected QueryRunner createQueryRunner() |
| 41 | + throws Exception |
| 42 | + { |
| 43 | + HiveMinioDataLake hiveMinioDataLake = closeAfterClass(new Hive3MinioDataLake("test-thrift-impersonation-" + randomNameSuffix(), HIVE3_IMAGE)); |
| 44 | + hiveMinioDataLake.start(); |
| 45 | + return S3HiveQueryRunner.builder(hiveMinioDataLake) |
| 46 | + .setMetastoreImpersonationEnabled(true) |
| 47 | + .setHiveProperties(ImmutableMap.<String, String>builder() |
| 48 | + .put("hive.security", "allow-all") |
| 49 | + .put("hive.metastore-cache-ttl", "1d") |
| 50 | + .put("hive.user-metastore-cache-ttl", "1d") |
| 51 | + .buildOrThrow()) |
| 52 | + .build(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void testFlushMetadataCache() |
| 57 | + { |
| 58 | + Session alice = Session.builder(getSession()).setIdentity(Identity.ofUser("alice")).build(); |
| 59 | + |
| 60 | + try (TestTable table = newTrinoTable("test_partition", "(id int, part int) WITH (partitioned_by = ARRAY['part'])", List.of("1, 10"))) { |
| 61 | + assertThat(computeScalar(alice, "SELECT count(1) FROM \"" + table.getName() + "$partitions\"")) |
| 62 | + .isEqualTo(1L); |
| 63 | + |
| 64 | + assertUpdate("INSERT INTO " + table.getName() + " VALUES (2, 20)", 1); |
| 65 | + assertThat(computeScalar(alice, "SELECT count(1) FROM \"" + table.getName() + "$partitions\"")) |
| 66 | + .isEqualTo(1L); |
| 67 | + |
| 68 | + assertUpdate(alice, "CALL system.flush_metadata_cache(schema_name => CURRENT_SCHEMA, table_name => '" + table.getName() + "')"); |
| 69 | + assertThat(computeScalar(alice, "SELECT count(1) FROM \"" + table.getName() + "$partitions\"")) |
| 70 | + .isEqualTo(2L); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments