07-add-column-with-delete.td 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #
  10. # Test that adding a column does not mess things up.
  11. # We expect that deletes where the data is only different in this column will
  12. # be handled correctly.
  13. #
  14. $ postgres-execute connection=postgres://postgres:postgres@postgres
  15. CREATE TABLE alter_add_column_with_delete (f1 INTEGER, f2 INTEGER PRIMARY KEY);
  16. ALTER TABLE alter_add_column_with_delete REPLICA IDENTITY FULL;
  17. INSERT INTO alter_add_column_with_delete VALUES (123, 0),(123, 1),(123, 2),(123, 3);
  18. $ schema-registry-wait topic=postgres.public.alter_add_column_with_delete
  19. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  20. URL '${testdrive.schema-registry-url}'
  21. );
  22. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  23. > CREATE SOURCE alter_add_column_with_delete
  24. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.alter_add_column_with_delete');
  25. > CREATE TABLE alter_add_column_with_delete_tbl FROM SOURCE alter_add_column_with_delete (REFERENCE "postgres.public.alter_add_column_with_delete")
  26. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  27. ENVELOPE DEBEZIUM;
  28. > SELECT f1 FROM alter_add_column_with_delete_tbl;
  29. 123
  30. 123
  31. 123
  32. 123
  33. $ postgres-execute connection=postgres://postgres:postgres@postgres
  34. ALTER TABLE alter_add_column_with_delete ADD COLUMN new_column INTEGER DEFAULT 1;
  35. INSERT INTO alter_add_column_with_delete VALUES (123,4,2);
  36. INSERT INTO alter_add_column_with_delete VALUES (123,5,2);
  37. DELETE FROM alter_add_column_with_delete WHERE new_column = 2;
  38. # Even though we do not have new_column in our source, we expect that the
  39. # updates above have landed on the appropriate distinct rows
  40. > SELECT f1 FROM alter_add_column_with_delete_tbl;
  41. 123
  42. 123
  43. 123
  44. 123
  45. $ postgres-execute connection=postgres://postgres:postgres@postgres
  46. DELETE FROM alter_add_column_with_delete WHERE new_column = 1;
  47. > SELECT COUNT(*) FROM alter_add_column_with_delete_tbl;
  48. 0