|
15 | 15 |
|
16 | 16 | import com.facebook.airlift.http.server.testing.TestingHttpServer; |
17 | 17 | import com.facebook.presto.Session; |
| 18 | +import com.facebook.presto.testing.MaterializedResult; |
18 | 19 | import com.facebook.presto.testing.QueryRunner; |
19 | 20 | import com.facebook.presto.tests.AbstractTestQueryFramework; |
20 | 21 | import com.google.common.collect.ImmutableMap; |
21 | 22 | import org.assertj.core.util.Files; |
| 23 | +import org.intellij.lang.annotations.Language; |
22 | 24 | import org.testng.annotations.AfterClass; |
23 | 25 | import org.testng.annotations.BeforeClass; |
24 | 26 | import org.testng.annotations.Test; |
|
29 | 31 | import static com.facebook.presto.iceberg.CatalogType.REST; |
30 | 32 | import static com.facebook.presto.iceberg.rest.IcebergRestTestUtil.getRestServer; |
31 | 33 | import static com.facebook.presto.iceberg.rest.IcebergRestTestUtil.restConnectorProperties; |
| 34 | +import static com.facebook.presto.tests.QueryAssertions.assertEqualsIgnoreOrder; |
32 | 35 | import static com.google.common.io.MoreFiles.deleteRecursively; |
33 | 36 | import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; |
34 | 37 |
|
@@ -188,8 +191,9 @@ public void testMaterializedViewMetadata() |
188 | 191 |
|
189 | 192 | assertUpdate("CREATE MATERIALIZED VIEW test_mv_metadata AS SELECT id, name FROM test_mv_metadata_base WHERE id > 0"); |
190 | 193 |
|
191 | | - assertQueryReturnsEmptyResult("SELECT table_name FROM information_schema.tables " + |
192 | | - "WHERE table_schema = 'test_schema' AND table_name = 'test_mv_metadata' AND table_type = 'MATERIALIZED VIEW'"); |
| 194 | + assertQuery("SELECT table_name, table_type FROM information_schema.tables " + |
| 195 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_mv_metadata'", |
| 196 | + "VALUES ('test_mv_metadata', 'MATERIALIZED VIEW')"); |
193 | 197 |
|
194 | 198 | assertUpdate("DROP MATERIALIZED VIEW test_mv_metadata"); |
195 | 199 | assertUpdate("DROP TABLE test_mv_metadata_base"); |
@@ -1400,4 +1404,113 @@ public void testCreateMaterializedViewWithSameNameAsExistingTable() |
1400 | 1404 | assertUpdate("DROP TABLE existing_table_name"); |
1401 | 1405 | assertUpdate("DROP TABLE test_mv_base"); |
1402 | 1406 | } |
| 1407 | + |
| 1408 | + @Test |
| 1409 | + public void testInformationSchemaMaterializedViews() |
| 1410 | + { |
| 1411 | + assertUpdate("CREATE TABLE test_is_mv_base1 (id BIGINT, name VARCHAR, value BIGINT)"); |
| 1412 | + assertUpdate("CREATE TABLE test_is_mv_base2 (category VARCHAR, amount BIGINT)"); |
| 1413 | + |
| 1414 | + assertUpdate("INSERT INTO test_is_mv_base1 VALUES (1, 'Alice', 100), (2, 'Bob', 200)", 2); |
| 1415 | + assertUpdate("INSERT INTO test_is_mv_base2 VALUES ('A', 50), ('B', 75)", 2); |
| 1416 | + |
| 1417 | + assertUpdate("CREATE MATERIALIZED VIEW test_is_mv1 AS SELECT id, name, value FROM test_is_mv_base1 WHERE id > 0"); |
| 1418 | + assertUpdate("CREATE MATERIALIZED VIEW test_is_mv2 AS SELECT category, SUM(amount) as total FROM test_is_mv_base2 GROUP BY category"); |
| 1419 | + |
| 1420 | + assertQuery( |
| 1421 | + "SELECT table_name FROM information_schema.materialized_views " + |
| 1422 | + "WHERE table_schema = 'test_schema' AND table_name IN ('test_is_mv1', 'test_is_mv2') " + |
| 1423 | + "ORDER BY table_name", |
| 1424 | + "VALUES ('test_is_mv1'), ('test_is_mv2')"); |
| 1425 | + |
| 1426 | + assertQuery( |
| 1427 | + "SELECT table_catalog, table_schema, table_name, storage_schema, storage_table_name, base_tables " + |
| 1428 | + "FROM information_schema.materialized_views " + |
| 1429 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv1'", |
| 1430 | + "SELECT 'iceberg', 'test_schema', 'test_is_mv1', 'test_schema', '__mv_storage__test_is_mv1', 'test_schema.test_is_mv_base1'"); |
| 1431 | + |
| 1432 | + assertQuery( |
| 1433 | + "SELECT COUNT(*) FROM information_schema.materialized_views " + |
| 1434 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv1' " + |
| 1435 | + "AND view_definition IS NOT NULL AND length(view_definition) > 0", |
| 1436 | + "SELECT 1"); |
| 1437 | + |
| 1438 | + assertQuery( |
| 1439 | + "SELECT table_name FROM information_schema.materialized_views " + |
| 1440 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv2'", |
| 1441 | + "VALUES ('test_is_mv2')"); |
| 1442 | + |
| 1443 | + assertQuery( |
| 1444 | + "SELECT COUNT(*) FROM information_schema.materialized_views " + |
| 1445 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv1' " + |
| 1446 | + "AND view_owner IS NOT NULL", |
| 1447 | + "SELECT 1"); |
| 1448 | + |
| 1449 | + assertQuery( |
| 1450 | + "SELECT COUNT(*) FROM information_schema.materialized_views " + |
| 1451 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv1' " + |
| 1452 | + "AND view_security IS NOT NULL", |
| 1453 | + "SELECT 1"); |
| 1454 | + |
| 1455 | + assertQuery( |
| 1456 | + "SELECT base_tables FROM information_schema.materialized_views " + |
| 1457 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv2'", |
| 1458 | + "VALUES ('test_schema.test_is_mv_base2')"); |
| 1459 | + |
| 1460 | + assertUpdate("DROP MATERIALIZED VIEW test_is_mv1"); |
| 1461 | + assertUpdate("DROP MATERIALIZED VIEW test_is_mv2"); |
| 1462 | + assertUpdate("DROP TABLE test_is_mv_base1"); |
| 1463 | + assertUpdate("DROP TABLE test_is_mv_base2"); |
| 1464 | + } |
| 1465 | + |
| 1466 | + @Test |
| 1467 | + public void testInformationSchemaMaterializedViewsAfterRefresh() |
| 1468 | + { |
| 1469 | + assertUpdate("CREATE TABLE test_is_mv_refresh_base (id BIGINT, value BIGINT)"); |
| 1470 | + assertUpdate("INSERT INTO test_is_mv_refresh_base VALUES (1, 100), (2, 200)", 2); |
| 1471 | + assertUpdate("CREATE MATERIALIZED VIEW test_is_mv_refresh AS SELECT id, value FROM test_is_mv_refresh_base"); |
| 1472 | + |
| 1473 | + assertQuery( |
| 1474 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1475 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1476 | + "SELECT 'NOT_MATERIALIZED'"); |
| 1477 | + |
| 1478 | + assertUpdate("REFRESH MATERIALIZED VIEW test_is_mv_refresh", 2); |
| 1479 | + |
| 1480 | + assertQuery( |
| 1481 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1482 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1483 | + "SELECT 'FULLY_MATERIALIZED'"); |
| 1484 | + |
| 1485 | + assertUpdate("INSERT INTO test_is_mv_refresh_base VALUES (3, 300)", 1); |
| 1486 | + |
| 1487 | + assertQuery( |
| 1488 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1489 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1490 | + "SELECT 'PARTIALLY_MATERIALIZED'"); |
| 1491 | + |
| 1492 | + assertUpdate("UPDATE test_is_mv_refresh_base SET value = 250 WHERE id = 2", 1); |
| 1493 | + |
| 1494 | + assertQuery( |
| 1495 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1496 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1497 | + "SELECT 'PARTIALLY_MATERIALIZED'"); |
| 1498 | + |
| 1499 | + assertUpdate("DELETE FROM test_is_mv_refresh_base WHERE id = 1", 1); |
| 1500 | + |
| 1501 | + assertQuery( |
| 1502 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1503 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1504 | + "SELECT 'PARTIALLY_MATERIALIZED'"); |
| 1505 | + |
| 1506 | + assertUpdate("REFRESH MATERIALIZED VIEW test_is_mv_refresh", 2); |
| 1507 | + |
| 1508 | + assertQuery( |
| 1509 | + "SELECT freshness_state FROM information_schema.materialized_views " + |
| 1510 | + "WHERE table_schema = 'test_schema' AND table_name = 'test_is_mv_refresh'", |
| 1511 | + "SELECT 'FULLY_MATERIALIZED'"); |
| 1512 | + |
| 1513 | + assertUpdate("DROP MATERIALIZED VIEW test_is_mv_refresh"); |
| 1514 | + assertUpdate("DROP TABLE test_is_mv_refresh_base"); |
| 1515 | + } |
1403 | 1516 | } |
0 commit comments