|
| 1 | +// Copyright 2024 PingCAP, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package pushdowntest |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/pingcap/tidb/pkg/testkit" |
| 21 | + "github.com/pingcap/tidb/tests/realtikvtest" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | +) |
| 24 | + |
| 25 | +// TestIssue44135WithTiKV tests that CAST(float AS DATETIME) returns consistent results |
| 26 | +// for both generated columns and base columns when running with real TiKV. |
| 27 | +// See https://github.com/pingcap/tidb/issues/44135 |
| 28 | +func TestIssue44135WithTiKV(t *testing.T) { |
| 29 | + store := realtikvtest.CreateMockStoreAndSetup(t) |
| 30 | + tk := testkit.NewTestKit(t, store) |
| 31 | + tk.MustExec("use test") |
| 32 | + |
| 33 | + // Case 1: With generated column |
| 34 | + tk.MustExec("DROP TABLE IF EXISTS t0") |
| 35 | + tk.MustExec("CREATE TABLE t0(`c0` float GENERATED ALWAYS AS (`c1`), `c1` float)") |
| 36 | + tk.MustExec("INSERT INTO t0(c1) VALUES (0.5822439)") |
| 37 | + result1 := tk.MustQuery("SELECT * FROM t0 WHERE (~ (CAST(c0 AS DATETIME)))") |
| 38 | + |
| 39 | + // Case 2: Without generated column (base column only) |
| 40 | + tk.MustExec("DROP TABLE IF EXISTS t1") |
| 41 | + tk.MustExec("CREATE TABLE t1(`c1` float)") |
| 42 | + tk.MustExec("INSERT INTO t1(c1) VALUES (0.5822439)") |
| 43 | + result2 := tk.MustQuery("SELECT * FROM t1 WHERE (~ (CAST(c1 AS DATETIME)))") |
| 44 | + |
| 45 | + // Both queries should return consistent results (either both return the row or both return empty) |
| 46 | + rows1 := result1.Rows() |
| 47 | + rows2 := result2.Rows() |
| 48 | + require.Equal(t, len(rows1), len(rows2), "CAST(float AS DATETIME) should return consistent results for generated column and base column") |
| 49 | +} |
0 commit comments