MCPcopy Create free account
hub / github.com/apecloud/myduckserver / RunTestColumnDefaults

Function RunTestColumnDefaults

main_test.go:2066–2114  ·  view source on GitHub ↗
(t *testing.T, harness enginetest.Harness)

Source from the content-addressed store, hash-verified

2064 if enginetest.IsServerEngine(e) {
2065 t.Skip("TODO: fix result formatting for server engine tests")
2066 }
2067 // ctx = NewContext(harness)
2068 // e.Query(ctx, "set @@session.time_zone='SYSTEM';")
2069 enginetest.TestQueryWithContext(t, ctx, e, harness, "CREATE TABLE t10(pk BIGINT PRIMARY KEY, v1 DATETIME(6) DEFAULT NOW(6), v2 DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),"+
2070 "v3 TIMESTAMP(6) DEFAULT NOW(6), v4 TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6))", []sql.Row{{types.NewOkResult(0)}}, nil, nil, nil)
2071
2072 // truncating time to microseconds for compatibility with integrators who may store more precision (go gives nanos)
2073 now := time.Now().Truncate(time.Microsecond).UTC()
2074 sql.RunWithNowFunc(func() time.Time {
2075 return now
2076 }, func() error {
2077 enginetest.RunQueryWithContext(t, e, harness, nil, "insert into t10(pk) values (1)")
2078 return nil
2079 })
2080 // enginetest.TestQueryWithContext(t, ctx, e, harness, "select * from t10 order by 1", []sql.Row{
2081 // {1, now, now, now, now},
2082 // }, nil, nil, nil)
2083 })
2084
2085 // TODO: zero timestamps work slightly differently than they do in MySQL, where the zero time is "0000-00-00 00:00:00"
2086 // We use "0000-01-01 00:00:00"
2087 t.Run("DATETIME/TIMESTAMP NOW/CURRENT_TIMESTAMP literals", func(t *testing.T) {
2088 if enginetest.IsServerEngine(e) {
2089 t.Skip("TODO: fix result formatting for server engine tests")
2090 }
2091 enginetest.TestQueryWithContext(t, ctx, e, harness, "CREATE TABLE t10zero(pk BIGINT PRIMARY KEY, v1 DATETIME DEFAULT '2020-01-01 01:02:03', v2 DATETIME DEFAULT '2020-01-01 01:02:03',"+
2092 "v3 TIMESTAMP DEFAULT '2020-01-01 01:02:03', v4 TIMESTAMP DEFAULT '2020-01-01 01:02:03')", []sql.Row{{types.NewOkResult(0)}}, nil, nil, nil)
2093
2094 enginetest.RunQueryWithContext(t, e, harness, ctx, "insert into t10zero(pk) values (1)")
2095
2096 // TODO: the string conversion does not transform to UTC like other NOW() calls, fix this
2097 enginetest.TestQueryWithContext(t, ctx, e, harness, "select * from t10zero order by 1", []sql.Row{{1, time.Date(2020, 1, 1, 1, 2, 3, 0, time.UTC), time.Date(2020, 1, 1, 1, 2, 3, 0, time.UTC), time.Date(2020, 1, 1, 1, 2, 3, 0, time.UTC), time.Date(2020, 1, 1, 1, 2, 3, 0, time.UTC)}}, nil, nil, nil)
2098 })
2099}
2100
2101func TestAlterTable(t *testing.T) {
2102
2103 harness := NewDefaultDuckHarness()
2104
2105 // patch the test script since we don't support column as default value yet
2106 replaceQueryInScriptTest(queries.AlterTableScripts, "variety of alter column statements in a single statement",
2107 "CREATE TABLE t32(pk BIGINT PRIMARY KEY, v1 int, v2 int, v3 int default (v1), toRename int)",
2108 "CREATE TABLE t32(pk BIGINT PRIMARY KEY, v1 int, v2 int, v3 int default (10), toRename int)",
2109 )
2110
2111 // patch the test script since we don't support check constraints yet
2112 replaceQueryInScriptTest(queries.AlterTableScripts, "drop column drops check constraint",
2113 `ALTER TABLE t34 ADD CONSTRAINT test_check CHECK (j < 12345)`,
2114 ``,
2115 )
2116
2117 harness.QueriesToSkip(

Callers 1

TestColumnDefaultsFunction · 0.85

Calls 6

mustNewEngineFunction · 0.85
SetupMethod · 0.80
TruncateMethod · 0.80
CloseMethod · 0.65
NewContextMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected