Skip to content

[Bug]: Python SDK dialect cannot compile supported MySQL DATETIME/TIME and related types #31204

Closed

Description

@Ariznawlll

Description

The MatrixOne Python SDK's SQLAlchemy dialect cannot compile many native MySQL scalar type classes that MatrixOne itself supports. Even simple mysql.DATETIME(fsp=6) or mysql.TIME(fsp=6) columns fail before a CREATE TABLE request is sent, preventing normal ORM schema creation and migration.

Environment

  • Official MatrixOne main: 5fe08a3307e246e1ab9951ab690b50557af0f509; isolated single-CN service reports 8.0.30-MatrixOne-v1.3.0, SQL port 36601.
  • Python SDK 0.1.16 from that exact source; Python 3.11.14, SQLAlchemy 2.0.55.
  • Standard SQLAlchemy MySQL dialect and isolated MySQL 8.3.0 used as controls.

Steps to reproduce

import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from matrixone.sqlalchemy_ext.dialect import MatrixOneDialect

table = sa.Table("sdk_dt_repro", sa.MetaData(),
                 sa.Column("id", sa.Integer, primary_key=True),
                 sa.Column("dt", mysql.DATETIME(fsp=6)))
print(sa.schema.CreateTable(table).compile(dialect=MatrixOneDialect()))

Repeat with mysql.TIME(fsp=6). In a connected SDK client, table.create(connection) fails identically and creates no table.

Actual behavior

Both cases raise sqlalchemy.exc.CompileError, because MatrixOneTypeCompiler cannot render DATETIME or TIME. Reproduced 3/3 with fresh table names. No failed target table remains; SELECT 1 succeeds and the pool checked-out count is zero after each failure.

Expected behavior / controls

  • Standard SQLAlchemy MySQL dialect compiles DATETIME(6) and TIME(6) successfully.
  • MatrixOne native SQL can create those two columns and retain a synthetic .123456 microsecond value, 3/3.
  • Isolated MySQL 8.3 native DDL/insert also succeeds.

Additional same-root compiler matrix

Compilation-only checks with the same SDK dialect also raise CompileError for mysql.YEAR, mysql.BIT(8), mysql.SET, mysql.ENUM, mysql.LONGTEXT, mysql.MEDIUMTEXT, mysql.TINYBLOB, mysql.LONGBLOB, mysql.INTEGER(unsigned=True), mysql.DOUBLE, and mysql.FLOAT. These are presented as one root-cause family, not separate bug reports. The standard MySQL dialect compiles each. Runtime support for each additional type was not separately asserted in this round.

Code analysis

clients/python/matrixone/sqlalchemy_ext/dialect.py: the SQLAlchemy 2.x MatrixOneTypeCompiler inherits generic TypeCompiler, not the MySQL compiler, and manually supplies only some visit_* methods. Missing MySQL-specific visitors cause the unsupported-compilation errors. SQLAlchemy 1.4 has a separate compiler branch; this reproducer specifically validates supported SQLAlchemy 2.0.55.

Regression coverage

Add a parameterized SDK dialect compilation test for native MySQL scalar types and an online create_all/insert/readback case for DATETIME(6), TIME(6), BIT and numeric/blob variants. Preserve a failure cleanup/connection reuse assertion.

Evidence

  • Three independent server-side checks and exact output: /private/tmp/mo-sdk-types-20261026/timestamp_fsp_3x.py.
  • Same-root type compilation matrix: /private/tmp/mo-sdk-types-20261026/compiler_matrix.py.

