未验证 提交 d86178e9 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #13866 from taosdata/FIX/TS-1438

feat: support case sensitive and CN names of db, stable, column, tags and so on
......@@ -5,6 +5,7 @@ build/
cmake-build-debug/
cmake-build-release/
cscope.out
cscope.files
.DS_Store
debug/
release/
......
......@@ -453,6 +453,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
return rowLen;
}
static int32_t tscSCreateSetValueToResObj(SSqlObj *pSql, int32_t rowLen, const char *tableName, const char *ddl) {
SSqlRes *pRes = &pSql->res;
......@@ -473,6 +474,7 @@ static int32_t tscSCreateSetValueToResObj(SSqlObj *pSql, int32_t rowLen, const c
STR_WITH_MAXSIZE_TO_VARSTR(dst, ddl, pField->bytes);
return 0;
}
static int32_t tscSCreateBuildResult(SSqlObj *pSql, BuildType type, const char *str, const char *result) {
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd);
int32_t rowLen = tscSCreateBuildResultFields(pSql, type, result);
......@@ -480,6 +482,7 @@ static int32_t tscSCreateBuildResult(SSqlObj *pSql, BuildType type, const char *
tscFieldInfoUpdateOffset(pQueryInfo);
return tscSCreateSetValueToResObj(pSql, rowLen, str, result);
}
int32_t tscRebuildCreateTableStatement(void *param,char *result) {
SCreateBuilder *builder = (SCreateBuilder *)param;
int32_t code = TSDB_CODE_SUCCESS;
......@@ -533,8 +536,8 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) {
memset(buf, 0, sizeof(buf));
int32_t* lengths = taos_fetch_lengths(pSql);
int32_t ret = tscGetNthFieldResult(row, fields, lengths, 0, buf);
if (0 == ret && STR_NOCASE_EQUAL(buf, strlen(buf), builder->buf, strlen(builder->buf))) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE DATABASE %s", buf);
if (0 == ret && 0 == strcmp(buf, builder->buf)) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE DATABASE `%s`", buf);
for (int i = 1; i < num_fields; i++) {
for (int j = 0; showColumns[j][0] != NULL; j++) {
if (STR_NOCASE_EQUAL(fields[i].name, strlen(fields[i].name), showColumns[j][0], strlen(showColumns[j][0]))) {
......
......@@ -606,8 +606,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case TSDB_SQL_DROP_TABLE:
case TSDB_SQL_DROP_USER:
case TSDB_SQL_DROP_ACCT:
case TSDB_SQL_DROP_DNODE:
case TSDB_SQL_DROP_DB: {
case TSDB_SQL_DROP_DNODE: {
const char* msg2 = "invalid name";
const char* msg3 = "param name too long";
......@@ -626,14 +625,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
}
if (pInfo->type == TSDB_SQL_DROP_DB) {
assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1);
code = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), pzName);
if (code != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
} else if (pInfo->type == TSDB_SQL_DROP_TABLE) {
if (pInfo->type == TSDB_SQL_DROP_TABLE) {
assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1);
code = tscSetTableFullName(&pTableMetaInfo->name, &sTblToken, pSql, dbIncluded);
......@@ -656,11 +648,12 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
break;
}
case TSDB_SQL_DROP_DB:
case TSDB_SQL_USE_DB: {
const char* msg = "invalid db name";
SStrToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0);
if (tscValidateName(pToken, false, NULL) != TSDB_CODE_SUCCESS) {
if (tscValidateName(pToken, true, NULL) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
......@@ -707,7 +700,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char buf[TSDB_DB_NAME_LEN] = {0};
SStrToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf));
if (tscValidateName(&token, false, NULL) != TSDB_CODE_SUCCESS) {
if (tscValidateName(&token, true, NULL) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......@@ -816,7 +809,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SStrToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0);
if (tscValidateName(pToken, false, NULL) != TSDB_CODE_SUCCESS) {
if (tscValidateName(pToken, true, NULL) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......@@ -1864,7 +1857,7 @@ int32_t validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
// field name must be unique
for (int32_t i = 0; i < numOfTags + numOfCols; ++i) {
if (strncasecmp(pColField->name, pSchema[i].name, sizeof(pColField->name) - 1) == 0) {
if (strncmp(pColField->name, pSchema[i].name, sizeof(pColField->name) - 1) == 0) {
//return tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pColField->name, NULL);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "duplicated column names");
}
......@@ -2277,10 +2270,6 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
hasDistinct = (pItem->distinct == true);
distIdx = hasDistinct ? i : -1;
}
if(pItem->aliasName != NULL && validateColumnName(pItem->aliasName) != TSDB_CODE_SUCCESS){
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11);
}
if(pItem->aliasName != NULL && strcasecmp(pItem->aliasName, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == 0){
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11);
}
......@@ -4110,7 +4099,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pDbPrefixToken->n <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
if (tscValidateName(pDbPrefixToken, false, NULL) != TSDB_CODE_SUCCESS) {
if (tscValidateName(pDbPrefixToken, true, NULL) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......
......@@ -3068,6 +3068,12 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
}
}
if (escapeEnabled && pToken->type == TK_ID) {
if (pToken->z[0] == TS_BACKQUOTE_CHAR) {
pToken->n = stringProcess(pToken->z, pToken->n);
firstPartQuote = true;
}
}
int32_t firstPartLen = pToken->n;
pToken->z = sep + 1;
......
......@@ -323,7 +323,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
int64_t oresult = atomic_load_64(&result);
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
if (regex_match(command, "^\\s*use\\s+([a-zA-Z0-9_]+|`.+`)\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
fprintf(stdout, "Database changed.\n\n");
fflush(stdout);
......
......@@ -1235,7 +1235,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
static int32_t mnodeFindSuperTableTagIndex(SSTableObj *pStable, const char *tagName) {
SSchema *schema = (SSchema *) pStable->schema;
for (int32_t tag = 0; tag < pStable->numOfTags; tag++) {
if (strcasecmp(schema[pStable->numOfColumns + tag].name, tagName) == 0) {
if (strcmp(schema[pStable->numOfColumns + tag].name, tagName) == 0) {
return tag;
}
}
......@@ -1388,7 +1388,7 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c
static int32_t mnodeFindSuperTableColumnIndex(SSTableObj *pStable, char *colName) {
SSchema *schema = (SSchema *) pStable->schema;
for (int32_t col = 0; col < pStable->numOfColumns; col++) {
if (strcasecmp(schema[col].name, colName) == 0) {
if (strcmp(schema[col].name, colName) == 0) {
return col;
}
}
......
......@@ -719,13 +719,13 @@ static int32_t monBuildMnodesTotalSql(char *sql) {
static int32_t monGetVgroupsTotalStats(char *dbName, int32_t *totalVgroups,
int32_t *totalVgroupsAlive) {
char subsql[TSDB_DB_NAME_LEN + 14];
char subsql[TSDB_DB_NAME_LEN + 16];
memset(subsql, 0, sizeof(subsql));
snprintf(subsql, TSDB_DB_NAME_LEN + 13, "show %s.vgroups", dbName);
snprintf(subsql, sizeof(subsql) - 1, "show `%s`.vgroups", dbName);
TAOS_RES *result = taos_query(tsMonitor.conn, subsql);
int32_t code = taos_errno(result);
if (code != TSDB_CODE_SUCCESS) {
monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code));
monError("failed to execute cmd: show `%s`.vgroups, reason:%s", dbName, tstrerror(code));
}
TAOS_ROW row;
......@@ -1110,11 +1110,11 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) {
int64_t ts = taosGetTimestampUs();
memset(sql, 0, SQL_LENGTH + 1);
snprintf(sql, SQL_LENGTH, "show %s.vgroups", dbName);
snprintf(sql, SQL_LENGTH, "show `%s`.vgroups", dbName);
TAOS_RES *result = taos_query(tsMonitor.conn, sql);
int32_t code = taos_errno(result);
if (code != TSDB_CODE_SUCCESS) {
monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code));
monError("failed to execute cmd: show `%s`.vgroups, reason:%s", dbName, tstrerror(code));
}
TAOS_ROW row;
......
......@@ -807,6 +807,11 @@
4,,pytest,python3 test.py -f insert/line_insert.py
3,,pytest,python3 test.py -f tag_lite/binary.py
3,,pytest,python3 test.py -f query/filterAllIntTypes.py
3,,pytest,python3 test.py -f dbmgmt/dbNameCaseSensitive.py
3,,pytest,python3 test.py -f insert/schemalessCaseSensitive.py
3,,pytest,python3 test.py -f table/columnNameCaseSensitive.py
3,,pytest,python3 test.py -f table/tagNameCaseSensitive.py
3,,pytest,python3 test.py -f table/tbNameCaseSensitive.py
3,,develop-test,python3 ./test.py -f 2-query/ts_hidden_column.py
3,,develop-test,python3 ./test.py -f 2-query/ts_shortcut.py
3,,develop-test,python3 ./test.py -f 2-query/nchar_funcs.py
......
###################################################################
# 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
import taos
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self._conn = conn
def run(self):
# database name
tdSql.execute("create database db")
tdSql.query("show databases")
tdSql.checkRows(1)
tdSql.error("create database Db")
tdSql.error("create database `db`")
tdSql.execute("create database `Db`")
tdSql.query("show databases")
tdSql.checkRows(2)
tdSql.execute("alter database db cachelast 1")
tdSql.execute("alter database `Db` cachelast 1")
tdSql.execute("use db")
tdSql.query("select database()")
tdSql.checkData(0, 0, 'db');
tdSql.query("show db.vgroups")
tdSql.checkRows(0)
tdSql.execute("use `Db`")
tdSql.query("select database()")
tdSql.checkData(0, 0, 'Db');
tdSql.query("show `Db`.vgroups")
tdSql.checkRows(0)
tdSql.query("show create database `Db`")
tdSql.checkRows(1)
sql = tdSql.getData(0, 1)
tdSql.checkEqual(True, sql.startswith("CREATE DATABASE `Db`"))
tdSql.execute("drop database db")
tdSql.execute("drop database `Db`")
tdSql.query("show databases")
tdSql.checkRows(0)
# corner cases
tdSql.execute("create database `电力系统`")
tdSql.query("show `电力系统`.vgroups")
tdSql.checkRows(0)
tdSql.query("show databases")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "电力系统")
tdSql.query("show create database `电力系统`")
sql = tdSql.getData(0, 1)
tdSql.checkEqual(True, sql.startswith("CREATE DATABASE `电力系统`"))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
###################################################################
# 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 -*-
from util.log import *
from util.cases import *
from util.sql import *
from util.types import TDSmlProtocolType, TDSmlTimestampType
import json
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self._conn = conn
def run(self):
# influxDB Line Protocol
self.influxDBLineProtocol()
# OpenTSDB Line Protocol
self.openTSDBLineProtocol()
# OpenTSDB JSON Protocol
self.openTSDBJSONProtocol()
def influxDBLineProtocol(self):
print("===== influxDB Line Protocol Case Sensitive Test =====\n")
tdSql.execute("create database influxdb precision 'ns' ")
tdSql.execute("use influxdb")
lines = [
"St,deviceId=1i voltage=1,phase=\"Test\" 1626006833639000000",
"St,DeviceId=3i voltage=2,phase=\"Test\" 1626006833639000000",
"St,deviceId=2i,DeviceId=3 Voltage=2,Phase=\"Test2\" 1626006833639000000",
"St,deviceId=4i,DeviceId=3 voltage=1,phase=\"Test\",Voltage=2,Phase=\"Test1\" 1626006833639000000",
"tbl,deviceId=\"sensor0\" Hello=3i 1646053743694400029",
"tbl,deviceId=\"sensor0\" n=3i,N=4i 1646053743694400030",
"tbl,deviceId=\"sensor0\" g=3i 1646053743694400031",
"tbl,deviceId=\"sensor0\" G=3i 1646053743694400032",
"tbl,deviceId=\"sensor0\" nice=2i,Nice=3i 1646053743694400033",
"tbl,deviceId=\"sensor0\" hello=3i 1646053743694400034",
"超级表,deviceId=\"sensor0\" 电压=3i 1646053743694400035",
]
self._conn.schemaless_insert(lines, TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
tdSql.query("show stables")
tdSql.checkRows(3)
tdSql.query("show tables")
tdSql.checkRows(6)
tdSql.query("describe `St`")
tdSql.checkRows(7)
tdSql.query("select * from `St`")
tdSql.checkRows(4)
tdSql.query("select * from tbl")
tdSql.checkRows(6)
tdSql.query("select * from `超级表`")
tdSql.checkRows(1)
def openTSDBLineProtocol(self):
print("===== OpenTSDB Line Protocol Case Sensitive Test =====\n")
tdSql.execute("create database opentsdbline")
tdSql.execute("use opentsdbline")
# format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
lines = [
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
"meters.Current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
"meters.Current 1648432611249 10.8 Location=California.LosAngeles groupid=3",
"meters.Current 1648432611249 10.8 Location=California.LosAngeles location=California.SanFrancisco groupid=3",
"Meters.current 1648432611250 11.3 location=California.LosAngeles Groupid=3",
"电表 1648432611250 11.3 位置=California.LosAngeles Groupid=3"
]
self._conn.schemaless_insert(lines, TDSmlProtocolType.TELNET.value, None)
tdSql.query("show stables")
tdSql.checkRows(4)
tdSql.query("show tables")
tdSql.checkRows(6)
tdSql.query("describe `meters.Current`")
tdSql.checkRows(5)
tdSql.checkData(2, 0, "groupid")
tdSql.checkData(3, 0, "location")
tdSql.checkData(4, 0, "Location")
tdSql.query("describe `Meters.current`")
tdSql.checkRows(4)
tdSql.checkData(2, 0, "Groupid")
tdSql.checkData(3, 0, "location")
tdSql.query("describe `电表`")
tdSql.checkRows(4)
tdSql.checkData(2, 0, "Groupid")
tdSql.checkData(3, 0, "位置")
def openTSDBJSONProtocol(self):
print("===== OpenTSDB JSON Protocol Case Sensitive Test =====\n")
tdSql.execute("create database opentsdbjson")
tdSql.execute("use opentsdbjson")
lines = [
{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"Location": "California.LosAngeles", "groupid": 1}},
{"metric": "meters.Current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "groupid": 1}},
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "Location": "California.SanFrancisco", "groupid": 2}},
{"metric": "电压", "timestamp": 1648432611250, "value": 221, "tags": {"位置": "California.LosAngeles", "groupid": 1}}
]
self._conn.schemaless_insert([json.dumps(lines)], TDSmlProtocolType.JSON.value, None)
tdSql.query("show stables")
tdSql.checkRows(4)
tdSql.query("show tables")
tdSql.checkRows(6)
tdSql.query("describe `meters.Current`")
tdSql.checkRows(4)
tdSql.query("describe `meters.voltage`")
tdSql.checkRows(5)
tdSql.checkData(3, 0, "Location")
tdSql.checkData(4, 0, "location")
tdSql.query("describe `电压`")
tdSql.checkRows(4)
tdSql.checkData(3, 0, "位置")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
###################################################################
# 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 -*-
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def run(self):
tdSql.prepare()
# column
tdSql.execute("create table tb(ts timestamp, c1 int)")
tdSql.execute("create table `TB`(ts timestamp, c1 int)")
tdSql.error("alter table tb add column C1 int")
tdSql.execute("alter table tb add column `C1` int")
tdSql.error("alter table `TB` add column C1 int")
tdSql.execute("alter table `TB` add column `C1` int")
tdSql.error("create table tb2(ts timestamp, c1 int, C1 int)")
tdSql.execute("create table tb2(ts timestamp, c1 int, `C1` int)")
tdSql.query("describe tb2")
tdSql.checkRows(3)
tdSql.checkData(0, 0, 'ts')
tdSql.checkData(1, 0, 'c1')
tdSql.checkData(2, 0, 'C1')
tdSql.execute("insert into tb2(ts, c1) values(now, 1)")
tdSql.execute("insert into tb2(ts, `C1`) values(now + 1s, 1)")
tdSql.execute("insert into tb2(ts, c1, `C1`) values(now + 2s, 1, 2)")
tdSql.query("select * from tb2")
tdSql.checkRows(3)
tdSql.query("select * from tb2 where c1 = 1")
tdSql.checkRows(2)
tdSql.query("select * from tb2 where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 `C1` from tb2 where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 as `C1` from tb2 where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` a from tb2 where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` as a from tb2 where `C1` = 1")
tdSql.checkRows(1)
tdSql.execute("alter table tb2 drop column c1")
tdSql.query("describe tb2")
tdSql.checkRows(2)
tdSql.error("create table `TB2`(ts timestamp, c1 int, C1 int)")
tdSql.execute("create table `TB2`(ts timestamp, c1 int, `C1` int)")
tdSql.query("describe `TB2`")
tdSql.checkRows(3)
tdSql.checkData(0, 0, 'ts')
tdSql.checkData(1, 0, 'c1')
tdSql.checkData(2, 0, 'C1')
tdSql.execute("insert into `TB2`(ts, c1) values(now, 1)")
tdSql.execute("insert into `TB2`(ts, `C1`) values(now + 1s, 1)")
tdSql.execute("insert into `TB2`(ts, c1, `C1`) values(now + 2s, 1, 2)")
tdSql.query("select * from `TB2`")
tdSql.checkRows(3)
tdSql.query("select * from `TB2` where c1 = 1")
tdSql.checkRows(2)
tdSql.query("select * from `TB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 `C1` from `TB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 as `C1` from `TB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` a from `TB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` as a from `TB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.execute("alter table `TB2` drop column `C1`")
tdSql.query("describe tb2")
tdSql.checkRows(2)
tdSql.error("create table `STB2`(ts timestamp, c1 int, C1 int) tags (t1 int)")
tdSql.execute("create table `STB2`(ts timestamp, c1 int, `C1` int) tags (t1 int)")
tdSql.query("describe `STB2`")
tdSql.checkRows(4)
tdSql.checkData(0, 0, 'ts')
tdSql.checkData(1, 0, 'c1')
tdSql.checkData(2, 0, 'C1')
tdSql.checkData(3, 0, 't1')
tdSql.execute("insert into tt2(ts, c1) using `STB2` tags(1) values(now, 1)")
tdSql.execute("insert into tt2(ts, `C1`) using `STB2` tags(1) values(now + 1s, 1)")
tdSql.execute("insert into tt2(ts, c1, `C1`) using `STB2` tags(1) values(now + 2s, 1, 2)")
tdSql.query("select * from `STB2`")
tdSql.checkRows(3)
tdSql.query("select * from `STB2` where c1 = 1")
tdSql.checkRows(2)
tdSql.query("select * from `STB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 `C1` from `STB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select c1 as `C1` from `STB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` a from `STB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("select `C1` as a from `STB2` where `C1` = 1")
tdSql.checkRows(1)
tdSql.query("show create table `STB2`")
tdSql.checkData(0, 1, "CREATE TABLE `STB2` (`ts` TIMESTAMP,`c1` INT,`C1` INT) TAGS (`t1` INT)")
tdSql.execute("alter table `STB2` drop column `C1`")
tdSql.query("describe tb2")
tdSql.checkRows(2)
# cornor cases
tdSql.execute("alter table `STB2` add column `数量` int")
tdSql.execute("insert into tt3(ts, `数量`) using `STB2` tags(2) values(now + 3s, 1)")
tdSql.query("show create table `STB2`")
tdSql.checkData(0, 1, "CREATE TABLE `STB2` (`ts` TIMESTAMP,`c1` INT,`数量` INT) TAGS (`t1` INT)")
tdSql.query("select * from tt3")
tdSql.checkRows(1)
tdSql.query("select ts `TS` from tt3")
tdSql.checkRows(1)
tdSql.query("select ts as `TS` from tt3")
tdSql.checkRows(1)
tdSql.query("select ts as `时间戳` from tt3")
tdSql.checkRows(1)
tdSql.query("select ts `时间戳` from tt3")
tdSql.checkRows(1)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
###################################################################
# 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 -*-
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self._conn = conn
def run(self):
tdSql.prepare()
# tag
tdSql.error("create table `STB3`(ts timesatmp, c1 int) tags(t1 int, T1 int)")
tdSql.execute("create table `STB3`(ts timestamp, c1 int) tags(t1 int)")
tdSql.execute("alter table `STB3` add tag `T1` int")
tdSql.execute("create table `STB4`(ts timestamp, c1 int) tags(t1 int, `T1` int)")
tdSql.execute("create table tt3 using `STB3`(t1) tags(1)")
tdSql.execute("create table tt4 using `STB3`(`T1`) tags(1)")
tdSql.query("select t1, `T1` from `STB3`")
tdSql.checkRows(2)
tdSql.query("show create table `STB3`")
tdSql.checkData(0, 1, "CREATE TABLE `STB3` (`ts` TIMESTAMP,`c1` INT) TAGS (`t1` INT,`T1` INT)")
tdSql.execute("alter table `STB3` drop tag `T1`")
tdSql.query("describe `STB3`")
tdSql.checkRows(3)
# cornor case
tdSql.execute("create table `STB5`(ts timestamp, c1 int) tags(t1 int, `标签` int)")
tdSql.execute("insert into `测试` using `STB5` tags(1, 1) values(now, 1)")
tdSql.query("show create table `STB5`")
tdSql.checkData(0, 1, "CREATE TABLE `STB5` (`ts` TIMESTAMP,`c1` INT) TAGS (`t1` INT,`标签` INT)")
tdSql.query("select * from `测试`")
tdSql.checkRows(1)
tdSql.query("select `标签` t from `测试`")
tdSql.checkRows(1)
tdSql.execute("alter table `STB5` add tag `标签2` double")
tdSql.query("describe `STB5`")
tdSql.checkRows(5)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
###################################################################
# 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 -*-
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def run(self):
# table/stable
tdSql.execute("create database test")
tdSql.execute("create database `Test`")
tdSql.execute("use test")
tdSql.execute("create table tb(ts timestamp, c1 int)")
tdSql.query("show tables")
tdSql.checkRows(1)
tdSql.query("show create table tb")
tdSql.checkRows(1)
tdSql.checkData(0, 1, "CREATE TABLE `tb` (`ts` TIMESTAMP,`c1` INT)")
tdSql.error("create table Tb(ts timestamp, c1 int)")
tdSql.execute("create table `TB`(ts timestamp, c1 int)")
tdSql.query("show tables")
tdSql.checkRows(2)
tdSql.query("show create table `TB`")
tdSql.checkRows(1)
tdSql.checkData(0, 1, "CREATE TABLE `TB` (`ts` TIMESTAMP,`c1` INT)")
tdSql.query("describe tb")
tdSql.checkRows(2)
tdSql.query("describe `TB`")
tdSql.checkRows(2)
tdSql.execute("insert into tb values(now, 1)")
tdSql.error("select * from `Test`.tb")
tdSql.query("select * from test.tb")
tdSql.checkRows(1)
tdSql.execute("insert into `TB` values(now, 1)")
tdSql.error("select * from `Test`.`TB`")
tdSql.query("select * from test.`TB`")
tdSql.checkRows(1)
tdSql.execute("create stable stb(ts timestamp, c1 int) tags(t1 int)")
tdSql.query("show stables")
tdSql.checkRows(1)
tdSql.error("crate stable STb(ts timestamp, c1 int) tags(t1 int)")
tdSql.error("create stable `stb`(ts timestamp, c1 int) tags(t1 int)")
tdSql.execute("create stable `STB`(ts timestamp, c1 int) tags(t1 int)")
tdSql.query("show stables")
tdSql.checkRows(2)
tdSql.query("describe stb")
tdSql.checkRows(3)
tdSql.query("describe `STB`")
tdSql.checkRows(3)
tdSql.execute("insert into t1 using stb tags(1) values(now, 1)")
tdSql.query("select * from stb")
tdSql.checkRows(1)
tdSql.execute("insert into t2 using `STB` tags(1) values(now, 1)")
tdSql.query("select * from `STB`")
tdSql.checkRows(1)
tdSql.execute("insert into `T2` using `STB` tags(1) values(now + 1s, 1)")
tdSql.query("select * from `STB`")
tdSql.checkRows(2)
tdSql.query("select tbname from `STB`")
tdSql.checkRows(2)
tdSql.execute("alter table stb add column c2 int")
tdSql.execute("alter table stb add tag t2 int")
tdSql.execute("alter table `STB` add column c2 int")
tdSql.execute("alter table `STB` add tag t2 int")
tdSql.execute("alter table `TB` add column c2 int")
tdSql.query("show create table `STB`")
tdSql.checkData(0, 1, "CREATE TABLE `STB` (`ts` TIMESTAMP,`c1` INT,`c2` INT) TAGS (`t1` INT,`t2` INT)")
# corner cases
tdSql.execute("create table `超级表`(ts timestamp, c1 int) tags(t1 int)")
tdSql.execute("create table `子表一` using `超级表` tags(1)")
tdSql.execute("insert into `子表二` using `超级表` tags(1) values(now, 1)")
tdSql.query("select * from `超级表`")
tdSql.checkRows(1)
tdSql.query("select * from `子表二`")
tdSql.checkRows(1)
tdSql.query("show tables")
tdSql.checkRows(7)
tdSql.execute("create table `普通表` (ts timestamp, c1 int)")
tdSql.execute("insert into `普通表` values(now, 2)")
tdSql.query("select * from `普通表`")
tdSql.checkRows(1)
tdSql.query("show tables")
tdSql.checkRows(8)
tdSql.query("show create table `普通表`")
tdSql.checkData(0, 1, "CREATE TABLE `普通表` (`ts` TIMESTAMP,`c1` INT)")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册