From 53d77c60498efafd26fd1e0231be3d137ea66e27 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Fri, 7 Feb 2025 11:12:48 +0800 Subject: [PATCH] fix: cast double --- include/common/ttypes.h | 10 +++++----- tests/army/query/function/cast.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index c50ce7ba73..675f774566 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -239,21 +239,21 @@ typedef struct { snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ break; \ case TSDB_DATA_TYPE_FLOAT: { \ - int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%.7f", *(float *)(_input)); \ if (n >= (_outputBytes)) { \ n = snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%e", *(float *)(_input)); \ } \ } \ break; \ } \ case TSDB_DATA_TYPE_DOUBLE: { \ - int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%.15f", *(double *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ + n = snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%e", *(double *)(_input)); \ } \ } \ break; \ diff --git a/tests/army/query/function/cast.py b/tests/army/query/function/cast.py index af72f1de2c..2765250d93 100644 --- a/tests/army/query/function/cast.py +++ b/tests/army/query/function/cast.py @@ -540,6 +540,18 @@ class TDTestCase(TBase): tdSql.query(f"select cast({add1}+{test_str} as nchar(2)) re;") tdSql.checkData(0, 0, "12") + + def ts5972(self): + tdSql.execute("CREATE DATABASE IF NOT EXISTS ts5972;") + tdSql.execute("DROP TABLE IF EXISTS ts5972.t1;") + tdSql.execute("DROP TABLE IF EXISTS ts5972.t1;") + tdSql.execute("CREATE TABLE ts5972.t1(time TIMESTAMP, c0 DOUBLE);") + tdSql.execute("INSERT INTO ts5972.t1(time, c0) VALUES (1641024000000, 0.018518518518519), (1641024005000, 0.015151515151515), (1641024010000, 0.1234567891012345);") + tdSql.query("SELECT c0, CAST(c0 AS BINARY(50)) FROM ts5972.t1 WHERE CAST(c0 AS BINARY(50)) != c0;") + tdSql.checkRows(0) + tdSql.query("SELECT c0, CAST(c0 AS BINARY(50)) FROM ts5972.t1 WHERE CAST(c0 AS BINARY(50)) == c0;") + tdSql.checkRows(3) + def cast_without_from(self): self.cast_from_int_to_other() @@ -556,6 +568,7 @@ class TDTestCase(TBase): def run(self): # 'from table' case see system-test/2-query/cast.py self.cast_without_from() + self.ts5972() tdLog.success(f"{__file__} successfully executed")