Activity

  1. added this to the MO-202610 milestone on Oct 26, 2026
  2. added
    kind/bug
    on Oct 26, 2026
  3. added theissue type on Oct 26, 2026
  4. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • SDK 源码:官方 main 861a2c4cb68961d8b6b01f18e0aa6ac52a3a505f。
    • 服务端:隔离本地单 CN,源码 5fe08a3307e246e1ab9951ab690b50557af0f509,SQL 端口 36601。
    • Python 3.11、SQLAlchemy 2.0.55、PyMySQL 1.2.3;2026-10-26。

    原问题验证

    补充同根的反射后 DDL 场景:CREATE TABLE t_f32(id INT PRIMARY KEY, v VECF32(3)) 后,SDK 的 MetaData.reflect(bind=client.get_sqlalchemy_engine(), only=['t_f32']) 成功,session.execute(select(reflected_table)) 返回 (1, [1.0, 2.0, 3.0]);但对反射表执行 CreateTable(reflected_table).compile(dialect=engine.dialect),3 个新库均报 CompileError: ... can't render element of type INTEGER。VECF64(3) 表也 3/3 同样失败。这里失败的是已存在表的 ORM schema 再生成,而非原 SQL DDL 或向量读取。

    Happy Path 覆盖

    1. 六种向量列的直接 SQL 插入/读取均得到一行 [1, 2, 3];正式 SDK ORM 范围内的 VECF32/F64 经反射后可读取并转换成 Python 浮点列表,3/3。

    Unhappy Path 覆盖

    1. 插入维度 2 的值到 VECF32(3) 拒绝为 20301;原有唯一一行完整保留,随后 SELECT 42 正常,3/3。
    2. VECBF16/F16/INT8/UINT8 的 ORM 反射另报 NullType() takes no arguments,但当前公开 SDK VectorType 仅声明 F32/F64;先作为未承诺的支持缺口记录,不并入本 issue 的失败结论。

    白盒验证

    clients/python/matrixone/sqlalchemy_ext/dialect.py 的 SQLAlchemy 2.x MatrixOneTypeCompiler 继承通用 TypeCompiler,只手工委托部分类型;反射返回 MySQL INTEGER 类型时缺对应 visitor。这与本 issue 已列出的 MySQL 类型 visitor 缺失同根。本轮未改源码或运行 Go UT。

    回归测试

    本轮未新增仓库测试或 PR。修复时建议在现有 Python SDK 在线反射测试中加入 VECF32/F64(3)+INT PRIMARY KEY 的反射→读数→CreateTable 编译链,防止只覆盖新建表类型编译。其它未承诺的窄向量类型应先单独确定 SDK 支持合同。

    测试证据

    本地可重复脚本:/private/tmp/mo-sdk-complete-20261026/orm_vector_reflection_probe.py。三轮每轮创建独立数据库、独立目标表,输出中 f32/f64 selected=[(1,[1.0,2.0,3.0])],两者 ddl=CompileError ... INTEGER,均执行数据库清理。

    测试结论

    测试不通过。

  5. added a commit that references this issue on Oct 26, 2026
    28e8760
  6. XuPeng-SH commented on Oct 26, 2026

    @XuPeng-SH
    Contributor

    Local SDK QA (2026-10-26): SDK source 28e8760905a7f39dba2ce436357ea75492f30512; isolated MatrixOne service binary 83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3 (SHA-256 6bebe05311ae6438967a824641e3849fbbc9af298003177351794601edf14b4b). Passed tests/online/test_sdk_quality_contracts.py::test_type_metadata_and_values for live DATETIME(6), TIME(6), and TIMESTAMP(6) DDL/value round-trip. Offline tests.offline.contracts.test_query_contracts::test_scalar_compiler_matches_upstream[type_0..type_18] also passed; the additional MySQL scalar types are compile-only here, not all live runtime cases. This verifies the reported compiler path with those scope limits.

  7. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;完整 commit:59bad9e8aea4314af30fd25ce53267df5140c8fa。修复 PR #31262 已 MERGED,merge commit 28e8760905a7f39dba2ce436357ea75492f30512 已核实为此 main 的祖先。
    • 部署方式:隔离 macOS arm64 本地 1 LogService / 1 TN / 2 CN,当前 commit 重建的 mo-service SHA-256 af1930d6b0fd6d387be01d55635a0ea5dc5f225440234ff942cddebb511078b2,SQL 端口 47011,git_version()=59bad9e8ae;Python 3.12、SQLAlchemy 2.0.55、PyMySQL 1.2.3。测试日期:2026-10-27。

    原问题验证

    此前 SDK 无法编译 mysql.DATETIME(fsp=6) / mysql.TIME(fsp=6),且本 issue 先前 QA 补充了反射表中 INTEGER visitor 缺失。当前 main 上,在线 test_type_metadata_and_values 在 3 个全新库均成功创建 DATETIME(6)、TIME(6) 并读回 2026-01-02 03:04:05.123456 和 0:00:05.123456,3/3;19 种 MySQL/SQLAlchemy 标量类型与上游 MySQL dialect 的离线编译结果相同,参数化测试 19/19 × 3 轮通过。

    Happy Path 覆盖

    1. 额外复验先前失败的反射路径:每轮新库建立 id INT PRIMARY KEY, v VECF32(3) 和 VECF64(3),MetaData.reflect 后 ORM 读取均为 (1, [1.0, 2.0, 3.0]),CreateTable(reflected_table).compile 成功生成 id INTEGER NOT NULL 与 v vecf32(3) / vecf64(3);两类均 3/3,不再报 INTEGER CompileError。
    2. SDK 在线质量合同文件 17 项通过(SQLAlchemy 2.0.55;SQLAlchemy 2.1.6 另跑 17 项通过)。

    Unhappy Path 覆盖

    1. 向 VECF32(3) 插入二维 [1,2],3/3 均被 20301 拒绝;原有唯一一行保持,随后 SELECT 42 返回 42。
    2. 在线类型合同向既有主键再次插入,3/3 返回 1062,原一行保留,随后 SELECT 1 成功;每轮独立库均删除并核对不存在,连接池无已借出连接。

    白盒验证

    本问题是 SDK SQLAlchemy TypeCompiler 的公开类型编译路径,不是 Go 内部竞态;未运行 Go UT/race。先前 QA 的失败复现与研发最新修复评论均已核对,本次用同一反射→读取→重新编译链独立复验。

    回归测试

    复用已合入 PR #31262 的 SDK 在线类型合同及离线 test_scalar_compiler_matches_upstream。本轮未新增 MO PR,也未把 SDK TypeCompiler 行为伪装成纯 SQL MOTR #278 回归。PR 的 Python SDK offline 6 个矩阵任务与 CI Required 成功;online CI 被路由跳过,已用本地隔离服务补测。除该 SDK 质量合同文件外,未跑完整 MatrixOne BVT/MOTR/CI;其它未承诺的窄向量 ORM 类型不计入本 issue 结论。

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions