mz-depends.td 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ set-arg-default single-replica-cluster=quickstart
  10. # Test `mz_internal.mz_object_dependencies`.
  11. $ skip-consistency-checks reason="workflow uses SSH keys which we currently can't check"
  12. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  13. ALTER SYSTEM SET enable_connection_validation_syntax = true
  14. > CREATE SOURCE with_subsources
  15. IN CLUSTER ${arg.single-replica-cluster}
  16. FROM LOAD GENERATOR AUCTION (UP TO 100);
  17. > CREATE TABLE accounts FROM SOURCE with_subsources (REFERENCE accounts);
  18. > CREATE TABLE auctions FROM SOURCE with_subsources (REFERENCE auctions);
  19. > CREATE TABLE bids FROM SOURCE with_subsources (REFERENCE bids);
  20. > CREATE TABLE organizations FROM SOURCE with_subsources (REFERENCE organizations);
  21. > CREATE TABLE users FROM SOURCE with_subsources (REFERENCE users);
  22. > SELECT
  23. top_level_s.name as source,
  24. s.name AS subsource
  25. FROM mz_internal.mz_object_dependencies AS d
  26. JOIN mz_sources AS s ON s.id = d.referenced_object_id OR s.id = d.object_id
  27. JOIN mz_sources AS top_level_s ON top_level_s.id = d.object_id OR top_level_s.id = d.referenced_object_id
  28. WHERE top_level_s.name = 'with_subsources' AND (s.type = 'progress' OR s.type = 'subsource');
  29. source subsource
  30. -------------------------
  31. with_subsources with_subsources_progress
  32. # make sure dropping works
  33. > DROP SOURCE with_subsources CASCADE
  34. > SELECT
  35. top_level_s.name as source,
  36. s.name AS subsource
  37. FROM mz_internal.mz_object_dependencies AS d
  38. JOIN mz_sources AS s ON s.id = d.referenced_object_id OR s.id = d.object_id
  39. JOIN mz_sources AS top_level_s ON top_level_s.id = d.object_id OR top_level_s.id = d.referenced_object_id
  40. WHERE top_level_s.name = 'with_subsources' AND (s.type = 'progress' OR s.type = 'subsource');
  41. source subsource
  42. -------------------------
  43. # Make sure other objects work as well.
  44. # TODO(guswynn): determine if we need to test all object types exhaustively
  45. > CREATE CONNECTION ssh_conn TO SSH TUNNEL (
  46. HOST 'unused',
  47. USER 'mz',
  48. PORT 22
  49. );
  50. > CREATE CONNECTION pg_conn TO POSTGRES (
  51. HOST unused,
  52. DATABASE unused,
  53. USER unused,
  54. SSH TUNNEL ssh_conn
  55. ) WITH (VALIDATE = false);
  56. > SELECT
  57. top_level_c.name as conn,
  58. c.name AS dep_conn
  59. FROM mz_internal.mz_object_dependencies AS d
  60. JOIN mz_connections AS c ON c.id = d.referenced_object_id
  61. JOIN mz_connections AS top_level_c ON top_level_c.id = d.object_id
  62. conn dep_conn
  63. -----------------
  64. pg_conn ssh_conn
  65. # Assert that we actually are populating all the system objects.
  66. > SELECT COUNT(*) > 200 FROM mz_internal.mz_object_dependencies WHERE object_id LIKE 's%'
  67. true
  68. # Ensure there are no duplicates
  69. > WITH cte AS (
  70. SELECT * FROM mz_internal.mz_object_dependencies
  71. GROUP BY object_id, referenced_object_id
  72. HAVING count(*) > 1
  73. )
  74. SELECT count(*) FROM cte
  75. 0
  76. # This isn't a full cycle check, but checks if 2 objects depend on each other
  77. > SELECT
  78. COUNT(*)
  79. FROM mz_internal.mz_object_dependencies AS first
  80. JOIN mz_internal.mz_object_dependencies AS second
  81. ON first.object_id = second.referenced_object_id AND first.referenced_object_id = second.object_id;
  82. 0