mz-setup.td 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  10. $ mysql-execute name=mysql
  11. DROP DATABASE IF EXISTS public;
  12. CREATE DATABASE public;
  13. USE public;
  14. CREATE TABLE table_mysql (a int);
  15. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  16. > CREATE CONNECTION mysql_conn TO MYSQL (
  17. HOST mysql,
  18. PORT 3306,
  19. USER root,
  20. PASSWORD SECRET mysqlpass
  21. )
  22. > CREATE SOURCE mysql_source
  23. FROM MYSQL CONNECTION mysql_conn;
  24. > CREATE TABLE table_mysql FROM SOURCE mysql_source (REFERENCE public.table_mysql);
  25. $ postgres-execute connection=postgres://postgres:postgres@postgres
  26. ALTER USER postgres WITH replication;
  27. DROP SCHEMA IF EXISTS public CASCADE;
  28. CREATE SCHEMA public;
  29. DROP PUBLICATION IF EXISTS mz_source;
  30. CREATE PUBLICATION mz_source FOR ALL TABLES;
  31. CREATE TABLE table_pg (a int);
  32. ALTER TABLE table_pg REPLICA IDENTITY FULL;
  33. DROP PUBLICATION IF EXISTS mz_source;
  34. CREATE PUBLICATION mz_source FOR ALL TABLES;
  35. > CREATE SECRET pgpass AS 'postgres'
  36. > CREATE CONNECTION pg_conn TO POSTGRES (
  37. HOST postgres,
  38. PORT 5432,
  39. DATABASE postgres,
  40. USER postgres,
  41. PASSWORD SECRET pgpass
  42. )
  43. > CREATE SOURCE pg_source
  44. FROM POSTGRES CONNECTION pg_conn (PUBLICATION 'mz_source');
  45. > CREATE TABLE table_pg FROM SOURCE pg_source (REFERENCE table_pg);
  46. $ kafka-create-topic topic=input
  47. $ kafka-ingest topic=input format=bytes repeat=1
  48. 0
  49. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER 'kafka:9092', SECURITY PROTOCOL PLAINTEXT);
  50. > CREATE SOURCE input_kafka
  51. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-input-${testdrive.seed}')
  52. > CREATE TABLE input_kafka_tbl (a) FROM SOURCE input_kafka (REFERENCE "testdrive-input-${testdrive.seed}")
  53. FORMAT CSV WITH 1 COLUMNS
  54. > CREATE MATERIALIZED VIEW sum AS
  55. SELECT sum(count)
  56. FROM (
  57. SELECT count(*) FROM table_mysql
  58. UNION ALL SELECT count(*) FROM table_pg
  59. UNION ALL SELECT count(*) FROM input_kafka_tbl
  60. ) AS x;
  61. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  62. ALTER SYSTEM SET allow_real_time_recency = true