提交 b2021a97 编写于 作者: C Cary Xu

Merge branch 'develop' into enhance/TS-385

import hudson.model.Result
import hudson.model.*;
import jenkins.model.CauseOfInterruption
properties([pipelineTriggers([githubPush()])])
node {
......@@ -6,6 +7,7 @@ node {
}
def skipbuild=0
def win_stop=0
def abortPreviousBuilds() {
def currentJobName = env.JOB_NAME
......@@ -110,7 +112,83 @@ def pre_test(){
'''
return 1
}
def pre_test_win(){
bat '''
cd C:\\
rd /s /Q C:\\TDengine
cd C:\\workspace\\TDinternal
rd /s /Q C:\\workspace\\TDinternal\\debug
cd C:\\workspace\\TDinternal\\community
git reset --hard HEAD~10
'''
script {
if (env.CHANGE_TARGET == 'master') {
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout 2.0
'''
}
else{
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout develop
'''
}
}
bat'''
cd C:\\workspace\\TDinternal\\community
git pull
git fetch origin +refs/pull/%CHANGE_ID%/merge
git checkout -qf FETCH_HEAD
git clean -dfx
cd C:\\workspace\\TDinternal
git reset --hard HEAD~10
'''
script {
if (env.CHANGE_TARGET == 'master') {
bat '''
cd C:\\workspace\\TDinternal
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
bat '''
cd C:\\workspace\\TDinternal
git checkout 2.0
'''
}
else{
bat '''
cd C:\\workspace\\TDinternal
git checkout develop
'''
}
}
bat '''
cd C:\\workspace\\TDinternal
git pull
date
git clean -dfx
mkdir debug
cd debug
call "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" amd64
cmake ../ -G "NMake Makefiles"
nmake
nmake install
xcopy /e/y/i/f C:\\workspace\\TDinternal\\debug\\build\\lib\\taos.dll C:\\Windows\\System32
cd C:\\workspace\\TDinternal\\community\\src\\connector\\python
python -m pip install .
'''
return 1
}
pipeline {
agent none
environment{
......@@ -387,7 +465,37 @@ pipeline {
date'''
}
}
}
}
stage('build'){
agent{label " wintest "}
steps {
pre_test()
script{
while(win_stop == 0){
sleep(1)
}
}
}
}
stage('test'){
agent{label "win"}
steps{
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
pre_test_win()
bat'''
cd C:\\workspace\\TDinternal\\community\\tests\\pytest
.\\test-all.bat Wintest
'''
}
script{
win_stop=1
}
}
}
}
}
}
......
......@@ -45,8 +45,10 @@ else
inc_link_dir="/usr/local/include"
install_main_dir="/usr/local/Cellar/tdengine/${verNumber}"
install_main_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}"
bin_dir="/usr/local/Cellar/tdengine/${verNumber}/bin"
bin_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}/bin"
fi
service_config_dir="/etc/systemd/system"
......@@ -121,16 +123,25 @@ function kill_taosd() {
function install_main_path() {
#create install main dir and all sub dir
${csudo} rm -rf ${install_main_dir} || :
${csudo} mkdir -p ${install_main_dir}
${csudo} mkdir -p ${install_main_dir}/cfg
${csudo} mkdir -p ${install_main_dir}/bin
${csudo} mkdir -p ${install_main_dir}/connector
${csudo} mkdir -p ${install_main_dir}/driver
${csudo} mkdir -p ${install_main_dir}/examples
${csudo} mkdir -p ${install_main_dir}/include
if [ "$osType" != "Darwin" ]; then
${csudo} rm -rf ${install_main_dir} || :
${csudo} mkdir -p ${install_main_dir}
${csudo} mkdir -p ${install_main_dir}/cfg
${csudo} mkdir -p ${install_main_dir}/bin
${csudo} mkdir -p ${install_main_dir}/connector
${csudo} mkdir -p ${install_main_dir}/driver
${csudo} mkdir -p ${install_main_dir}/examples
${csudo} mkdir -p ${install_main_dir}/include
${csudo} mkdir -p ${install_main_dir}/init.d
else
${csudo} rm -rf ${install_main_dir} || ${csudo} rm -rf ${install_main_2_dir} || :
${csudo} mkdir -p ${install_main_dir} || ${csudo} mkdir -p ${install_main_2_dir}
${csudo} mkdir -p ${install_main_dir}/cfg || ${csudo} mkdir -p ${install_main_2_dir}/cfg
${csudo} mkdir -p ${install_main_dir}/bin || ${csudo} mkdir -p ${install_main_2_dir}/bin
${csudo} mkdir -p ${install_main_dir}/connector || ${csudo} mkdir -p ${install_main_2_dir}/connector
${csudo} mkdir -p ${install_main_dir}/driver || ${csudo} mkdir -p ${install_main_2_dir}/driver
${csudo} mkdir -p ${install_main_dir}/examples || ${csudo} mkdir -p ${install_main_2_dir}/examples
${csudo} mkdir -p ${install_main_dir}/include || ${csudo} mkdir -p ${install_main_2_dir}/include
fi
}
......@@ -145,33 +156,34 @@ function install_bin() {
${csudo} rm -f ${bin_link_dir}/perfMonitor || :
${csudo} rm -f ${bin_link_dir}/set_core || :
${csudo} rm -f ${bin_link_dir}/rmtaos || :
fi
${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin
${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin
if [ "$osType" != "Darwin" ]; then
${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin
${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin
${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin
${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin
${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin
else
${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin
fi
${csudo} chmod 0555 ${install_main_dir}/bin/*
#Make link
[ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || :
[ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || :
[ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
[ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
if [ "$osType" != "Darwin" ]; then
${csudo} chmod 0555 ${install_main_dir}/bin/*
#Make link
[ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || :
[ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || :
[ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
[ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
[ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo} ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || :
[ -x ${install_main_dir}/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
fi
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || :
else
if [ "$osType" != "Darwin" ]; then
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || :
${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || :
${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || :
${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin
${csudo} chmod 0555 ${install_main_dir}/bin/* || ${csudo} chmod 0555 ${install_main_2_dir}/bin/*
#Make link
[ -x ${install_main_dir}/bin/taos ] || [ -x ${install_main_2_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || ${csudo} ln -s ${install_main_2_dir}/bin/taos || :
[ -x ${install_main_dir}/bin/taosd ] || [ -x ${install_main_2_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || ${csudo} ln -s ${install_main_2_dir}/bin/taosd || :
[ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
[ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
fi
}
......@@ -243,12 +255,12 @@ function install_lib() {
${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so
fi
else
${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${install_main_dir}/driver/libtaos.1.dylib || :
${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${install_main_dir}/driver/libtaos.dylib || :
${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib || :
${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || :
${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib ${install_main_dir}/driver || ${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib ${install_main_2_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* || ${csudo} chmod 777 ${install_main_2_dir}/driver/*
${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${install_main_dir}/driver/libtaos.1.dylib || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.* ${install_main_2_dir}/driver/libtaos.1.dylib || :
${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${install_main_dir}/driver/libtaos.dylib || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib ${install_main_2_dir}/driver/libtaos.dylib || :
${csudo} ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib ${lib_link_dir}/libtaos.1.dylib || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib ${lib_link_dir}/libtaos.1.dylib || :
${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || :
fi
install_jemalloc
......@@ -261,12 +273,12 @@ function install_lib() {
function install_header() {
if [ "$osType" != "Darwin" ]; then
${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || :
fi
${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/*
if [ "$osType" != "Darwin" ]; then
${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || :
${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/*
${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
else
${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_dir}/include || ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_2_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* || ${csudo} chmod 644 ${install_main_2_dir}/include/*
fi
}
......@@ -278,23 +290,30 @@ function install_config() {
[ -f ${script_dir}/../cfg/taos.cfg ] &&
${csudo} cp ${script_dir}/../cfg/taos.cfg ${cfg_install_dir}
${csudo} chmod 644 ${cfg_install_dir}/*
fi
${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org
if [ "$osType" != "Darwin" ]; then ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg
${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org
${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg
else
${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org || ${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_2_dir}/cfg/taos.cfg.org
fi
}
function install_log() {
${csudo} rm -rf ${log_dir} || :
${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir}
${csudo} ln -s ${log_dir} ${install_main_dir}/log
if [ "$osType" != "Darwin" ]; then
${csudo} ln -s ${log_dir} ${install_main_dir}/log
else
${csudo} ln -s ${log_dir} ${install_main_dir}/log || ${csudo} ln -s ${log_dir} ${install_main_2_dir}/log
fi
}
function install_data() {
${csudo} mkdir -p ${data_dir}
${csudo} ln -s ${data_dir} ${install_main_dir}/data
if [ "$osType" != "Darwin" ]; then
${csudo} ln -s ${data_dir} ${install_main_dir}/data
else
${csudo} ln -s ${data_dir} ${install_main_dir}/data || ${csudo} ln -s ${data_dir} ${install_main_2_dir}/data
fi
}
function install_connector() {
......@@ -308,12 +327,21 @@ function install_connector() {
else
echo "WARNING: go connector not found, please check if want to use it!"
fi
${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector
${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null
if [ "$osType" != "Darwin" ]; then
${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector
${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null
else
${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector}
${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null || cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || ${csudo} chmod 777 ${install_main_2_dir}/connector/*.jar || echo &> /dev/null
fi
}
function install_examples() {
${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples
if [ "$osType" != "Darwin" ]; then
${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples
else
${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples || ${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_2_dir}/examples
fi
}
function clean_service_on_sysvinit() {
......@@ -532,8 +560,16 @@ function install_TDengine() {
## ==============================Main program starts from here============================
echo source directory: $1
echo binary directory: $2
if [ -x ${bin_dir}/taos ]; then
update_TDengine
if [ "$osType" != "Darwin" ]; then
if [ -x ${bin_dir}/taos ]; then
update_TDengine
else
install_TDengine
fi
else
install_TDengine
if [ -x ${bin_dir}/taos ] || [ -x ${bin_2_dir}/taos ]; then
update_TDengine
else
install_TDengine
fi
fi
......@@ -41,6 +41,15 @@ extern "C" {
#define UTIL_TABLE_IS_TMP_TABLE(metaInfo) \
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
#define UTIL_GET_VGROUPMAP(pSql) \
(pSql->pTscObj->pClusterInfo->vgroupMap)
#define UTIL_GET_TABLEMETA(pSql) \
(pSql->pTscObj->pClusterInfo->tableMetaMap)
#define UTIL_GET_VGROUPLIST(pSql) \
(pSql->pTscObj->pClusterInfo->vgroupListBuf)
#pragma pack(push,1)
// this struct is transfered as binary, padding two bytes to avoid
// an 'uid' whose low bytes is 0xff being recoginized as NULL,
......@@ -106,10 +115,11 @@ typedef struct SBlockKeyInfo {
SBlockKeyTuple* pKeyTuple;
} SBlockKeyInfo;
int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *len);
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta);
void tscDestroyDataBlock(SSqlObj *pSql, STableDataBlocks* pDataBlock, bool removeMeta);
void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf);
int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo);
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
......@@ -120,12 +130,12 @@ void doRetrieveSubqueryData(SSchedMsg *pMsg);
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, int16_t bytes,
uint32_t offset);
void* tscDestroyBlockArrayList(SArray* pDataBlockList);
void* tscDestroyBlockArrayList(SSqlObj* pSql, SArray* pDataBlockList);
void* tscDestroyUdfArrayList(SArray* pUdfList);
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta);
void* tscDestroyBlockHashTable(SSqlObj* pSql, SHashObj* pBlockHashTable, bool removeMeta);
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBlockMap);
int32_t tscMergeTableDataBlocks(SSqlObj *pSql, SInsertStatementParam *pInsertParam, bool freeBlockMap);
int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, SName* pName, STableMeta* pTableMeta,
STableDataBlocks** dataBlocks, SArray* pBlockList);
......@@ -139,6 +149,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
bool tscIsIrateQuery(SQueryInfo* pQueryInfo);
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId);
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
......@@ -155,7 +166,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo);
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo);
bool tscIsDiffDerivLikeQuery(SQueryInfo* pQueryInfo);
bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscIsProjectionQuery(SQueryInfo* pQueryInfo);
......@@ -353,7 +364,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild);
uint32_t tscGetTableMetaSize(STableMeta* pTableMeta);
CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta);
uint32_t tscGetTableMetaMaxSize();
int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta **ppStable);
int32_t tscCreateTableMetaFromSTableMeta(SSqlObj *pSql, STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta **ppStable);
STableMeta* tscTableMetaDup(STableMeta* pTableMeta);
SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo);
......@@ -374,6 +385,7 @@ void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id);
char* cloneCurrentDBName(SSqlObj* pSql);
#ifdef __cplusplus
}
#endif
......
......@@ -48,6 +48,7 @@ struct SSqlInfo;
typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int32_t numOfRows);
typedef struct SNewVgroupInfo {
int32_t vgId;
int8_t inUse;
......@@ -139,6 +140,13 @@ typedef enum {
ROW_COMPARE_NEED = 1,
} ERowCompareStat;
typedef struct {
void *vgroupMap;
void *tableMetaMap;
void *vgroupListBuf;
int64_t ref;
} SClusterInfo;
int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int16_t timePrec);
int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint32_t nCols, uint32_t nBoundCols,
......@@ -324,6 +332,7 @@ typedef struct STscObj {
char acctId[TSDB_ACCT_ID_LEN];
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
char sversion[TSDB_VERSION_LEN];
char clusterId[TSDB_CLUSTER_ID_LEN];
char writeAuth : 1;
char superAuth : 1;
uint32_t connId;
......@@ -332,9 +341,11 @@ typedef struct STscObj {
struct SSqlObj * sqlList;
struct SSqlStream *streamList;
SRpcObj *pRpcObj;
SClusterInfo *pClusterInfo;
SRpcCorEpSet *tscCorMgmtEpSet;
pthread_mutex_t mutex;
int32_t numOfObj; // number of sqlObj from this tscObj
SReqOrigin from;
} STscObj;
......@@ -417,6 +428,9 @@ int tscAcquireRpc(const char *key, const char *user, const char *secret,void **
void tscReleaseRpc(void *param);
void tscInitMsgsFp();
void *tscAcquireClusterInfo(const char *clusterId);
void tscReleaseClusterInfo(const char *clusterId);
int tsParseSql(SSqlObj *pSql, bool initial);
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet);
......
......@@ -648,7 +648,8 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD
for(int32_t j = 0; j < numOfExpr; ++j) {
pCtx[j].pOutput += (pCtx[j].outputBytes * numOfRows);
if (pCtx[j].functionId == TSDB_FUNC_TOP || pCtx[j].functionId == TSDB_FUNC_BOTTOM) {
if (pCtx[j].functionId == TSDB_FUNC_TOP || pCtx[j].functionId == TSDB_FUNC_BOTTOM ||
pCtx[j].functionId == TSDB_FUNC_SAMPLE) {
if(j > 0) pCtx[j].ptsOutputBuf = pCtx[j - 1].pOutput;
}
}
......
......@@ -924,8 +924,8 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
} else if (pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE) {
pRes->code = tscProcessShowCreateDatabase(pSql);
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
taosHashClear(tscTableMetaMap);
taosCacheEmpty(tscVgroupListBuf);
taosHashClear(UTIL_GET_TABLEMETA(pSql));
taosCacheEmpty(UTIL_GET_VGROUPLIST(pSql));
pRes->code = TSDB_CODE_SUCCESS;
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
pRes->code = tscProcessServerVer(pSql);
......
......@@ -771,6 +771,10 @@ void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
TSKEY tj = *(TSKEY *)(pBlockData + dataBuf->rowSize * j);
if (ti == tj) {
if (dataBuf->pTableMeta && dataBuf->pTableMeta->tableInfo.update != TD_ROW_DISCARD_UPDATE) {
memmove(pBlockData + dataBuf->rowSize * i, pBlockData + dataBuf->rowSize * j, dataBuf->rowSize);
}
++j;
continue;
}
......@@ -841,6 +845,10 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk
TSKEY tj = (pBlkKeyTuple + j)->skey;
if (ti == tj) {
if (dataBuf->pTableMeta && dataBuf->pTableMeta->tableInfo.update != TD_ROW_DISCARD_UPDATE) {
memmove(pBlkKeyTuple + i, pBlkKeyTuple + j, sizeof(SBlockKeyTuple));
}
++j;
continue;
}
......@@ -1529,7 +1537,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
// merge according to vgId
if (!TSDB_QUERY_HAS_TYPE(pInsertParam->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && taosHashGetSize(pInsertParam->pTableBlockHashList) > 0) {
if ((code = tscMergeTableDataBlocks(pInsertParam, true)) != TSDB_CODE_SUCCESS) {
if ((code = tscMergeTableDataBlocks(pSql, pInsertParam, true)) != TSDB_CODE_SUCCESS) {
goto _clean;
}
}
......@@ -1635,7 +1643,7 @@ static int doPackSendDataBlock(SSqlObj* pSql, SInsertStatementParam *pInsertPara
return tscInvalidOperationMsg(pInsertParam->msg, "too many rows in sql, total number of rows should be less than 32767", NULL);
}
if ((code = tscMergeTableDataBlocks(pInsertParam, true)) != TSDB_CODE_SUCCESS) {
if ((code = tscMergeTableDataBlocks(pSql, pInsertParam, true)) != TSDB_CODE_SUCCESS) {
return code;
}
......@@ -1696,7 +1704,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow
SInsertStatementParam *pInsertParam = &pCmd->insertParam;
destroyTableNameList(pInsertParam);
pInsertParam->pDataBlocks = tscDestroyBlockArrayList(pInsertParam->pDataBlocks);
pInsertParam->pDataBlocks = tscDestroyBlockArrayList(pParentSql, pInsertParam->pDataBlocks);
if (pInsertParam->pTableBlockHashList == NULL) {
pInsertParam->pTableBlockHashList = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
......
......@@ -574,10 +574,10 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl
char fullTableName[TSDB_TABLE_FNAME_LEN] = {0};
memset(fullTableName, 0, tListLen(fullTableName));
tNameExtractFullName(&sname, fullTableName);
tscFreeRegisteredSqlObj(pSql);
size_t size = 0;
taosHashGetCloneExt(tscTableMetaMap, fullTableName, strlen(fullTableName), NULL, (void**)&tableMeta, &size);
taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), fullTableName, strlen(fullTableName), NULL, (void**)&tableMeta, &size);
tscFreeRegisteredSqlObj(pSql);
}
if (tableMeta != NULL) {
......
......@@ -1163,7 +1163,7 @@ static int insertStmtExecute(STscStmt* stmt) {
fillTablesColumnsNull(stmt->pSql);
int code = tscMergeTableDataBlocks(&stmt->pSql->cmd.insertParam, false);
int code = tscMergeTableDataBlocks(stmt->pSql, &stmt->pSql->cmd.insertParam, false);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
......@@ -1194,7 +1194,7 @@ static int insertStmtExecute(STscStmt* stmt) {
pCmd->insertParam.numOfTables = 0;
tfree(pCmd->insertParam.pTableNameList);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pCmd->insertParam.pDataBlocks);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pSql, pCmd->insertParam.pDataBlocks);
return pSql->res.code;
}
......@@ -1215,7 +1215,7 @@ static void insertBatchClean(STscStmt* pStmt) {
tfree(pCmd->insertParam.pTableNameList);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pCmd->insertParam.pDataBlocks);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pSql, pCmd->insertParam.pDataBlocks);
pCmd->insertParam.numOfTables = 0;
taosHashClear(pCmd->insertParam.pTableBlockHashList);
......@@ -1242,7 +1242,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
fillTablesColumnsNull(pStmt->pSql);
if ((code = tscMergeTableDataBlocks(&pStmt->pSql->cmd.insertParam, false)) != TSDB_CODE_SUCCESS) {
if ((code = tscMergeTableDataBlocks(pStmt->pSql, &pStmt->pSql->cmd.insertParam, false)) != TSDB_CODE_SUCCESS) {
return code;
}
......@@ -1773,8 +1773,8 @@ int taos_stmt_close(TAOS_STMT* stmt) {
if (pStmt->pSql && pStmt->pSql->res.code != 0) {
rmMeta = true;
}
tscDestroyDataBlock(pStmt->mtb.lastBlock, rmMeta);
pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta);
tscDestroyDataBlock(pStmt->pSql, pStmt->mtb.lastBlock, rmMeta);
pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->pSql, pStmt->mtb.pTableBlockHashList, rmMeta);
if (pStmt->pSql){
taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList);
}
......
......@@ -2499,6 +2499,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_MAX:
case TSDB_FUNC_DIFF:
case TSDB_FUNC_DERIVATIVE:
case TSDB_FUNC_CSUM:
case TSDB_FUNC_CEIL:
case TSDB_FUNC_FLOOR:
case TSDB_FUNC_ROUND:
......@@ -2551,7 +2552,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// set the first column ts for diff query
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE || functionId == TSDB_FUNC_CSUM) {
SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0};
SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP,
TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false);
......@@ -2591,7 +2592,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tickPerSec /= TSDB_TICK_PER_SECOND(TSDB_TIME_PRECISION_MICRO);
} else if (info.precision == TSDB_TIME_PRECISION_MICRO) {
tickPerSec /= TSDB_TICK_PER_SECOND(TSDB_TIME_PRECISION_MILLI);
}
}
if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10);
......@@ -2747,6 +2748,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_TOP:
case TSDB_FUNC_BOTTOM:
case TSDB_FUNC_MAVG:
case TSDB_FUNC_SAMPLE:
case TSDB_FUNC_PERCT:
case TSDB_FUNC_APERCT: {
// 1. valid the number of parameters
......@@ -2778,7 +2781,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// 2. valid the column type
if (!IS_NUMERIC_TYPE(pSchema->type)) {
if (functionId != TSDB_FUNC_SAMPLE && !IS_NUMERIC_TYPE(pSchema->type)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......@@ -2817,11 +2820,38 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), interResult, false);
tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
} else if (functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE) {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true);
int64_t numRowsSelected = GET_INT32_VAL(val);
if (numRowsSelected <= 0 || numRowsSelected > 1000) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12);
}
// todo REFACTOR
// set the first column ts for top/bottom query
int32_t tsFuncId = (functionId == TSDB_FUNC_MAVG) ? TSDB_FUNC_TS_DUMMY : TSDB_FUNC_TS;
SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
pExpr = tscExprAppend(pQueryInfo, tsFuncId, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd),
0, false);
tstrncpy(pExpr->base.aliasName, aAggs[tsFuncId].name, sizeof(pExpr->base.aliasName));
const int32_t TS_COLUMN_INDEX = PRIMARYKEY_TIMESTAMP_COL_INDEX;
SColumnList ids = createColumnList(1, index.tableIndex, TS_COLUMN_INDEX);
insertResultField(pQueryInfo, colIndex, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP,
aAggs[tsFuncId].name, pExpr);
colIndex += 1; // the first column is ts
getResultDataInfo(pSchema->type, pSchema->bytes, functionId, (int32_t)numRowsSelected, &resultType, &resultSize, &interResult, 0, false,
pUdfInfo);
pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), interResult, false);
tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
} else {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true);
int64_t nTop = GET_INT32_VAL(val);
if (nTop <= 0 || nTop > 100) { // todo use macro
int64_t numRowsSelected = GET_INT32_VAL(val);
if (numRowsSelected <= 0 || numRowsSelected > 100) { // todo use macro
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12);
}
......@@ -3314,7 +3344,8 @@ int32_t tscTansformFuncForSTableQuery(SQueryInfo* pQueryInfo) {
if ((functionId >= TSDB_FUNC_SUM && functionId <= TSDB_FUNC_TWA) ||
(functionId >= TSDB_FUNC_FIRST_DST && functionId <= TSDB_FUNC_STDDEV_DST) ||
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_IRATE)) {
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_IRATE) ||
(functionId == TSDB_FUNC_SAMPLE)) {
if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, (int32_t)pExpr->base.param[0].i64, &type, &bytes,
&interBytes, 0, true, NULL) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
......@@ -3369,8 +3400,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) {
}
bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
const char* msg1 = "TWA/Diff/Derivative/Irate are not allowed to apply to super table directly";
const char* msg2 = "TWA/Diff/Derivative/Irate only support group by tbname for super table query";
const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE are not allowed to apply to super table directly";
const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE only support group by tbname for super table query";
const char* msg3 = "functions not support for super table query";
// filter sql function not supported by metric query yet.
......@@ -3387,7 +3418,8 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
}
}
if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo)) {
if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivLikeQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo) ||
tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE)) {
if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return true;
......@@ -5446,7 +5478,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
const char* msg1 = "value is expected";
const char* msg2 = "invalid fill option";
const char* msg3 = "top/bottom not support fill";
const char* msg3 = "top/bottom/sample not support fill";
const char* msg4 = "illegal value or data overflow";
const char* msg5 = "fill only available for interval query";
const char* msg6 = "not supported function now";
......@@ -5554,7 +5586,8 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
for(int32_t i = 0; i < numOfExprs; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr->base.functionId == TSDB_FUNC_TOP || pExpr->base.functionId == TSDB_FUNC_BOTTOM) {
if (pExpr->base.functionId == TSDB_FUNC_TOP || pExpr->base.functionId == TSDB_FUNC_BOTTOM
|| pExpr->base.functionId == TSDB_FUNC_SAMPLE) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
}
......@@ -6284,7 +6317,9 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
}
int32_t f = pExpr->base.functionId;
if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE ||
if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) ||
f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE ||
f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG ||
f == TSDB_FUNC_CEIL || f == TSDB_FUNC_FLOOR || f == TSDB_FUNC_ROUND)
{
isProjectionFunction = true;
......@@ -7025,7 +7060,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
int32_t f = TSDB_FUNC_TAG;
if (tscIsDiffDerivQuery(pQueryInfo)) {
if (tscIsDiffDerivLikeQuery(pQueryInfo)) {
f = TSDB_FUNC_TAGPRJ;
}
......@@ -7170,6 +7205,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
}
if (IS_MULTIOUTPUT(aAggs[f].status) && f != TSDB_FUNC_TOP && f != TSDB_FUNC_BOTTOM && f != TSDB_FUNC_DIFF &&
f != TSDB_FUNC_MAVG && f != TSDB_FUNC_CSUM && f != TSDB_FUNC_SAMPLE &&
f != TSDB_FUNC_DERIVATIVE && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_PRJ) {
return invalidOperationMsg(msg, msg1);
}
......@@ -7188,7 +7224,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
}
// projection query on super table does not compatible with "group by" syntax
if (tscIsProjectionQuery(pQueryInfo) && !(tscIsDiffDerivQuery(pQueryInfo))) {
if (tscIsProjectionQuery(pQueryInfo) && !(tscIsDiffDerivLikeQuery(pQueryInfo))) {
return invalidOperationMsg(msg, msg3);
}
......@@ -8280,7 +8316,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
size_t len = strlen(name);
if (NULL == taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&pTableMeta, &tableMetaCapacity)) {
if (NULL == taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), name, len, NULL, (void **)&pTableMeta, &tableMetaCapacity)) {
// not found
tfree(pTableMeta);
}
......@@ -8291,7 +8327,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// avoid mem leak, may should update pTableMeta
void* pVgroupIdList = NULL;
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity, (STableMeta **)(&pSTMeta));
code = tscCreateTableMetaFromSTableMeta(pSql, (STableMeta **)(&pTableMeta), name, &tableMetaCapacity, (STableMeta **)(&pSTMeta));
pSql->pBuf = (void *)pSTMeta;
// create the child table meta from super table failed, try load it from mnode
......@@ -8303,7 +8339,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} else if (pTableMeta->tableType == TSDB_SUPER_TABLE) {
// the vgroup list of super table is not kept in local buffer, so here need retrieve it from the mnode each time
tscDebug("0x%"PRIx64" try to acquire cached super table %s vgroup id list", pSql->self, name);
void* pv = taosCacheAcquireByKey(tscVgroupListBuf, name, len);
void* pv = taosCacheAcquireByKey(UTIL_GET_VGROUPLIST(pSql), name, len);
if (pv == NULL) {
char* t = strdup(name);
taosArrayPush(pVgroupList, &t);
......@@ -8316,7 +8352,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
taosArrayAddBatch(pVgroupIdList, pdata->data, (int32_t) pdata->num);
taosCacheRelease(tscVgroupListBuf, &pv, false);
taosCacheRelease(UTIL_GET_VGROUPLIST(pSql), &pv, false);
}
}
......@@ -8466,7 +8502,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
// check if current buffer contains the vgroup info. If not, add it
SNewVgroupInfo existVgroupInfo = {.inUse = -1,};
taosHashGetClone(tscVgroupMap, id, sizeof(*id), NULL, &existVgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), id, sizeof(*id), NULL, &existVgroupInfo);
assert(existVgroupInfo.inUse >= 0);
SVgroupMsg *pVgroup = &pTableMetaInfo->vgroupList->vgroups[j];
......
......@@ -158,7 +158,7 @@ static void tscUpdateVgroupInfo(SSqlObj *pSql, SRpcEpSet *pEpSet) {
assert(vgId > 0);
SNewVgroupInfo vgroupInfo = {.vgId = -1};
taosHashGetClone(tscVgroupMap, &vgId, sizeof(vgId), NULL, &vgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), &vgId, sizeof(vgId), NULL, &vgroupInfo);
assert(vgroupInfo.numOfEps > 0 && vgroupInfo.vgId > 0);
tscDebug("before: Endpoint in use:%d, numOfEps:%d", vgroupInfo.inUse, vgroupInfo.numOfEps);
......@@ -170,7 +170,7 @@ static void tscUpdateVgroupInfo(SSqlObj *pSql, SRpcEpSet *pEpSet) {
}
tscDebug("after: EndPoint in use:%d, numOfEps:%d", vgroupInfo.inUse, vgroupInfo.numOfEps);
taosHashPut(tscVgroupMap, &vgId, sizeof(vgId), &vgroupInfo, sizeof(SNewVgroupInfo));
taosHashPut(UTIL_GET_VGROUPMAP(pSql), &vgId, sizeof(vgId), &vgroupInfo, sizeof(SNewVgroupInfo));
// Update the local cached epSet info cached by SqlObj
int32_t inUse = pSql->epSet.inUse;
......@@ -654,7 +654,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT;
SNewVgroupInfo vgroupInfo = {0};
taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo);
tscDebug("0x%"PRIx64" submit msg built, numberOfEP:%d", pSql->self, pSql->epSet.numOfEps);
......@@ -737,7 +737,7 @@ static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STab
vgId = pTableMeta->vgId;
SNewVgroupInfo vgroupInfo = {0};
taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo);
}
......@@ -1650,7 +1650,7 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
STableMeta *pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
SNewVgroupInfo vgroupInfo = {.vgId = -1};
taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo);
assert(vgroupInfo.vgId > 0);
tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo);
......@@ -2036,21 +2036,21 @@ static int32_t tableMetaMsgConvert(STableMetaMsg* pMetaMsg) {
}
// update the vgroupInfo if needed
static void doUpdateVgroupInfo(int32_t vgId, SVgroupMsg *pVgroupMsg) {
static void doUpdateVgroupInfo(SSqlObj *pSql, int32_t vgId, SVgroupMsg *pVgroupMsg) {
assert(vgId > 0);
SNewVgroupInfo vgroupInfo = {.inUse = -1};
taosHashGetClone(tscVgroupMap, &vgId, sizeof(vgId), NULL, &vgroupInfo);
taosHashGetClone(UTIL_GET_VGROUPMAP(pSql), &vgId, sizeof(vgId), NULL, &vgroupInfo);
// vgroup info exists, compare with it
if (((vgroupInfo.inUse >= 0) && !vgroupInfoIdentical(&vgroupInfo, pVgroupMsg)) || (vgroupInfo.inUse < 0)) {
vgroupInfo = createNewVgroupInfo(pVgroupMsg);
taosHashPut(tscVgroupMap, &vgId, sizeof(vgId), &vgroupInfo, sizeof(vgroupInfo));
tscDebug("add/update new VgroupInfo, vgId:%d, total cached:%d", vgId, (int32_t) taosHashGetSize(tscVgroupMap));
taosHashPut(UTIL_GET_VGROUPMAP(pSql), &vgId, sizeof(vgId), &vgroupInfo, sizeof(vgroupInfo));
tscDebug("add/update new VgroupInfo, vgId:%d, total cached:%d", vgId, (int32_t) taosHashGetSize(UTIL_GET_VGROUPMAP(pSql)));
}
}
static void doAddTableMetaToLocalBuf(STableMeta* pTableMeta, STableMetaMsg* pMetaMsg, bool updateSTable) {
static void doAddTableMetaToLocalBuf(SSqlObj *pSql, STableMeta* pTableMeta, STableMetaMsg* pMetaMsg, bool updateSTable) {
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
// add or update the corresponding super table meta data info
int32_t len = (int32_t) strnlen(pTableMeta->sTableName, TSDB_TABLE_FNAME_LEN);
......@@ -2059,18 +2059,18 @@ static void doAddTableMetaToLocalBuf(STableMeta* pTableMeta, STableMetaMsg* pMet
if (updateSTable) {
STableMeta* pSupTableMeta = createSuperTableMeta(pMetaMsg);
uint32_t size = tscGetTableMetaSize(pSupTableMeta);
int32_t code = taosHashPut(tscTableMetaMap, pTableMeta->sTableName, len, pSupTableMeta, size);
int32_t code = taosHashPut(UTIL_GET_TABLEMETA(pSql), pTableMeta->sTableName, len, pSupTableMeta, size);
assert(code == TSDB_CODE_SUCCESS);
tfree(pSupTableMeta);
}
CChildTableMeta* cMeta = tscCreateChildMeta(pTableMeta);
taosHashPut(tscTableMetaMap, pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), cMeta, sizeof(CChildTableMeta));
taosHashPut(UTIL_GET_TABLEMETA(pSql), pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), cMeta, sizeof(CChildTableMeta));
tfree(cMeta);
} else {
uint32_t s = tscGetTableMetaSize(pTableMeta);
taosHashPut(tscTableMetaMap, pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), pTableMeta, s);
taosHashPut(UTIL_GET_TABLEMETA(pSql), pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), pTableMeta, s);
}
}
......@@ -2098,9 +2098,9 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
tNameExtractFullName(&pTableMetaInfo->name, name);
assert(strncmp(pMetaMsg->tableFname, name, tListLen(pMetaMsg->tableFname)) == 0);
doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, true);
doAddTableMetaToLocalBuf(pSql, pTableMeta, pMetaMsg, true);
if (pTableMeta->tableType != TSDB_SUPER_TABLE) {
doUpdateVgroupInfo(pTableMeta->vgId, &pMetaMsg->vgroup);
doUpdateVgroupInfo(pSql, pTableMeta->vgId, &pMetaMsg->vgroup);
}
tscDebug("0x%"PRIx64" recv table meta, uid:%" PRIu64 ", tid:%d, name:%s, numOfCols:%d, numOfTags:%d", pSql->self,
......@@ -2111,7 +2111,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
return TSDB_CODE_SUCCESS;
}
static SArray* createVgroupIdListFromMsg(char* pMsg, SHashObj* pSet, char* name, int32_t* size, uint64_t id) {
static SArray* createVgroupIdListFromMsg(SSqlObj *pSql, char* pMsg, SHashObj* pSet, char* name, int32_t* size, uint64_t id) {
SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)pMsg;
pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups);
......@@ -2134,7 +2134,7 @@ static SArray* createVgroupIdListFromMsg(char* pMsg, SHashObj* pSet, char* name,
if (taosHashGet(pSet, &vmsg->vgId, sizeof(vmsg->vgId)) == NULL) {
taosHashPut(pSet, &vmsg->vgId, sizeof(vmsg->vgId), "", 0);
doUpdateVgroupInfo(vmsg->vgId, vmsg);
doUpdateVgroupInfo(pSql, vmsg->vgId, vmsg);
}
}
}
......@@ -2142,7 +2142,7 @@ static SArray* createVgroupIdListFromMsg(char* pMsg, SHashObj* pSet, char* name,
return vgroupIdList;
}
static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t id) {
static SVgroupsInfo* createVgroupInfoFromMsg(SSqlObj *pSql, char* pMsg, int32_t* size, uint64_t id) {
SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)pMsg;
pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups);
......@@ -2174,7 +2174,7 @@ static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t
// pVgroup->epAddr[k].fqdn = strndup(vmsg->epAddr[k].fqdn, TSDB_FQDN_LEN);
}
doUpdateVgroupInfo(pVgroup->vgId, vmsg);
doUpdateVgroupInfo(pSql, pVgroup->vgId, vmsg);
}
}
......@@ -2309,12 +2309,12 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) {
}
// create the tableMeta and add it into the TableMeta map
doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, updateStableMeta);
doAddTableMetaToLocalBuf(pParentSql, pTableMeta, pMetaMsg, updateStableMeta);
// for each vgroup, only update the information once.
int64_t vgId = pMetaMsg->vgroup.vgId;
if (pTableMeta->tableType != TSDB_SUPER_TABLE && taosHashGet(pSet, &vgId, sizeof(vgId)) == NULL) {
doUpdateVgroupInfo((int32_t) vgId, &pMetaMsg->vgroup);
doUpdateVgroupInfo(pParentSql, (int32_t) vgId, &pMetaMsg->vgroup);
taosHashPut(pSet, &vgId, sizeof(vgId), "", 0);
}
......@@ -2339,7 +2339,7 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) {
taosArrayDestroy(p->vgroupIdList);
}
p->vgroupIdList = createVgroupIdListFromMsg(pMsg, pSet, fname, &size, pSql->self);
p->vgroupIdList = createVgroupIdListFromMsg(pParentSql, pMsg, pSet, fname, &size, pSql->self);
int32_t numOfVgId = (int32_t) taosArrayGetSize(p->vgroupIdList);
int32_t s = sizeof(tFilePage) + numOfVgId * sizeof(int32_t);
......@@ -2348,8 +2348,8 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) {
idList->num = numOfVgId;
memcpy(idList->data, TARRAY_GET_START(p->vgroupIdList), numOfVgId * sizeof(int32_t));
void* idListInst = taosCachePut(tscVgroupListBuf, fname, len, idList, s, 5000);
taosCacheRelease(tscVgroupListBuf, (void*) &idListInst, false);
void* idListInst = taosCachePut(UTIL_GET_VGROUPLIST(pParentSql), fname, len, idList, s, 5000);
taosCacheRelease(UTIL_GET_VGROUPLIST(pParentSql), (void*) &idListInst, false);
tfree(idList);
pMsg += size;
......@@ -2439,7 +2439,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
continue;
}
int32_t size = 0;
pInfo->vgroupList = createVgroupInfoFromMsg(pMsg, &size, pSql->self);
pInfo->vgroupList = createVgroupInfoFromMsg(parent, pMsg, &size, pSql->self);
pMsg += size;
}
......@@ -2570,7 +2570,8 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
pObj->writeAuth = pConnect->writeAuth;
pObj->superAuth = pConnect->superAuth;
pObj->connId = htonl(pConnect->connId);
tstrncpy(pObj->clusterId, pConnect->clusterId, sizeof(pObj->clusterId));
createHbObj(pObj);
//launch a timer to send heartbeat to maintain the connection and send status to mnode
......@@ -2595,9 +2596,9 @@ int tscProcessDropDbRsp(SSqlObj *pSql) {
//TODO LOCK DB WHEN MODIFY IT
//pSql->pTscObj->db[0] = 0;
taosHashClear(tscTableMetaMap);
taosHashClear(tscVgroupMap);
taosCacheEmpty(tscVgroupListBuf);
taosHashClear(UTIL_GET_TABLEMETA(pSql));
taosHashClear(UTIL_GET_VGROUPMAP(pSql));
taosCacheEmpty(UTIL_GET_VGROUPLIST(pSql));
return 0;
}
......@@ -2617,7 +2618,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
tscDebug("0x%"PRIx64" remove tableMeta in hashMap after alter-table: %s", pSql->self, name);
bool isSuperTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo);
taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
taosHashRemove(UTIL_GET_TABLEMETA(pSql), name, strnlen(name, TSDB_TABLE_FNAME_LEN));
tfree(pTableMetaInfo->pTableMeta);
if (isSuperTable) { // if it is a super table, iterate the hashTable and remove all the childTableMeta
......@@ -2932,7 +2933,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity);
}
if (NULL == taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity)) {
if (NULL == taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity)) {
tfree(pTableMetaInfo->pTableMeta);
}
......@@ -2942,7 +2943,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
if (pMeta && pMeta->id.uid > 0) {
// in case of child table, here only get the
if (pMeta->tableType == TSDB_CHILD_TABLE) {
int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta));
int32_t code = tscCreateTableMetaFromSTableMeta(pSql, &pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta));
pSql->pBuf = (void *)(pSTMeta);
if (code != TSDB_CODE_SUCCESS) {
return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate);
......
......@@ -194,6 +194,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
tscBuildAndSendRequest(pSql, NULL);
tsem_wait(&pSql->rspSem);
pSql->pTscObj->pClusterInfo = (SClusterInfo *)tscAcquireClusterInfo(pSql->pTscObj->clusterId);
if (pSql->res.code != TSDB_CODE_SUCCESS) {
terrno = pSql->res.code;
if (terrno ==TSDB_CODE_RPC_FQDN_ERROR) {
......@@ -256,6 +257,7 @@ static void asyncConnCallback(void *param, TAOS_RES *tres, int code) {
SSqlObj *pSql = (SSqlObj *) tres;
assert(pSql != NULL);
pSql->pTscObj->pClusterInfo = (SClusterInfo *)tscAcquireClusterInfo(pSql->pTscObj->clusterId);
pSql->fetchFp(pSql->param, tres, code);
}
......@@ -268,7 +270,6 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port,
}
if (taos) *taos = pObj;
pSql->fetchFp = fp;
pSql->res.code = tscBuildAndSendRequest(pSql, NULL);
tscDebug("%p DB async connection is opening", taos);
......
......@@ -3213,7 +3213,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
for(int32_t i = 0; i < pParentObj->cmd.insertParam.numOfTables; ++i) {
char name[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(pParentObj->cmd.insertParam.pTableNameList[i], name);
taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
taosHashRemove(UTIL_GET_TABLEMETA(pParentObj), name, strnlen(name, TSDB_TABLE_FNAME_LEN));
}
pParentObj->res.code = TSDB_CODE_SUCCESS;
......@@ -3358,7 +3358,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
goto _error;
}
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pCmd->insertParam.pDataBlocks);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pSql, pCmd->insertParam.pDataBlocks);
// use the local variable
for (int32_t j = 0; j < numOfSub; ++j) {
......
......@@ -33,9 +33,11 @@
int32_t sentinel = TSC_VAR_NOT_RELEASE;
SHashObj *tscVgroupMap; // hash map to keep the vgroup info from mnode
SHashObj *tscTableMetaMap; // table meta info buffer
SCacheObj *tscVgroupListBuf; // super table vgroup list information, only survives 5 seconds for each super table vgroup list
//SHashObj *tscVgroupMap; // hash map to keep the vgroup info from mnode
//SHashObj *tscTableMetaMap; // table meta info buffer
//SCacheObj *tscVgroupListBuf; // super table vgroup list information, only survives 5 seconds for each super table vgroup list
SHashObj *tscClusterMap = NULL; // cluster obj
static pthread_mutex_t clusterMutex; // mutex to protect open the cluster obj
int32_t tscObjRef = -1;
void *tscTmr;
......@@ -121,6 +123,57 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry
return 0;
}
void tscClusterInfoDestroy(SClusterInfo *pObj) {
if (pObj == NULL) { return; }
taosHashCleanup(pObj->vgroupMap);
taosHashCleanup(pObj->tableMetaMap);
taosCacheCleanup(pObj->vgroupListBuf);
tfree(pObj);
}
void *tscAcquireClusterInfo(const char *clusterId) {
pthread_mutex_lock(&clusterMutex);
size_t len = strlen(clusterId);
SClusterInfo *pObj = NULL;
SClusterInfo **ppObj = taosHashGet(tscClusterMap, clusterId, len);
if (ppObj == NULL || *ppObj == NULL) {
pObj = calloc(1, sizeof(SClusterInfo));
if (pObj) {
pObj->vgroupMap = taosHashInit(256, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
pObj->tableMetaMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); //
pObj->vgroupListBuf = taosCacheInit(TSDB_DATA_TYPE_BINARY, 5, false, NULL, "stable-vgroup-list");
if (pObj->vgroupMap == NULL || pObj->tableMetaMap == NULL || pObj->vgroupListBuf == NULL) {
tscClusterInfoDestroy(pObj);
pObj = NULL;
} else {
taosHashPut(tscClusterMap, clusterId, len, &pObj, POINTER_BYTES);
}
}
} else {
pObj = *ppObj;
}
if (pObj) { pObj->ref += 1; }
pthread_mutex_unlock(&clusterMutex);
return pObj;
}
void tscReleaseClusterInfo(const char *clusterId) {
pthread_mutex_lock(&clusterMutex);
size_t len = strlen(clusterId);
SClusterInfo *pObj = NULL;
SClusterInfo **ppObj = taosHashGet(tscClusterMap, clusterId, len);
if (ppObj != NULL && *ppObj != NULL) {
pObj = *ppObj;
}
if (pObj && --pObj->ref == 0) {
taosHashRemove(tscClusterMap, clusterId, len);
tscClusterInfoDestroy(pObj);
}
pthread_mutex_unlock(&clusterMutex);
}
void taos_init_imp(void) {
char temp[128] = {0};
......@@ -188,12 +241,16 @@ void taos_init_imp(void) {
taosTmrReset(tscCheckDiskUsage, 20 * 1000, NULL, tscTmr, &tscCheckDiskUsageTmr);
}
if (tscTableMetaMap == NULL) {
if (tscClusterMap == NULL) {
tscObjRef = taosOpenRef(40960, tscFreeRegisteredSqlObj);
tscVgroupMap = taosHashInit(256, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
tscTableMetaMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
tscVgroupListBuf = taosCacheInit(TSDB_DATA_TYPE_BINARY, 5, false, NULL, "stable-vgroup-list");
tscDebug("TableMeta:%p, vgroup:%p is initialized", tscTableMetaMap, tscVgroupMap);
tscClusterMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
pthread_mutex_init(&clusterMutex, NULL);
//tscVgroupMap = taosHashInit(256, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
//tscTableMetaMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
//tscVgroupListBuf = taosCacheInit(TSDB_DATA_TYPE_BINARY, 5, false, NULL, "stable-vgroup-list");
//tscDebug("TableMeta:%p, vgroup:%p is initialized", tscTableMetaMap, tscVgroupMap);
}
int refreshTime = 5;
......@@ -222,12 +279,6 @@ void taos_cleanup(void) {
scriptEnvPoolCleanup();
}
taosHashCleanup(tscTableMetaMap);
tscTableMetaMap = NULL;
taosHashCleanup(tscVgroupMap);
tscVgroupMap = NULL;
int32_t id = tscObjRef;
tscObjRef = -1;
taosCloseRef(id);
......@@ -251,14 +302,16 @@ void taos_cleanup(void) {
}
pthread_mutex_destroy(&setConfMutex);
taosCacheCleanup(tscVgroupListBuf);
tscVgroupListBuf = NULL;
if (tscEmbedded == 0) {
rpcCleanup();
taosCloseLog();
};
taosHashCleanup(tscClusterMap);
tscClusterMap = NULL;
pthread_mutex_destroy(&clusterMutex);
p = tscTmr;
tscTmr = NULL;
taosTmrCleanUp(p);
......
......@@ -271,6 +271,8 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId != TSDB_FUNC_TS_COMP &&
functionId != TSDB_FUNC_DIFF &&
functionId != TSDB_FUNC_DERIVATIVE &&
functionId != TSDB_FUNC_MAVG &&
functionId != TSDB_FUNC_CSUM &&
functionId != TSDB_FUNC_TS_DUMMY &&
functionId != TSDB_FUNC_TID_TAG &&
functionId != TSDB_FUNC_CEIL &&
......@@ -321,7 +323,9 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
return true;
}
bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo) {
// these functions diff/derivative/csum/mavg will return the result computed on current row and history row/rows
// as the result for current row
bool tscIsDiffDerivLikeQuery(SQueryInfo* pQueryInfo) {
size_t size = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < size; ++i) {
......@@ -330,7 +334,8 @@ bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo) {
continue;
}
if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE) {
if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE ||
f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG) {
return true;
}
}
......@@ -551,6 +556,22 @@ bool tscIsIrateQuery(SQueryInfo* pQueryInfo) {
return false;
}
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId) {
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < numOfExprs; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr == NULL) {
continue;
}
if (pExpr->base.functionId == functionId) {
return true;
}
}
return false;
}
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) {
return pQueryInfo->sessionWindow.gap > 0;
}
......@@ -589,7 +610,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
return false;
}
if (tscIsDiffDerivQuery(pQueryInfo)) {
if (tscIsDiffDerivLikeQuery(pQueryInfo)) {
return false;
}
......@@ -615,7 +636,9 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
}
if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) ||
(functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_TS_COMP)) {
(functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_TS_COMP ||
functionId == TSDB_FUNC_SAMPLE)) {
return true;
}
}
......@@ -1421,6 +1444,7 @@ void destroyTableNameList(SInsertStatementParam* pInsertParam) {
}
void tscResetSqlCmd(SSqlCmd* pCmd, bool clearCachedMeta, uint64_t id) {
SSqlObj *pSql = (SSqlObj*)taosAcquireRef(tscObjRef, id);
pCmd->command = 0;
pCmd->numOfCols = 0;
pCmd->count = 0;
......@@ -1429,13 +1453,14 @@ void tscResetSqlCmd(SSqlCmd* pCmd, bool clearCachedMeta, uint64_t id) {
pCmd->insertParam.sql = NULL;
destroyTableNameList(&pCmd->insertParam);
pCmd->insertParam.pTableBlockHashList = tscDestroyBlockHashTable(pCmd->insertParam.pTableBlockHashList, clearCachedMeta);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pCmd->insertParam.pDataBlocks);
pCmd->insertParam.pTableBlockHashList = tscDestroyBlockHashTable(pSql, pCmd->insertParam.pTableBlockHashList, clearCachedMeta);
pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pSql, pCmd->insertParam.pDataBlocks);
tfree(pCmd->insertParam.tagData.data);
pCmd->insertParam.tagData.dataLen = 0;
tscFreeQueryInfo(pCmd, clearCachedMeta, id);
pCmd->pTableMetaMap = tscCleanupTableMetaMap(pCmd->pTableMetaMap);
taosReleaseRef(tscObjRef, id);
}
void* tscCleanupTableMetaMap(SHashObj* pTableMetaMap) {
......@@ -1571,7 +1596,7 @@ void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo) {
tfree(pColInfo->colIdxInfo);
}
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
void tscDestroyDataBlock(SSqlObj *pSql, STableDataBlocks* pDataBlock, bool removeMeta) {
if (pDataBlock == NULL) {
return;
}
......@@ -1582,7 +1607,7 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
char name[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(&pDataBlock->tableName, name);
taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
taosHashRemove(UTIL_GET_TABLEMETA(pSql), name, strnlen(name, TSDB_TABLE_FNAME_LEN));
}
if (!pDataBlock->cloned) {
......@@ -1623,7 +1648,7 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint
return param;
}
void* tscDestroyBlockArrayList(SArray* pDataBlockList) {
void* tscDestroyBlockArrayList(SSqlObj *pSql, SArray* pDataBlockList) {
if (pDataBlockList == NULL) {
return NULL;
}
......@@ -1631,7 +1656,7 @@ void* tscDestroyBlockArrayList(SArray* pDataBlockList) {
size_t size = taosArrayGetSize(pDataBlockList);
for (int32_t i = 0; i < size; i++) {
void* d = taosArrayGetP(pDataBlockList, i);
tscDestroyDataBlock(d, false);
tscDestroyDataBlock(pSql, d, false);
}
taosArrayDestroy(pDataBlockList);
......@@ -1679,14 +1704,14 @@ void* tscDestroyUdfArrayList(SArray* pUdfList) {
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta) {
void* tscDestroyBlockHashTable(SSqlObj *pSql, SHashObj* pBlockHashTable, bool removeMeta) {
if (pBlockHashTable == NULL) {
return NULL;
}
STableDataBlocks** p = taosHashIterate(pBlockHashTable, NULL);
while(p) {
tscDestroyDataBlock(*p, removeMeta);
tscDestroyDataBlock(pSql, *p, removeMeta);
p = taosHashIterate(pBlockHashTable, p);
}
......@@ -1927,7 +1952,7 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
return result;
}
static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeBlockMap) {
static void extractTableNameList(SSqlObj *pSql, SInsertStatementParam *pInsertParam, bool freeBlockMap) {
pInsertParam->numOfTables = (int32_t) taosHashGetSize(pInsertParam->pTableBlockHashList);
if (pInsertParam->pTableNameList == NULL) {
pInsertParam->pTableNameList = malloc(pInsertParam->numOfTables * POINTER_BYTES);
......@@ -1944,11 +1969,11 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB
}
if (freeBlockMap) {
pInsertParam->pTableBlockHashList = tscDestroyBlockHashTable(pInsertParam->pTableBlockHashList, false);
pInsertParam->pTableBlockHashList = tscDestroyBlockHashTable(pSql, pInsertParam->pTableBlockHashList, false);
}
}
int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBlockMap) {
int32_t tscMergeTableDataBlocks(SSqlObj *pSql, SInsertStatementParam *pInsertParam, bool freeBlockMap) {
const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg);
int code = 0;
bool isRawPayload = IS_RAW_PAYLOAD(pInsertParam->payloadType);
......@@ -1973,7 +1998,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
if (ret != TSDB_CODE_SUCCESS) {
tscError("0x%"PRIx64" failed to prepare the data block buffer for merging table data, code:%d", pInsertParam->objectId, ret);
taosHashCleanup(pVnodeDataBlockHashList);
tscDestroyBlockArrayList(pVnodeDataBlockList);
tscDestroyBlockArrayList(pSql, pVnodeDataBlockList);
tfree(blkKeyInfo.pKeyTuple);
return ret;
}
......@@ -1992,7 +2017,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
tscError("0x%"PRIx64" failed to allocate memory for merging submit block, size:%d", pInsertParam->objectId, dataBuf->nAllocSize);
taosHashCleanup(pVnodeDataBlockHashList);
tscDestroyBlockArrayList(pVnodeDataBlockList);
tscDestroyBlockArrayList(pSql, pVnodeDataBlockList);
tfree(dataBuf->pData);
tfree(blkKeyInfo.pKeyTuple);
......@@ -2010,7 +2035,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
} else {
if ((code = tscSortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) {
taosHashCleanup(pVnodeDataBlockHashList);
tscDestroyBlockArrayList(pVnodeDataBlockList);
tscDestroyBlockArrayList(pSql, pVnodeDataBlockList);
tfree(dataBuf->pData);
tfree(blkKeyInfo.pKeyTuple);
return code;
......@@ -2057,7 +2082,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
pOneTableBlock = *p;
}
extractTableNameList(pInsertParam, freeBlockMap);
extractTableNameList(pSql, pInsertParam, freeBlockMap);
// free the table data blocks;
pInsertParam->pDataBlocks = pVnodeDataBlockList;
......@@ -2077,6 +2102,7 @@ void tscCloseTscObj(void *param) {
tfree(pObj->tscCorMgmtEpSet);
tscReleaseRpc(pObj->pRpcObj);
pthread_mutex_destroy(&pObj->mutex);
tscReleaseClusterInfo(pObj->clusterId);
tfree(pObj);
}
......@@ -4509,6 +4535,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild) {
pTableMeta->tableInfo.numOfTags = pChild->numOfTags;
pTableMeta->tableInfo.numOfColumns = pChild->numOfColumns;
pTableMeta->tableInfo.precision = pChild->precision;
pTableMeta->tableInfo.update = pChild->update;
pTableMeta->id.tid = 0;
pTableMeta->id.uid = pChild->suid;
......@@ -4550,7 +4577,7 @@ CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta) {
return cMeta;
}
int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta**ppSTable) {
int32_t tscCreateTableMetaFromSTableMeta(SSqlObj *pSql, STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta**ppSTable) {
assert(*ppChild != NULL);
STableMeta* p = *ppSTable;
STableMeta* pChild = *ppChild;
......@@ -4560,11 +4587,10 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name,
memset((char *)p, 0, sz);
}
if (NULL == taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz)) {
if (NULL == taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz)) {
tfree(p);
} else {
*ppSTable = p;
}
}
*ppSTable = p;
// tableMeta exists, build child table meta according to the super table meta
// the uid need to be checked in addition to the general name of the super table.
......@@ -4586,7 +4612,7 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name,
*ppChild = pChild;
return TSDB_CODE_SUCCESS;
} else { // super table has been removed, current tableMeta is also expired. remove it here
taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
taosHashRemove(UTIL_GET_TABLEMETA(pSql), name, strnlen(name, TSDB_TABLE_FNAME_LEN));
return -1;
}
}
......@@ -4834,7 +4860,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo);
pQueryAttr->stabledev = isStabledev(pQueryInfo);
pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo);
pQueryAttr->diffQuery = tscIsDiffDerivQuery(pQueryInfo);
pQueryAttr->diffQuery = tscIsDiffDerivLikeQuery(pQueryInfo);
pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo);
pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo);
pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type);
......@@ -5105,18 +5131,20 @@ SNewVgroupInfo createNewVgroupInfo(SVgroupMsg *pVgroupMsg) {
void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id) {
char fname[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(&pTableMetaInfo->name, fname);
SSqlObj *p = (SSqlObj *)taosAcquireRef(tscObjRef, id);
tNameExtractFullName(&pTableMetaInfo->name, fname);
int32_t len = (int32_t) strnlen(fname, TSDB_TABLE_FNAME_LEN);
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
void* pv = taosCacheAcquireByKey(tscVgroupListBuf, fname, len);
void* pv = taosCacheAcquireByKey(UTIL_GET_VGROUPLIST(p), fname, len);
if (pv != NULL) {
taosCacheRelease(tscVgroupListBuf, &pv, true);
taosCacheRelease(UTIL_GET_VGROUPLIST(p), &pv, true);
}
}
taosHashRemove(tscTableMetaMap, fname, len);
tscDebug("0x%"PRIx64" remove table meta %s, numOfRemain:%d", id, fname, (int32_t) taosHashGetSize(tscTableMetaMap));
taosHashRemove(UTIL_GET_TABLEMETA(p), fname, len);
tscDebug("0x%"PRIx64" remove table meta %s, numOfRemain:%d", id, fname, (int32_t) taosHashGetSize(UTIL_GET_TABLEMETA(p)));
taosReleaseRef(tscObjRef, id);
}
char* cloneCurrentDBName(SSqlObj* pSql) {
......
......@@ -780,6 +780,7 @@ typedef struct STableMetaMsg {
char tableFname[TSDB_TABLE_FNAME_LEN]; // table id
uint8_t numOfTags;
uint8_t precision;
uint8_t update;
uint8_t tableType;
int16_t numOfColumns;
int16_t sversion;
......
......@@ -1792,6 +1792,7 @@ static int32_t mnodeDoGetSuperTableMeta(SMnodeMsg *pMsg, STableMetaMsg* pMeta) {
pMeta->sversion = htons(pTable->sversion);
pMeta->tversion = htons(pTable->tversion);
pMeta->precision = pMsg->pDb->cfg.precision;
pMeta->update = pMsg->pDb->cfg.update;
pMeta->numOfTags = (uint8_t)pTable->numOfTags;
pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns);
pMeta->tableType = pTable->info.type;
......@@ -2509,6 +2510,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta->uid = htobe64(pTable->uid);
pMeta->tid = htonl(pTable->tid);
pMeta->precision = pDb->cfg.precision;
pMeta->update = pDb->cfg.update;
pMeta->tableType = pTable->info.type;
tstrncpy(pMeta->tableFname, pTable->info.tableId, TSDB_TABLE_FNAME_LEN);
......
......@@ -380,10 +380,40 @@ int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrec
assert(toPrecision == TSDB_TIME_PRECISION_MILLI ||
toPrecision == TSDB_TIME_PRECISION_MICRO ||
toPrecision == TSDB_TIME_PRECISION_NANO);
static double factors[3][3] = { {1., 1000., 1000000.},
{1.0 / 1000, 1., 1000.},
{1.0 / 1000000, 1.0 / 1000, 1.} };
return (int64_t)((double)time * factors[fromPrecision][toPrecision]);
switch(fromPrecision) {
case TSDB_TIME_PRECISION_MILLI: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time;
case TSDB_TIME_PRECISION_MICRO:
return time * 1000;
case TSDB_TIME_PRECISION_NANO:
return time * 1000000;
}
} // end from milli
case TSDB_TIME_PRECISION_MICRO: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time / 1000;
case TSDB_TIME_PRECISION_MICRO:
return time;
case TSDB_TIME_PRECISION_NANO:
return time * 1000;
}
} //end from micro
case TSDB_TIME_PRECISION_NANO: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time / 1000000;
case TSDB_TIME_PRECISION_MICRO:
return time / 1000;
case TSDB_TIME_PRECISION_NANO:
return time;
}
} //end from nano
default:
assert(0);
} //end switch fromPrecision
}
static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) {
......
......@@ -68,18 +68,23 @@ extern "C" {
#define TSDB_FUNC_IRATE 30
#define TSDB_FUNC_TID_TAG 31
#define TSDB_FUNC_DERIVATIVE 32
#define TSDB_FUNC_BLKINFO 33
#define TSDB_FUNC_CEIL 34
#define TSDB_FUNC_FLOOR 35
#define TSDB_FUNC_ROUND 36
#define TSDB_FUNC_HISTOGRAM 37
#define TSDB_FUNC_HLL 38
#define TSDB_FUNC_MODE 39
#define TSDB_FUNC_SAMPLE 40
#define TSDB_FUNC_MAVG 41
#define TSDB_FUNC_CSUM 42
#define TSDB_FUNC_CEIL 33
#define TSDB_FUNC_FLOOR 34
#define TSDB_FUNC_ROUND 35
#define TSDB_FUNC_CSUM 36
#define TSDB_FUNC_MAVG 37
#define TSDB_FUNC_SAMPLE 38
#define TSDB_FUNC_BLKINFO 39
///////////////////////////////////////////
// the following functions is not implemented.
// after implementation, move them before TSDB_FUNC_BLKINFO. also make TSDB_FUNC_BLKINFO the maxium function index
// #define TSDB_FUNC_HISTOGRAM 40
// #define TSDB_FUNC_HLL 41
// #define TSDB_FUNC_MODE 42
#define TSDB_FUNCSTATE_SO 0x1u // single output
#define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
......
......@@ -56,6 +56,7 @@ typedef struct SGroupbyExpr {
typedef struct STableComInfo {
uint8_t numOfTags;
uint8_t precision;
uint8_t update;
int16_t numOfColumns;
int32_t rowSize;
} STableComInfo;
......
此差异已折叠。
......@@ -2060,7 +2060,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
int32_t functionId = pCtx->functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) {
int32_t f = pExpr[0].base.functionId;
int32_t f = pExpr[i-1].base.functionId;
assert(f == TSDB_FUNC_TS || f == TSDB_FUNC_TS_DUMMY);
pCtx->param[2].i64 = pQueryAttr->order.order;
......@@ -3653,7 +3653,8 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i
// set the timestamp output buffer for top/bottom/diff query
int32_t fid = pCtx[i].functionId;
if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE) {
if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE ||
fid == TSDB_FUNC_SAMPLE || fid == TSDB_FUNC_MAVG || fid == TSDB_FUNC_CSUM) {
if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
}
......@@ -3690,7 +3691,10 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
// set the correct pointer after the memory buffer reallocated.
int32_t functionId = pBInfo->pCtx[i].functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG ||
functionId == TSDB_FUNC_SAMPLE ) {
if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput;
}
}
......@@ -3702,7 +3706,9 @@ void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput)
char *src = NULL;
for (int32_t i = 0; i < numOfOutput; i++) {
int32_t functionId = pCtx[i].functionId;
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_CSUM ||
functionId == TSDB_FUNC_SAMPLE) {
needCopyTs = true;
if (i > 0 && pCtx[i-1].functionId == TSDB_FUNC_TS_DUMMY){
SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data
......@@ -3918,7 +3924,8 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
continue;
}
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF ||
functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE) {
if(i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
......@@ -3979,7 +3986,9 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
offset += pCtx[i].outputBytes;
int32_t functionId = pCtx[i].functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_SAMPLE || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_CSUM) {
if(i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
......@@ -7922,7 +7931,7 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol
for (int32_t i = 0; i < numOfOutput; ++i) {
int16_t functId = pExprs[i].base.functionId;
if (functId == TSDB_FUNC_TOP || functId == TSDB_FUNC_BOTTOM) {
if (functId == TSDB_FUNC_TOP || functId == TSDB_FUNC_BOTTOM || functId == TSDB_FUNC_SAMPLE) {
int32_t j = getColumnIndexInSource(pTableInfo, &pExprs[i].base, pTagCols);
if (j < 0 || j >= pTableInfo->numOfCols) {
return TSDB_CODE_QRY_INVALID_MSG;
......@@ -8914,6 +8923,7 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type
if (IS_VAR_DATA_TYPE(type)) {
// Binary data overflows for sort of unknown reasons. Let trim the overflow data
// overflow one reason is client tag length is less than server tag length
if (varDataTLen(val) > bytes) {
int32_t maxLen = bytes - VARSTR_HEADER_SIZE;
int32_t len = (varDataLen(val) > maxLen)? maxLen:varDataLen(val);
......
......@@ -84,6 +84,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) {
pTableMeta->tableInfo = (STableComInfo) {
.numOfTags = pTableMetaMsg->numOfTags,
.precision = pTableMetaMsg->precision,
.update = pTableMetaMsg->update,
.numOfColumns = pTableMetaMsg->numOfColumns,
};
......
......@@ -33,7 +33,9 @@ typedef struct SCompSupporter {
int32_t getRowNumForMultioutput(SQueryAttr* pQueryAttr, bool topBottomQuery, bool stable) {
if (pQueryAttr && (!stable)) {
for (int16_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_TOP || pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_BOTTOM) {
if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_TOP ||
pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_BOTTOM ||
pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_SAMPLE) {
return (int32_t)pQueryAttr->pExpr1[i].base.param[0].i64;
}
}
......
......@@ -210,7 +210,7 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_
}
char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId);
assert(type == pCol->type && bytes >= pCol->bytes);
assert(type == pCol->type);
// if (val != NULL && IS_VAR_DATA_TYPE(type)) {
// assert(varDataLen(val) < pCol->bytes);
......
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "taos.h"
int numOfThreads = 1;
void* connectClusterAndDeal(void *arg) {
int port = *(int *)arg;
const char *host = "127.0.0.1";
const char *user = "root";
const char *passwd = "taosdata";
TAOS* taos1 = taos_connect(host, user, passwd, "", port);
TAOS* taos2 = taos_connect(host, user, passwd, "", port + 1000);
if (NULL == taos1 || NULL == taos2) {
printf("connect to (%d/%d) failed \n", port, port + 1000);
return NULL;
}
TAOS_RES *result = NULL;
result = taos_query(taos1, "drop database if exists db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
taos_query(taos2, "drop database if exists db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
// ========= build database
{
result = taos_query(taos1, "create database db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
{
result = taos_query(taos2, "create database db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
//======== create table
{
result = taos_query(taos1, "create stable db.stest (ts timestamp, port int) tags(tport int)");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
{
result = taos_query(taos2, "create stable db.stest (ts timestamp, port int) tags(tport int)");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
//======== create table
{
result = taos_query(taos1, "use db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
{
result = taos_query(taos2, "use db");
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
}
{
char buf[1024] = {0};
sprintf(buf, "insert into db.t1 using stest tags(%d) values(now, %d)", port, port);
for (int i = 0; i < 100000; i++) {
//printf("error here\t");
result = taos_query(taos1, buf);
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
//sleep(1);
}
}
{
char buf[1024] = {0};
sprintf(buf, "insert into db.t1 using stest tags(%d) values(now, %d)", port + 1000, port + 1000);
for (int i = 0; i < 100000; i++) {
result = taos_query(taos2, buf);
if (0 != taos_errno(result)) {
printf("failed %s\n", taos_errstr(result));
}
taos_free_result(result);
//sleep(1);
}
}
// query result
{
result = taos_query(taos1, "select * from stest");
if (result == NULL || taos_errno(result) != 0) {
printf("query failed %s\n", taos_errstr(result));
taos_free_result(result);
}
TAOS_ROW row;
int rows = 0;
int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result);
while ((row = taos_fetch_row(result))) {
char temp[1024] = {0};
rows++;
taos_print_row(temp, row, fields , num_fields);
printf("%s\n", temp);
}
taos_free_result(result);
}
// query result
{
result = taos_query(taos2, "select * from stest");
if (result == NULL || taos_errno(result) != 0) {
printf("query failed %s\n", taos_errstr(result));
taos_free_result(result);
}
TAOS_ROW row;
int rows = 0;
int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result);
while ((row = taos_fetch_row(result))) {
char temp[1024] = {0};
rows++;
taos_print_row(temp, row, fields , num_fields);
printf("%s\n", temp);
}
taos_free_result(result);
}
taos_close(taos1);
taos_close(taos2);
return NULL;
}
int main(int argc, char* argv[]) {
pthread_t *pthreads = malloc(sizeof(pthread_t) * numOfThreads);
int *port = malloc(sizeof(int) * numOfThreads);
port[0] = 6030;
for (int i = 0; i < numOfThreads; i++) {
pthread_create(&pthreads[i], NULL, connectClusterAndDeal, (void *)&port[i]);
}
for (int i = 0; i < numOfThreads; i++) {
pthread_join(pthreads[i], NULL);
}
free(port);
}
###################################################################
# 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 json
import taos
import time
import random
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
'''
Before test start,Two TDengine services have been set up on different servers
'''
host1 = '192.168.1.101'
host2 = '192.168.1.102'
user = 'root'
password = 'taosdata'
cfgdir = '/home/cp/taos/TDengine/sim/dnode1/cfg'
conn1 = taos.connect(host=host1, user=user, password=password, config=cfgdir)
conn2 = taos.connect(host=host2, user=user, password=password, config=cfgdir)
cursor1 = conn1.cursor()
cursor2 = conn2.cursor()
tdSql1 = TDSql()
tdSql2 = TDSql()
tdSql1.init(cursor1)
tdSql2.init(cursor2)
dbname11 = 'db11'
dbname12 = 'db12'
dbname21 = 'db21'
stbname11 = 'stb11'
stbname12 = 'stb12'
stbname21 = 'stb21'
tbnum = 100
data_row = 100
db1_stb1_column = 'ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool, c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) '
db1_stb1_tag = 'st1 int, st2 float, st3 timestamp, st4 binary(16), st5 double, st6 bool, st7 bigint, st8 smallint, st9 tinyint, st10 nchar(16)'
def dbsql(dbname):
return f"create database {dbname} keep 3650"
def stbsql(stbname, columntype, tagtype):
return f'create stable {stbname} ({columntype}) tags ({tagtype}) '
def tbsql(tbname, stbname, tags):
return f'create table {tbname} using {stbname} tags ({tags})'
def datasql(tbname, data):
return f'insert into {tbname} values ({data})'
def testquery():
ti = random.randint(0,tbnum-1)
tdSql1.query(f"select c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 from tm{ti}")
tdSql1.checkData(0, 0, ti)
tdSql1.checkData(0, 1, ti)
tdSql1.checkData(0, 2, ti)
tdSql1.checkData(0, 3, f'binary_{ti}')
tdSql1.checkData(0, 4, ti)
tdSql1.checkData(0, 5, ti%2)
tdSql1.checkData(0, 6, ti)
tdSql1.checkData(0, 7, ti%32768)
tdSql1.checkData(0, 8, ti%128)
tdSql1.checkData(0, 9, f'nchar_{ti}')
tdSql2.query(f"select c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 from tn{ti}")
tdSql2.checkData(0, 0, ti+10000)
tdSql2.checkData(0, 1, ti+10000)
tdSql2.checkData(0, 2, ti+10000)
tdSql2.checkData(0, 3, f'binary_{ti+10000}')
tdSql2.checkData(0, 4, ti+10000)
tdSql2.checkData(0, 5, (ti+10000)%2)
tdSql2.checkData(0, 6, ti+10000)
tdSql2.checkData(0, 7, (ti+10000)%32768)
tdSql2.checkData(0, 8, (ti+10000)%128)
tdSql2.checkData(0, 9, f'nchar_{ti+10000}')
tdSql1.query(f"select last(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) from {stbname11}")
tdSql1.checkData(0, 0, data_row-1)
tdSql1.checkData(0, 1, data_row-1)
tdSql1.checkData(0, 2, data_row-1)
tdSql1.checkData(0, 3, f'binary_{data_row-1}')
tdSql1.checkData(0, 4, data_row-1)
tdSql1.checkData(0, 5, (data_row-1)%2)
tdSql1.checkData(0, 6, data_row-1)
tdSql1.checkData(0, 7, (data_row-1)%32768)
tdSql1.checkData(0, 8, (data_row-1)%128)
tdSql1.checkData(0, 9, f'nchar_{data_row-1}')
tdSql1.query(f"select first(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) from {stbname11}")
tdSql1.checkData(0, 0, 0)
tdSql1.checkData(0, 1, 0)
tdSql1.checkData(0, 2, 0)
tdSql1.checkData(0, 3, f'binary_0')
tdSql1.checkData(0, 4, 0)
tdSql1.checkData(0, 5, 0)
tdSql1.checkData(0, 6, 0)
tdSql1.checkData(0, 7, 0)
tdSql1.checkData(0, 8, 0)
tdSql1.checkData(0, 9, f'nchar_0')
tdSql1.error("select * from")
tdSql1.query(f"select last(*) from tm1")
tdSql1.checkData(0, 1, 1)
tdSql1.checkData(0, 4, "binary_1")
tdSql1.query(f"select min(c1),max(c2) from {stbname11}")
tdSql1.checkData(0, 0, 0)
tdSql1.checkData(0, 1, data_row-1)
tdSql2.query(f"select count(*), count(c1) from {stbname21}")
tdSql2.checkData(0, 0, data_row)
tdSql2.checkData(0, 1, data_row)
tdSql2.query(f"select first(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) from {stbname21}")
tdSql2.checkData(0, 0, 10000)
tdSql2.checkData(0, 1, 10000)
tdSql2.checkData(0, 2, 10000)
tdSql2.checkData(0, 3, f'binary_10000')
tdSql2.checkData(0, 4, 10000)
tdSql2.checkData(0, 5, 10000%2)
tdSql2.checkData(0, 6, 10000)
tdSql2.checkData(0, 7, 10000%32768)
tdSql2.checkData(0, 8, 10000%128)
tdSql2.checkData(0, 9, f'nchar_10000')
tdSql2.query(f"select last(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) from {stbname21}")
tdSql2.checkData(0, 0, data_row+9999)
tdSql2.checkData(0, 1, data_row+9999)
tdSql2.checkData(0, 2, data_row+9999)
tdSql2.checkData(0, 3, f'binary_{data_row+9999}')
tdSql2.checkData(0, 4, data_row+9999)
tdSql2.checkData(0, 5, (data_row+9999)%2)
tdSql2.checkData(0, 6, data_row+9999)
tdSql2.checkData(0, 7, (data_row+9999)%32768)
tdSql2.checkData(0, 8, (data_row+9999)%128)
tdSql2.checkData(0, 9, f'nchar_{data_row+9999}')
tdSql1.query(f"select max(c1) from (select top(c1,10) c1 from {stbname11})")
tdSql1.checkData(0, 0, data_row-1)
tdSql2.query(f"select max(c1) from (select top(c1,10) c1 from {stbname21})")
tdSql2.checkData(0, 0, data_row+9999)
tdSql1.query(f"select avg(c1) from {stbname11}")
tdSql1.checkData(0, 0, sum(range(data_row))/data_row)
tdSql2.query(f"select avg(c1) from {stbname21}")
tdSql2.checkData(0, 0, sum(range(data_row))/data_row+10000)
tdSql1.query(f"select spread(c1) from {stbname11}")
tdSql1.checkData(0, 0, data_row-1)
tdSql2.query(f"select spread(c1) from {stbname21}")
tdSql2.checkData(0, 0, data_row-1)
tdSql1.query(f"select max(c1)*2 from {stbname11}")
tdSql1.checkData(0, 0, (data_row-1)*2)
tdSql2.query(f"select max(c1)*2 from {stbname21}")
tdSql2.checkData(0, 0, (data_row+9999)*2)
tdSql1.query(f"select avg(c1) from {stbname11} where c1 <= 10")
tdSql1.checkData(0, 0, 5)
tdSql2.query(f"select avg(c1) from {stbname21} where c1 <= 10010")
tdSql2.checkData(0, 0, 10005)
tdSql1.query(f"select * from {stbname11} where tbname like 'tn%'")
tdSql1.checkRows(0)
tdSql2.query(f"select * from {stbname21} where tbname like 'tm%'")
tdSql2.checkRows(0)
tdSql1.query(f"select max(c1) from {stbname11} group by tbname")
tdSql1.checkRows(tbnum)
tdSql2.query(f"select max(c1) from {stbname21} group by tbname")
tdSql2.checkRows(tbnum)
tdSql1.error(f"select * from {stbname11}, {stbname21} where {stbname11}.ts = {stbname21}.ts and {stbname11}.st1 = {stbname21}.st1")
tdSql2.error(f"select * from {stbname11}, {stbname21} where {stbname11}.ts = {stbname21}.ts and {stbname11}.st1 = {stbname21}.st1")
if __name__ == '__main__':
tdSql1.execute('reset query cache')
tdSql2.execute('reset query cache')
tdSql1.execute(f'drop database if exists {dbname11}')
tdSql1.execute(f'drop database if exists {dbname12}')
tdSql1.execute(f'drop database if exists {dbname21}')
tdSql2.execute(f'drop database if exists {dbname21}')
tdSql2.execute(f'drop database if exists {dbname11}')
tdSql2.execute(f'drop database if exists {dbname12}')
tdSql1.execute(dbsql(dbname11))
tdSql1.query('show databases')
tdSql1.checkRows(1)
tdSql2.query('show databases')
tdSql2.checkRows(0)
tdSql2.execute(dbsql(dbname21))
tdSql1.query(f'show databases')
tdSql1.checkData(0, 0, dbname11)
tdSql2.query(f'show databases')
tdSql2.checkData(0, 0, dbname21)
tdSql1.execute(f'use {dbname11}')
tdSql1.query("show stables")
tdSql1.checkRows(0)
tdSql2.error("show stables")
### conn1 create stable
tdSql1.execute(stbsql(stbname11, db1_stb1_column, db1_stb1_tag))
tdSql1.query(f"show stables like '{stbname11}' ")
tdSql1.checkRows(1)
tdSql2.error("show stables")
# 'st1 int, st2 float, st3 timestamp, st4 binary(16), st5 double, st6 bool, st7 bigint, st8 smallint, st9 tinyint, st10 nchar(16)'
for i in range(100):
t1name = f"t{i}"
stname = stbname11
tags = f'{i}, {i}, {i}, "binary_{i}", {i}, {i%2}, {i}, {i%32768}, {i%128}, "nchar_{i}"'
tdSql1.execute(tbsql(t1name, stname, tags))
tdSql2.error(f'select * from t{random.randint(0, 99)}')
tdSql1.query("show tables")
tdSql1.checkRows(100)
tdSql2.error("show tables")
tdSql1.query(f'select * from {stbname11}')
# tdSql1.query(f'select * from t1')
tdSql1.checkRows(0)
tdSql2.error(f'select * from {stname}')
# conn1 insert data
# 'ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool, c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) '
nowtime = int(round(time.time() * 1000))
for i in range(100):
data = f'{nowtime+i*10}, {i}, {i}, {i}, "binary_{i}", {i}, {i%2}, {i}, {i%32768}, {i%128}, "nchar_{i}"'
tdSql1.execute(datasql(f"t{i}", data))
# tdSql2.error(datasql(f't{i}', data))
ti = random.randint(0,99)
tdSql1.query(f"select c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 from t{ti}")
tdSql1.checkData(0, 0, ti)
tdSql1.checkData(0, 1, ti)
tdSql1.checkData(0, 2, ti)
tdSql1.checkData(0, 3, f'binary_{ti}')
tdSql1.checkData(0, 4, ti)
tdSql1.checkData(0, 5, ti%2)
tdSql1.checkData(0, 6, ti)
tdSql1.checkData(0, 7, ti%32768)
tdSql1.checkData(0, 8, ti%128)
tdSql1.checkData(0, 9, f'nchar_{ti}')
tdSql2.error(f"select c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 from t{ti}")
# delete conn1.database and reinsert the data to conn1.db and conn2.db
tdSql1.execute(f"drop database if exists {dbname11}")
tdSql1.query("show databases")
tdSql1.checkRows(0)
tdSql2.query(f"show databases")
tdSql2.checkData(0, 0, dbname21)
tdSql1.execute(dbsql(dbname11))
tdSql1.query(f"show databases")
tdSql1.checkData(0, 0, dbname11)
tdSql2.query(f"show databases ")
tdSql2.checkData(0, 0, dbname21)
tdSql1.execute(dbsql(dbname12))
tdSql1.query("show databases")
tdSql1.checkData(0, 0, dbname11)
tdSql1.checkData(1, 0, dbname12)
tdSql2.query("show databases")
tdSql2.checkData(0, 0, dbname21)
tdSql1.execute(f"use {dbname11}")
tdSql1.query("show stables")
tdSql1.checkRows(0)
tdSql2.error("show stables")
tdSql2.execute(f"use {dbname21}")
tdSql2.query("show stables")
tdSql2.checkRows(0)
tdSql2.error(f"use {dbname12}")
tdSql1.execute(stbsql(stbname11, db1_stb1_column, db1_stb1_tag))
tdSql1.query("show stables")
tdSql1.checkRows(1)
tdSql2.query("show stables")
tdSql2.checkRows(0)
tdSql2.execute(stbsql(stbname21, db1_stb1_column, db1_stb1_tag))
tdSql1.query("show stables ")
tdSql1.checkRows(1)
tdSql1.query(f"show stables like '{stbname11}' ")
tdSql1.checkRows(1)
tdSql2.query("show stables ")
tdSql1.checkRows(1)
tdSql2.query(f"show stables like '{stbname21}' ")
tdSql1.checkRows(1)
for i in range(tbnum):
t1name = f"tm{i}"
t2name = f"tn{i}"
s1tname = stbname11
s2tname = stbname21
tags = f'{i}, {i}, {i}, "binary_{i}", {i}, {i % 2}, {i}, {i % 32768}, {i % 128}, "nchar_{i}"'
tdSql1.execute(tbsql(t1name, s1tname, tags))
# tdSql2.error(f'select * from {t1name}')
tdSql2.execute(tbsql(t2name, s2tname, tags))
# tdSql2.query(f'select * from {t2name}')
# tdSql1.error(f'select * from {t2name}')
tdSql1.query("show tables like 'tm%' ")
tdSql1.checkRows(tbnum)
tdSql2.query("show tables like 'tn%' ")
tdSql2.checkRows(tbnum)
for i in range(data_row):
data1 = f'{nowtime + i * 10}, {i}, {i}, {i}, "binary_{i}", {i}, {i % 2}, {i}, {i % 32768}, {i % 128}, "nchar_{i}"'
data2 = f'{nowtime+i*10}, {i+10000}, {i+10000}, {i+10000}, "binary_{i+10000}", {i+10000}, {(i+10000)%2}, {i+10000}, {(i+10000)%32768}, {(i+10000)%128}, "nchar_{i+10000}" '
tdSql1.execute(datasql(f"tm{i}", data1))
tdSql2.execute(datasql(f'tn{i}', data2))
testquery()
\ No newline at end of file
python .\test.py -f insert\basic.py
python .\test.py -f insert\int.py
python .\test.py -f insert\float.py
python .\test.py -f insert\bigint.py
python .\test.py -f insert\bool.py
python .\test.py -f insert\double.py
python .\test.py -f insert\smallint.py
python .\test.py -f insert\tinyint.py
python .\test.py -f insert\date.py
python .\test.py -f insert\binary.py
python .\test.py -f insert\nchar.py
python .\test.py -f query\filter.py
python .\test.py -f query\filterCombo.py
python .\test.py -f query\queryNormal.py
python .\test.py -f query\queryError.py
python .\test.py -f query\filterAllIntTypes.py
python .\test.py -f query\filterFloatAndDouble.py
python .\test.py -f query\filterOtherTypes.py
python .\test.py -f query\querySort.py
python .\test.py -f query\queryJoin.py
\ No newline at end of file
......@@ -345,6 +345,7 @@ python3 ./test.py -f functions/function_spread.py -r 1
python3 ./test.py -f functions/function_stddev.py -r 1
python3 ./test.py -f functions/function_sum.py -r 1
python3 ./test.py -f functions/function_top.py -r 1
python3 ./test.py -f functions/function_sample.py -r 1
python3 ./test.py -f functions/function_twa.py -r 1
python3 ./test.py -f functions/function_twa_test2.py
python3 ./test.py -f functions/function_stddev_td2555.py
......@@ -403,7 +404,7 @@ python3 ./test.py -f query/queryDiffColsOr.py
python3 ./test.py -f client/nettest.py
python3 ./test.py -f query/queryRegex.py
python3 ./test.py -f tools/taosdemoTestdatatype.py
#======================p4-end===============
......
###################################################################
# 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 *
import numpy as np
import collections
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.rowNum = 10
self.sample_times = 10000
self.ts = 1537146000000
def run(self):
tdSql.prepare()
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
tdSql.execute("create table test1 using test tags('beijing')")
for i in range(self.rowNum):
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
% (self.ts + i, i, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
print("begin sampling. sql: select sample(col1, 2) from test1")
freqDict = collections.defaultdict(int)
for i in range(self.sample_times):
tdSql.query('select sample(col1, 2) from test1')
res1 = tdSql.getData(0, 1);
res2 = tdSql.getData(1, 1);
freqDict[res1] = freqDict[res1] + 1
freqDict[res2] = freqDict[res2] + 1
print("end sampling.")
lower_bound = self.sample_times/5 - self.sample_times/50;
upper_bound = self.sample_times/5 + self.sample_times/50;
for i in range(self.rowNum):
print("{} are sampled in {} times".format(i, freqDict[i]))
if not (freqDict[i]>=lower_bound and freqDict[i]<=upper_bound):
print("run it aggain. if it keeps appearing, sample function bug")
caller = inspect.getframeinfo(inspect.stack()[0][0])
args = (caller.filename, caller.lineno-2)
tdLog.exit("{}({}) failed. sample function failure".format(args[0], args[1]))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# 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 *
import numpy as np
import collections
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.rowNum = 10
self.sample_times = 10000
self.ts = 1537146000000
def run(self):
tdSql.prepare()
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
tdSql.execute("create table test1 using test tags('beijing')")
for i in range(self.rowNum):
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
% (self.ts + i, i, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
print("begin sampling. sql: select sample(col1, 2) from test1")
freqDict = collections.defaultdict(int)
for i in range(self.sample_times):
tdSql.query('select sample(col1, 2) from test1')
res1 = tdSql.getData(0, 1);
res2 = tdSql.getData(1, 1);
freqDict[res1] = freqDict[res1] + 1
freqDict[res2] = freqDict[res2] + 1
print("end sampling.")
lower_bound = self.sample_times/5 - self.sample_times/50;
upper_bound = self.sample_times/5 + self.sample_times/50;
for i in range(self.rowNum):
print("{} are sampled in {} times".format(i, freqDict[i]))
if not (freqDict[i]>=lower_bound and freqDict[i]<=upper_bound):
print("run it aggain. if it keeps appearing, sample function bug")
caller = inspect.getframeinfo(inspect.stack()[0][0])
args = (caller.filename, caller.lineno-2)
tdLog.exit("{}({}) failed. sample function failure".format(args[0], args[1]))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
# -*- coding: utf-8 -*-
import platform
import sys
from util.log import *
from util.cases import *
......@@ -53,9 +54,10 @@ class TDTestCase:
tdLog.info("tdSql.checkData(0, 0, '34567')")
tdSql.checkData(0, 0, '34567')
tdLog.info("insert into tb values (now+4a, \"'';\")")
config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '')
result = ''.join(os.popen(r"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines())
if "Query OK" not in result: tdLog.exit("err:insert '';")
if platform.system() == "Linux":
config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '')
result = ''.join(os.popen(r"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines())
if "Query OK" not in result: tdLog.exit("err:insert '';")
tdLog.info('drop database db')
tdSql.execute('drop database db')
tdLog.info('show databases')
......
......@@ -15,6 +15,7 @@ import sys
from util.log import *
from util.cases import *
from util.sql import *
import platform
class TDTestCase:
......@@ -37,7 +38,7 @@ class TDTestCase:
tdSql.error("insert into tb values (now, 'taosdata001')")
tdSql.error("insert into tb(now, 😀)")
if platform.system() == "Linux" : tdSql.error("insert into tb(now, 😀)")
tdSql.query("select * from tb")
tdSql.checkRows(2)
......
......@@ -17,6 +17,7 @@ from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
import platform
class TDTestCase:
def init(self, conn, logSql):
......@@ -137,8 +138,9 @@ class TDTestCase:
tdSql.checkData(1, 1, 421)
tdSql.checkData(1, 2, "tm1")
tdDnodes.stop(1)
tdDnodes.start(1)
if platform.system() == "Linux":
tdDnodes.stop(1)
tdDnodes.start(1)
tdSql.query("select last(*) from m1 group by tbname")
tdSql.checkData(0, 0, "2020-03-01 01:01:01")
......
......@@ -29,37 +29,75 @@ class TDTestCase:
print("==============step1")
##2021-09-17 For jira: https://jira.taosdata.com:18080/browse/TD-6585
tdSql.execute(
"create stable if not exists stb_test(ts timestamp,c0 binary(32)) tags(t0 binary(32))"
"create stable if not exists stb_test(ts timestamp,c0 binary(32),c1 int) tags(t0 binary(32))"
)
tdSql.execute(
'create table if not exists stb_1 using stb_test tags("abcdefgasdfg12346")'
)
tdLog.info('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345"')
tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345")')
tdLog.info('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345",15')
tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.002","abcefdasdqwerxasdazx12345",15)')
tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.003","aaaaafffwwqqxzz",16)')
tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.004","fffwwqqxzz",17)')
tdSql.execute('insert into stb_1 values("2020-10-13 10:00:00.001","abcd\\\efgh",100)')
tdSql.query('select * from stb_test where tbname match "asd"')
tdSql.checkRows(0)
tdSql.query('select * from stb_test where tbname nmatch "asd"')
tdSql.checkRows(1)
tdSql.checkRows(4)
tdSql.query('select * from stb_test where c0 match "abc"')
tdSql.checkRows(2)
tdSql.query('select * from stb_test where c0 nmatch "abc"')
tdSql.checkRows(2)
tdSql.query('select * from stb_test where c0 match "^a"')
tdSql.checkRows(3)
tdSql.query('select * from stb_test where c0 nmatch "^a"')
tdSql.checkRows(1)
tdSql.query('select * from stb_test where c0 match "5$"')
tdSql.checkData(0,1,"abcefdasdqwerxasdazx12345")
tdSql.query('select * from stb_test where c0 nmatch "5$"')
tdSql.checkRows(3)
tdSql.query('select * from stb_test where c0 match "a*"')
tdSql.checkRows(4)
tdSql.query('select * from stb_test where c0 nmatch "a*"')
tdSql.checkRows(0)
tdSql.query('select * from stb_test where c0 nmatch "abc"')
tdSql.query('select * from stb_test where c0 match "a+"')
tdSql.checkRows(3)
tdSql.query('select * from stb_test where c0 nmatch "a+"')
tdSql.checkRows(1)
tdSql.query('select * from stb_test where c0 match "a?"')
tdSql.checkRows(4)
tdSql.query('select * from stb_test where c0 nmatch "a?"')
tdSql.checkRows(0)
tdSql.query('select last(c1) from stb_test where c0 match "a"')
tdSql.checkData(0,0,16)
tdSql.query('select count(c1) from stb_test where t0 match "a"')
tdSql.checkData(0,0,4)
tdSql.error('select * from stb_test where c0 match abc')
tdSql.error('select * from stb_test where c0 nmatch abc')
tdSql.execute('insert into stb_1 values("2020-10-13 10:00:00.001","abcd\\\efgh")')
tdSql.query("select * from stb_1 where c0 match '\\\\'")
tdSql.checkRows(1)
tdSql.query("select * from stb_1 where c0 nmatch '\\\\'")
tdSql.checkRows(3)
......
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "DEL=%%a")
for /F "usebackq tokens=*" %%i in (fulltest.bat) do (
echo Processing %%i
call %%i ARG1 -w 1 -m %1 > result.txt 2>error.txt
if errorlevel 1 ( call :colorEcho 0c "failed" &echo. && exit 8 ) else ( call :colorEcho 0a "Success" &echo. )
)
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
\ No newline at end of file
......@@ -18,6 +18,7 @@ import getopt
import subprocess
import time
from distutils.log import warn as printf
from fabric2 import Connection
from util.log import *
from util.dnodes import *
......@@ -35,8 +36,9 @@ if __name__ == "__main__":
logSql = True
stop = 0
restart = False
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghr', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help'])
windows = 0
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrw', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'windows'])
for key, value in opts:
if key in ['-h', '--help']:
tdLog.printNoPrefix(
......@@ -49,6 +51,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-c Test Cluster Flag')
tdLog.printNoPrefix('-g valgrind Test Flag')
tdLog.printNoPrefix('-r taosd restart test')
tdLog.printNoPrefix('-w taos on windows')
sys.exit(0)
if key in ['-r', '--restart']:
......@@ -81,6 +84,9 @@ if __name__ == "__main__":
if key in ['-s', '--stop']:
stop = 1
if key in ['-w', '--windows']:
windows = 1
if (stop != 0):
if (valgrind == 0):
toBeKilled = "taosd"
......@@ -111,66 +117,81 @@ if __name__ == "__main__":
tdLog.info('stop All dnodes')
tdDnodes.init(deployPath)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
is_test_framework = 0
key_word = 'tdCases.addLinux'
try:
if key_word in open(fileName).read():
is_test_framework = 1
except:
pass
if is_test_framework:
moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName)
try:
ucase = uModule.TDTestCase()
tdDnodes.deploy(1,ucase.updatecfgDict)
except :
tdDnodes.deploy(1,{})
else:
tdDnodes.deploy(1,{})
tdDnodes.start(1)
if masterIp == "":
host = '127.0.0.1'
else:
host = masterIp
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdCases.logSql(logSql)
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
else:
if windows:
tdCases.logSql(logSql)
tdLog.info("Procedures for testing self-deployment")
td_clinet = TDSimClient("C:\\TDengine")
td_clinet.deploy()
remote_conn = Connection("root@%s"%host)
with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'):
remote_conn.run("python3 ./test.py")
conn = taos.connect(
host,
config=tdDnodes.getSimCfgPath())
if fileName == "all":
tdCases.runAllLinux(conn)
host="%s"%(host),
config=td_clinet.cfgDir)
tdCases.runOneWindows(conn, fileName)
else:
tdDnodes.init(deployPath)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
is_test_framework = 0
key_word = 'tdCases.addLinux'
try:
if key_word in open(fileName).read():
is_test_framework = 1
except:
pass
if is_test_framework:
moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName)
try:
ucase = uModule.TDTestCase()
tdDnodes.deploy(1,ucase.updatecfgDict)
except :
tdDnodes.deploy(1,{})
else:
pass
tdDnodes.deploy(1,{})
tdDnodes.start(1)
tdCases.logSql(logSql)
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
else:
tdCases.runOneLinux(conn, fileName)
if restart:
if fileName == "all":
tdLog.info("not need to query ")
else:
sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
time.sleep(1)
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py")
tdLog.info("Procedures for testing self-deployment")
conn = taos.connect(
host,
config=tdDnodes.getSimCfgPath())
if fileName == "all":
tdCases.runAllLinux(conn)
else:
tdLog.info("not need to query")
tdCases.runOneWindows(conn, fileName)
if restart:
if fileName == "all":
tdLog.info("not need to query ")
else:
sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
time.sleep(1)
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py")
else:
tdLog.info("not need to query")
conn.close()
###################################################################
# 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 os
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)
self.numberOfTables = 10
self.numberOfRecords = 10
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def run(self):
buildPath = self.getBuildPath()
if (buildPath == ""):
tdLog.exit("taosdemo not found!")
else:
tdLog.info("taosdemo found in %s" % buildPath)
binPath = buildPath + "/build/bin/"
os.system("%staosdemo -d test002 -y -t %d -n %d -b INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" %
(binPath, self.numberOfTables, self.numberOfRecords))
tdSql.execute('use test002')
tdSql.query("select count(*) from meters")
tdSql.checkData(0, 0, self.numberOfTables * self.numberOfRecords)
tdSql.query("select * from meters")
tdSql.checkRows(self.numberOfTables * self.numberOfRecords)
tdLog.info('insert into d1 values(now,100,"abcd1234","abcdefgh12345678","abcdefgh","abcdefgh")')
tdSql.execute('insert into d1 values(now,100,"abcd1234","abcdefgh12345678","abcdefgh","abcdefgh")')
tdSql.query("select * from meters")
tdSql.checkRows(101)
tdSql.error('insert into d1 values(now,100,"abcd","abcd"')
tdSql.error('insert into d1 values(now,100,100,100)')
os.system("%staosdemo -d test002 -y -t %d -n %d --data-type INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" %
(binPath, self.numberOfTables, self.numberOfRecords))
tdSql.execute('use test002')
tdSql.query("select count(*) from meters")
tdSql.checkData(0, 0, self.numberOfTables * self.numberOfRecords)
os.system("%staosdemo -d test002 -y -t %d -n %d -bINT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" %
(binPath, self.numberOfTables, self.numberOfRecords))
tdSql.execute('use test002')
tdSql.query("select count(*) from meters")
tdSql.checkData(0, 0, self.numberOfTables * self.numberOfRecords)
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
......@@ -27,7 +27,7 @@ class TDTestCase:
def restart_taosd(self,db):
tdDnodes.stop(1)
tdDnodes.startWithoutSleep(1)
tdDnodes.start(1)
tdSql.execute("use %s;" % db)
def date_to_timestamp_microseconds(self, date):
......
......@@ -34,7 +34,7 @@ class TDCases:
self.clusterCases = []
def __dynamicLoadModule(self, fileName):
moduleName = fileName.replace(".py", "").replace("/", ".")
moduleName = fileName.replace(".py", "").replace(os.sep, ".")
return importlib.import_module(moduleName, package='..')
def logSql(self, logSql):
......@@ -80,7 +80,7 @@ class TDCases:
runNum += 1
continue
def runAllWindows(self, conn):
def runAllWindows(self, conn, fileName):
# TODO: load all Windows cases here
runNum = 0
for tmp in self.windowsCases:
......@@ -101,12 +101,17 @@ class TDCases:
for tmp in self.windowsCases:
if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase()
case.init(conn)
case.run()
case.init(conn, self._logSql)
try:
case.run()
except Exception as e:
tdLog.notice(repr(e))
tdLog.exit("%s failed" % (fileName))
case.stop()
runNum += 1
continue
tdLog.notice("total %d Windows case(s) executed" % (runNum))
def runAllCluster(self):
# TODO: load all cluster case module here
......
......@@ -15,6 +15,8 @@ import sys
import os
import os.path
import platform
import pathlib
import shutil
import subprocess
from time import sleep
from util.log import *
......@@ -62,32 +64,45 @@ class TDSimClient:
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
if os.system(cmd) != 0:
tdLog.exit(cmd)
def os_string(self,path):
os_path = path.replace("/",os.sep)
return os_path
def deploy(self):
self.logDir = "%s/sim/psim/log" % (self.path)
self.cfgDir = "%s/sim/psim/cfg" % (self.path)
self.cfgPath = "%s/sim/psim/cfg/taos.cfg" % (self.path)
cmd = "rm -rf " + self.logDir
if os.system(cmd) != 0:
tdLog.exit(cmd)
cmd = "mkdir -p " + self.logDir
if os.system(cmd) != 0:
tdLog.exit(cmd)
cmd = "rm -rf " + self.cfgDir
if os.system(cmd) != 0:
tdLog.exit(cmd)
cmd = "mkdir -p " + self.cfgDir
if os.system(cmd) != 0:
tdLog.exit(cmd)
cmd = "touch " + self.cfgPath
if os.system(cmd) != 0:
tdLog.exit(cmd)
self.logDir = self.os_string("%s/sim/psim/log" % (self.path))
self.cfgDir = self.os_string("%s/sim/psim/cfg" % (self.path))
self.cfgPath = self.os_string("%s/sim/psim/cfg/taos.cfg" % (self.path))
# cmd = "rm -rf " + self.logDir
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
if os.path.exists(self.logDir):
try:
shutil.rmtree(self.logDir)
except:
tdLog.exit("del %s failed"%self.logDir)
# cmd = "mkdir -p " + self.logDir
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
os.makedirs(self.logDir)
# cmd = "rm -rf " + self.cfgDir
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
if os.path.exists(self.cfgDir):
try:
shutil.rmtree(self.cfgDir)
except:
tdLog.exit("del %s failed"%self.cfgDir)
# cmd = "mkdir -p " + self.cfgDir
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
os.makedirs(self.cfgDir)
# cmd = "touch " + self.cfgPath
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
try:
pathlib.Path(self.cfgPath).touch()
except:
tdLog.exit("create %s failed"%self.cfgPath)
if self.testCluster:
self.cfg("masterIp", "192.168.0.1")
self.cfg("secondIp", "192.168.0.2")
......
......@@ -21,6 +21,10 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select csum(tbcol) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) from $tb where ts > $ms
print ===> $data11
if $data11 != 11 then
return -1
endi
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) from $tb where ts <= $ms
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step4
sql select csum(tbcol) as b from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step5
sql select csum(tbcol) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 2
$rowNum = 1000
$totalNum = 2000
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 nchar(5), c9 binary(10)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
$tinyint = $x / 128
sql insert into $tb values ($ms , $x , $x , $x , $x , $tinyint , $x , $x , $x , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select csum(c1) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c2) from $tb
print ===> $data11
if $data11 != 1.000000000 then
return -1
endi
sql select csum(c3) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c4) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c5) from $tb
print ===> $data11
if $data11 != 0 then
return -1
endi
sql select csum(c6) from $tb
print ===> $data11
if $data11 != 1.000000000 then
return -1
endi
sql_error select csum(c7) from $tb
sql_error select csum(c8) from $tb
sql_error select csum(c9) from $tb
sql_error select csum(ts) from $tb
sql_error select csum(c1), csum(c2) from $tb
#sql_error select 2+csum(c1) from $tb
sql_error select csum(c1+2) from $tb
sql_error select csum(c1) from $tb where ts > 0 and ts < now + 100m interval(10m)
sql_error select csum(c1) from $mt
sql_error select csum(csum(c1)) from $tb
sql_error select csum(c1) from m_di_tb1 where c2 like '2%'
print =============== step3
sql select csum(c1) from $tb where c1 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c2) from $tb where c2 > 5
print ===> $data11
if $data11 != 13.000000000 then
return -1
endi
sql select csum(c3) from $tb where c3 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c4) from $tb where c4 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c5) from $tb where c5 > 5
print ===> $data11
if $data11 != 12 then
return -1
endi
sql select csum(c6) from $tb where c6 > 5
print ===> $data11
if $data11 != 13.000000000 then
return -1
endi
print =============== step4
sql select csum(c1) from $tb where c1 > 5 and c2 < $rowNum
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c1) from $tb where c9 like '%9' and c1 <= 20
print ===> $rows
if $rows != 2 then
return -1
endi
print ===>$data01, $data11
if $data01 != 9 then
return -1
endi
if $data11 != 28 then
return -1
endi
print =============== step5
sql select csum(c1) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
sql select csum(c1) as b from $tb where ts < now + 4m interval(1m) -x step6
return -1
step6:
print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select mavg(tbcol,2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol,2) from $tb where ts > $ms
print ===> $data11
if $data11 != 6.500000000 then
return -1
endi
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol,2) from $tb where ts <= $ms
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step4
sql select mavg(tbcol,2) as b from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step5
sql select mavg(tbcol, 2) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol, 2) as b from $tb where ts <= $ms interval(1m) -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 2
$rowNum = 10000
$totalNum = 20000
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 nchar(5), c9 binary(10)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
$tinyint = $x / 128
sql insert into $tb values ($ms , $x , $x , $x , $x , $tinyint , $x , $x , $x , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select mavg(c1, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c2, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c3, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c4, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c5, 2) from $tb
print ===> $data11
if $data11 != 0.000000000 then
return -1
endi
sql select mavg(c6, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql_error select mavg(c7,2) from $tb
sql_error select mavg(c8,2) from $tb
sql_error select mavg(c9,2) from $tb
sql_error select mavg(ts,2) from $tb
sql_error select mavg(c1,2), mavg(c2,2) from $tb
#sql_error select 2+mavg(c1,2) from $tb
sql_error select mavg(c1+2) from $tb
sql_error select mavg(c1,2) from $tb where ts > 0 and ts < now + 100m interval(10m)
sql_error select mavg(c1,2) from $mt
sql_error select mavg(mavg(c1,2)) from $tb
sql_error select mavg(c1,2) from m_di_tb1 where c2 like '2%'
print =============== step3
sql select mavg(c1,2) from $tb where c1 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c2,2) from $tb where c2 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c3,2) from $tb where c3 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c4,2) from $tb where c4 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c5,2) from $tb where c5 > 5
print ===> $data11
if $data11 != 6.000000000 then
return -1
endi
sql select mavg(c6,2) from $tb where c6 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
print =============== step4
sql select mavg(c1,2) from $tb where c1 > 5 and c2 < $rowNum
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c1,2) from $tb where c9 like '%9' and c1 <= 20
if $rows != 1 then
return -1
endi
print ===> $data01
if $data01 != 14.000000000 then
return -1
endi
print =============== step5
sql select mavg(c1,2) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
sql select mavg(c1,2) as b from $tb where ts < now + 4m interval(1m) -x step6
return -1
step6:
print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_db
$tbPrefix = m_tb
$mtPrefix = m_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int, bin binary(43), nch nchar(43)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x , 'binary' , 'nchar' )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select sample(tbcol, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 > 19 then
return -1
endi
sql select sample(bin, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 != @binary@ then
return -1
endi
sql select sample(nch, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 != @nchar@ then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select sample(tbcol, 1) from $tb where ts <= $ms
if $data01 > 4 then
return -1
endi
sql select sample(bin, 1) from $tb where ts <= $ms
if $data01 != @binary@ then
return -1
endi
sql select sample(nch, 1) from $tb where ts <= $ms
if $data01 != @nchar@ then
return -1
endi
print =============== step4
sql select sample(tbcol, 1) as b from $tb
if $data01 > 19 then
return -1
endi
sql select sample(bin, 1) as b from $tb
print =============== step5
sql select sample(tbcol, 2) as b from $tb
if $rows != 2 then
return -1
endi
if $data01 > 19 then
return -1
endi
if $data11 > 19 then
return -1
endi
sql_error select sample(nchar, 2) as b from $tb
sql select sample(nch, 2) as b from $tb
if $rows != 2 then
return -1
endi
print =====> $data01 , $data11
if $data01 != @nchar@ then
return -1
endi
if $data11 != @nchar@ then
return -1
endi
sql select sample(bin, 2) as b from $tb
if $rows != 2 then
return -1
endi
if $data01 != @binary@ then
return -1
endi
if $data11 != @binary@ then
return -1
endi
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select sample(tbcol, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
if $data01 > 4 then
return -1
endi
if $data11 > 4 then
return -1
endi
sql select sample(bin, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
sql select sample(nch, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
sql select sample(tbcol, 1001) as b from $tb -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -3,6 +3,11 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/sample.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
......@@ -124,8 +124,11 @@ sql select spread(ts )/(1000*3600*24) from $stb interval(1y)
sql_error select first(c1, c2) - last(c1, c2) from $stb interval(1y)
sql_error select first(ts) - last(ts) from $stb interval(1y)
sql_error select top(c1, 2) - last(c1) from $stb;
sql_error select sample(c1, 2) - last(c1) from $stb;
sql_error select stddev(c1) - last(c1) from $stb;
sql_error select diff(c1) - last(c1) from $stb;
sql_error select mavg(c1, 2) - last(c1) from $stb;
sql_error select csum(c1) - last(c1) from $stb;
sql_error select first(c7) - last(c7) from $stb;
sql_error select first(c8) - last(c8) from $stb;
sql_error select first(c9) - last(c9) from $stb;
......@@ -151,4 +154,4 @@ if $data02 != 225000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -174,6 +174,9 @@ endi
sql_error select top(c1, 1) - bottom(c1, 1) from $tb
sql_error select top(c1, 99) - bottom(c1, 99) from $tb
sql_error select top(c1,1) - 88 from $tb
sql_error select sample(c1, 1) - bottom(c1, 1) from $tb
sql_error select sample(c1, 99) - bottom(c1, 99) from $tb
sql_error select sample(c1,1) - 88 from $tb
# all data types [d.6] ================================================================
sql select c2-c1*1.1, c3/c2, c4*c3, c5%c4, (c6+c4)%22, c2-c2 from $tb
......@@ -475,11 +478,16 @@ endi
sql_error select first(c1, c2) - last(c1, c2) from $stb
sql_error select top(c1, 5) - bottom(c1, 5) from $stb
sql_error select first(*) - 99 from $stb
sql_error select sample(c1, 5) - bottom(c1, 5) from $stb
# multi row result aggregation [d.4]
sql_error select top(c1, 1) - bottom(c1, 1) from $stb
sql_error select top(c1, 99) - bottom(c1, 99) from $stb
sql_error select sample(c1, 1) - top(c1, 1) from $stb
sql_error select sample(c1, 99) - top(c1, 99) from $stb
# query on super table [d.5]=============================================================
# all cases in this part are query on super table
......
......@@ -1087,6 +1087,14 @@ sql select diff(val) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql select mavg(val,2) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql select csum(val) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql insert into t1 values('2020-1-1 1:1:4', 20);
sql insert into t1 values('2020-1-1 1:1:6', 200);
......
......@@ -121,6 +121,7 @@ if $data31 != 4 then
return -1
endi
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql select last(f1) from st2 group by f1 having count(f2) > 0;
......@@ -140,9 +141,12 @@ if $data30 != 4 then
return -1
endi
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having avg(f1) > 0;
sql select avg(f1),count(f1) from st2 group by f1 having avg(f1) > 2;
if $rows != 2 then
......@@ -1059,6 +1063,13 @@ if $data26 != 4 then
endi
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having sample(f1,1);
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having sample(f1,1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1) from st2 group by f1 having sum(f1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from st2 group by f1 having bottom(f1,1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having top(f1,1);
......@@ -1149,6 +1160,18 @@ sql_error select avg(f1),diff(f1) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),diff(f1) from st2 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from st2 group by f1 having mavg(f1, 2) > 0;
sql_error select avg(f1),mavg(f1, 3) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),mavg(f1, 4) from st2 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from st2 group by f1 having csum(f1) > 0;
sql_error select avg(f1),csum(f1) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),csum(f1) from st2 group by f1 having spread(f2) > 0;
sql select avg(f1) from st2 group by f1 having spread(f2) > 0;
if $rows != 0 then
return -1
......@@ -1834,6 +1857,7 @@ if $data04 != 1 then
return -1
endi
sql_error select sample(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select top(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select count(*) from tb1 group by f1 having last(*) > 0;
......
......@@ -120,6 +120,7 @@ if $data31 != 4 then
endi
sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql select last(f1) from tb1 group by f1 having count(f2) > 0;
if $rows != 4 then
......@@ -144,6 +145,12 @@ sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from tb1 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having avg(f1) > 0;
sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2;
if $rows != 2 then
return -1
......@@ -1067,7 +1074,13 @@ if $data26 != 4 then
return -1
endi
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having sample(f1,1);
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having sample(f1,1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from tb1 group by f1 having bottom(f1,1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from tb1 group by f1 having sum(f1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having top(f1,1);
......@@ -1164,6 +1177,20 @@ sql_error select avg(f1),diff(f1) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),diff(f1) from tb1 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from tb1 group by f1 having mavg(f1,4) > 0;
sql_error select avg(f1),mavg(f1,5) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),mavg(f1,6) from tb1 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from tb1 group by f1 having csum(f1) > 0;
sql_error select avg(f1),csum(f1) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),csum(f1) from tb1 group by f1 having spread(f2) > 0;
sql select avg(f1) from tb1 group by f1 having spread(f2) > 0;
if $rows != 0 then
return -1
......@@ -1857,4 +1884,6 @@ endi
sql_error select top(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f1) > 0;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -80,4 +80,7 @@ sql use $db
sql select * from (select ts, top(c1, 5) from $tb where ts >= $ts0 order by ts desc limit 3 offset 1)
sql select * from (select ts, top(c1, 5) from $stb where ts >= $ts0 order by ts desc limit 3 offset 1)
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
sql select * from (select ts, sample(c1, 5) from $tb where ts >= $ts0 order by ts desc limit 3 offset 1)
sql_error select * from (select ts, sample(c1, 5) from $stb where ts >= $ts0 order by ts desc limit 3 offset 1)
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -471,6 +471,92 @@ if $data81 != -9 then
return -1
endi
sql select mavg(c1,2) from $tb
$res = $rowNum - 1
if $rows != $res then
return -1
endi
sql select mavg(c1,2) from $tb where c1 > 5 limit 2 offset 1
print $rows , $data00 , $data01 , $data10 , $data11
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data01 != 7.500000000 then
return -1
endi
if $data10 != @18-09-17 10:30:00.000@ then
return -1
endi
if $data11 != 8.500000000 then
return -1
endi
$limit = $rowNum / 2
$offset = $limit - 1
sql select mavg(c1,2) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $limit then
return -1
endi
$limit = $rowNum / 2
$offset = $limit + 1
$val = $limit - 2
sql select mavg(c1,2) from $tb where c1 >= 0 limit $limit offset $offset
print $rows , $data01 , $data81
if $rows != $val then
return -1
endi
if $data01 != 1.500000000 then
return -1
endi
if $data81 != 4.500000000 then
return -1
endi
sql select csum(c1) from $tb
$res = $rowNum
if $rows != $res then
return -1
endi
sql select csum(c1) from $tb where c1 > 5 limit 2 offset 1
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:10:00.000@ then
return -1
endi
if $data01 != 13 then
return -1
endi
if $data10 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data11 != 21 then
return -1
endi
$limit = $rowNum / 2
$offset = $limit - 1
sql select csum(c1) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $limit then
return -1
endi
$limit = $rowNum / 2
$offset = $limit + 1
$val = $limit - 1
sql select csum(c1) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $val then
return -1
endi
if $data01 != 22501 then
return -1
endi
if $data81 != 22545 then
return -1
endi
### aggregation + limit offset (with interval)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5
if $rows != 5 then
......
......@@ -828,6 +828,8 @@ if $data59 != 4 then
return -1
endi
sql_error select sample(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
sql select top(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
......
......@@ -355,6 +355,21 @@ sql select top(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
endi
sql select sample(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
endi
sql select * from (select ts, sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1)
sql select ts,sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
if $rows != 3 then
return -1
endi
print select ts,sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
print $data00 $data01 $data02
print $data10 $data11 $data12
print $data20 $data21 $data22
print ========> TD-6017
sql select * from (select ts, top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1)
......@@ -463,6 +478,35 @@ if $data11 != 1 then
return -1
endi
sql select mavg(c1,3) from $tb where c1 > 5 limit 2 offset 1
print $rows , $data00 , $data01
if $rows != 1 then
return -1
endi
if $data00 != @18-09-17 10:30:00.000@ then
return -1
endi
if $data01 != 8.000000000 then
return -1
endi
sql select csum(c1) from $tb where c1 > 5 limit 2 offset 1
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:10:00.000@ then
return -1
endi
if $data01 != 13 then
return -1
endi
if $data10 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data11 != 21 then
return -1
endi
### aggregation + limit offset (with interval)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5
if $rows != 5 then
......
......@@ -186,6 +186,8 @@ sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
sql_error select twa(c1) from (select c1 from nest_tb0);
sql_error select irate(c1) from (select c1 from nest_tb0);
sql_error select diff(c1), twa(c1) from (select * from nest_tb0);
sql_error select mavg(c1,2), twa(c1) from (select * from nest_tb0);
sql_error select csum(c1), twa(c1) from (select * from nest_tb0);
sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0);
sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d)
......@@ -273,6 +275,14 @@ sql select diff(c1) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
sql select mavg(c1,2) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
sql select csum(c1) from (select * from nest_tb0);
if $rows != 10000 then
return -1
endi
sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d);
if $rows != 7 then
......@@ -330,6 +340,8 @@ if $data12 != 71680.000000000 then
return -1
endi
sql select sample(x, 20) from (select c1 x from nest_tb0);
sql select top(x, 20) from (select c1 x from nest_tb0);
sql select bottom(x, 20) from (select c1 x from nest_tb0)
......@@ -420,6 +432,35 @@ if $data01 != 1 then
return -1
endi
sql select mavg(val, 2) from (select c1 val from nest_tb0);
if $rows != 9999 then
return -1
endi
if $data00 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data01 != 0.500000000 then
return -1
endi
sql select csum(val) from (select c1 val from nest_tb0);
if $rows != 10000 then
return -1
endi
if $data00 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data41 != 10 then
return -1
endi
sql_error select last_row(*) from (select * from nest_tb0) having c1 > 0
print ===========>td-4805
......@@ -508,4 +549,4 @@ if $data11 != 2.000000000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -296,6 +296,7 @@ sql_error select last(t1) from group_mt0;
sql_error select min(t1) from group_mt0;
sql_error select max(t1) from group_mt0;
sql_error select top(t1, 20) from group_mt0;
sql_error select sample(t1, 20) from group_mt0;
sql_error select bottom(t1, 20) from group_mt0;
sql_error select avg(t1) from group_mt0;
sql_error select percentile(t1, 50) from group_mt0;
......@@ -393,6 +394,25 @@ if $data21 != -1 then
return -1
endi
sql select mavg(k,3) from tm0
print ====> $rows , $data21
if $row != 2 then
return -1
endi
if $data11 != 2.333333333 then
return -1
endi
sql select csum(k) from tm0
print ====> $rows , $data21
if $row != 4 then
return -1
endi
if $data21 != 6 then
return -1
endi
#error sql
sql_error select * from 1;
#sql_error select 1; // equals to select server_status();
......
......@@ -181,6 +181,12 @@ if $data03 != @abc15@ then
return -1
endi
sql_error select sample(c6, 3) from select_tags_mt0 interval(10a)
sql select sample(c3,10) from select_tags_mt0 interval(10a) group by tbname,t1,t2
sql select sample(c6, 3) from select_tags_mt0 interval(10a) group by tbname;
sql_error select sample(c6, 10) from select_tags_mt0 interval(10a);
sql_error select sample(c1, 80), tbname, t1, t2 from select_tags_mt0;
sql select top(c6, 3) from select_tags_mt0 interval(10a)
sql select top(c3,10) from select_tags_mt0 interval(10a) group by tbname,t1,t2
sql select top(c6, 3) from select_tags_mt0 interval(10a) group by tbname;
......@@ -418,6 +424,11 @@ if $data11 != @70-01-01 08:01:40.001@ then
return -1
endi
sql select sample(c1, 100), tbname, t1, t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname;
if $rows != 200 then
return -1
endi
sql select top(c1, 100), tbname, t1, t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname;
if $row != 200 then
return -1
......@@ -455,6 +466,11 @@ if $data04 != @abc0@ then
return -1
endi
sql select sample(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2;
if $rows != 4 then
return -1
endi
sql select top(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2;
if $row != 4 then
return -1
......@@ -542,6 +558,11 @@ endi
# slimit /limit
sql select sample(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2 limit 2 offset 1;
if $rows != 2 then
return -1
endi
sql select top(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2 limit 2 offset 1;
if $row != 2 then
return -1
......@@ -715,6 +736,11 @@ if $data25 != @select_tags_tb2@ then
return -1
endi
sql select sample(c1, 5), t2 from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 15 then
return -1
endi
sql select top(c1, 5), t2 from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 15 then
return -1
......@@ -753,6 +779,11 @@ if $data93 != @select_tags_tb1@ then
endi
#if data
sql select sample(c1, 50), t2, t1, tbname from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 48 then
return -1
endi
sql select top(c1, 50), t2, t1, tbname from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 48 then
return -1
......@@ -838,6 +869,8 @@ endi
print TODO ======= selectivity + tags+ group by + tags + filter + interval + join===========
print ==========================mix tag columns and group by columns======================
sql_error select sample(c1, 100), tbname from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by t3
sql select top(c1, 100), tbname from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by t3
if $rows != 100 then
return -1
......
......@@ -489,6 +489,7 @@ sql_error select ts,sum_double(f1),f1 from tb1;
sql_error select add_one(f1),count(f1) from tb1;
sql_error select sum_double(f1),count(f1) from tb1;
sql_error select add_one(f1),top(f1,3) from tb1;
sql_error select add_one(f1),sample(f1,3) from tb1;
sql_error select add_one(f1) from tb1 interval(10a);
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -508,6 +508,7 @@ sql_error select ts,sum_double(f1),f1 from tb1;
sql_error select add_one(f1),count(f1) from tb1;
sql_error select sum_double(f1),count(f1) from tb1;
sql_error select add_one(f1),top(f1,3) from tb1;
sql_error select add_one(f1),sample(f1,3) from tb1;
sql_error select add_one(f1) from tb1 interval(10a);
......
......@@ -21,6 +21,11 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/sample.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册