apecloud / myduckserver

MySQL & Postgres Analytics, Reimagined
184 stars 8 forks source link

Support `AUTO_INCREMENT` #83

Open GaoYusong opened 2 months ago

GaoYusong commented 2 months ago
{
        Name: "ALTER TABLE remove AUTO_INCREMENT",
        SetUpScript: []string{
            "CREATE TABLE t40 (pk int AUTO_INCREMENT PRIMARY KEY, val int)",
            "INSERT into t40 VALUES (1, 1), (NULL, 2), (NULL, 3)",
        },
        Assertions: []ScriptTestAssertion{
            {
                Query:    "ALTER TABLE t40 MODIFY COLUMN pk int",
                Expected: []sql.Row{{types.NewOkResult(0)}},
            },
            {
                Query: "describe t40",
                Expected: []sql.Row{
                    {"pk", "int", "NO", "PRI", nil, ""},
                    {"val", "int", "YES", "", nil, ""},
                },
            },
            {
                Query:       "INSERT INTO t40 VALUES (NULL, 4)",
                ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull,
            },
            {
                Query:    "drop table t40",
                Expected: []sql.Row{{types.NewOkResult(0)}},
            },
            {
                Query:    "CREATE TABLE t40 (pk int AUTO_INCREMENT PRIMARY KEY, val int)",
                Expected: []sql.Row{{types.NewOkResult(0)}},
            },
            {
                Query: "INSERT INTO t40 VALUES (NULL, 1)",
                Expected: []sql.Row{{types.OkResult{
                    RowsAffected: 1,
                    InsertID:     1,
                }}},
            },
            {
                Query:    "SELECT * FROM t40",
                Expected: []sql.Row{{1, 1}},
            },
        },
    },
 --- FAIL: TestAlterTable/ALTER_TABLE_remove_AUTO_INCREMENT (0.01s)
        /Users/shannon/code/myduckserver/evaluation.go:51: 
                Error Trace:    /Users/shannon/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.2-0.20240815142344-761713e36043/enginetest/evaluation.go:51
                                            /Users/shannon/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.2-0.20240815142344-761713e36043/enginetest/evaluation.go:93
                Error:          Received unexpected error:
                                Constraint Error: NOT NULL constraint failed: t40.pk
                Test:           TestAlterTable/ALTER_TABLE_remove_AUTO_INCREMENT
                Messages:       error running query INSERT into t40 VALUES (1, 1), (NULL, 2), (NULL, 3): Constraint Error: NOT NULL constraint failed: t40.p
GaoYusong commented 2 months ago
{
        Name: "ALTER TABLE AUTO INCREMENT no-ops on table with no original auto increment key",
        SetUpScript: []string{
            "CREATE table test (pk int primary key)",
            "ALTER TABLE `test` auto_increment = 2;",
            "INSERT INTO test VALUES (1)",
        },
        Assertions: []ScriptTestAssertion{
            {
                Query:    "SELECT * FROM test",
                Expected: []sql.Row{{1}},
            },
        },
    },