diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 72d55a7ff1524f4d717f485ea26ac7691c077057..a46f1a1248e731c283065cd4a532476f9f308648 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1084,8 +1084,9 @@ static int32_t addPrimaryTsColumnForTimeWindowQuery(SQueryInfo* pQueryInfo, SSql uint64_t uid = tscExprGet(pQueryInfo, 0)->base.uid; int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL; + STableMetaInfo* pTableMetaInfo = NULL; for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); + pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); if (pTableMetaInfo->pTableMeta->id.uid == uid) { tableIndex = i; break; @@ -1097,7 +1098,11 @@ static int32_t addPrimaryTsColumnForTimeWindowQuery(SQueryInfo* pQueryInfo, SSql } SSchema s = {.bytes = TSDB_KEYSIZE, .type = TSDB_DATA_TYPE_TIMESTAMP, .colId = PRIMARYKEY_TIMESTAMP_COL_INDEX}; - tstrncpy(s.name, aAggs[TSDB_FUNC_TS].name, sizeof(s.name)); + if (pTableMetaInfo) { + tstrncpy(s.name, pTableMetaInfo->pTableMeta->schema[PRIMARYKEY_TIMESTAMP_COL_INDEX].name, sizeof(s.name)); + } else { + tstrncpy(s.name, aAggs[TSDB_FUNC_TS].name, sizeof(s.name)); + } SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; tscAddFuncInSelectClause(pQueryInfo, 0, TSDB_FUNC_TS, &index, &s, TSDB_COL_NORMAL, 0); diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 5d27a177924a77639f13bcd074b0eae3cb01c17f..c9cf6a2af4241d17d9a9536374a25d1c3add604b 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -288,6 +288,7 @@ python3 test.py -f query/nestedQuery/queryWithSpread.py python3 ./test.py -f query/bug6586.py # python3 ./test.py -f query/bug5903.py python3 ./test.py -f query/queryLimit.py +python3 ./test.py -f query/queryPriKey.py #stream python3 ./test.py -f stream/metric_1.py diff --git a/tests/pytest/query/queryPriKey.py b/tests/pytest/query/queryPriKey.py new file mode 100644 index 0000000000000000000000000000000000000000..c2a68b23ed681fef68c59f487af32c913a2abdfe --- /dev/null +++ b/tests/pytest/query/queryPriKey.py @@ -0,0 +1,54 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + tdSql.execute("drop database if exists tdb") + tdSql.execute("create database if not exists tdb keep 3650") + tdSql.execute("use tdb") + + tdSql.execute( + "create table stb1 (time timestamp, c1 int) TAGS (t1 int)" + ) + + tdSql.execute( + "insert into t1 using stb1 tags(1) values (now - 1m, 1)" + ) + tdSql.execute( + "insert into t1 using stb1 tags(1) values (now - 2m, 2)" + ) + tdSql.execute( + "insert into t1 using stb1 tags(1) values (now - 3m, 3)" + ) + + res = tdSql.getColNameList("select count(*) from t1 interval(1m)") + assert res[0] == 'time' + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase())