Skip to content

Commit fe6897e

Browse files
committed
platform-checks: Add check for mysql invisible columns
1 parent 0af5488 commit fe6897e

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

misc/python/materialize/checks/all_checks/mysql_cdc.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,106 @@ def validate(self) -> Testdrive:
480480
)
481481

482482

483+
@externally_idempotent(False)
484+
class MySqlInvisibleColumn(Check):
485+
def _can_run(self, e: Executor) -> bool:
486+
return self.base_version > MzVersion.parse_mz("v0.132.0-dev")
487+
488+
def initialize(self) -> Testdrive:
489+
return Testdrive(
490+
dedent(
491+
f"""
492+
$ mysql-connect name=mysql url=mysql://root@mysql password={MySql.DEFAULT_ROOT_PASSWORD}
493+
494+
$ mysql-execute name=mysql
495+
# create the database if it does not exist yet but do not drop it
496+
CREATE DATABASE IF NOT EXISTS public;
497+
USE public;
498+
499+
CREATE USER mysql4 IDENTIFIED BY 'mysql';
500+
GRANT REPLICATION SLAVE ON *.* TO mysql4;
501+
GRANT ALL ON public.* TO mysql4;
502+
503+
DROP TABLE IF EXISTS mysql_invisible_table;
504+
505+
CREATE TABLE mysql_invisible_table (f1 INT, f2 FLOAT INVISIBLE, f3 DATE INVISIBLE, f4 TEXT INVISIBLE);
506+
507+
INSERT INTO mysql_invisible_table (f1, f2, f3, f4) VALUES (1, 0.1, '2025-01-01', 'one');
508+
509+
> CREATE SECRET mysql_invisible_pass AS 'mysql';
510+
> CREATE CONNECTION mysql_invisible_conn TO MYSQL (
511+
HOST 'mysql',
512+
USER mysql4,
513+
PASSWORD SECRET mysql_invisible_pass
514+
)
515+
516+
> CREATE SOURCE mysql_invisible_source
517+
FROM MYSQL CONNECTION mysql_invisible_conn;
518+
> CREATE TABLE mysql_invisible_table FROM SOURCE mysql_invisible_source (REFERENCE public.mysql_invisible_table);
519+
520+
# Return all rows
521+
> CREATE MATERIALIZED VIEW mysql_invisible_view AS
522+
SELECT * FROM mysql_invisible_table
523+
"""
524+
)
525+
)
526+
527+
def manipulate(self) -> list[Testdrive]:
528+
return [
529+
Testdrive(dedent(s))
530+
for s in [
531+
f"""
532+
$ mysql-connect name=mysql url=mysql://root@mysql password={MySql.DEFAULT_ROOT_PASSWORD}
533+
534+
$ mysql-execute name=mysql
535+
USE public;
536+
INSERT INTO mysql_invisible_table (f1, f2, f3, f4) VALUES (2, 0.2, '2025-02-02', 'two');
537+
""",
538+
f"""
539+
$ mysql-connect name=mysql url=mysql://root@mysql password={MySql.DEFAULT_ROOT_PASSWORD}
540+
541+
$ mysql-execute name=mysql
542+
USE public;
543+
INSERT INTO mysql_invisible_table (f1, f2, f3, f4) VALUES (3, 0.3, '2025-03-03', 'three');
544+
""",
545+
]
546+
]
547+
548+
def validate(self) -> Testdrive:
549+
return Testdrive(
550+
dedent(
551+
f"""
552+
> SELECT * FROM mysql_invisible_table;
553+
1 0.1 2025-01-01 one
554+
2 0.2 2025-02-02 two
555+
3 0.3 2025-03-03 three
556+
557+
$ mysql-connect name=mysql url=mysql://root@mysql password={MySql.DEFAULT_ROOT_PASSWORD}
558+
559+
$ mysql-execute name=mysql
560+
USE public;
561+
ALTER TABLE mysql_invisible_table ALTER COLUMN f2 SET VISIBLE;
562+
INSERT INTO mysql_invisible_table (f1, f2, f3, f4) VALUES (4, 0.4, '2025-04-04', 'four');
563+
564+
> SELECT * FROM mysql_invisible_table;
565+
1 0.1 2025-01-01 one
566+
2 0.2 2025-02-02 two
567+
3 0.3 2025-03-03 three
568+
4 0.4 2025-04-04 four
569+
570+
# Rollback the last INSERTs so that validate() can be called multiple times
571+
$ mysql-execute name=mysql
572+
DELETE FROM mysql_invisible_table WHERE f1 = 4;
573+
ALTER TABLE mysql_invisible_table ALTER COLUMN f2 SET INVISIBLE;
574+
575+
> SELECT * FROM mysql_invisible_table;
576+
1 0.1 2025-01-01 one
577+
2 0.2 2025-02-02 two
578+
3 0.3 2025-03-03 three
579+
"""
580+
)
581+
)
582+
583+
483584
def remove_target_cluster_from_explain(sql: str) -> str:
484585
return re.sub(r"\n\s*Target cluster: \w+\n", "", sql)

0 commit comments

Comments
 (0)