Merge remote-tracking branch 'origin/develop' into hotfix/sf
This commit is contained in:
commit
9f8f3c89f9
|
@ -46,6 +46,7 @@ def pre_test(){
|
||||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||||
git checkout -qf FETCH_HEAD
|
git checkout -qf FETCH_HEAD
|
||||||
git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD develop)|grep -v -E '.*md|//src//connector|Jenkinsfile' || exit 0
|
git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD develop)|grep -v -E '.*md|//src//connector|Jenkinsfile' || exit 0
|
||||||
|
find ${WKC}/tests/pytest -name \'*\'.sql -exec rm -rf {} \\;
|
||||||
cd ${WK}
|
cd ${WK}
|
||||||
git reset --hard HEAD~10
|
git reset --hard HEAD~10
|
||||||
git checkout develop
|
git checkout develop
|
||||||
|
@ -115,7 +116,6 @@ pipeline {
|
||||||
sh '''
|
sh '''
|
||||||
date
|
date
|
||||||
cd ${WKC}/tests
|
cd ${WKC}/tests
|
||||||
find pytest -name '*'sql|xargs rm -rf
|
|
||||||
./test-all.sh p1
|
./test-all.sh p1
|
||||||
date'''
|
date'''
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,6 @@ pipeline {
|
||||||
sh '''
|
sh '''
|
||||||
date
|
date
|
||||||
cd ${WKC}/tests
|
cd ${WKC}/tests
|
||||||
find pytest -name '*'sql|xargs rm -rf
|
|
||||||
./test-all.sh p2
|
./test-all.sh p2
|
||||||
date'''
|
date'''
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
|
||||||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||||
IF (TD_MVN_INSTALLED)
|
IF (TD_MVN_INSTALLED)
|
||||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.21-dist.jar DESTINATION connector/jdbc)
|
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.22-dist.jar DESTINATION connector/jdbc)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
ELSEIF (TD_DARWIN)
|
ELSEIF (TD_DARWIN)
|
||||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||||
|
|
|
@ -123,6 +123,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
|
||||||
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
|
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
|
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
|
||||||
|
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||||
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
|
@ -133,6 +134,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
bool tscQueryTags(SQueryInfo* pQueryInfo);
|
bool tscQueryTags(SQueryInfo* pQueryInfo);
|
||||||
bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
|
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
SSqlExpr* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
|
SSqlExpr* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
|
||||||
SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType);
|
SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType);
|
||||||
|
@ -152,7 +154,6 @@ SInternalField* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_F
|
||||||
SInternalField* tscFieldInfoGetInternalField(SFieldInfo* pFieldInfo, int32_t index);
|
SInternalField* tscFieldInfoGetInternalField(SFieldInfo* pFieldInfo, int32_t index);
|
||||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
|
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
|
||||||
|
|
||||||
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
|
|
||||||
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
|
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||||
|
|
|
@ -198,9 +198,10 @@ typedef struct STableDataBlocks {
|
||||||
typedef struct SQueryInfo {
|
typedef struct SQueryInfo {
|
||||||
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
||||||
uint32_t type; // query/insert type
|
uint32_t type; // query/insert type
|
||||||
|
STimeWindow window; // the whole query time window
|
||||||
|
|
||||||
STimeWindow window; // query time window
|
SInterval interval; // tumble time window
|
||||||
SInterval interval;
|
SSessionWindow sessionWindow; // session time window
|
||||||
|
|
||||||
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
||||||
SArray * colList; // SArray<SColumn*>
|
SArray * colList; // SArray<SColumn*>
|
||||||
|
@ -232,6 +233,7 @@ typedef struct SQueryInfo {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int command;
|
int command;
|
||||||
uint8_t msgType;
|
uint8_t msgType;
|
||||||
|
char reserve1[3]; // fix bus error on arm32
|
||||||
bool autoCreated; // create table if it is not existed during retrieve table meta in mnode
|
bool autoCreated; // create table if it is not existed during retrieve table meta in mnode
|
||||||
|
|
||||||
union {
|
union {
|
||||||
|
@ -244,8 +246,10 @@ typedef struct {
|
||||||
|
|
||||||
char * curSql; // current sql, resume position of sql after parsing paused
|
char * curSql; // current sql, resume position of sql after parsing paused
|
||||||
int8_t parseFinished;
|
int8_t parseFinished;
|
||||||
|
char reserve2[3]; // fix bus error on arm32
|
||||||
|
|
||||||
int16_t numOfCols;
|
int16_t numOfCols;
|
||||||
|
char reserve3[2]; // fix bus error on arm32
|
||||||
uint32_t allocSize;
|
uint32_t allocSize;
|
||||||
char * payload;
|
char * payload;
|
||||||
int32_t payloadLen;
|
int32_t payloadLen;
|
||||||
|
@ -255,7 +259,9 @@ typedef struct {
|
||||||
int32_t numOfParams;
|
int32_t numOfParams;
|
||||||
|
|
||||||
int8_t dataSourceType; // load data from file or not
|
int8_t dataSourceType; // load data from file or not
|
||||||
|
char reserve4[3]; // fix bus error on arm32
|
||||||
int8_t submitSchema; // submit block is built with table schema
|
int8_t submitSchema; // submit block is built with table schema
|
||||||
|
char reserve5[3]; // fix bus error on arm32
|
||||||
STagData tagData; // NOTE: pTagData->data is used as a variant length array
|
STagData tagData; // NOTE: pTagData->data is used as a variant length array
|
||||||
|
|
||||||
SName **pTableNameList; // all involved tableMeta list of current insert sql statement.
|
SName **pTableNameList; // all involved tableMeta list of current insert sql statement.
|
||||||
|
@ -397,7 +403,6 @@ typedef struct SSqlStream {
|
||||||
|
|
||||||
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable);
|
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable);
|
||||||
|
|
||||||
|
|
||||||
int tscAcquireRpc(const char *key, const char *user, const char *secret,void **pRpcObj);
|
int tscAcquireRpc(const char *key, const char *user, const char *secret,void **pRpcObj);
|
||||||
void tscReleaseRpc(void *param);
|
void tscReleaseRpc(void *param);
|
||||||
void tscInitMsgsFp();
|
void tscInitMsgsFp();
|
||||||
|
|
|
@ -481,15 +481,19 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
case TSDB_DATA_TYPE_TINYINT:
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
case TSDB_DATA_TYPE_SMALLINT:
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
case TSDB_DATA_TYPE_INT:
|
case TSDB_DATA_TYPE_INT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]);
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]);
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -100,6 +100,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalMerger *pReducer, tOrderDescr
|
||||||
} else if (functionId == TSDB_FUNC_APERCT) {
|
} else if (functionId == TSDB_FUNC_APERCT) {
|
||||||
pCtx->param[0].i64 = pExpr->param[0].i64;
|
pCtx->param[0].i64 = pExpr->param[0].i64;
|
||||||
pCtx->param[0].nType = pExpr->param[0].nType;
|
pCtx->param[0].nType = pExpr->param[0].nType;
|
||||||
|
} else if (functionId == TSDB_FUNC_BLKINFO) {
|
||||||
|
pCtx->param[0].i64 = pExpr->param[0].i64;
|
||||||
|
pCtx->param[0].nType = pExpr->param[0].nType;
|
||||||
|
pCtx->numOfParams = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCtx->interBufBytes = pExpr->interBytes;
|
pCtx->interBufBytes = pExpr->interBytes;
|
||||||
|
@ -951,10 +955,10 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
|
||||||
// todo extract function
|
// todo extract function
|
||||||
int64_t actualETime = (pQueryInfo->order.order == TSDB_ORDER_ASC)? pQueryInfo->window.ekey: pQueryInfo->window.skey;
|
int64_t actualETime = (pQueryInfo->order.order == TSDB_ORDER_ASC)? pQueryInfo->window.ekey: pQueryInfo->window.skey;
|
||||||
|
|
||||||
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput);
|
void** pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput);
|
||||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||||
pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalMerge->resColModel->capacity);
|
pResPages[i] = calloc(1, pField->bytes * pLocalMerge->resColModel->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -966,7 +970,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
|
||||||
if (pQueryInfo->limit.offset > 0) {
|
if (pQueryInfo->limit.offset > 0) {
|
||||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||||
memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pQueryInfo->limit.offset,
|
memmove(pResPages[i], ((char*)pResPages[i]) + pField->bytes * pQueryInfo->limit.offset,
|
||||||
(size_t)(newRows * pField->bytes));
|
(size_t)(newRows * pField->bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1014,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
|
||||||
int32_t offset = 0;
|
int32_t offset = 0;
|
||||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||||
memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i]->data, (size_t)(pField->bytes * pRes->numOfRows));
|
memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i], (size_t)(pField->bytes * pRes->numOfRows));
|
||||||
offset += pField->bytes;
|
offset += pField->bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,7 +307,8 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
||||||
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
*((float *)payload) = (float)dv;
|
// *((float *)payload) = (float)dv;
|
||||||
|
SET_FLOAT_VAL(payload, dv);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1359,7 +1360,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
|
SSqlInfo SQLInfo = qSqlParse(pSql->sqlstr);
|
||||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||||
if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) {
|
if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) {
|
||||||
tscResetSqlCmd(pCmd, true);
|
tscResetSqlCmd(pCmd, true);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -497,8 +497,6 @@ int tscProcessSql(SSqlObj *pSql) {
|
||||||
return pSql->res.code;
|
return pSql->res.code;
|
||||||
}
|
}
|
||||||
} else if (pCmd->command >= TSDB_SQL_LOCAL) {
|
} else if (pCmd->command >= TSDB_SQL_LOCAL) {
|
||||||
//pSql->epSet = tscMgmtEpSet;
|
|
||||||
// } else { // local handler
|
|
||||||
return (*tscProcessMsgRsp[pCmd->command])(pSql);
|
return (*tscProcessMsgRsp[pCmd->command])(pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +643,6 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->epSet.inUse = rand()%pSql->epSet.numOfEps;
|
pSql->epSet.inUse = rand()%pSql->epSet.numOfEps;
|
||||||
|
|
||||||
pQueryMsg->head.vgId = htonl(vgId);
|
pQueryMsg->head.vgId = htonl(vgId);
|
||||||
|
|
||||||
STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg;
|
STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg;
|
||||||
|
@ -660,8 +657,6 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
|
||||||
int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables);
|
int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables);
|
||||||
assert(index >= 0 && index < numOfVgroups);
|
assert(index >= 0 && index < numOfVgroups);
|
||||||
|
|
||||||
tscDebug("%p query on stable, vgIndex:%d, numOfVgroups:%d", pSql, index, numOfVgroups);
|
|
||||||
|
|
||||||
SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, index);
|
SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, index);
|
||||||
|
|
||||||
// set the vgroup info
|
// set the vgroup info
|
||||||
|
@ -671,6 +666,9 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
|
||||||
int32_t numOfTables = (int32_t)taosArrayGetSize(pTableIdList->itemList);
|
int32_t numOfTables = (int32_t)taosArrayGetSize(pTableIdList->itemList);
|
||||||
pQueryMsg->numOfTables = htonl(numOfTables); // set the number of tables
|
pQueryMsg->numOfTables = htonl(numOfTables); // set the number of tables
|
||||||
|
|
||||||
|
tscDebug("%p query on stable, vgId:%d, numOfTables:%d, vgIndex:%d, numOfVgroups:%d", pSql,
|
||||||
|
pTableIdList->vgInfo.vgId, numOfTables, index, numOfVgroups);
|
||||||
|
|
||||||
// serialize each table id info
|
// serialize each table id info
|
||||||
for(int32_t i = 0; i < numOfTables; ++i) {
|
for(int32_t i = 0; i < numOfTables; ++i) {
|
||||||
STableIdInfo* pItem = taosArrayGet(pTableIdList->itemList, i);
|
STableIdInfo* pItem = taosArrayGet(pTableIdList->itemList, i);
|
||||||
|
@ -705,7 +703,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
|
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
|
||||||
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo)) {
|
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo) && !tscQueryBlockInfo(pQueryInfo)) {
|
||||||
tscError("%p illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", pSql, (uint64_t)numOfSrcCols,
|
tscError("%p illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", pSql, (uint64_t)numOfSrcCols,
|
||||||
tscGetNumOfColumns(pTableMeta));
|
tscGetNumOfColumns(pTableMeta));
|
||||||
|
|
||||||
|
@ -756,6 +754,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
pQueryMsg->vgroupLimit = htobe64(pQueryInfo->vgroupLimit);
|
pQueryMsg->vgroupLimit = htobe64(pQueryInfo->vgroupLimit);
|
||||||
pQueryMsg->sqlstrLen = htonl(sqlLen);
|
pQueryMsg->sqlstrLen = htonl(sqlLen);
|
||||||
pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen);
|
pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen);
|
||||||
|
pQueryMsg->sw.gap = htobe64(pQueryInfo->sessionWindow.gap);
|
||||||
|
pQueryMsg->sw.primaryColId = htonl(PRIMARYKEY_TIMESTAMP_COL_INDEX);
|
||||||
|
|
||||||
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
pQueryMsg->numOfOutput = htons((int16_t)numOfOutput); // this is the stage one output column number
|
pQueryMsg->numOfOutput = htons((int16_t)numOfOutput); // this is the stage one output column number
|
||||||
|
@ -835,13 +835,31 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
pSqlFuncExpr->colInfo.colIndex = htons(pExpr->colInfo.colIndex);
|
pSqlFuncExpr->colInfo.colIndex = htons(pExpr->colInfo.colIndex);
|
||||||
pSqlFuncExpr->colInfo.flag = htons(pExpr->colInfo.flag);
|
pSqlFuncExpr->colInfo.flag = htons(pExpr->colInfo.flag);
|
||||||
|
|
||||||
|
if (TSDB_COL_IS_UD_COL(pExpr->colInfo.flag)) {
|
||||||
|
pSqlFuncExpr->colType = htons(pExpr->resType);
|
||||||
|
pSqlFuncExpr->colBytes = htons(pExpr->resBytes);
|
||||||
|
} else if (pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
|
SSchema *s = tGetTbnameColumnSchema();
|
||||||
|
|
||||||
|
pSqlFuncExpr->colType = htons(s->type);
|
||||||
|
pSqlFuncExpr->colBytes = htons(s->bytes);
|
||||||
|
} else if (pExpr->colInfo.colId == TSDB_BLOCK_DIST_COLUMN_INDEX) {
|
||||||
|
SSchema s = tGetBlockDistColumnSchema();
|
||||||
|
|
||||||
|
pSqlFuncExpr->colType = htons(s.type);
|
||||||
|
pSqlFuncExpr->colBytes = htons(s.bytes);
|
||||||
|
} else {
|
||||||
|
SSchema* s = tscGetColumnSchemaById(pTableMeta, pExpr->colInfo.colId);
|
||||||
|
pSqlFuncExpr->colType = htons(s->type);
|
||||||
|
pSqlFuncExpr->colBytes = htons(s->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
pSqlFuncExpr->functionId = htons(pExpr->functionId);
|
pSqlFuncExpr->functionId = htons(pExpr->functionId);
|
||||||
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
|
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
|
||||||
pSqlFuncExpr->resColId = htons(pExpr->resColId);
|
pSqlFuncExpr->resColId = htons(pExpr->resColId);
|
||||||
pMsg += sizeof(SSqlFuncMsg);
|
pMsg += sizeof(SSqlFuncMsg);
|
||||||
|
|
||||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) {
|
for (int32_t j = 0; j < pExpr->numOfParams; ++j) { // todo add log
|
||||||
// todo add log
|
|
||||||
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
||||||
pSqlFuncExpr->arg[j].argBytes = htons(pExpr->param[j].nLen);
|
pSqlFuncExpr->arg[j].argBytes = htons(pExpr->param[j].nLen);
|
||||||
|
|
||||||
|
@ -866,6 +884,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
for (int32_t i = 0; i < output; ++i) {
|
for (int32_t i = 0; i < output; ++i) {
|
||||||
SInternalField* pField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i);
|
SInternalField* pField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i);
|
||||||
SSqlExpr *pExpr = pField->pSqlExpr;
|
SSqlExpr *pExpr = pField->pSqlExpr;
|
||||||
|
|
||||||
|
// this should be switched to projection query
|
||||||
if (pExpr != NULL) {
|
if (pExpr != NULL) {
|
||||||
// the queried table has been removed and a new table with the same name has already been created already
|
// the queried table has been removed and a new table with the same name has already been created already
|
||||||
// return error msg
|
// return error msg
|
||||||
|
@ -879,27 +899,25 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSqlFuncExpr1->colInfo.colId = htons(pExpr->colInfo.colId);
|
pSqlFuncExpr1->numOfParams = 0; // no params for projection query
|
||||||
pSqlFuncExpr1->colInfo.colIndex = htons(pExpr->colInfo.colIndex);
|
pSqlFuncExpr1->functionId = htons(TSDB_FUNC_PRJ);
|
||||||
pSqlFuncExpr1->colInfo.flag = htons(pExpr->colInfo.flag);
|
pSqlFuncExpr1->colInfo.colId = htons(pExpr->resColId);
|
||||||
|
pSqlFuncExpr1->colInfo.flag = htons(TSDB_COL_NORMAL);
|
||||||
|
|
||||||
pSqlFuncExpr1->functionId = htons(pExpr->functionId);
|
bool assign = false;
|
||||||
pSqlFuncExpr1->numOfParams = htons(pExpr->numOfParams);
|
for (int32_t f = 0; f < tscSqlExprNumOfExprs(pQueryInfo); ++f) {
|
||||||
|
SSqlExpr *pe = tscSqlExprGet(pQueryInfo, f);
|
||||||
|
if (pe == pExpr) {
|
||||||
|
pSqlFuncExpr1->colInfo.colIndex = htons(f);
|
||||||
|
pSqlFuncExpr1->colType = htons(pe->resType);
|
||||||
|
pSqlFuncExpr1->colBytes = htons(pe->resBytes);
|
||||||
|
assign = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(assign);
|
||||||
pMsg += sizeof(SSqlFuncMsg);
|
pMsg += sizeof(SSqlFuncMsg);
|
||||||
|
|
||||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) {
|
|
||||||
// todo add log
|
|
||||||
pSqlFuncExpr1->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
|
||||||
pSqlFuncExpr1->arg[j].argBytes = htons(pExpr->param[j].nLen);
|
|
||||||
|
|
||||||
if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) {
|
|
||||||
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
|
|
||||||
pMsg += pExpr->param[j].nLen;
|
|
||||||
} else {
|
|
||||||
pSqlFuncExpr1->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
|
pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
|
||||||
} else {
|
} else {
|
||||||
assert(pField->pArithExprInfo != NULL);
|
assert(pField->pArithExprInfo != NULL);
|
||||||
|
@ -1332,7 +1350,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &(pSql->cmd);
|
SSqlCmd *pCmd = &(pSql->cmd);
|
||||||
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg);
|
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg);
|
||||||
|
|
||||||
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
|
SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo;
|
||||||
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
|
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
|
||||||
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
|
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
|
||||||
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN);
|
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN);
|
||||||
|
@ -1341,7 +1359,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreateTableInfo->pSelect != NULL) {
|
if (pCreateTableInfo->pSelect != NULL) {
|
||||||
size += (pCreateTableInfo->pSelect->selectToken.n + 1);
|
size += (pCreateTableInfo->pSelect->sqlstr.n + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return size + TSDB_EXTRA_PAYLOAD_SIZE;
|
return size + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||||
|
@ -1399,7 +1417,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateMsg->tableName);
|
int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateMsg->tableName);
|
||||||
assert(code == 0);
|
assert(code == 0);
|
||||||
|
|
||||||
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
|
SCreateTableSql *pCreateTable = pInfo->pCreateTableInfo;
|
||||||
|
|
||||||
pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0;
|
pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0;
|
||||||
pCreateMsg->numOfColumns = htons(pCmd->numOfCols);
|
pCreateMsg->numOfColumns = htons(pCmd->numOfCols);
|
||||||
|
@ -1422,11 +1440,11 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
pMsg = (char *)pSchema;
|
pMsg = (char *)pSchema;
|
||||||
if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql
|
if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql
|
||||||
SQuerySQL *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
SQuerySqlNode *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
||||||
|
|
||||||
strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1);
|
strncpy(pMsg, pQuerySql->sqlstr.z, pQuerySql->sqlstr.n + 1);
|
||||||
pCreateMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
|
pCreateMsg->sqlLen = htons(pQuerySql->sqlstr.n + 1);
|
||||||
pMsg += pQuerySql->selectToken.n + 1;
|
pMsg += pQuerySql->sqlstr.n + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -503,9 +503,19 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
if (taosArrayGetSize(pSub->progress) > 0) { // fix crash in single tabel subscription
|
if (taosArrayGetSize(pSub->progress) > 0) { // fix crash in single table subscription
|
||||||
pQueryInfo->window.skey = ((SSubscriptionProgress*)taosArrayGet(pSub->progress, 0))->key;
|
|
||||||
tscDebug("subscribe:%s set subscribe skey:%"PRId64, pSub->topic, pQueryInfo->window.skey);
|
size_t size = taosArrayGetSize(pSub->progress);
|
||||||
|
TSKEY s = INT64_MAX;
|
||||||
|
for(int32_t i = 0; i < size; ++i) {
|
||||||
|
TSKEY k = ((SSubscriptionProgress*)taosArrayGet(pSub->progress, i))->key;
|
||||||
|
if (s > k) {
|
||||||
|
s = k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pQueryInfo->window.skey = s;
|
||||||
|
tscDebug("subscribe:%s set next round subscribe skey:%"PRId64, pSub->topic, pQueryInfo->window.skey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSub->pTimer == NULL) {
|
if (pSub->pTimer == NULL) {
|
||||||
|
|
|
@ -74,14 +74,14 @@ static bool allSubqueryDone(SSqlObj *pParentSql) {
|
||||||
SSubqueryState *subState = &pParentSql->subState;
|
SSubqueryState *subState = &pParentSql->subState;
|
||||||
|
|
||||||
//lock in caller
|
//lock in caller
|
||||||
|
tscDebug("%p total subqueries: %d", pParentSql, subState->numOfSub);
|
||||||
for (int i = 0; i < subState->numOfSub; i++) {
|
for (int i = 0; i < subState->numOfSub; i++) {
|
||||||
if (0 == subState->states[i]) {
|
if (0 == subState->states[i]) {
|
||||||
tscDebug("%p subquery:%p,%d is NOT finished, total:%d", pParentSql, pParentSql->pSubs[i], i, subState->numOfSub);
|
tscDebug("%p subquery:%p, index: %d NOT finished, abort query completion check", pParentSql, pParentSql->pSubs[i], i);
|
||||||
done = false;
|
done = false;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
tscDebug("%p subquery:%p,%d is finished, total:%d", pParentSql, pParentSql->pSubs[i], i, subState->numOfSub);
|
tscDebug("%p subquery:%p, index: %d finished", pParentSql, pParentSql->pSubs[i], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
||||||
pSubQueryInfo->tsBuf = NULL;
|
pSubQueryInfo->tsBuf = NULL;
|
||||||
|
|
||||||
// free result for async object will also free sqlObj
|
// free result for async object will also free sqlObj
|
||||||
assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one resutl columns
|
assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one result columns
|
||||||
taos_free_result(pPrevSub);
|
taos_free_result(pPrevSub);
|
||||||
|
|
||||||
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
|
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
|
||||||
|
@ -507,6 +507,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||||
int16_t funcId = pExpr->functionId;
|
int16_t funcId = pExpr->functionId;
|
||||||
|
|
||||||
|
// add the invisible timestamp column
|
||||||
if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) ||
|
if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) ||
|
||||||
(funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) {
|
(funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) {
|
||||||
|
|
||||||
|
@ -847,6 +848,8 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
||||||
SSqlRes* pRes = &pSql->res;
|
SSqlRes* pRes = &pSql->res;
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
|
|
||||||
|
// todo, the type may not include TSDB_QUERY_TYPE_TAG_FILTER_QUERY
|
||||||
assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY));
|
assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY));
|
||||||
|
|
||||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1059,7 +1062,6 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
||||||
tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
|
tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
|
||||||
|
|
||||||
pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
||||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)){
|
if (quitAllSubquery(pSql, pParentSql, pSupporter)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1880,6 +1882,13 @@ void doAppendData(SInterResult* pInterResult, TAOS_ROW row, int32_t numOfCols, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p && taosArrayGetSize(p) > 0) {
|
||||||
|
SResPair *l = taosArrayGetLast(p);
|
||||||
|
if (l->key == key && key == INT64_MIN) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//append a new column
|
//append a new column
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
SStddevInterResult t = {.colId = id, .pResult = taosArrayInit(10, sizeof(SResPair)),};
|
SStddevInterResult t = {.colId = id, .pResult = taosArrayInit(10, sizeof(SResPair)),};
|
||||||
|
@ -2643,6 +2652,11 @@ static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsuppo
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
||||||
|
|
||||||
pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY;
|
pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY;
|
||||||
|
|
||||||
|
// clear the limit/offset info, since it should not be sent to vnode to be executed.
|
||||||
|
pQueryInfo->limit.limit = -1;
|
||||||
|
pQueryInfo->limit.offset = 0;
|
||||||
|
|
||||||
assert(pQueryInfo->numOfTables == 1 && pNew->cmd.numOfClause == 1 && trsupport->subqueryIndex < pSql->subState.numOfSub);
|
assert(pQueryInfo->numOfTables == 1 && pNew->cmd.numOfClause == 1 && trsupport->subqueryIndex < pSql->subState.numOfSub);
|
||||||
|
|
||||||
// launch subquery for each vnode, so the subquery index equals to the vgroupIndex.
|
// launch subquery for each vnode, so the subquery index equals to the vgroupIndex.
|
||||||
|
@ -3102,30 +3116,6 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static UNUSED_FUNC void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pField) {
|
|
||||||
SSqlRes *pRes = &pSql->res;
|
|
||||||
|
|
||||||
if (pRes->tsrow[columnIndex] != NULL && pField->type == TSDB_DATA_TYPE_NCHAR) {
|
|
||||||
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
|
|
||||||
if (pRes->buffer[columnIndex] == NULL) {
|
|
||||||
pRes->buffer[columnIndex] = malloc(pField->bytes + TSDB_NCHAR_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* string terminated char for binary data*/
|
|
||||||
memset(pRes->buffer[columnIndex], 0, pField->bytes + TSDB_NCHAR_SIZE);
|
|
||||||
|
|
||||||
int32_t length = taosUcs4ToMbs(pRes->tsrow[columnIndex], pRes->length[columnIndex], pRes->buffer[columnIndex]);
|
|
||||||
if ( length >= 0 ) {
|
|
||||||
pRes->tsrow[columnIndex] = (unsigned char*)pRes->buffer[columnIndex];
|
|
||||||
pRes->length[columnIndex] = length;
|
|
||||||
} else {
|
|
||||||
tscError("%p charset:%s to %s. val:%s convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)pRes->tsrow[columnIndex]);
|
|
||||||
pRes->tsrow[columnIndex] = NULL;
|
|
||||||
pRes->length[columnIndex] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) {
|
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) {
|
||||||
SArithmeticSupport *pSupport = (SArithmeticSupport *) param;
|
SArithmeticSupport *pSupport = (SArithmeticSupport *) param;
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,22 @@ bool tscQueryTags(SQueryInfo* pQueryInfo) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo) {
|
||||||
|
int32_t numOfCols = (int32_t) tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
int32_t functId = pExpr->functionId;
|
||||||
|
|
||||||
|
// "select count(tbname)" query
|
||||||
|
if (functId == TSDB_FUNC_BLKINFO) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
if (pQueryInfo == NULL) {
|
if (pQueryInfo == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -223,6 +239,21 @@ bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tscGroupbyColumn(SQueryInfo* pQueryInfo) {
|
||||||
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
int32_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
SSqlGroupbyExpr* pGroupbyExpr = &pQueryInfo->groupbyExpr;
|
||||||
|
for (int32_t k = 0; k < pGroupbyExpr->numOfGroupCols; ++k) {
|
||||||
|
SColIndex* pIndex = taosArrayGet(pGroupbyExpr->columnInfo, k);
|
||||||
|
if (!TSDB_COL_IS_TAG(pIndex->flag) && pIndex->colIndex < numOfCols) { // group by normal columns
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
|
bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
|
||||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||||
|
@ -1726,6 +1757,11 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
|
||||||
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
||||||
pQueryInfo->udColumnId = TSDB_UD_COLUMN_INDEX;
|
pQueryInfo->udColumnId = TSDB_UD_COLUMN_INDEX;
|
||||||
pQueryInfo->resColumnId = -1000;
|
pQueryInfo->resColumnId = -1000;
|
||||||
|
pQueryInfo->limit.limit = -1;
|
||||||
|
pQueryInfo->limit.offset = 0;
|
||||||
|
|
||||||
|
pQueryInfo->slimit.limit = -1;
|
||||||
|
pQueryInfo->slimit.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
||||||
|
|
|
@ -283,12 +283,37 @@ typedef struct {
|
||||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
|
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
|
||||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||||
#define dataColsTKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, 0))
|
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
|
||||||
#define dataColsKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, 0))
|
if (pCols->numOfRows) {
|
||||||
#define dataColsTKeyLast(pCols) \
|
return dataColsTKeyAt(pCols, 0);
|
||||||
(((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, (pCols)->numOfRows - 1))
|
} else {
|
||||||
#define dataColsKeyLast(pCols) \
|
return TKEY_INVALID;
|
||||||
(((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, (pCols)->numOfRows - 1))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE TSKEY dataColsKeyFirst(SDataCols *pCols) {
|
||||||
|
if (pCols->numOfRows) {
|
||||||
|
return dataColsKeyAt(pCols, 0);
|
||||||
|
} else {
|
||||||
|
return TSDB_DATA_TIMESTAMP_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE TKEY dataColsTKeyLast(SDataCols *pCols) {
|
||||||
|
if (pCols->numOfRows) {
|
||||||
|
return dataColsTKeyAt(pCols, pCols->numOfRows - 1);
|
||||||
|
} else {
|
||||||
|
return TKEY_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) {
|
||||||
|
if (pCols->numOfRows) {
|
||||||
|
return dataColsKeyAt(pCols, pCols->numOfRows - 1);
|
||||||
|
} else {
|
||||||
|
return TSDB_DATA_TIMESTAMP_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows);
|
SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows);
|
||||||
void tdResetDataCols(SDataCols *pCols);
|
void tdResetDataCols(SDataCols *pCols);
|
||||||
|
|
|
@ -33,7 +33,7 @@ typedef struct SDataStatis {
|
||||||
|
|
||||||
typedef struct SColumnInfoData {
|
typedef struct SColumnInfoData {
|
||||||
SColumnInfo info;
|
SColumnInfo info;
|
||||||
void* pData; // the corresponding block data in memory
|
char* pData; // the corresponding block data in memory
|
||||||
} SColumnInfoData;
|
} SColumnInfoData;
|
||||||
|
|
||||||
typedef struct SResPair {
|
typedef struct SResPair {
|
||||||
|
|
|
@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
|
||||||
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.21-dist.jar ${LIBRARY_OUTPUT_PATH}
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.22-dist.jar ${LIBRARY_OUTPUT_PATH}
|
||||||
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||||
COMMENT "build jdbc driver")
|
COMMENT "build jdbc driver")
|
||||||
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.21</version>
|
<version>2.0.22</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.21</version>
|
<version>2.0.22</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
|
@ -102,6 +102,8 @@
|
||||||
<include>**/*Test.java</include>
|
<include>**/*Test.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
<excludes>
|
<excludes>
|
||||||
|
<exclude>**/TSDBJNIConnectorTest.java</exclude>
|
||||||
|
<exclude>**/UnsignedNumberJniTest.java</exclude>
|
||||||
<exclude>**/DatetimeBefore1970Test.java</exclude>
|
<exclude>**/DatetimeBefore1970Test.java</exclude>
|
||||||
<exclude>**/AppMemoryLeakTest.java</exclude>
|
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||||
<exclude>**/AuthenticationTest.java</exclude>
|
<exclude>**/AuthenticationTest.java</exclude>
|
||||||
|
|
|
@ -12,7 +12,7 @@ public abstract class AbstractDriver implements Driver {
|
||||||
hostProp.required = false;
|
hostProp.required = false;
|
||||||
hostProp.description = "Hostname";
|
hostProp.description = "Hostname";
|
||||||
|
|
||||||
DriverPropertyInfo portProp = new DriverPropertyInfo(TSDBDriver.PROPERTY_KEY_PORT, info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
DriverPropertyInfo portProp = new DriverPropertyInfo(TSDBDriver.PROPERTY_KEY_PORT, info.getProperty(TSDBDriver.PROPERTY_KEY_PORT));
|
||||||
portProp.required = false;
|
portProp.required = false;
|
||||||
portProp.description = "Port";
|
portProp.description = "Port";
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ public abstract class AbstractDriver implements Driver {
|
||||||
protected Properties parseURL(String url, Properties defaults) {
|
protected Properties parseURL(String url, Properties defaults) {
|
||||||
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
||||||
|
|
||||||
// parse properties
|
// parse properties in url
|
||||||
int beginningOfSlashes = url.indexOf("//");
|
int beginningOfSlashes = url.indexOf("//");
|
||||||
int index = url.indexOf("?");
|
int index = url.indexOf("?");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
String paramString = url.substring(index + 1, url.length());
|
String paramString = url.substring(index + 1);
|
||||||
url = url.substring(0, index);
|
url = url.substring(0, index);
|
||||||
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
||||||
while (queryParams.hasMoreElements()) {
|
while (queryParams.hasMoreElements()) {
|
||||||
|
@ -68,6 +68,7 @@ public abstract class AbstractDriver implements Driver {
|
||||||
String dbProductName = url.substring(0, beginningOfSlashes);
|
String dbProductName = url.substring(0, beginningOfSlashes);
|
||||||
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
||||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||||
|
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PRODUCT_NAME,dbProductName);
|
||||||
// parse dbname
|
// parse dbname
|
||||||
url = url.substring(beginningOfSlashes + 2);
|
url = url.substring(beginningOfSlashes + 2);
|
||||||
int indexOfSlash = url.indexOf("/");
|
int indexOfSlash = url.indexOf("/");
|
||||||
|
|
|
@ -29,12 +29,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
||||||
public abstract boolean getBoolean(int columnIndex) throws SQLException;
|
public abstract boolean getBoolean(int columnIndex) throws SQLException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getByte(int columnIndex) throws SQLException {
|
public abstract byte getByte(int columnIndex) throws SQLException;
|
||||||
if (isClosed())
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
|
||||||
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract short getShort(int columnIndex) throws SQLException;
|
public abstract short getShort(int columnIndex) throws SQLException;
|
||||||
|
@ -1205,6 +1200,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
||||||
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); }
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,8 +122,7 @@ public class SavedPreparedStatement {
|
||||||
initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize);
|
initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// not match
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("the sql is not complete!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -189,7 +188,7 @@ public class SavedPreparedStatement {
|
||||||
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize);
|
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize);
|
||||||
|
|
||||||
if (parameterIndex < 1 || parameterIndex > paramSize) {
|
if (parameterIndex < 1 || parameterIndex > paramSize) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE,errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isAddBatch = false; //set isAddBatch to false
|
this.isAddBatch = false; //set isAddBatch to false
|
||||||
|
@ -212,7 +211,7 @@ public class SavedPreparedStatement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE,errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBatch() {
|
public void addBatch() {
|
||||||
|
|
|
@ -16,16 +16,11 @@ package com.taosdata.jdbc;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class TSDBConstants {
|
public abstract class TSDBConstants {
|
||||||
|
|
||||||
public static final String DEFAULT_PORT = "6200";
|
|
||||||
public static Map<Integer, String> DATATYPE_MAP = null;
|
|
||||||
|
|
||||||
public static final long JNI_NULL_POINTER = 0L;
|
public static final long JNI_NULL_POINTER = 0L;
|
||||||
|
// JNI_ERROR_NUMBER
|
||||||
public static final int JNI_SUCCESS = 0;
|
public static final int JNI_SUCCESS = 0;
|
||||||
public static final int JNI_TDENGINE_ERROR = -1;
|
public static final int JNI_TDENGINE_ERROR = -1;
|
||||||
public static final int JNI_CONNECTION_NULL = -2;
|
public static final int JNI_CONNECTION_NULL = -2;
|
||||||
|
@ -34,8 +29,7 @@ public abstract class TSDBConstants {
|
||||||
public static final int JNI_SQL_NULL = -5;
|
public static final int JNI_SQL_NULL = -5;
|
||||||
public static final int JNI_FETCH_END = -6;
|
public static final int JNI_FETCH_END = -6;
|
||||||
public static final int JNI_OUT_OF_MEMORY = -7;
|
public static final int JNI_OUT_OF_MEMORY = -7;
|
||||||
|
// TSDB Data Types
|
||||||
public static final int TSDB_DATA_TYPE_NULL = 0;
|
|
||||||
public static final int TSDB_DATA_TYPE_BOOL = 1;
|
public static final int TSDB_DATA_TYPE_BOOL = 1;
|
||||||
public static final int TSDB_DATA_TYPE_TINYINT = 2;
|
public static final int TSDB_DATA_TYPE_TINYINT = 2;
|
||||||
public static final int TSDB_DATA_TYPE_SMALLINT = 3;
|
public static final int TSDB_DATA_TYPE_SMALLINT = 3;
|
||||||
|
@ -46,46 +40,36 @@ public abstract class TSDBConstants {
|
||||||
public static final int TSDB_DATA_TYPE_BINARY = 8;
|
public static final int TSDB_DATA_TYPE_BINARY = 8;
|
||||||
public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
|
public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
|
||||||
public static final int TSDB_DATA_TYPE_NCHAR = 10;
|
public static final int TSDB_DATA_TYPE_NCHAR = 10;
|
||||||
|
/*
|
||||||
// nchar field's max length
|
系统增加新的无符号数据类型,分别是:
|
||||||
|
unsigned tinyint, 数值范围:0-254, NULL 为255
|
||||||
|
unsigned smallint,数值范围: 0-65534, NULL 为65535
|
||||||
|
unsigned int,数值范围:0-4294967294,NULL 为4294967295u
|
||||||
|
unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
|
||||||
|
example:
|
||||||
|
create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
|
||||||
|
*/
|
||||||
|
public static final int TSDB_DATA_TYPE_UTINYINT = 11; //unsigned tinyint
|
||||||
|
public static final int TSDB_DATA_TYPE_USMALLINT = 12; //unsigned smallint
|
||||||
|
public static final int TSDB_DATA_TYPE_UINT = 13; //unsigned int
|
||||||
|
public static final int TSDB_DATA_TYPE_UBIGINT = 14; //unsigned bigint
|
||||||
|
// nchar column max length
|
||||||
public static final int maxFieldSize = 16 * 1024;
|
public static final int maxFieldSize = 16 * 1024;
|
||||||
|
|
||||||
public static String WrapErrMsg(String msg) {
|
|
||||||
return "TDengine Error: " + msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String FixErrMsg(int code) {
|
|
||||||
switch (code) {
|
|
||||||
case JNI_TDENGINE_ERROR:
|
|
||||||
return WrapErrMsg("internal error of database!");
|
|
||||||
case JNI_CONNECTION_NULL:
|
|
||||||
return WrapErrMsg("invalid tdengine connection!");
|
|
||||||
case JNI_RESULT_SET_NULL:
|
|
||||||
return WrapErrMsg("invalid resultset pointer!");
|
|
||||||
case JNI_NUM_OF_FIELDS_0:
|
|
||||||
return WrapErrMsg("invalid num of fields!");
|
|
||||||
case JNI_SQL_NULL:
|
|
||||||
return WrapErrMsg("can't execute empty sql!");
|
|
||||||
case JNI_FETCH_END:
|
|
||||||
return WrapErrMsg("fetch to the end of resultset");
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return WrapErrMsg("unkown error!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int taosType2JdbcType(int taosType) throws SQLException {
|
public static int taosType2JdbcType(int taosType) throws SQLException {
|
||||||
switch (taosType) {
|
switch (taosType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NULL:
|
|
||||||
return Types.NULL;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Types.BOOLEAN;
|
return Types.BOOLEAN;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
return Types.TINYINT;
|
return Types.TINYINT;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return Types.SMALLINT;
|
return Types.SMALLINT;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return Types.INTEGER;
|
return Types.INTEGER;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return Types.BIGINT;
|
return Types.BIGINT;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
@ -99,13 +83,42 @@ public abstract class TSDBConstants {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
return Types.NCHAR;
|
return Types.NCHAR;
|
||||||
}
|
}
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String taosType2JdbcTypeName(int taosType) throws SQLException {
|
||||||
|
switch (taosType){
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
|
return "BOOL";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return "TINYINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return "SMALLINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return "INT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return "BIGINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
return "FLOAT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return "DOUBLE";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return "BINARY";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
return "TIMESTAMP";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
return "NCHAR";
|
||||||
|
default:
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int jdbcType2TaosType(int jdbcType) throws SQLException {
|
public static int jdbcType2TaosType(int jdbcType) throws SQLException {
|
||||||
switch (jdbcType){
|
switch (jdbcType){
|
||||||
case Types.NULL:
|
|
||||||
return TSDBConstants.TSDB_DATA_TYPE_NULL;
|
|
||||||
case Types.BOOLEAN:
|
case Types.BOOLEAN:
|
||||||
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
|
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
|
@ -130,22 +143,31 @@ public abstract class TSDBConstants {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException {
|
||||||
DATATYPE_MAP = new HashMap<>();
|
switch (jdbcType){
|
||||||
DATATYPE_MAP.put(0, "NULL");
|
case Types.BOOLEAN:
|
||||||
DATATYPE_MAP.put(1, "BOOL");
|
return "BOOL";
|
||||||
DATATYPE_MAP.put(2, "TINYINT");
|
case Types.TINYINT:
|
||||||
DATATYPE_MAP.put(3, "SMALLINT");
|
return "TINYINT";
|
||||||
DATATYPE_MAP.put(4, "INT");
|
case Types.SMALLINT:
|
||||||
DATATYPE_MAP.put(5, "BIGINT");
|
return "SMALLINT";
|
||||||
DATATYPE_MAP.put(6, "FLOAT");
|
case Types.INTEGER:
|
||||||
DATATYPE_MAP.put(7, "DOUBLE");
|
return "INT";
|
||||||
DATATYPE_MAP.put(8, "BINARY");
|
case Types.BIGINT:
|
||||||
DATATYPE_MAP.put(9, "TIMESTAMP");
|
return "BIGINT";
|
||||||
DATATYPE_MAP.put(10, "NCHAR");
|
case Types.FLOAT:
|
||||||
|
return "FLOAT";
|
||||||
|
case Types.DOUBLE:
|
||||||
|
return "DOUBLE";
|
||||||
|
case Types.BINARY:
|
||||||
|
return "BINARY";
|
||||||
|
case Types.TIMESTAMP:
|
||||||
|
return "TIMESTAMP";
|
||||||
|
case Types.NCHAR:
|
||||||
|
return "NCHAR";
|
||||||
|
default:
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String jdbcType2TaosTypeName(int type) throws SQLException {
|
|
||||||
return DATATYPE_MAP.get(jdbcType2TaosType(type));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
|
|
||||||
private static final String URL_PREFIX = "jdbc:TAOS://";
|
private static final String URL_PREFIX = "jdbc:TAOS://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PRODUCT_NAME
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_PRODUCT_NAME = "productName";
|
||||||
/**
|
/**
|
||||||
* Key used to retrieve the host value from the properties instance passed to
|
* Key used to retrieve the host value from the properties instance passed to
|
||||||
* the driver.
|
* the driver.
|
||||||
|
@ -96,38 +100,34 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
||||||
} catch (SQLException E) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!"));
|
throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
|
|
||||||
if (!acceptsURL(url))
|
if (!acceptsURL(url))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Properties props = null;
|
Properties props = parseURL(url, info);
|
||||||
if ((props = parseURL(url, info)) == null) {
|
if (props == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE),
|
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE),
|
||||||
(String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE));
|
(String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE));
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
return new TSDBConnection(props, this.dbMetaData);
|
||||||
return newConn;
|
|
||||||
} catch (SQLWarning sqlWarning) {
|
} catch (SQLWarning sqlWarning) {
|
||||||
sqlWarning.printStackTrace();
|
sqlWarning.printStackTrace();
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
return new TSDBConnection(props, this.dbMetaData);
|
||||||
return newConn;
|
|
||||||
} catch (SQLException sqlEx) {
|
} catch (SQLException sqlEx) {
|
||||||
throw sqlEx;
|
throw sqlEx;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SQLException sqlEx = new SQLException("SQLException:" + ex.toString());
|
throw new SQLException("SQLException:" + ex.toString(), ex);
|
||||||
sqlEx.initCause(ex);
|
|
||||||
throw sqlEx;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,8 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
*/
|
*/
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
return url.length() > 0 && url.trim().length() > 0 && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.taosdata.jdbc;
|
||||||
import java.sql.SQLClientInfoException;
|
import java.sql.SQLClientInfoException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLFeatureNotSupportedException;
|
import java.sql.SQLFeatureNotSupportedException;
|
||||||
|
import java.sql.SQLWarning;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -18,18 +19,25 @@ public class TSDBError {
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "invalid sql for executeQuery: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "invalid sql for executeUpdate: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "invalid sql for execute: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE, "unknown sql type in tdengine");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, "can't register JDBC-JNI driver");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_RESTFUL_DRIVER, "can't register JDBC-RESTful driver");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_URL_NOT_SET, "url is not set");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_SQL, "invalid sql");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE, "numeric value out of range");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE, "unknown taos type in tdengine");
|
||||||
|
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
|
||||||
|
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection is NULL");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection is NULL");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "JNI result set is NULL");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "JNI result set is NULL");
|
||||||
|
@ -65,4 +73,12 @@ public class TSDBError {
|
||||||
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
|
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RuntimeException createRuntimeException(int errorCode, Throwable t) {
|
||||||
|
String message = TSDBErrorMap.get(errorCode);
|
||||||
|
return new RuntimeException("ERROR (" + Integer.toHexString(errorCode) + "): " + message, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SQLWarning createSQLWarning(String message) {
|
||||||
|
return new SQLWarning(message);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,12 +19,17 @@ public class TSDBErrorNumbers {
|
||||||
public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
|
public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
|
||||||
public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
|
public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
|
||||||
public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
|
public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
|
||||||
|
public static final int ERROR_CANNOT_REGISTER_JNI_DRIVER = 0x2310; // can't register JDBC-JNI driver
|
||||||
|
public static final int ERROR_CANNOT_REGISTER_RESTFUL_DRIVER = 0x2311; // can't register JDBC-RESTful driver
|
||||||
|
public static final int ERROR_URL_NOT_SET = 0x2312; // url is not set
|
||||||
|
public static final int ERROR_INVALID_SQL = 0x2313; // invalid sql
|
||||||
|
public static final int ERROR_NUMERIC_VALUE_OUT_OF_RANGE = 0x2314; // numeric value out of range
|
||||||
|
public static final int ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE = 0x2315; //unknown taos type in tdengine
|
||||||
|
|
||||||
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
||||||
|
|
||||||
public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
|
public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
|
||||||
public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; // Unsupported encoding
|
public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; // Unsupported encoding
|
||||||
|
|
||||||
public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353; // internal error of database
|
public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353; // internal error of database
|
||||||
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
|
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
|
||||||
public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355; // invalid JNI result set
|
public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355; // invalid JNI result set
|
||||||
|
@ -51,11 +56,16 @@ public class TSDBErrorNumbers {
|
||||||
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
|
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
|
||||||
errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
|
errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
|
||||||
errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
|
errorNumbers.add(ERROR_CANNOT_REGISTER_JNI_DRIVER);
|
||||||
|
errorNumbers.add(ERROR_CANNOT_REGISTER_RESTFUL_DRIVER);
|
||||||
|
errorNumbers.add(ERROR_URL_NOT_SET);
|
||||||
|
errorNumbers.add(ERROR_INVALID_SQL);
|
||||||
|
errorNumbers.add(ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
errorNumbers.add(ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
|
||||||
/*****************************************************/
|
/*****************************************************/
|
||||||
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
||||||
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
||||||
|
|
||||||
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
|
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
|
||||||
errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
|
errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
|
||||||
errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
|
errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
|
||||||
|
@ -63,7 +73,6 @@ public class TSDBErrorNumbers {
|
||||||
errorNumbers.add(ERROR_JNI_SQL_NULL);
|
errorNumbers.add(ERROR_JNI_SQL_NULL);
|
||||||
errorNumbers.add(ERROR_JNI_FETCH_END);
|
errorNumbers.add(ERROR_JNI_FETCH_END);
|
||||||
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
|
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TSDBErrorNumbers() {
|
private TSDBErrorNumbers() {
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
/**
|
/**
|
||||||
* *************************************************************************
|
* *************************************************************************
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
*
|
* <p>
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
**************************************************************************** */
|
* ***************************************************************************
|
||||||
|
*/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import com.taosdata.jdbc.utils.TaosInfo;
|
import com.taosdata.jdbc.utils.TaosInfo;
|
||||||
|
@ -23,7 +24,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JNI connector
|
* JNI connector
|
||||||
* */
|
*/
|
||||||
public class TSDBJNIConnector {
|
public class TSDBJNIConnector {
|
||||||
private static volatile Boolean isInitialized = false;
|
private static volatile Boolean isInitialized = false;
|
||||||
|
|
||||||
|
@ -72,13 +73,13 @@ public class TSDBJNIConnector {
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
initImp(configDir);
|
initImp(configDir);
|
||||||
if (setOptions(0, locale) < 0) {
|
if (setOptions(0, locale) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set locale: " + locale + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set locale: " + locale + ". System default will be used.");
|
||||||
}
|
}
|
||||||
if (setOptions(1, charset) < 0) {
|
if (setOptions(1, charset) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set charset: " + charset + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used.");
|
||||||
}
|
}
|
||||||
if (setOptions(2, timezone) < 0) {
|
if (setOptions(2, timezone) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set timezone: " + timezone + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used.");
|
||||||
}
|
}
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
TaosGlobalConfig.setCharset(getTsCharset());
|
TaosGlobalConfig.setCharset(getTsCharset());
|
||||||
|
|
|
@ -27,8 +27,8 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
private final TSDBResultSetRowData rowData;
|
private final TSDBResultSetRowData rowData;
|
||||||
private final TSDBResultSetBlockData blockData;
|
private final TSDBResultSetBlockData blockData;
|
||||||
|
|
||||||
private boolean batchFetch = false;
|
private boolean batchFetch;
|
||||||
private boolean lastWasNull = false;
|
private boolean lastWasNull;
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
|
||||||
public void setBatchFetch(boolean batchFetch) {
|
public void setBatchFetch(boolean batchFetch) {
|
||||||
|
@ -86,7 +86,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (rowData != null) {
|
if (rowData != null) {
|
||||||
this.rowData.clear();
|
this.rowData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
|
int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
|
||||||
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
|
@ -124,30 +123,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
String res = null;
|
String res = null;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getString(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return this.blockData.getString(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||||
boolean res = false;
|
boolean res = false;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getBoolean(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return this.blockData.getBoolean(colIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,91 +151,84 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
byte res = 0;
|
byte res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return (byte) this.blockData.getInt(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return (byte) this.blockData.getInt(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getShort(int columnIndex) throws SQLException {
|
public short getShort(int columnIndex) throws SQLException {
|
||||||
short res = 0;
|
short res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return (short) this.blockData.getInt(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return (short) this.blockData.getInt(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(int columnIndex) throws SQLException {
|
public int getInt(int columnIndex) throws SQLException {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getInt(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return this.blockData.getInt(colIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(int columnIndex) throws SQLException {
|
public long getLong(int columnIndex) throws SQLException {
|
||||||
long res = 0L;
|
long res = 0L;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getLong(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return this.blockData.getLong(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat(int columnIndex) throws SQLException {
|
public float getFloat(int columnIndex) throws SQLException {
|
||||||
float res = 0;
|
float res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return (float) this.blockData.getDouble(colIndex);
|
return (float) this.blockData.getDouble(colIndex);
|
||||||
}
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull)
|
||||||
|
res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(int columnIndex) throws SQLException {
|
public double getDouble(int columnIndex) throws SQLException {
|
||||||
double res = 0;
|
double res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getDouble(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return this.blockData.getDouble(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -255,15 +244,14 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
Timestamp res = null;
|
Timestamp res = null;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.getTimestamp(columnIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getTimestamp(colIndex);
|
res = this.rowData.getTimestamp(colIndex);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else {
|
|
||||||
return this.blockData.getTimestamp(columnIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSetMetaData getMetaData() throws SQLException {
|
public ResultSetMetaData getMetaData() throws SQLException {
|
||||||
|
@ -274,12 +262,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public Object getObject(int columnIndex) throws SQLException {
|
public Object getObject(int columnIndex) throws SQLException {
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
|
return this.blockData.get(colIndex);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
return this.rowData.get(colIndex);
|
return this.rowData.get(colIndex);
|
||||||
} else {
|
|
||||||
return this.blockData.get(colIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -100,24 +100,28 @@ public class TSDBResultSetBlockData {
|
||||||
this.colData.set(col, buf);
|
this.colData.set(col, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.colData.set(col, buf);
|
this.colData.set(col, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||||
this.colData.set(col, sb);
|
this.colData.set(col, sb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
||||||
this.colData.set(col, ib);
|
this.colData.set(col, ib);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||||
|
|
|
@ -126,34 +126,12 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
|
||||||
|
|
||||||
public int getColumnType(int column) throws SQLException {
|
public int getColumnType(int column) throws SQLException {
|
||||||
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
||||||
switch (meta.getColType()) {
|
return TSDBConstants.taosType2JdbcType(meta.getColType());
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
|
||||||
return Types.BOOLEAN;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
return java.sql.Types.TINYINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
|
||||||
return java.sql.Types.SMALLINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
|
||||||
return java.sql.Types.INTEGER;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
|
||||||
return java.sql.Types.BIGINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
|
||||||
return java.sql.Types.FLOAT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
return java.sql.Types.DOUBLE;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
|
||||||
return Types.BINARY;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
return java.sql.Types.TIMESTAMP;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
|
||||||
return Types.NCHAR;
|
|
||||||
}
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnTypeName(int column) throws SQLException {
|
public String getColumnTypeName(int column) throws SQLException {
|
||||||
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
||||||
return TSDBConstants.DATATYPE_MAP.get(meta.getColType());
|
return TSDBConstants.taosType2JdbcTypeName(meta.getColType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReadOnly(int column) throws SQLException {
|
public boolean isReadOnly(int column) throws SQLException {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -55,14 +56,21 @@ public class TSDBResultSetRowData {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj) == 1.0? Boolean.TRUE:Boolean.FALSE;
|
return (Boolean) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj) == 1.0? Boolean.TRUE:Boolean.FALSE;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return ((Byte) obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return ((Short)obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return ((Integer)obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
return ((Double) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L? Boolean.TRUE:Boolean.FALSE;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
@ -84,16 +92,48 @@ public class TSDBResultSetRowData {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue();
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double)obj).intValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return ((Float) obj).intValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).intValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return (Byte) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj).intValue();
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return ((Long) obj).intValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj);
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return Integer.parseInt((String) obj);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = (byte) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
short value = (short) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
int value = (int) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
long value = (long) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return new Long(value).intValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -107,16 +147,48 @@ public class TSDBResultSetRowData {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).longValue();
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).longValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return ((Float) obj).longValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).longValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return (Byte) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj);
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return Long.parseLong((String) obj);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = (byte) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
short value = (short) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
int value = (int) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
long value = (long) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -130,14 +202,21 @@ public class TSDBResultSetRowData {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).floatValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return (Float) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).floatValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return (Byte) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -151,14 +230,21 @@ public class TSDBResultSetRowData {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return (Double) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return (Float) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return (Double) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return (Byte) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -178,14 +264,42 @@ public class TSDBResultSetRowData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The original type may not be a string type, but will be converted to by calling this method
|
* The original type may not be a string type, but will be converted to by calling this method
|
||||||
|
*
|
||||||
* @param col column index
|
* @param col column index
|
||||||
* @return
|
* @return
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public String getString(int col, int srcType) throws SQLException {
|
public String getString(int col, int srcType) throws SQLException {
|
||||||
if (srcType == TSDBConstants.TSDB_DATA_TYPE_BINARY || srcType == TSDBConstants.TSDB_DATA_TYPE_NCHAR) {
|
switch (srcType) {
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
return (String) data.get(col);
|
return (String) data.get(col);
|
||||||
} else {
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = new Byte(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Integer.toString(value & 0xff);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
Short value = new Short(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Integer.toString(value & 0xffff);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
Integer value = new Integer(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Long.toString(value & 0xffffffffl);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
Long value = new Long(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
long lowValue = value & 0x7fffffffffffffffL;
|
||||||
|
return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString();
|
||||||
|
}
|
||||||
|
default:
|
||||||
return String.valueOf(data.get(col));
|
return String.valueOf(data.get(col));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class TSDBStatement extends AbstractStatement {
|
||||||
this.connector.freeResultSet(pSql);
|
this.connector.freeResultSet(pSql);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
|
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
|
||||||
res.setBatchFetch(this.connection.getBatchFetch());
|
res.setBatchFetch(this.connection.getBatchFetch());
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -21,27 +21,23 @@ public class TSDBSubscribe {
|
||||||
private final long id;
|
private final long id;
|
||||||
|
|
||||||
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
|
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
|
||||||
if (null != connecter) {
|
if (connecter == null)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
|
|
||||||
this.connecter = connecter;
|
this.connecter = connecter;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
} else {
|
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* consume
|
* consume
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public TSDBResultSet consume() throws SQLException {
|
public TSDBResultSet consume() throws SQLException {
|
||||||
if (this.connecter.isClosed()) {
|
if (this.connecter.isClosed())
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
|
||||||
|
|
||||||
long resultSetPointer = this.connecter.consume(this.id);
|
long resultSetPointer = this.connecter.consume(this.id);
|
||||||
|
|
||||||
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,9 +52,9 @@ public class TSDBSubscribe {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void close(boolean keepProgress) throws SQLException {
|
public void close(boolean keepProgress) throws SQLException {
|
||||||
if (this.connecter.isClosed()) {
|
if (this.connecter.isClosed())
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
|
||||||
this.connecter.unsubscribe(this.id, keepProgress);
|
this.connecter.unsubscribe(this.id, keepProgress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class RestfulConnection extends AbstractConnection {
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
;
|
|
||||||
|
|
||||||
return new RestfulStatement(this, database);
|
return new RestfulStatement(this, database);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@ package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.taosdata.jdbc.AbstractDriver;
|
import com.taosdata.jdbc.*;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
|
||||||
import com.taosdata.jdbc.TSDBDriver;
|
|
||||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -21,15 +19,16 @@ public class RestfulDriver extends AbstractDriver {
|
||||||
try {
|
try {
|
||||||
DriverManager.registerDriver(new RestfulDriver());
|
DriverManager.registerDriver(new RestfulDriver());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can not register Restful JDBC driver"), e);
|
throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_URL_NOT_SET, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
// throw SQLException if url is null
|
// throw SQLException if url is null
|
||||||
if (url == null)
|
if (url == null || url.trim().isEmpty() || url.trim().replaceAll("\\s", "").isEmpty())
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
|
|
||||||
// return null if url is not be accepted
|
// return null if url is not be accepted
|
||||||
if (!acceptsURL(url))
|
if (!acceptsURL(url))
|
||||||
return null;
|
return null;
|
||||||
|
@ -61,14 +60,20 @@ public class RestfulDriver extends AbstractDriver {
|
||||||
throw new SQLException(jsonResult.getString("desc"));
|
throw new SQLException(jsonResult.getString("desc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RestfulConnection(host, port, props, database, url);
|
RestfulConnection conn = new RestfulConnection(host, port, props, database, url);
|
||||||
|
if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) {
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("use " + database);
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.startsWith(URL_PREFIX);
|
return url.length() > 0 && url.trim().length() > 0 && url.startsWith(URL_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,7 +9,6 @@ import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
private volatile boolean isClosed;
|
private volatile boolean isClosed;
|
||||||
|
@ -17,8 +16,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
|
|
||||||
private final String database;
|
private final String database;
|
||||||
private final Statement statement;
|
private final Statement statement;
|
||||||
|
// private final JSONObject resultJson;
|
||||||
// data
|
// data
|
||||||
private ArrayList<ArrayList<Object>> resultSet;
|
private final ArrayList<ArrayList<Object>> resultSet;
|
||||||
// meta
|
// meta
|
||||||
private ArrayList<String> columnNames;
|
private ArrayList<String> columnNames;
|
||||||
private ArrayList<Field> columns;
|
private ArrayList<Field> columns;
|
||||||
|
@ -32,6 +32,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public RestfulResultSet(String database, Statement statement, JSONObject resultJson) throws SQLException {
|
public RestfulResultSet(String database, Statement statement, JSONObject resultJson) throws SQLException {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.statement = statement;
|
this.statement = statement;
|
||||||
|
// this.resultJson = resultJson;
|
||||||
|
|
||||||
// column metadata
|
// column metadata
|
||||||
JSONArray columnMeta = resultJson.getJSONArray("column_meta");
|
JSONArray columnMeta = resultJson.getJSONArray("column_meta");
|
||||||
columnNames = new ArrayList<>();
|
columnNames = new ArrayList<>();
|
||||||
|
@ -39,10 +41,11 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
|
for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
|
||||||
JSONArray col = columnMeta.getJSONArray(colIndex);
|
JSONArray col = columnMeta.getJSONArray(colIndex);
|
||||||
String col_name = col.getString(0);
|
String col_name = col.getString(0);
|
||||||
int col_type = TSDBConstants.taosType2JdbcType(col.getInteger(1));
|
int taos_type = col.getInteger(1);
|
||||||
|
int col_type = TSDBConstants.taosType2JdbcType(taos_type);
|
||||||
int col_length = col.getInteger(2);
|
int col_length = col.getInteger(2);
|
||||||
columnNames.add(col_name);
|
columnNames.add(col_name);
|
||||||
columns.add(new Field(col_name, col_type, col_length, ""));
|
columns.add(new Field(col_name, col_type, col_length, "", taos_type));
|
||||||
}
|
}
|
||||||
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
||||||
|
|
||||||
|
@ -53,105 +56,50 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
ArrayList row = new ArrayList();
|
ArrayList row = new ArrayList();
|
||||||
JSONArray jsonRow = data.getJSONArray(rowIndex);
|
JSONArray jsonRow = data.getJSONArray(rowIndex);
|
||||||
for (int colIndex = 0; colIndex < jsonRow.size(); colIndex++) {
|
for (int colIndex = 0; colIndex < jsonRow.size(); colIndex++) {
|
||||||
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).type));
|
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type));
|
||||||
}
|
}
|
||||||
resultSet.add(row);
|
resultSet.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int columnIndex = 0;
|
|
||||||
for (; columnIndex < data.size(); columnIndex++) {
|
|
||||||
ArrayList oneRow = new ArrayList<>();
|
|
||||||
JSONArray one = data.getJSONArray(columnIndex);
|
|
||||||
for (int j = 0; j < one.size(); j++) {
|
|
||||||
oneRow.add(one.getString(j));
|
|
||||||
}
|
|
||||||
resultSet.add(oneRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// column only names
|
private Object parseColumnData(JSONArray row, int colIndex, int taosType) {
|
||||||
JSONArray head = resultJson.getJSONArray("head");
|
switch (taosType) {
|
||||||
for (int i = 0; i < head.size(); i++) {
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
String name = head.getString(i);
|
|
||||||
columnNames.add(name);
|
|
||||||
columns.add(new Field(name, "", 0, ""));
|
|
||||||
}
|
|
||||||
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object parseColumnData(JSONArray row, int colIndex, int sqlType) {
|
|
||||||
switch (sqlType) {
|
|
||||||
case Types.NULL:
|
|
||||||
return null;
|
|
||||||
case Types.BOOLEAN:
|
|
||||||
return row.getBoolean(colIndex);
|
return row.getBoolean(colIndex);
|
||||||
case Types.TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case Types.SMALLINT:
|
return row.getByte(colIndex);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return row.getShort(colIndex);
|
return row.getShort(colIndex);
|
||||||
case Types.INTEGER:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return row.getInteger(colIndex);
|
return row.getInteger(colIndex);
|
||||||
case Types.BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return row.getBigInteger(colIndex);
|
return row.getBigInteger(colIndex);
|
||||||
case Types.FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
return row.getFloat(colIndex);
|
return row.getFloat(colIndex);
|
||||||
case Types.DOUBLE:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
return row.getDouble(colIndex);
|
return row.getDouble(colIndex);
|
||||||
case Types.TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return new Timestamp(row.getDate(colIndex).getTime());
|
return new Timestamp(row.getDate(colIndex).getTime());
|
||||||
case Types.BINARY:
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
case Types.NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
default:
|
default:
|
||||||
return row.getString(colIndex);
|
return row.getString(colIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 由多个resultSet的JSON构造结果集
|
|
||||||
// *
|
|
||||||
// * @param resultJson: 包含data信息的结果集,有sql返回的结果集
|
|
||||||
// * @param fieldJson: 包含多个(最多2个)meta信息的结果集,有describe xxx
|
|
||||||
// **/
|
|
||||||
// public RestfulResultSet(String database, Statement statement, JSONObject resultJson, List<JSONObject> fieldJson) throws SQLException {
|
|
||||||
// this(database, statement, resultJson);
|
|
||||||
// ArrayList<Field> newColumns = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// for (Field column : columns) {
|
|
||||||
// Field field = findField(column.name, fieldJson);
|
|
||||||
// if (field != null) {
|
|
||||||
// newColumns.add(field);
|
|
||||||
// } else {
|
|
||||||
// newColumns.add(column);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// this.columns = newColumns;
|
|
||||||
// this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Field findField(String columnName, List<JSONObject> fieldJsonList) {
|
|
||||||
// for (JSONObject fieldJSON : fieldJsonList) {
|
|
||||||
// JSONArray fieldDataJson = fieldJSON.getJSONArray("data");
|
|
||||||
// for (int i = 0; i < fieldDataJson.size(); i++) {
|
|
||||||
// JSONArray field = fieldDataJson.getJSONArray(i);
|
|
||||||
// if (columnName.equalsIgnoreCase(field.getString(0))) {
|
|
||||||
// return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public class Field {
|
public class Field {
|
||||||
String name;
|
String name;
|
||||||
int type;
|
int type;
|
||||||
int length;
|
int length;
|
||||||
String note;
|
String note;
|
||||||
|
int taos_type;
|
||||||
|
|
||||||
public Field(String name, int type, int length, String note) {
|
public Field(String name, int type, int length, String note, int taos_type) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.note = note;
|
this.note = note;
|
||||||
|
this.taos_type = taos_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,10 +132,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public String getString(int columnIndex) throws SQLException {
|
public String getString(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
if (columnIndex > resultSet.get(pos).size()) {
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return resultSet.get(pos).get(columnIndex).toString();
|
return resultSet.get(pos).get(columnIndex).toString();
|
||||||
|
@ -197,40 +143,107 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
int result = getInt(columnIndex);
|
int result = getInt(columnIndex);
|
||||||
return result == 0 ? false : true;
|
return result == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getByte(int columnIndex) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Byte.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Byte.MIN_VALUE || valueAsLong > Byte.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.TINYINT);
|
||||||
|
|
||||||
|
return (byte) valueAsLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwRangeException(String valueAsString, int columnIndex, int jdbcType) throws SQLException {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE,
|
||||||
|
"'" + valueAsString + "' in column '" + columnIndex + "' is outside valid range for the jdbcType " + TSDBConstants.jdbcType2TaosTypeName(jdbcType));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getShort(int columnIndex) throws SQLException {
|
public short getShort(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Short.parseShort(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Short.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Short.MIN_VALUE || valueAsLong > Short.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.SMALLINT);
|
||||||
|
return (short) valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInt(int columnIndex) throws SQLException {
|
public int getInt(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Integer.parseInt(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Integer.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Integer.MIN_VALUE || valueAsLong > Integer.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.INTEGER);
|
||||||
|
return (int) valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLong(int columnIndex) throws SQLException {
|
public long getLong(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Long.parseLong(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
long valueAsLong = 0;
|
||||||
|
try {
|
||||||
|
valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Long.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.BIGINT);
|
||||||
|
}
|
||||||
|
return valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getFloat(int columnIndex) throws SQLException {
|
public float getFloat(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
||||||
}
|
}
|
||||||
|
@ -239,6 +252,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public double getDouble(int columnIndex) throws SQLException {
|
public double getDouble(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
||||||
|
@ -246,12 +261,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
|
|
||||||
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
||||||
if (columnIndex < 1) {
|
if (columnIndex < 1) {
|
||||||
throw new SQLException("Column Index out of range, " + columnIndex + " < 1");
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE
|
||||||
|
, "Column Index out of range, " + columnIndex + " < 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
int numOfCols = resultSet.get(pos).size();
|
int numOfCols = resultSet.get(pos).size();
|
||||||
if (columnIndex > numOfCols) {
|
if (columnIndex > numOfCols) {
|
||||||
throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE
|
||||||
|
, "Column Index out of range, " + columnIndex + " > " + numOfCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
return columnIndex - 1;
|
return columnIndex - 1;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.taosdata.jdbc.rs;
|
package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
import com.taosdata.jdbc.TSDBConstants;
|
||||||
|
import com.taosdata.jdbc.WrapperImpl;
|
||||||
|
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -8,7 +9,7 @@ import java.sql.Timestamp;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
public class RestfulResultSetMetaData extends WrapperImpl implements ResultSetMetaData {
|
||||||
|
|
||||||
private final String database;
|
private final String database;
|
||||||
private ArrayList<RestfulResultSet.Field> fields;
|
private ArrayList<RestfulResultSet.Field> fields;
|
||||||
|
@ -20,6 +21,10 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<RestfulResultSet.Field> getFields() {
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() throws SQLException {
|
public int getColumnCount() throws SQLException {
|
||||||
return fields.size();
|
return fields.size();
|
||||||
|
@ -134,8 +139,8 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnTypeName(int column) throws SQLException {
|
public String getColumnTypeName(int column) throws SQLException {
|
||||||
int type = fields.get(column - 1).type;
|
int taos_type = fields.get(column - 1).taos_type;
|
||||||
return TSDBConstants.jdbcType2TaosTypeName(type);
|
return TSDBConstants.taosType2JdbcTypeName(taos_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,18 +185,4 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
return columnClassName;
|
return columnClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
|
||||||
try {
|
|
||||||
return iface.cast(this);
|
|
||||||
} catch (ClassCastException cce) {
|
|
||||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
|
||||||
return iface.isInstance(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,14 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.taosdata.jdbc.AbstractStatement;
|
import com.taosdata.jdbc.AbstractStatement;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
|
||||||
import com.taosdata.jdbc.TSDBError;
|
import com.taosdata.jdbc.TSDBError;
|
||||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
import java.util.ArrayList;
|
import java.sql.ResultSet;
|
||||||
import java.util.Arrays;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class RestfulStatement extends AbstractStatement {
|
public class RestfulStatement extends AbstractStatement {
|
||||||
|
|
||||||
|
@ -30,39 +27,6 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] parseTableIdentifier(String sql) {
|
|
||||||
sql = sql.trim().toLowerCase();
|
|
||||||
String[] ret = null;
|
|
||||||
if (sql.contains("where"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("where"));
|
|
||||||
if (sql.contains("interval"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("interval"));
|
|
||||||
if (sql.contains("fill"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("fill"));
|
|
||||||
if (sql.contains("sliding"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("sliding"));
|
|
||||||
if (sql.contains("group by"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("group by"));
|
|
||||||
if (sql.contains("order by"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("order by"));
|
|
||||||
if (sql.contains("slimit"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("slimit"));
|
|
||||||
if (sql.contains("limit"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("limit"));
|
|
||||||
// parse
|
|
||||||
if (sql.contains("from")) {
|
|
||||||
sql = sql.substring(sql.indexOf("from") + 4).trim();
|
|
||||||
return Arrays.asList(sql.split(",")).stream()
|
|
||||||
.map(tableIdentifier -> {
|
|
||||||
tableIdentifier = tableIdentifier.trim();
|
|
||||||
if (tableIdentifier.contains(" "))
|
|
||||||
tableIdentifier = tableIdentifier.substring(0, tableIdentifier.indexOf(" "));
|
|
||||||
return tableIdentifier;
|
|
||||||
}).collect(Collectors.joining(",")).split(",");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet executeQuery(String sql) throws SQLException {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
|
@ -75,9 +39,8 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
return executeOneQuery(url, sql);
|
return executeOneQuery(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.database == null || this.database.isEmpty())
|
// if (this.database != null && !this.database.trim().replaceAll("\\s","").isEmpty())
|
||||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
|
||||||
return executeOneQuery(url, sql);
|
return executeOneQuery(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +56,8 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
return executeOneUpdate(url, sql);
|
return executeOneUpdate(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.database == null || this.database.isEmpty())
|
// if (this.database != null && !this.database.trim().replaceAll("\\s", "").isEmpty())
|
||||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||||
|
|
||||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
|
||||||
return executeOneUpdate(url, sql);
|
return executeOneUpdate(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,24 +109,9 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
JSONObject resultJson = JSON.parseObject(result);
|
JSONObject resultJson = JSON.parseObject(result);
|
||||||
if (resultJson.getString("status").equals("error")) {
|
if (resultJson.getString("status").equals("error")) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
|
throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc"));
|
||||||
}
|
}
|
||||||
// parse table name from sql
|
|
||||||
// String[] tableIdentifiers = parseTableIdentifier(sql);
|
|
||||||
// if (tableIdentifiers != null) {
|
|
||||||
// List<JSONObject> fieldJsonList = new ArrayList<>();
|
|
||||||
// for (String tableIdentifier : tableIdentifiers) {
|
|
||||||
// String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier);
|
|
||||||
// JSONObject fieldJson = JSON.parseObject(fields);
|
|
||||||
// if (fieldJson.getString("status").equals("error")) {
|
|
||||||
// throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code")));
|
|
||||||
// }
|
|
||||||
// fieldJsonList.add(fieldJson);
|
|
||||||
// }
|
|
||||||
// this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList);
|
|
||||||
// } else {
|
|
||||||
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
||||||
// }
|
|
||||||
this.affectedRows = 0;
|
this.affectedRows = 0;
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +123,7 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
JSONObject jsonObject = JSON.parseObject(result);
|
||||||
if (jsonObject.getString("status").equals("error")) {
|
if (jsonObject.getString("status").equals("error")) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code")));
|
throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc"));
|
||||||
}
|
}
|
||||||
this.resultSet = null;
|
this.resultSet = null;
|
||||||
this.affectedRows = checkJsonResultSet(jsonObject);
|
this.affectedRows = checkJsonResultSet(jsonObject);
|
||||||
|
|
|
@ -15,12 +15,12 @@ public class TSDBJNIConnectorTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
try {
|
try {
|
||||||
// init
|
// init
|
||||||
TSDBJNIConnector.init(null, null, null, null);
|
TSDBJNIConnector.init("/etc/taos/taos.cfg", null, null, null);
|
||||||
// connect
|
// connect
|
||||||
TSDBJNIConnector connector = new TSDBJNIConnector();
|
TSDBJNIConnector connector = new TSDBJNIConnector();
|
||||||
connector.connect("127.0.0.1", 6030, null, "root", "taosdata");
|
connector.connect("127.0.0.1", 6030, "unsign_jni", "root", "taosdata");
|
||||||
// executeQuery
|
// executeQuery
|
||||||
long pSql = connector.executeQuery("show variables");
|
long pSql = connector.executeQuery("select * from unsign_jni.us_table");
|
||||||
if (connector.isUpdateQuery(pSql)) {
|
if (connector.isUpdateQuery(pSql)) {
|
||||||
connector.freeResultSet(pSql);
|
connector.freeResultSet(pSql);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||||
|
@ -29,13 +29,13 @@ public class TSDBJNIConnectorTest {
|
||||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||||
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
|
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
|
||||||
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
}
|
||||||
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
|
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
|
||||||
}
|
}
|
||||||
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
|
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
|
||||||
}
|
}
|
||||||
int columnSize = columnMetaDataList.size();
|
int columnSize = columnMetaDataList.size();
|
||||||
// print metadata
|
// print metadata
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class InsertDbwithoutUseDbTest {
|
||||||
|
|
||||||
|
private static String host = "127.0.0.1";
|
||||||
|
// private static String host = "master";
|
||||||
|
private static Properties properties;
|
||||||
|
private static Random random = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void case001() throws ClassNotFoundException, SQLException {
|
||||||
|
// prepare schema
|
||||||
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
|
||||||
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
stmt.execute("drop database if exists inWithoutDb");
|
||||||
|
stmt.execute("create database if not exists inWithoutDb");
|
||||||
|
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
|
||||||
|
}
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
// execute insert
|
||||||
|
url = "jdbc:TAOS://127.0.0.1:6030/inWithoutDb?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(1, affectedRow);
|
||||||
|
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(false, flag);
|
||||||
|
ResultSet rs = stmt.executeQuery("select count(*) from weather");
|
||||||
|
rs.next();
|
||||||
|
int count = rs.getInt("count(*)");
|
||||||
|
Assert.assertEquals(2, count);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void case002() throws ClassNotFoundException, SQLException {
|
||||||
|
// prepare the schema
|
||||||
|
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||||
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata";
|
||||||
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
stmt.execute("drop database if exists inWithoutDb");
|
||||||
|
stmt.execute("create database if not exists inWithoutDb");
|
||||||
|
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
|
||||||
|
}
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
// execute
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(1, affectedRow);
|
||||||
|
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(false, flag);
|
||||||
|
ResultSet rs = stmt.executeQuery("select count(*) from weather");
|
||||||
|
rs.next();
|
||||||
|
int count = rs.getInt("count(*)");
|
||||||
|
Assert.assertEquals(2, count);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
properties = new Properties();
|
||||||
|
properties.setProperty("charset", "UTF-8");
|
||||||
|
properties.setProperty("locale", "en_US.UTF-8");
|
||||||
|
properties.setProperty("timezone", "UTC-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,191 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UnsignedNumberJniTest {
|
||||||
|
private static final String host = "127.0.0.1";
|
||||||
|
private static Connection conn;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase001() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("127", rs.getString(2));
|
||||||
|
Assert.assertEquals("32767", rs.getString(3));
|
||||||
|
Assert.assertEquals("2147483647", rs.getString(4));
|
||||||
|
Assert.assertEquals("9223372036854775807", rs.getString(5));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase002() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
Assert.assertEquals(2147483647, rs.getInt(4));
|
||||||
|
Assert.assertEquals(9223372036854775807l, rs.getLong(5));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase003() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,2147483647, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
Assert.assertEquals(2147483647, rs.getInt(4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase004() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase005() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase006() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase007() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("254", rs.getString(2));
|
||||||
|
Assert.assertEquals("65534", rs.getString(3));
|
||||||
|
Assert.assertEquals("4294967294", rs.getString(4));
|
||||||
|
Assert.assertEquals("18446744073709551614", rs.getString(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("drop database if exists unsign_jni");
|
||||||
|
stmt.execute("create database if not exists unsign_jni");
|
||||||
|
stmt.execute("use unsign_jni");
|
||||||
|
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(now, 127, 32767,2147483647, 9223372036854775807)");
|
||||||
|
stmt.close();
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
try {
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UnsignedNumberRestfulTest {
|
||||||
|
private static final String host = "127.0.0.1";
|
||||||
|
// private static final String host = "master";
|
||||||
|
private static Connection conn;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase001() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase002() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase003() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,2147483647, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase004() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase005() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase006() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase007() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("254", rs.getString(2));
|
||||||
|
Assert.assertEquals("65534", rs.getString(3));
|
||||||
|
Assert.assertEquals("4294967294", rs.getString(4));
|
||||||
|
Assert.assertEquals("18446744073709551614", rs.getString(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||||
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("drop database if exists unsign_restful");
|
||||||
|
stmt.execute("create database if not exists unsign_restful");
|
||||||
|
stmt.execute("use unsign_restful");
|
||||||
|
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(now, 127, 32767,2147483647, 9223372036854775807)");
|
||||||
|
stmt.close();
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
try {
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -40,9 +40,12 @@ public class RestfulResultSetTest {
|
||||||
Assert.assertEquals(true, f9);
|
Assert.assertEquals(true, f9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
@Test
|
||||||
public void getByte() throws SQLException {
|
public void getByte() throws SQLException {
|
||||||
rs.getByte(1);
|
byte f8 = rs.getByte("f8");
|
||||||
|
Assert.assertEquals(10, f8);
|
||||||
|
f8 = rs.getByte(8);
|
||||||
|
Assert.assertEquals(10, f8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="taos",
|
name="taos",
|
||||||
version="2.0.6",
|
version="2.0.7",
|
||||||
author="Taosdata Inc.",
|
author="Taosdata Inc.",
|
||||||
author_email="support@taosdata.com",
|
author_email="support@taosdata.com",
|
||||||
description="TDengine python client package",
|
description="TDengine python client package",
|
||||||
|
|
|
@ -22,10 +22,10 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
else:
|
else:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
|
|
||||||
|
|
||||||
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
@ -145,10 +145,10 @@ def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
"""
|
"""
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
def _crow_bigint_unsigned_to_python(
|
def _crow_bigint_unsigned_to_python(
|
||||||
|
@ -162,13 +162,13 @@ def _crow_bigint_unsigned_to_python(
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
||||||
|
@ -608,7 +608,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
||||||
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
||||||
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="taos",
|
name="taos",
|
||||||
version="2.0.5",
|
version="2.0.7",
|
||||||
author="Taosdata Inc.",
|
author="Taosdata Inc.",
|
||||||
author_email="support@taosdata.com",
|
author_email="support@taosdata.com",
|
||||||
description="TDengine python client package",
|
description="TDengine python client package",
|
||||||
|
|
|
@ -22,10 +22,10 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
else:
|
else:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
|
|
||||||
|
|
||||||
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
@ -145,10 +145,10 @@ def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
"""
|
"""
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
def _crow_bigint_unsigned_to_python(
|
def _crow_bigint_unsigned_to_python(
|
||||||
|
@ -162,13 +162,13 @@ def _crow_bigint_unsigned_to_python(
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
||||||
|
@ -608,7 +608,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
||||||
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
||||||
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from .cinterface import CTaosInterface
|
from .cinterface import CTaosInterface
|
||||||
from .error import *
|
from .error import *
|
||||||
from .constants import FieldType
|
from .constants import FieldType
|
||||||
import threading
|
|
||||||
|
|
||||||
# querySeqNum = 0
|
# querySeqNum = 0
|
||||||
|
|
||||||
|
@ -38,7 +37,6 @@ class TDengineCursor(object):
|
||||||
self._block_iter = 0
|
self._block_iter = 0
|
||||||
self._affected_rows = 0
|
self._affected_rows = 0
|
||||||
self._logfile = ""
|
self._logfile = ""
|
||||||
self._threadId = threading.get_ident()
|
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
@ -105,12 +103,6 @@ class TDengineCursor(object):
|
||||||
def execute(self, operation, params=None):
|
def execute(self, operation, params=None):
|
||||||
"""Prepare and execute a database operation (query or command).
|
"""Prepare and execute a database operation (query or command).
|
||||||
"""
|
"""
|
||||||
# if threading.get_ident() != self._threadId:
|
|
||||||
# info ="Cursor execute:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
|
||||||
# raise OperationalError(info)
|
|
||||||
# print(info)
|
|
||||||
# return None
|
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -280,12 +272,6 @@ class TDengineCursor(object):
|
||||||
def _handle_result(self):
|
def _handle_result(self):
|
||||||
"""Handle the return result from query.
|
"""Handle the return result from query.
|
||||||
"""
|
"""
|
||||||
# if threading.get_ident() != self._threadId:
|
|
||||||
# info = "Cursor handleresult:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
|
||||||
# raise OperationalError(info)
|
|
||||||
# print(info)
|
|
||||||
# return None
|
|
||||||
|
|
||||||
self._description = []
|
self._description = []
|
||||||
for ele in self._fields:
|
for ele in self._fields:
|
||||||
self._description.append(
|
self._description.append(
|
||||||
|
|
|
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="taos",
|
name="taos",
|
||||||
version="2.0.5",
|
version="2.0.7",
|
||||||
author="Taosdata Inc.",
|
author="Taosdata Inc.",
|
||||||
author_email="support@taosdata.com",
|
author_email="support@taosdata.com",
|
||||||
description="TDengine python client package",
|
description="TDengine python client package",
|
||||||
|
|
|
@ -22,10 +22,10 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
else:
|
else:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
|
|
||||||
|
|
||||||
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
@ -145,10 +145,10 @@ def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
"""
|
"""
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
def _crow_bigint_unsigned_to_python(
|
def _crow_bigint_unsigned_to_python(
|
||||||
|
@ -162,13 +162,13 @@ def _crow_bigint_unsigned_to_python(
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
||||||
|
@ -608,7 +608,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
||||||
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
||||||
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from .cinterface import CTaosInterface
|
from .cinterface import CTaosInterface
|
||||||
from .error import *
|
from .error import *
|
||||||
from .constants import FieldType
|
from .constants import FieldType
|
||||||
import threading
|
|
||||||
|
|
||||||
# querySeqNum = 0
|
# querySeqNum = 0
|
||||||
|
|
||||||
|
@ -38,7 +37,6 @@ class TDengineCursor(object):
|
||||||
self._block_iter = 0
|
self._block_iter = 0
|
||||||
self._affected_rows = 0
|
self._affected_rows = 0
|
||||||
self._logfile = ""
|
self._logfile = ""
|
||||||
self._threadId = threading.get_ident()
|
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
@ -105,12 +103,6 @@ class TDengineCursor(object):
|
||||||
def execute(self, operation, params=None):
|
def execute(self, operation, params=None):
|
||||||
"""Prepare and execute a database operation (query or command).
|
"""Prepare and execute a database operation (query or command).
|
||||||
"""
|
"""
|
||||||
# if threading.get_ident() != self._threadId:
|
|
||||||
# info ="Cursor execute:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
|
||||||
# raise OperationalError(info)
|
|
||||||
# print(info)
|
|
||||||
# return None
|
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -280,12 +272,6 @@ class TDengineCursor(object):
|
||||||
def _handle_result(self):
|
def _handle_result(self):
|
||||||
"""Handle the return result from query.
|
"""Handle the return result from query.
|
||||||
"""
|
"""
|
||||||
# if threading.get_ident() != self._threadId:
|
|
||||||
# info = "Cursor handleresult:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
|
||||||
# raise OperationalError(info)
|
|
||||||
# print(info)
|
|
||||||
# return None
|
|
||||||
|
|
||||||
self._description = []
|
self._description = []
|
||||||
for ele in self._fields:
|
for ele in self._fields:
|
||||||
self._description.append(
|
self._description.append(
|
||||||
|
|
|
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="taos",
|
name="taos",
|
||||||
version="2.0.4",
|
version="2.0.7",
|
||||||
author="Taosdata Inc.",
|
author="Taosdata Inc.",
|
||||||
author_email="support@taosdata.com",
|
author_email="support@taosdata.com",
|
||||||
description="TDengine python client package",
|
description="TDengine python client package",
|
||||||
|
|
|
@ -22,10 +22,10 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
else:
|
else:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
|
|
||||||
|
|
||||||
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
@ -145,10 +145,10 @@ def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
"""
|
"""
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
def _crow_bigint_unsigned_to_python(
|
def _crow_bigint_unsigned_to_python(
|
||||||
|
@ -162,13 +162,13 @@ def _crow_bigint_unsigned_to_python(
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
||||||
|
@ -608,7 +608,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
||||||
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
||||||
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from .cinterface import CTaosInterface
|
from .cinterface import CTaosInterface
|
||||||
from .error import *
|
from .error import *
|
||||||
from .constants import FieldType
|
from .constants import FieldType
|
||||||
import threading
|
|
||||||
|
|
||||||
# querySeqNum = 0
|
# querySeqNum = 0
|
||||||
|
|
||||||
|
@ -38,7 +37,6 @@ class TDengineCursor(object):
|
||||||
self._block_iter = 0
|
self._block_iter = 0
|
||||||
self._affected_rows = 0
|
self._affected_rows = 0
|
||||||
self._logfile = ""
|
self._logfile = ""
|
||||||
self._threadId = threading.get_ident()
|
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
|
|
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="taos",
|
name="taos",
|
||||||
version="2.0.4",
|
version="2.0.7",
|
||||||
author="Taosdata Inc.",
|
author="Taosdata Inc.",
|
||||||
author_email="support@taosdata.com",
|
author_email="support@taosdata.com",
|
||||||
description="TDengine python client package",
|
description="TDengine python client package",
|
||||||
|
|
|
@ -22,10 +22,10 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
else:
|
else:
|
||||||
return list(map(_timestamp_converter, ctypes.cast(
|
return list(map(_timestamp_converter, ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]))
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]))
|
||||||
|
|
||||||
|
|
||||||
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
|
@ -145,10 +145,10 @@ def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
|
||||||
"""
|
"""
|
||||||
if num_of_rows > 0:
|
if num_of_rows > 0:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(ctypes.c_long))[:abs(num_of_rows)]]
|
data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
def _crow_bigint_unsigned_to_python(
|
def _crow_bigint_unsigned_to_python(
|
||||||
|
@ -162,13 +162,13 @@ def _crow_bigint_unsigned_to_python(
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast(
|
||||||
data, ctypes.POINTER(
|
data, ctypes.POINTER(
|
||||||
ctypes.c_ulong))[
|
ctypes.c_uint64))[
|
||||||
:abs(num_of_rows)]]
|
:abs(num_of_rows)]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
|
||||||
|
@ -608,7 +608,7 @@ class CTaosInterface(object):
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
|
||||||
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
|
||||||
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_long))[0]
|
# return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0]
|
||||||
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
# elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
|
||||||
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from .cinterface import CTaosInterface
|
from .cinterface import CTaosInterface
|
||||||
from .error import *
|
from .error import *
|
||||||
from .constants import FieldType
|
from .constants import FieldType
|
||||||
import threading
|
|
||||||
|
|
||||||
# querySeqNum = 0
|
# querySeqNum = 0
|
||||||
|
|
||||||
|
@ -38,7 +37,6 @@ class TDengineCursor(object):
|
||||||
self._block_iter = 0
|
self._block_iter = 0
|
||||||
self._affected_rows = 0
|
self._affected_rows = 0
|
||||||
self._logfile = ""
|
self._logfile = ""
|
||||||
self._threadId = threading.get_ident()
|
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
|
|
@ -253,7 +253,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_QRY_IN_EXEC TAOS_DEF_ERROR_CODE(0, 0x0709) //"Multiple retrieval of this query")
|
#define TSDB_CODE_QRY_IN_EXEC TAOS_DEF_ERROR_CODE(0, 0x0709) //"Multiple retrieval of this query")
|
||||||
#define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query")
|
#define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query")
|
||||||
#define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached")
|
#define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached")
|
||||||
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistance in replica")
|
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica")
|
||||||
|
|
||||||
|
|
||||||
// grant
|
// grant
|
||||||
|
|
|
@ -394,7 +394,7 @@ typedef struct SColIndex {
|
||||||
int16_t colId; // column id
|
int16_t colId; // column id
|
||||||
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
|
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
|
||||||
uint16_t flag; // denote if it is a tag or a normal column
|
uint16_t flag; // denote if it is a tag or a normal column
|
||||||
char name[TSDB_COL_NAME_LEN];
|
char name[TSDB_COL_NAME_LEN]; // TODO remove it
|
||||||
} SColIndex;
|
} SColIndex;
|
||||||
|
|
||||||
/* sql function msg, to describe the message to vnode about sql function
|
/* sql function msg, to describe the message to vnode about sql function
|
||||||
|
@ -402,7 +402,10 @@ typedef struct SColIndex {
|
||||||
typedef struct SSqlFuncMsg {
|
typedef struct SSqlFuncMsg {
|
||||||
int16_t functionId;
|
int16_t functionId;
|
||||||
int16_t numOfParams;
|
int16_t numOfParams;
|
||||||
|
|
||||||
int16_t resColId; // result column id, id of the current output column
|
int16_t resColId; // result column id, id of the current output column
|
||||||
|
int16_t colType;
|
||||||
|
int16_t colBytes;
|
||||||
|
|
||||||
SColIndex colInfo;
|
SColIndex colInfo;
|
||||||
struct ArgElem {
|
struct ArgElem {
|
||||||
|
@ -482,6 +485,7 @@ typedef struct {
|
||||||
int16_t orderColId;
|
int16_t orderColId;
|
||||||
int16_t numOfCols; // the number of columns will be load from vnode
|
int16_t numOfCols; // the number of columns will be load from vnode
|
||||||
SInterval interval;
|
SInterval interval;
|
||||||
|
SSessionWindow sw; // session window
|
||||||
uint16_t tagCondLen; // tag length in current query
|
uint16_t tagCondLen; // tag length in current query
|
||||||
uint32_t tbnameCondLen; // table name filter condition string length
|
uint32_t tbnameCondLen; // table name filter condition string length
|
||||||
int16_t numOfGroupCols; // num of group by columns
|
int16_t numOfGroupCols; // num of group by columns
|
||||||
|
@ -625,6 +629,7 @@ typedef struct {
|
||||||
int32_t maxtablesPerVnode;
|
int32_t maxtablesPerVnode;
|
||||||
int32_t maxVgroupsPerDb;
|
int32_t maxVgroupsPerDb;
|
||||||
char arbitrator[TSDB_EP_LEN]; // tsArbitrator
|
char arbitrator[TSDB_EP_LEN]; // tsArbitrator
|
||||||
|
char reserve[2]; // to solve arm32 bus error
|
||||||
char timezone[64]; // tsTimezone
|
char timezone[64]; // tsTimezone
|
||||||
int64_t checkTime; // 1970-01-01 00:00:00.000
|
int64_t checkTime; // 1970-01-01 00:00:00.000
|
||||||
char locale[TSDB_LOCALE_LEN]; // tsLocale
|
char locale[TSDB_LOCALE_LEN]; // tsLocale
|
||||||
|
|
|
@ -158,13 +158,18 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR
|
||||||
|
|
||||||
typedef void *TsdbQueryHandleT; // Use void to hide implementation details
|
typedef void *TsdbQueryHandleT; // Use void to hide implementation details
|
||||||
|
|
||||||
// query condition to build vnode iterator
|
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
||||||
|
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||||
|
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||||
|
|
||||||
|
// query condition to build multi-table data block iterator
|
||||||
typedef struct STsdbQueryCond {
|
typedef struct STsdbQueryCond {
|
||||||
STimeWindow twindow;
|
STimeWindow twindow;
|
||||||
int32_t order; // desc|asc order to iterate the data block
|
int32_t order; // desc|asc order to iterate the data block
|
||||||
int32_t numOfCols;
|
int32_t numOfCols;
|
||||||
SColumnInfo *colList;
|
SColumnInfo *colList;
|
||||||
bool loadExternalRows; // load external rows or not
|
bool loadExternalRows; // load external rows or not
|
||||||
|
int32_t type; // data block load type:
|
||||||
} STsdbQueryCond;
|
} STsdbQueryCond;
|
||||||
|
|
||||||
typedef struct SMemRef {
|
typedef struct SMemRef {
|
||||||
|
@ -181,17 +186,31 @@ typedef struct SDataBlockInfo {
|
||||||
int32_t tid;
|
int32_t tid;
|
||||||
} SDataBlockInfo;
|
} SDataBlockInfo;
|
||||||
|
|
||||||
|
typedef struct SFileBlockInfo {
|
||||||
|
int32_t numOfRows;
|
||||||
|
} SFileBlockInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *pTable;
|
void *pTable;
|
||||||
TSKEY lastKey;
|
TSKEY lastKey;
|
||||||
} STableKeyInfo;
|
} STableKeyInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t numOfTables;
|
uint32_t numOfTables;
|
||||||
SArray * pGroupList;
|
SArray * pGroupList;
|
||||||
SHashObj *map; // speedup acquire the tableQueryInfo by table uid
|
SHashObj *map; // speedup acquire the tableQueryInfo by table uid
|
||||||
} STableGroupInfo;
|
} STableGroupInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t rowSize;
|
||||||
|
uint16_t numOfFiles;
|
||||||
|
uint32_t numOfTables;
|
||||||
|
uint64_t totalSize;
|
||||||
|
int32_t firstSeekTimeUs;
|
||||||
|
uint32_t numOfRowsInMemTable;
|
||||||
|
SArray *dataBlockInfos;
|
||||||
|
} STableBlockDist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data block iterator, starting from position according to the query condition
|
* Get the data block iterator, starting from position according to the query condition
|
||||||
*
|
*
|
||||||
|
@ -252,16 +271,7 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle);
|
||||||
* @param pQueryHandle
|
* @param pQueryHandle
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool tsdbNextDataBlock(TsdbQueryHandleT *pQueryHandle);
|
bool tsdbNextDataBlock(TsdbQueryHandleT pQueryHandle);
|
||||||
/**
|
|
||||||
* move to next block if exists but not merge data in memtable
|
|
||||||
*
|
|
||||||
* @param pQueryHandle
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool tsdbNextDataBlockWithoutMerge(TsdbQueryHandleT *pQueryHandle);
|
|
||||||
|
|
||||||
SArray* tsdbGetExternalRow(TsdbQueryHandleT *pHandle, SMemRef* pMemRef, int16_t type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current data block information
|
* Get current data block information
|
||||||
|
@ -306,7 +316,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo *tsdb, uint64_t uid, TSKEY key, const
|
||||||
SColIndex *pColIndex, int32_t numOfCols);
|
SColIndex *pColIndex, int32_t numOfCols);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destory the created table group list, which is generated by tag query
|
* destroy the created table group list, which is generated by tag query
|
||||||
* @param pGroupList
|
* @param pGroupList
|
||||||
*/
|
*/
|
||||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||||
|
@ -336,6 +346,12 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo *tsdb, SArray *pTableIdList, STabl
|
||||||
*/
|
*/
|
||||||
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle);
|
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle);
|
||||||
|
|
||||||
|
void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond);
|
||||||
|
|
||||||
|
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList);
|
||||||
|
|
||||||
|
int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT* queryHandle, STableBlockDist* pTableBlockInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the statistics of repo usage
|
* get the statistics of repo usage
|
||||||
* @param repo. point to the tsdbrepo
|
* @param repo. point to the tsdbrepo
|
||||||
|
|
|
@ -135,108 +135,75 @@
|
||||||
#define TK_FROM 116
|
#define TK_FROM 116
|
||||||
#define TK_VARIABLE 117
|
#define TK_VARIABLE 117
|
||||||
#define TK_INTERVAL 118
|
#define TK_INTERVAL 118
|
||||||
#define TK_FILL 119
|
#define TK_SESSION 119
|
||||||
#define TK_SLIDING 120
|
#define TK_FILL 120
|
||||||
#define TK_ORDER 121
|
#define TK_SLIDING 121
|
||||||
#define TK_BY 122
|
#define TK_ORDER 122
|
||||||
#define TK_ASC 123
|
#define TK_BY 123
|
||||||
#define TK_DESC 124
|
#define TK_ASC 124
|
||||||
#define TK_GROUP 125
|
#define TK_DESC 125
|
||||||
#define TK_HAVING 126
|
#define TK_GROUP 126
|
||||||
#define TK_LIMIT 127
|
#define TK_HAVING 127
|
||||||
#define TK_OFFSET 128
|
#define TK_LIMIT 128
|
||||||
#define TK_SLIMIT 129
|
#define TK_OFFSET 129
|
||||||
#define TK_SOFFSET 130
|
#define TK_SLIMIT 130
|
||||||
#define TK_WHERE 131
|
#define TK_SOFFSET 131
|
||||||
#define TK_NOW 132
|
#define TK_WHERE 132
|
||||||
#define TK_RESET 133
|
#define TK_NOW 133
|
||||||
#define TK_QUERY 134
|
#define TK_RESET 134
|
||||||
#define TK_ADD 135
|
#define TK_QUERY 135
|
||||||
#define TK_COLUMN 136
|
#define TK_ADD 136
|
||||||
#define TK_TAG 137
|
#define TK_COLUMN 137
|
||||||
#define TK_CHANGE 138
|
#define TK_TAG 138
|
||||||
#define TK_SET 139
|
#define TK_CHANGE 139
|
||||||
#define TK_KILL 140
|
#define TK_SET 140
|
||||||
#define TK_CONNECTION 141
|
#define TK_KILL 141
|
||||||
#define TK_STREAM 142
|
#define TK_CONNECTION 142
|
||||||
#define TK_COLON 143
|
#define TK_STREAM 143
|
||||||
#define TK_ABORT 144
|
#define TK_COLON 144
|
||||||
#define TK_AFTER 145
|
#define TK_ABORT 145
|
||||||
#define TK_ATTACH 146
|
#define TK_AFTER 146
|
||||||
#define TK_BEFORE 147
|
#define TK_ATTACH 147
|
||||||
#define TK_BEGIN 148
|
#define TK_BEFORE 148
|
||||||
#define TK_CASCADE 149
|
#define TK_BEGIN 149
|
||||||
#define TK_CLUSTER 150
|
#define TK_CASCADE 150
|
||||||
#define TK_CONFLICT 151
|
#define TK_CLUSTER 151
|
||||||
#define TK_COPY 152
|
#define TK_CONFLICT 152
|
||||||
#define TK_DEFERRED 153
|
#define TK_COPY 153
|
||||||
#define TK_DELIMITERS 154
|
#define TK_DEFERRED 154
|
||||||
#define TK_DETACH 155
|
#define TK_DELIMITERS 155
|
||||||
#define TK_EACH 156
|
#define TK_DETACH 156
|
||||||
#define TK_END 157
|
#define TK_EACH 157
|
||||||
#define TK_EXPLAIN 158
|
#define TK_END 158
|
||||||
#define TK_FAIL 159
|
#define TK_EXPLAIN 159
|
||||||
#define TK_FOR 160
|
#define TK_FAIL 160
|
||||||
#define TK_IGNORE 161
|
#define TK_FOR 161
|
||||||
#define TK_IMMEDIATE 162
|
#define TK_IGNORE 162
|
||||||
#define TK_INITIALLY 163
|
#define TK_IMMEDIATE 163
|
||||||
#define TK_INSTEAD 164
|
#define TK_INITIALLY 164
|
||||||
#define TK_MATCH 165
|
#define TK_INSTEAD 165
|
||||||
#define TK_KEY 166
|
#define TK_MATCH 166
|
||||||
#define TK_OF 167
|
#define TK_KEY 167
|
||||||
#define TK_RAISE 168
|
#define TK_OF 168
|
||||||
#define TK_REPLACE 169
|
#define TK_RAISE 169
|
||||||
#define TK_RESTRICT 170
|
#define TK_REPLACE 170
|
||||||
#define TK_ROW 171
|
#define TK_RESTRICT 171
|
||||||
#define TK_STATEMENT 172
|
#define TK_ROW 172
|
||||||
#define TK_TRIGGER 173
|
#define TK_STATEMENT 173
|
||||||
#define TK_VIEW 174
|
#define TK_TRIGGER 174
|
||||||
#define TK_COUNT 175
|
#define TK_VIEW 175
|
||||||
#define TK_SUM 176
|
#define TK_SEMI 176
|
||||||
#define TK_AVG 177
|
#define TK_NONE 177
|
||||||
#define TK_MIN 178
|
#define TK_PREV 178
|
||||||
#define TK_MAX 179
|
#define TK_LINEAR 179
|
||||||
#define TK_FIRST 180
|
#define TK_IMPORT 180
|
||||||
#define TK_LAST 181
|
#define TK_METRIC 181
|
||||||
#define TK_TOP 182
|
#define TK_TBNAME 182
|
||||||
#define TK_BOTTOM 183
|
#define TK_JOIN 183
|
||||||
#define TK_STDDEV 184
|
#define TK_METRICS 184
|
||||||
#define TK_PERCENTILE 185
|
#define TK_INSERT 185
|
||||||
#define TK_APERCENTILE 186
|
#define TK_INTO 186
|
||||||
#define TK_LEASTSQUARES 187
|
#define TK_VALUES 187
|
||||||
#define TK_HISTOGRAM 188
|
|
||||||
#define TK_DIFF 189
|
|
||||||
#define TK_SPREAD 190
|
|
||||||
#define TK_TWA 191
|
|
||||||
#define TK_INTERP 192
|
|
||||||
#define TK_LAST_ROW 193
|
|
||||||
#define TK_RATE 194
|
|
||||||
#define TK_IRATE 195
|
|
||||||
#define TK_SUM_RATE 196
|
|
||||||
#define TK_SUM_IRATE 197
|
|
||||||
#define TK_AVG_RATE 198
|
|
||||||
#define TK_AVG_IRATE 199
|
|
||||||
#define TK_TBID 200
|
|
||||||
#define TK_SEMI 201
|
|
||||||
#define TK_NONE 202
|
|
||||||
#define TK_PREV 203
|
|
||||||
#define TK_LINEAR 204
|
|
||||||
#define TK_IMPORT 205
|
|
||||||
#define TK_METRIC 206
|
|
||||||
#define TK_TBNAME 207
|
|
||||||
#define TK_JOIN 208
|
|
||||||
#define TK_METRICS 209
|
|
||||||
#define TK_INSERT 210
|
|
||||||
#define TK_INTO 211
|
|
||||||
#define TK_VALUES 212
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TK_SPACE 300
|
#define TK_SPACE 300
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"confirm_parameter_prompt": "no",
|
"confirm_parameter_prompt": "no",
|
||||||
"insert_interval": 0,
|
"insert_interval": 0,
|
||||||
"num_of_records_per_req": 100,
|
"num_of_records_per_req": 100,
|
||||||
|
"max_sql_len": 1024000,
|
||||||
"databases": [{
|
"databases": [{
|
||||||
"dbinfo": {
|
"dbinfo": {
|
||||||
"name": "db",
|
"name": "db",
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
"super_tables": [{
|
"super_tables": [{
|
||||||
"name": "stb",
|
"name": "stb",
|
||||||
"child_table_exists":"no",
|
"child_table_exists":"no",
|
||||||
"childtable_count": 100,
|
"childtable_count": 10000,
|
||||||
"childtable_prefix": "stb_",
|
"childtable_prefix": "stb_",
|
||||||
"auto_create_table": "no",
|
"auto_create_table": "no",
|
||||||
"data_source": "rand",
|
"data_source": "rand",
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -72,6 +72,11 @@ typedef struct SInterval {
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
} SInterval;
|
} SInterval;
|
||||||
|
|
||||||
|
typedef struct SSessionWindow {
|
||||||
|
int64_t gap; // gap between two session window(in microseconds)
|
||||||
|
int32_t primaryColId; // primary timestamp column
|
||||||
|
} SSessionWindow;
|
||||||
|
|
||||||
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
|
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
|
||||||
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
|
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
|
||||||
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
|
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
|
||||||
|
|
|
@ -63,9 +63,11 @@ void httpJsonString(JsonBuf* buf, char* sVal, int32_t len);
|
||||||
void httpJsonOriginString(JsonBuf* buf, char* sVal, int32_t len);
|
void httpJsonOriginString(JsonBuf* buf, char* sVal, int32_t len);
|
||||||
void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int32_t maxLen);
|
void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int32_t maxLen);
|
||||||
void httpJsonInt64(JsonBuf* buf, int64_t num);
|
void httpJsonInt64(JsonBuf* buf, int64_t num);
|
||||||
|
void httpJsonUInt64(JsonBuf* buf, uint64_t num);
|
||||||
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us);
|
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us);
|
||||||
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us);
|
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us);
|
||||||
void httpJsonInt(JsonBuf* buf, int32_t num);
|
void httpJsonInt(JsonBuf* buf, int32_t num);
|
||||||
|
void httpJsonUInt(JsonBuf* buf, uint32_t num);
|
||||||
void httpJsonFloat(JsonBuf* buf, float num);
|
void httpJsonFloat(JsonBuf* buf, float num);
|
||||||
void httpJsonDouble(JsonBuf* buf, double num);
|
void httpJsonDouble(JsonBuf* buf, double num);
|
||||||
void httpJsonNull(JsonBuf* buf);
|
void httpJsonNull(JsonBuf* buf);
|
||||||
|
|
|
@ -256,6 +256,12 @@ void httpJsonInt64(JsonBuf* buf, int64_t num) {
|
||||||
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%" PRId64, num);
|
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%" PRId64, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void httpJsonUInt64(JsonBuf* buf, uint64_t num) {
|
||||||
|
httpJsonItemToken(buf);
|
||||||
|
httpJsonTestBuf(buf, MAX_NUM_STR_SZ);
|
||||||
|
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%" PRIu64, num);
|
||||||
|
}
|
||||||
|
|
||||||
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
|
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
|
||||||
char ts[35] = {0};
|
char ts[35] = {0};
|
||||||
struct tm* ptm;
|
struct tm* ptm;
|
||||||
|
@ -303,6 +309,12 @@ void httpJsonInt(JsonBuf* buf, int32_t num) {
|
||||||
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%d", num);
|
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%d", num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void httpJsonUInt(JsonBuf* buf, uint32_t num) {
|
||||||
|
httpJsonItemToken(buf);
|
||||||
|
httpJsonTestBuf(buf, MAX_NUM_STR_SZ);
|
||||||
|
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%u", num);
|
||||||
|
}
|
||||||
|
|
||||||
void httpJsonFloat(JsonBuf* buf, float num) {
|
void httpJsonFloat(JsonBuf* buf, float num) {
|
||||||
httpJsonItemToken(buf);
|
httpJsonItemToken(buf);
|
||||||
httpJsonTestBuf(buf, MAX_NUM_STR_SZ);
|
httpJsonTestBuf(buf, MAX_NUM_STR_SZ);
|
||||||
|
|
|
@ -110,7 +110,7 @@ static void httpCleanupString(HttpString *str) {
|
||||||
static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) {
|
static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) {
|
||||||
if (str->size == 0) {
|
if (str->size == 0) {
|
||||||
str->pos = 0;
|
str->pos = 0;
|
||||||
str->size = len;
|
str->size = len + 1;
|
||||||
str->str = malloc(str->size);
|
str->str = malloc(str->size);
|
||||||
} else if (str->pos + len + 1 >= str->size) {
|
} else if (str->pos + len + 1 >= str->size) {
|
||||||
str->size += len;
|
str->size += len;
|
||||||
|
|
|
@ -162,6 +162,18 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
|
httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
httpJsonUInt(jsonBuf, *((uint8_t *)row[i]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
httpJsonUInt(jsonBuf, *((uint16_t *)row[i]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
|
httpJsonUInt(jsonBuf, *((uint32_t *)row[i]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
httpJsonUInt64(jsonBuf, *((uint64_t *)row[i]));
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_FLOAT:
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
httpJsonFloat(jsonBuf, GET_FLOAT_VAL(row[i]));
|
httpJsonFloat(jsonBuf, GET_FLOAT_VAL(row[i]));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
||||||
#define TSDB_FUNC_INVALID_ID -1
|
#define TSDB_FUNC_INVALID_ID -1
|
||||||
#define TSDB_FUNC_COUNT 0
|
#define TSDB_FUNC_COUNT 0
|
||||||
|
@ -70,15 +71,17 @@ extern "C" {
|
||||||
#define TSDB_FUNC_AVG_IRATE 34
|
#define TSDB_FUNC_AVG_IRATE 34
|
||||||
|
|
||||||
#define TSDB_FUNC_TID_TAG 35
|
#define TSDB_FUNC_TID_TAG 35
|
||||||
#define TSDB_FUNC_HISTOGRAM 36
|
#define TSDB_FUNC_BLKINFO 36
|
||||||
#define TSDB_FUNC_HLL 37
|
|
||||||
#define TSDB_FUNC_MODE 38
|
#define TSDB_FUNC_HISTOGRAM 37
|
||||||
#define TSDB_FUNC_SAMPLE 39
|
#define TSDB_FUNC_HLL 38
|
||||||
#define TSDB_FUNC_CEIL 40
|
#define TSDB_FUNC_MODE 39
|
||||||
#define TSDB_FUNC_FLOOR 41
|
#define TSDB_FUNC_SAMPLE 40
|
||||||
#define TSDB_FUNC_ROUND 42
|
#define TSDB_FUNC_CEIL 41
|
||||||
#define TSDB_FUNC_MAVG 43
|
#define TSDB_FUNC_FLOOR 42
|
||||||
#define TSDB_FUNC_CSUM 44
|
#define TSDB_FUNC_ROUND 43
|
||||||
|
#define TSDB_FUNC_MAVG 44
|
||||||
|
#define TSDB_FUNC_CSUM 45
|
||||||
|
|
||||||
|
|
||||||
#define TSDB_FUNCSTATE_SO 0x1u // single output
|
#define TSDB_FUNCSTATE_SO 0x1u // single output
|
||||||
|
@ -214,13 +217,14 @@ typedef struct SAggFunctionInfo {
|
||||||
void (*xFinalize)(SQLFunctionCtx *pCtx);
|
void (*xFinalize)(SQLFunctionCtx *pCtx);
|
||||||
void (*mergeFunc)(SQLFunctionCtx *pCtx);
|
void (*mergeFunc)(SQLFunctionCtx *pCtx);
|
||||||
|
|
||||||
int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId);
|
int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId);
|
||||||
} SAggFunctionInfo;
|
} SAggFunctionInfo;
|
||||||
|
|
||||||
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
|
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
|
||||||
|
|
||||||
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
|
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
|
||||||
int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable);
|
int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable);
|
||||||
|
int32_t isValidFunction(const char* name, int32_t len);
|
||||||
|
|
||||||
#define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0)
|
#define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0)
|
||||||
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
|
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
|
||||||
|
@ -242,12 +246,16 @@ typedef struct STwaInfo {
|
||||||
STimeWindow win;
|
STimeWindow win;
|
||||||
} STwaInfo;
|
} STwaInfo;
|
||||||
|
|
||||||
|
struct SBufferWriter;
|
||||||
|
void blockDistInfoToBinary(STableBlockDist* pDist, struct SBufferWriter* bw);
|
||||||
|
void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist);
|
||||||
|
|
||||||
/* global sql function array */
|
/* global sql function array */
|
||||||
extern struct SAggFunctionInfo aAggs[];
|
extern struct SAggFunctionInfo aAggs[];
|
||||||
|
|
||||||
extern int32_t functionCompatList[]; // compatible check array list
|
extern int32_t functionCompatList[]; // compatible check array list
|
||||||
|
|
||||||
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval);
|
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the numOfRes should be kept, since it may be used later
|
* the numOfRes should be kept, since it may be used later
|
||||||
|
@ -258,14 +266,14 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
|
||||||
(_r)->initialized = false; \
|
(_r)->initialized = false; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, uint32_t bufLen) {
|
static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, int32_t bufLen) {
|
||||||
pResInfo->initialized = true; // the this struct has been initialized flag
|
pResInfo->initialized = true; // the this struct has been initialized flag
|
||||||
|
|
||||||
pResInfo->complete = false;
|
pResInfo->complete = false;
|
||||||
pResInfo->hasResult = false;
|
pResInfo->hasResult = false;
|
||||||
pResInfo->numOfRes = 0;
|
pResInfo->numOfRes = 0;
|
||||||
|
|
||||||
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, (size_t)bufLen);
|
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef TDENGINE_QUERYEXECUTOR_H
|
#ifndef TDENGINE_QEXECUTOR_H
|
||||||
#define TDENGINE_QUERYEXECUTOR_H
|
#define TDENGINE_QEXECUTOR_H
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -37,30 +37,24 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
|
||||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
||||||
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
|
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
|
||||||
|
|
||||||
#define SET_STABLE_QUERY_OVER(_q) ((_q)->tableIndex = (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
|
|
||||||
#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
|
|
||||||
|
|
||||||
#define GET_TABLEGROUP(q, _index) ((SArray*) taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
|
#define GET_TABLEGROUP(q, _index) ((SArray*) taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
|
||||||
|
|
||||||
|
#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL? 0:((_r)->outputBuf)->info.rows)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
// when query starts to execute, this status will set
|
// when query starts to execute, this status will set
|
||||||
QUERY_NOT_COMPLETED = 0x1u,
|
QUERY_NOT_COMPLETED = 0x1u,
|
||||||
|
|
||||||
/* result output buffer is full, current query is paused.
|
|
||||||
* this status is only exist in group-by clause and diff/add/division/multiply/ query.
|
|
||||||
*/
|
|
||||||
QUERY_RESBUF_FULL = 0x2u,
|
|
||||||
|
|
||||||
/* query is over
|
/* query is over
|
||||||
* 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc.
|
* 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc.
|
||||||
* 2. when all data within queried time window, it is also denoted as query_completed
|
* 2. when all data within queried time window, it is also denoted as query_completed
|
||||||
*/
|
*/
|
||||||
QUERY_COMPLETED = 0x4u,
|
QUERY_COMPLETED = 0x2u,
|
||||||
|
|
||||||
/* when the result is not completed return to client, this status will be
|
/* when the result is not completed return to client, this status will be
|
||||||
* usually used in case of interval query with interpolation option
|
* usually used in case of interval query with interpolation option
|
||||||
*/
|
*/
|
||||||
QUERY_OVER = 0x8u,
|
QUERY_OVER = 0x4u,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SResultRowPool {
|
typedef struct SResultRowPool {
|
||||||
|
@ -86,13 +80,13 @@ typedef struct SSqlGroupbyExpr {
|
||||||
|
|
||||||
typedef struct SResultRow {
|
typedef struct SResultRow {
|
||||||
int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer
|
int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer
|
||||||
int32_t rowId:29; // row index in buffer page
|
int32_t offset:29; // row index in buffer page
|
||||||
bool startInterp; // the time window start timestamp has done the interpolation already.
|
bool startInterp; // the time window start timestamp has done the interpolation already.
|
||||||
bool endInterp; // the time window end timestamp has done the interpolation already.
|
bool endInterp; // the time window end timestamp has done the interpolation already.
|
||||||
bool closed; // this result status: closed or opened
|
bool closed; // this result status: closed or opened
|
||||||
uint32_t numOfRows; // number of rows of current time window
|
uint32_t numOfRows; // number of rows of current time window
|
||||||
SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo
|
SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo
|
||||||
union {STimeWindow win; char* key;}; // start key of current time window
|
union {STimeWindow win; char* key;}; // start key of current result row
|
||||||
} SResultRow;
|
} SResultRow;
|
||||||
|
|
||||||
typedef struct SGroupResInfo {
|
typedef struct SGroupResInfo {
|
||||||
|
@ -106,12 +100,11 @@ typedef struct SGroupResInfo {
|
||||||
* If the number of generated results is greater than this value,
|
* If the number of generated results is greater than this value,
|
||||||
* query query will be halt and return results to client immediate.
|
* query query will be halt and return results to client immediate.
|
||||||
*/
|
*/
|
||||||
typedef struct SResultRec {
|
typedef struct SRspResultInfo {
|
||||||
int64_t total; // total generated result size in rows
|
int64_t total; // total generated result size in rows
|
||||||
int64_t rows; // current result set size in rows
|
int32_t capacity; // capacity of current result output buffer
|
||||||
int64_t capacity; // capacity of current result output buffer
|
|
||||||
int32_t threshold; // result size threshold in rows.
|
int32_t threshold; // result size threshold in rows.
|
||||||
} SResultRec;
|
} SRspResultInfo;
|
||||||
|
|
||||||
typedef struct SResultRowInfo {
|
typedef struct SResultRowInfo {
|
||||||
SResultRow** pResult; // result list
|
SResultRow** pResult; // result list
|
||||||
|
@ -138,7 +131,6 @@ typedef struct SSingleColumnFilterInfo {
|
||||||
typedef struct STableQueryInfo {
|
typedef struct STableQueryInfo {
|
||||||
TSKEY lastKey;
|
TSKEY lastKey;
|
||||||
int32_t groupIndex; // group id in table list
|
int32_t groupIndex; // group id in table list
|
||||||
int16_t queryRangeSet; // denote if the query range is set, only available for interval query
|
|
||||||
tVariant tag;
|
tVariant tag;
|
||||||
STimeWindow win;
|
STimeWindow win;
|
||||||
STSCursor cur;
|
STSCursor cur;
|
||||||
|
@ -179,72 +171,77 @@ typedef struct {
|
||||||
SArray* pResult; // SArray<SStddevInterResult>
|
SArray* pResult; // SArray<SStddevInterResult>
|
||||||
} SInterResult;
|
} SInterResult;
|
||||||
|
|
||||||
|
typedef struct SSDataBlock {
|
||||||
|
SDataStatis *pBlockStatis;
|
||||||
|
SArray *pDataBlock;
|
||||||
|
SDataBlockInfo info;
|
||||||
|
} SSDataBlock;
|
||||||
|
|
||||||
typedef struct SQuery {
|
typedef struct SQuery {
|
||||||
int16_t numOfCols;
|
|
||||||
int16_t numOfTags;
|
|
||||||
SOrderVal order;
|
|
||||||
STimeWindow window;
|
|
||||||
SInterval interval;
|
|
||||||
int16_t precision;
|
|
||||||
int16_t numOfOutput;
|
|
||||||
int16_t fillType;
|
|
||||||
int16_t checkResultBuf; // check if the buffer is full during scan each block
|
|
||||||
SLimitVal limit;
|
SLimitVal limit;
|
||||||
|
|
||||||
int32_t srcRowSize; // todo extract struct
|
|
||||||
int32_t resultRowSize;
|
|
||||||
int32_t maxSrcColumnSize;
|
|
||||||
int32_t tagLen; // tag value length of current query
|
|
||||||
|
|
||||||
SSqlGroupbyExpr* pGroupbyExpr;
|
|
||||||
SExprInfo* pExpr1;
|
|
||||||
SExprInfo* pExpr2;
|
|
||||||
int32_t numOfExpr2;
|
|
||||||
|
|
||||||
SColumnInfo* colList;
|
|
||||||
SColumnInfo* tagColList;
|
|
||||||
int32_t numOfFilterCols;
|
|
||||||
int64_t* fillVal;
|
|
||||||
uint32_t status; // query status
|
|
||||||
SResultRec rec;
|
|
||||||
int32_t pos;
|
|
||||||
tFilePage** sdata;
|
|
||||||
STableQueryInfo* current;
|
|
||||||
int32_t numOfCheckedBlocks; // number of check data blocks
|
|
||||||
|
|
||||||
SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query.
|
|
||||||
SSingleColumnFilterInfo* pFilterInfo;
|
|
||||||
} SQuery;
|
|
||||||
|
|
||||||
typedef struct SQueryRuntimeEnv {
|
|
||||||
jmp_buf env;
|
|
||||||
SQuery* pQuery;
|
|
||||||
SQLFunctionCtx* pCtx;
|
|
||||||
int32_t numOfRowsPerPage;
|
|
||||||
uint16_t* offset;
|
|
||||||
uint16_t scanFlag; // denotes reversed scan of data or not
|
|
||||||
SFillInfo* pFillInfo;
|
|
||||||
SResultRowInfo resultRowInfo;
|
|
||||||
|
|
||||||
SQueryCostInfo summary;
|
|
||||||
void* pQueryHandle;
|
|
||||||
void* pSecQueryHandle; // another thread for
|
|
||||||
bool stableQuery; // super table query or not
|
bool stableQuery; // super table query or not
|
||||||
bool topBotQuery; // TODO used bitwise flag
|
bool topBotQuery; // TODO used bitwise flag
|
||||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||||
bool hasTagResults; // if there are tag values in final result or not
|
bool hasTagResults; // if there are tag values in final result or not
|
||||||
bool timeWindowInterpo;// if the time window start/end required interpolation
|
bool timeWindowInterpo;// if the time window start/end required interpolation
|
||||||
bool queryWindowIdentical; // all query time windows are identical for all tables in one group
|
|
||||||
bool queryBlockDist; // if query data block distribution
|
bool queryBlockDist; // if query data block distribution
|
||||||
bool stabledev; // super table stddev query
|
bool stabledev; // super table stddev query
|
||||||
int32_t interBufSize; // intermediate buffer sizse
|
int32_t interBufSize; // intermediate buffer sizse
|
||||||
|
|
||||||
|
SOrderVal order;
|
||||||
|
int16_t numOfCols;
|
||||||
|
int16_t numOfTags;
|
||||||
|
|
||||||
|
STimeWindow window;
|
||||||
|
SInterval interval;
|
||||||
|
SSessionWindow sw;
|
||||||
|
int16_t precision;
|
||||||
|
int16_t numOfOutput;
|
||||||
|
int16_t fillType;
|
||||||
|
int16_t checkResultBuf; // check if the buffer is full during scan each block
|
||||||
|
|
||||||
|
int32_t srcRowSize; // todo extract struct
|
||||||
|
int32_t resultRowSize;
|
||||||
|
int32_t intermediateResultRowSize; // intermediate result row size, in case of top-k query.
|
||||||
|
int32_t maxSrcColumnSize;
|
||||||
|
int32_t tagLen; // tag value length of current query
|
||||||
|
SSqlGroupbyExpr* pGroupbyExpr;
|
||||||
|
SExprInfo* pExpr1;
|
||||||
|
SExprInfo* pExpr2;
|
||||||
|
int32_t numOfExpr2;
|
||||||
|
SColumnInfo* colList;
|
||||||
|
SColumnInfo* tagColList;
|
||||||
|
int32_t numOfFilterCols;
|
||||||
|
int64_t* fillVal;
|
||||||
|
SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query.
|
||||||
|
SSingleColumnFilterInfo* pFilterInfo;
|
||||||
|
|
||||||
|
STableQueryInfo* current;
|
||||||
|
void* tsdb;
|
||||||
|
SMemRef memRef;
|
||||||
|
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
||||||
|
int32_t vgId;
|
||||||
|
} SQuery;
|
||||||
|
|
||||||
|
typedef SSDataBlock* (*__operator_fn_t)(void* param);
|
||||||
|
typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
|
||||||
|
|
||||||
|
struct SOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SQueryRuntimeEnv {
|
||||||
|
jmp_buf env;
|
||||||
|
SQuery* pQuery;
|
||||||
|
uint32_t status; // query status
|
||||||
|
void* qinfo;
|
||||||
|
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||||
|
void* pQueryHandle;
|
||||||
|
|
||||||
int32_t prevGroupId; // previous executed group id
|
int32_t prevGroupId; // previous executed group id
|
||||||
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||||
char* keyBuf; // window key buffer
|
char* keyBuf; // window key buffer
|
||||||
SResultRowPool* pool; // window result object pool
|
SResultRowPool* pool; // window result object pool
|
||||||
|
|
||||||
int32_t* rowCellInfoOffset;// offset value for each row result cell info
|
|
||||||
char** prevRow;
|
char** prevRow;
|
||||||
|
|
||||||
SArray* prevResult; // intermediate result, SArray<SInterResult>
|
SArray* prevResult; // intermediate result, SArray<SInterResult>
|
||||||
|
@ -253,8 +250,57 @@ typedef struct SQueryRuntimeEnv {
|
||||||
|
|
||||||
char* tagVal; // tag value of current data block
|
char* tagVal; // tag value of current data block
|
||||||
SArithmeticSupport *sasArray;
|
SArithmeticSupport *sasArray;
|
||||||
|
|
||||||
|
SSDataBlock *outputBuf;
|
||||||
|
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||||
|
struct SOperatorInfo *proot;
|
||||||
|
struct SOperatorInfo *pTableScanner; // table scan operator
|
||||||
|
SGroupResInfo groupResInfo;
|
||||||
|
int64_t currentOffset; // dynamic offset value
|
||||||
|
|
||||||
|
SRspResultInfo resultInfo;
|
||||||
|
SHashObj *pTableRetrieveTsMap;
|
||||||
} SQueryRuntimeEnv;
|
} SQueryRuntimeEnv;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
OP_IN_EXECUTING = 1,
|
||||||
|
OP_RES_TO_RETURN = 2,
|
||||||
|
OP_EXEC_DONE = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum OPERATOR_TYPE_E {
|
||||||
|
OP_TableScan = 1,
|
||||||
|
OP_DataBlocksOptScan = 2,
|
||||||
|
OP_TableSeqScan = 3,
|
||||||
|
OP_TagScan = 4,
|
||||||
|
OP_TableBlockInfoScan= 5,
|
||||||
|
OP_Aggregate = 6,
|
||||||
|
OP_Arithmetic = 7,
|
||||||
|
OP_Groupby = 8,
|
||||||
|
OP_Limit = 9,
|
||||||
|
OP_Offset = 10,
|
||||||
|
OP_TimeWindow = 11,
|
||||||
|
OP_SessionWindow = 12,
|
||||||
|
OP_Fill = 13,
|
||||||
|
OP_MultiTableAggregate = 14,
|
||||||
|
OP_MultiTableTimeInterval = 15,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct SOperatorInfo {
|
||||||
|
uint8_t operatorType;
|
||||||
|
bool blockingOptr; // block operator or not
|
||||||
|
uint8_t status; // denote if current operator is completed
|
||||||
|
int32_t numOfOutput; // number of columns of the current operator results
|
||||||
|
char *name; // name, used to show the query execution plan
|
||||||
|
void *info; // extension attribution
|
||||||
|
SExprInfo *pExpr;
|
||||||
|
SQueryRuntimeEnv *pRuntimeEnv;
|
||||||
|
|
||||||
|
struct SOperatorInfo *upstream;
|
||||||
|
__operator_fn_t exec;
|
||||||
|
__optr_cleanup_fn_t cleanup;
|
||||||
|
} SOperatorInfo;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
QUERY_RESULT_NOT_READY = 1,
|
QUERY_RESULT_NOT_READY = 1,
|
||||||
QUERY_RESULT_READY = 2,
|
QUERY_RESULT_READY = 2,
|
||||||
|
@ -264,21 +310,9 @@ typedef struct SQInfo {
|
||||||
void* signature;
|
void* signature;
|
||||||
int32_t code; // error code to returned to client
|
int32_t code; // error code to returned to client
|
||||||
int64_t owner; // if it is in execution
|
int64_t owner; // if it is in execution
|
||||||
void* tsdb;
|
|
||||||
SMemRef memRef;
|
|
||||||
int32_t vgId;
|
|
||||||
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
|
||||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
|
||||||
SQueryRuntimeEnv runtimeEnv;
|
|
||||||
SHashObj* arrTableIdInfo;
|
|
||||||
int32_t groupIndex;
|
|
||||||
|
|
||||||
/*
|
SQueryRuntimeEnv runtimeEnv;
|
||||||
* the query is executed position on which meter of the whole list.
|
SQuery query;
|
||||||
* when the index reaches the last one of the list, it means the query is completed.
|
|
||||||
*/
|
|
||||||
int32_t tableIndex;
|
|
||||||
SGroupResInfo groupResInfo;
|
|
||||||
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
|
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
|
||||||
|
|
||||||
pthread_mutex_t lock; // used to synchronize the rsp/query threads
|
pthread_mutex_t lock; // used to synchronize the rsp/query threads
|
||||||
|
@ -287,6 +321,7 @@ typedef struct SQInfo {
|
||||||
void* rspContext; // response context
|
void* rspContext; // response context
|
||||||
int64_t startExecTs; // start to exec timestamp
|
int64_t startExecTs; // start to exec timestamp
|
||||||
char* sql; // query sql string
|
char* sql; // query sql string
|
||||||
|
SQueryCostInfo summary;
|
||||||
} SQInfo;
|
} SQInfo;
|
||||||
|
|
||||||
typedef struct SQueryParam {
|
typedef struct SQueryParam {
|
||||||
|
@ -305,10 +340,93 @@ typedef struct SQueryParam {
|
||||||
SSqlGroupbyExpr *pGroupbyExpr;
|
SSqlGroupbyExpr *pGroupbyExpr;
|
||||||
} SQueryParam;
|
} SQueryParam;
|
||||||
|
|
||||||
|
typedef struct STableScanInfo {
|
||||||
|
void *pQueryHandle;
|
||||||
|
int32_t numOfBlocks;
|
||||||
|
int32_t numOfSkipped;
|
||||||
|
int32_t numOfBlockStatis;
|
||||||
|
int64_t numOfRows;
|
||||||
|
|
||||||
|
int32_t order; // scan order
|
||||||
|
int32_t times; // repeat counts
|
||||||
|
int32_t current;
|
||||||
|
int32_t reverseTimes; // 0 by default
|
||||||
|
|
||||||
|
SQLFunctionCtx *pCtx; // next operator query context
|
||||||
|
SResultRowInfo *pResultRowInfo;
|
||||||
|
int32_t *rowCellInfoOffset;
|
||||||
|
SExprInfo *pExpr;
|
||||||
|
SSDataBlock block;
|
||||||
|
bool loadExternalRows; // load external rows (prev & next rows)
|
||||||
|
int32_t numOfOutput;
|
||||||
|
int64_t elapsedTime;
|
||||||
|
|
||||||
|
int32_t tableIndex;
|
||||||
|
} STableScanInfo;
|
||||||
|
|
||||||
|
typedef struct STagScanInfo {
|
||||||
|
SColumnInfo* pCols;
|
||||||
|
SSDataBlock* pRes;
|
||||||
|
int32_t totalTables;
|
||||||
|
int32_t currentIndex;
|
||||||
|
} STagScanInfo;
|
||||||
|
|
||||||
|
typedef struct SOptrBasicInfo {
|
||||||
|
SResultRowInfo resultRowInfo;
|
||||||
|
int32_t *rowCellInfoOffset; // offset value for each row result cell info
|
||||||
|
SQLFunctionCtx *pCtx;
|
||||||
|
SSDataBlock *pRes;
|
||||||
|
} SOptrBasicInfo;
|
||||||
|
|
||||||
|
typedef struct SOptrBasicInfo STableIntervalOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SAggOperatorInfo {
|
||||||
|
SOptrBasicInfo binfo;
|
||||||
|
uint32_t seed;
|
||||||
|
} SAggOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SArithOperatorInfo {
|
||||||
|
SOptrBasicInfo binfo;
|
||||||
|
int32_t bufCapacity;
|
||||||
|
uint32_t seed;
|
||||||
|
} SArithOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SLimitOperatorInfo {
|
||||||
|
int64_t limit;
|
||||||
|
int64_t total;
|
||||||
|
} SLimitOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SOffsetOperatorInfo {
|
||||||
|
int64_t offset;
|
||||||
|
} SOffsetOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SFillOperatorInfo {
|
||||||
|
SFillInfo *pFillInfo;
|
||||||
|
SSDataBlock *pRes;
|
||||||
|
int64_t totalInputRows;
|
||||||
|
} SFillOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SGroupbyOperatorInfo {
|
||||||
|
SOptrBasicInfo binfo;
|
||||||
|
int32_t colIndex;
|
||||||
|
char *prevData; // previous group by value
|
||||||
|
} SGroupbyOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SSWindowOperatorInfo {
|
||||||
|
SOptrBasicInfo binfo;
|
||||||
|
STimeWindow curWindow; // current time window
|
||||||
|
TSKEY prevTs; // previous timestamp
|
||||||
|
int32_t numOfRows; // number of rows
|
||||||
|
int32_t start; // start row index
|
||||||
|
} SSWindowOperatorInfo;
|
||||||
|
|
||||||
void freeParam(SQueryParam *param);
|
void freeParam(SQueryParam *param);
|
||||||
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
|
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
|
||||||
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
|
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
|
||||||
SColumnInfo* pTagCols);
|
SColumnInfo* pTagCols);
|
||||||
|
int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo,
|
||||||
|
SSqlFuncMsg **pExprMsg, SExprInfo *prevExpr);
|
||||||
|
|
||||||
SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code);
|
SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code);
|
||||||
SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
|
SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
|
||||||
SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, bool stableQuery, char* sql);
|
SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, bool stableQuery, char* sql);
|
||||||
|
@ -318,13 +436,9 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters);
|
||||||
bool isQueryKilled(SQInfo *pQInfo);
|
bool isQueryKilled(SQInfo *pQInfo);
|
||||||
int32_t checkForQueryBuf(size_t numOfTables);
|
int32_t checkForQueryBuf(size_t numOfTables);
|
||||||
bool doBuildResCheck(SQInfo* pQInfo);
|
bool doBuildResCheck(SQInfo* pQInfo);
|
||||||
void setQueryStatus(SQuery *pQuery, int8_t status);
|
void setQueryStatus(SQueryRuntimeEnv *pRuntimeEnv, int8_t status);
|
||||||
|
|
||||||
bool onlyQueryTags(SQuery* pQuery);
|
bool onlyQueryTags(SQuery* pQuery);
|
||||||
void buildTagQueryResult(SQInfo *pQInfo);
|
|
||||||
void stableQueryImpl(SQInfo *pQInfo);
|
|
||||||
void buildTableBlockDistResult(SQInfo *pQInfo);
|
|
||||||
void tableQueryImpl(SQInfo *pQInfo);
|
|
||||||
bool isValidQInfo(void *param);
|
bool isValidQInfo(void *param);
|
||||||
|
|
||||||
int32_t doDumpQueryResult(SQInfo *pQInfo, char *data);
|
int32_t doDumpQueryResult(SQInfo *pQInfo, char *data);
|
||||||
|
@ -336,4 +450,4 @@ void freeQInfo(SQInfo *pQInfo);
|
||||||
|
|
||||||
int32_t getMaximumIdleDurationSec();
|
int32_t getMaximumIdleDurationSec();
|
||||||
|
|
||||||
#endif // TDENGINE_QUERYEXECUTOR_H
|
#endif // TDENGINE_QEXECUTOR_H
|
||||||
|
|
|
@ -24,6 +24,8 @@ extern "C" {
|
||||||
#include "qExtbuffer.h"
|
#include "qExtbuffer.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
|
struct SSDataBlock;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STColumn col; // column info
|
STColumn col; // column info
|
||||||
int16_t functionId; // sql function id
|
int16_t functionId; // sql function id
|
||||||
|
@ -78,7 +80,7 @@ void* taosDestroyFillInfo(SFillInfo *pFillInfo);
|
||||||
|
|
||||||
void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
|
void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
|
||||||
|
|
||||||
void taosFillSetDataBlockFromFilePage(SFillInfo* pFillInfo, const tFilePage** pInput);
|
void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
|
||||||
|
|
||||||
void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage* pInput);
|
void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage* pInput);
|
||||||
|
|
||||||
|
@ -88,7 +90,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t
|
||||||
|
|
||||||
int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType);
|
int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType);
|
||||||
|
|
||||||
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, tFilePage** output, int32_t capacity);
|
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ typedef struct SResultBufStatis {
|
||||||
} SResultBufStatis;
|
} SResultBufStatis;
|
||||||
|
|
||||||
typedef struct SDiskbasedResultBuf {
|
typedef struct SDiskbasedResultBuf {
|
||||||
int32_t numOfRowsPerPage;
|
|
||||||
int32_t numOfPages;
|
int32_t numOfPages;
|
||||||
int64_t totalBufSize;
|
int64_t totalBufSize;
|
||||||
int64_t fileSize; // disk file size
|
int64_t fileSize; // disk file size
|
||||||
|
@ -77,7 +76,7 @@ typedef struct SDiskbasedResultBuf {
|
||||||
SResultBufStatis statis;
|
SResultBufStatis statis;
|
||||||
} SDiskbasedResultBuf;
|
} SDiskbasedResultBuf;
|
||||||
|
|
||||||
#define DEFAULT_INTERN_BUF_PAGE_SIZE (256L) // in bytes
|
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
|
||||||
#define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1}
|
#define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,8 +88,7 @@ typedef struct SDiskbasedResultBuf {
|
||||||
* @param handle
|
* @param handle
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t rowSize, int32_t pagesize,
|
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t pagesize, int32_t inMemBufSize, const void* handle);
|
||||||
int32_t inMemBufSize, const void* handle);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -101,13 +99,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro
|
||||||
*/
|
*/
|
||||||
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
|
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param pResultBuf
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
size_t getNumOfRowsPerPage(const SDiskbasedResultBuf* pResultBuf);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param pResultBuf
|
* @param pResultBuf
|
||||||
|
|
|
@ -27,6 +27,23 @@ extern "C" {
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
#define ParseTOKENTYPE SStrToken
|
#define ParseTOKENTYPE SStrToken
|
||||||
|
|
||||||
|
#define NON_ARITHMEIC_EXPR 0
|
||||||
|
#define NORMAL_ARITHMETIC 1
|
||||||
|
#define AGG_ARIGHTMEIC 2
|
||||||
|
|
||||||
|
enum SQL_NODE_TYPE {
|
||||||
|
SQL_NODE_TABLE_COLUMN= 1,
|
||||||
|
SQL_NODE_SQLFUNCTION = 2,
|
||||||
|
SQL_NODE_VALUE = 3,
|
||||||
|
SQL_NODE_EXPR = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SQL_NODE_FROM_TYPE {
|
||||||
|
SQL_NODE_FROM_SUBQUERY = 1,
|
||||||
|
SQL_NODE_FROM_NAMELIST = 2,
|
||||||
|
};
|
||||||
|
|
||||||
extern char tTokenTypeSwitcher[13];
|
extern char tTokenTypeSwitcher[13];
|
||||||
|
|
||||||
#define toTSDBType(x) \
|
#define toTSDBType(x) \
|
||||||
|
@ -38,6 +55,9 @@ extern char tTokenTypeSwitcher[13];
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0)
|
||||||
|
#define TPARSER_SET_NONE_TOKEN(_t) ((_t).n = 0)
|
||||||
|
|
||||||
typedef struct SLimitVal {
|
typedef struct SLimitVal {
|
||||||
int64_t limit;
|
int64_t limit;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
|
@ -58,20 +78,45 @@ typedef struct SIntervalVal {
|
||||||
SStrToken offset;
|
SStrToken offset;
|
||||||
} SIntervalVal;
|
} SIntervalVal;
|
||||||
|
|
||||||
typedef struct SQuerySQL {
|
typedef struct SSessionWindowVal {
|
||||||
struct tSQLExprList *pSelection; // select clause
|
SStrToken col;
|
||||||
SArray * from; // from clause SArray<tVariantListItem>
|
SStrToken gap;
|
||||||
struct tSQLExpr * pWhere; // where clause [optional]
|
} SSessionWindowVal;
|
||||||
|
|
||||||
|
struct SFromInfo;
|
||||||
|
|
||||||
|
typedef struct SQuerySqlNode {
|
||||||
|
struct SArray *pSelectList; // select clause
|
||||||
|
struct SFromInfo *from; // from clause SArray<SQuerySqlNode>
|
||||||
|
struct tSqlExpr *pWhere; // where clause [optional]
|
||||||
SArray *pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
|
SArray *pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
|
||||||
SArray *pSortOrder; // orderby [optional], SArray<tVariantListItem>
|
SArray *pSortOrder; // orderby [optional], SArray<tVariantListItem>
|
||||||
SStrToken interval; // interval [optional]
|
SArray *fillType; // fill type[optional], SArray<tVariantListItem>
|
||||||
SStrToken offset; // offset window [optional]
|
SIntervalVal interval; // (interval, interval_offset) [optional]
|
||||||
|
SSessionWindowVal sessionVal; // session window [optional]
|
||||||
SStrToken sliding; // sliding window [optional]
|
SStrToken sliding; // sliding window [optional]
|
||||||
SLimitVal limit; // limit offset [optional]
|
SLimitVal limit; // limit offset [optional]
|
||||||
SLimitVal slimit; // group limit offset [optional]
|
SLimitVal slimit; // group limit offset [optional]
|
||||||
SArray * fillType; // fill type[optional], SArray<tVariantListItem>
|
SStrToken sqlstr; // sql string in select clause
|
||||||
SStrToken selectToken; // sql string
|
} SQuerySqlNode;
|
||||||
} SQuerySQL;
|
|
||||||
|
typedef struct STableNamePair {
|
||||||
|
SStrToken name;
|
||||||
|
SStrToken aliasName;
|
||||||
|
} STableNamePair;
|
||||||
|
|
||||||
|
typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
|
||||||
|
SQuerySqlNode **pClause;
|
||||||
|
int32_t numOfClause;
|
||||||
|
} SSubclauseInfo;
|
||||||
|
|
||||||
|
typedef struct SFromInfo {
|
||||||
|
int32_t type; // nested query|table name list
|
||||||
|
union {
|
||||||
|
SSubclauseInfo *pNode;
|
||||||
|
SArray *tableList; // SArray<STableNamePair>
|
||||||
|
};
|
||||||
|
} SFromInfo;
|
||||||
|
|
||||||
typedef struct SCreatedTableInfo {
|
typedef struct SCreatedTableInfo {
|
||||||
SStrToken name; // table name token
|
SStrToken name; // table name token
|
||||||
|
@ -83,7 +128,7 @@ typedef struct SCreatedTableInfo {
|
||||||
int8_t igExist; // ignore if exists
|
int8_t igExist; // ignore if exists
|
||||||
} SCreatedTableInfo;
|
} SCreatedTableInfo;
|
||||||
|
|
||||||
typedef struct SCreateTableSQL {
|
typedef struct SCreateTableSql {
|
||||||
SStrToken name; // table name, create table [name] xxx
|
SStrToken name; // table name, create table [name] xxx
|
||||||
int8_t type; // create normal table/from super table/ stream
|
int8_t type; // create normal table/from super table/ stream
|
||||||
bool existCheck;
|
bool existCheck;
|
||||||
|
@ -94,8 +139,8 @@ typedef struct SCreateTableSQL {
|
||||||
} colInfo;
|
} colInfo;
|
||||||
|
|
||||||
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
||||||
SQuerySQL *pSelect;
|
SQuerySqlNode *pSelect;
|
||||||
} SCreateTableSQL;
|
} SCreateTableSql;
|
||||||
|
|
||||||
typedef struct SAlterTableInfo {
|
typedef struct SAlterTableInfo {
|
||||||
SStrToken name;
|
SStrToken name;
|
||||||
|
@ -168,51 +213,104 @@ typedef struct SMiscInfo {
|
||||||
};
|
};
|
||||||
} SMiscInfo;
|
} SMiscInfo;
|
||||||
|
|
||||||
typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
|
|
||||||
SQuerySQL **pClause;
|
|
||||||
int32_t numOfClause;
|
|
||||||
} SSubclauseInfo;
|
|
||||||
|
|
||||||
typedef struct SSqlInfo {
|
typedef struct SSqlInfo {
|
||||||
int32_t type;
|
int32_t type;
|
||||||
bool valid;
|
bool valid;
|
||||||
SSubclauseInfo subclauseInfo;
|
SSubclauseInfo subclauseInfo;
|
||||||
char msg[256];
|
char msg[256];
|
||||||
union {
|
union {
|
||||||
SCreateTableSQL *pCreateTableInfo;
|
SCreateTableSql *pCreateTableInfo;
|
||||||
SAlterTableInfo *pAlterInfo;
|
SAlterTableInfo *pAlterInfo;
|
||||||
SMiscInfo *pMiscInfo;
|
SMiscInfo *pMiscInfo;
|
||||||
};
|
};
|
||||||
} SSqlInfo;
|
} SSqlInfo;
|
||||||
|
|
||||||
typedef struct tSQLExpr {
|
typedef struct tSqlExpr {
|
||||||
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
uint16_t type; // sql node type
|
||||||
|
uint32_t tokenId; // TK_LE: less than(binary expr)
|
||||||
|
|
||||||
// the full sql string of function(col, param), which is actually the raw
|
// the whole string of the function(col, param), while the function name is kept in token
|
||||||
// field name, since the function name is kept in nSQLOptr already
|
|
||||||
SStrToken operand;
|
SStrToken operand;
|
||||||
SStrToken colInfo; // field id
|
uint32_t functionId; // function id
|
||||||
tVariant val; // value only for string, float, int
|
|
||||||
|
SStrToken colInfo; // table column info
|
||||||
|
tVariant value; // the use input value
|
||||||
SStrToken token; // original sql expr string
|
SStrToken token; // original sql expr string
|
||||||
|
|
||||||
struct tSQLExpr *pLeft; // left child
|
struct tSqlExpr *pLeft; // left child
|
||||||
struct tSQLExpr *pRight; // right child
|
struct tSqlExpr *pRight; // right child
|
||||||
struct tSQLExprList *pParam; // function parameters
|
struct SArray *pParam; // function parameters list
|
||||||
} tSQLExpr;
|
} tSqlExpr;
|
||||||
|
|
||||||
// used in select clause. select <tSQLExprList> from xxx
|
// used in select clause. select <SArray> from xxx
|
||||||
typedef struct tSqlExprItem {
|
typedef struct tSqlExprItem {
|
||||||
tSQLExpr *pNode; // The list of expressions
|
tSqlExpr *pNode; // The list of expressions
|
||||||
char *aliasName; // alias name, null-terminated string
|
char *aliasName; // alias name, null-terminated string
|
||||||
bool distinct;
|
bool distinct;
|
||||||
} tSqlExprItem;
|
} tSqlExprItem;
|
||||||
|
|
||||||
// todo refactor by using SArray
|
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
|
||||||
typedef struct tSQLExprList {
|
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||||
int32_t nExpr; /* Number of expressions on the list */
|
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
||||||
int32_t nAlloc; /* Number of entries allocated below */
|
|
||||||
tSqlExprItem *a; /* One entry for each expression */
|
SFromInfo *setTableNameList(SFromInfo* pFromInfo, SStrToken *pName, SStrToken* pAlias);
|
||||||
} tSQLExprList;
|
SFromInfo *setSubquery(SFromInfo* pFromInfo, SQuerySqlNode *pSqlNode);
|
||||||
|
void *destroyFromInfo(SFromInfo* pFromInfo);
|
||||||
|
|
||||||
|
// sql expr leaf node
|
||||||
|
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType);
|
||||||
|
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
|
||||||
|
|
||||||
|
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType);
|
||||||
|
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc);
|
||||||
|
void tSqlExprCompact(tSqlExpr** pExpr);
|
||||||
|
bool tSqlExprIsLeaf(tSqlExpr* pExpr);
|
||||||
|
bool tSqlExprIsParentOfLeaf(tSqlExpr* pExpr);
|
||||||
|
void tSqlExprDestroy(tSqlExpr *pExpr);
|
||||||
|
SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct, SStrToken *pToken);
|
||||||
|
void tSqlExprListDestroy(SArray *pList);
|
||||||
|
|
||||||
|
SQuerySqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelectList, SFromInfo *pFrom, tSqlExpr *pWhere,
|
||||||
|
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps,
|
||||||
|
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit);
|
||||||
|
|
||||||
|
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SQuerySqlNode *pSelect, int32_t type);
|
||||||
|
|
||||||
|
SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableTable);
|
||||||
|
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNames, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
|
||||||
|
|
||||||
|
void destroyAllSelectClause(SSubclauseInfo *pSql);
|
||||||
|
void destroyQuerySqlNode(SQuerySqlNode *pSql);
|
||||||
|
void freeCreateTableInfo(void* p);
|
||||||
|
|
||||||
|
SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
|
||||||
|
SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo);
|
||||||
|
|
||||||
|
SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause);
|
||||||
|
|
||||||
|
void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken *pIfNotExists);
|
||||||
|
|
||||||
|
void SqlInfoDestroy(SSqlInfo *pInfo);
|
||||||
|
|
||||||
|
void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
|
||||||
|
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck,int16_t dbType,int16_t tableType);
|
||||||
|
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
|
||||||
|
|
||||||
|
void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDbInfo *pDB, SStrToken *pIgExists);
|
||||||
|
|
||||||
|
void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctInfo *pAcctInfo);
|
||||||
|
void setCreateUserSql(SSqlInfo *pInfo, SStrToken *pName, SStrToken *pPasswd);
|
||||||
|
void setKillSql(SSqlInfo *pInfo, int32_t type, SStrToken *ip);
|
||||||
|
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken* pPwd, SStrToken *pPrivilege);
|
||||||
|
|
||||||
|
void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
|
||||||
|
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
|
||||||
|
|
||||||
|
// prefix show db.tables;
|
||||||
|
void tSetDbName(SStrToken *pCpxName, SStrToken *pDb);
|
||||||
|
|
||||||
|
void tSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
|
||||||
|
void tSetColumnType(TAOS_FIELD *pField, SStrToken *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -229,82 +327,19 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
||||||
*/
|
*/
|
||||||
void ParseFree(void *p, void (*freeProc)(void *));
|
void ParseFree(void *p, void (*freeProc)(void *));
|
||||||
|
|
||||||
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
|
/**
|
||||||
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
*
|
||||||
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
* @param mallocProc The parser allocator
|
||||||
|
* @return
|
||||||
tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType);
|
*/
|
||||||
|
|
||||||
tSQLExpr *tSqlExprClone(tSQLExpr *pSrc);
|
|
||||||
|
|
||||||
void tSqlExprDestroy(tSQLExpr *pExpr);
|
|
||||||
|
|
||||||
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pDistinct, SStrToken *pToken);
|
|
||||||
|
|
||||||
void tSqlExprListDestroy(tSQLExprList *pList);
|
|
||||||
|
|
||||||
SQuerySQL *tSetQuerySqlElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
|
||||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
|
||||||
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
|
||||||
|
|
||||||
SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSelect, int32_t type);
|
|
||||||
|
|
||||||
void tSqlExprNodeDestroy(tSQLExpr *pExpr);
|
|
||||||
|
|
||||||
SAlterTableInfo * tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableTable);
|
|
||||||
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNames, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
|
|
||||||
|
|
||||||
void destroyAllSelectClause(SSubclauseInfo *pSql);
|
|
||||||
void doDestroyQuerySql(SQuerySQL *pSql);
|
|
||||||
void freeCreateTableInfo(void* p);
|
|
||||||
|
|
||||||
SSqlInfo * setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
|
|
||||||
SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo);
|
|
||||||
|
|
||||||
SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause);
|
|
||||||
|
|
||||||
void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken *pIfNotExists);
|
|
||||||
|
|
||||||
void SqlInfoDestroy(SSqlInfo *pInfo);
|
|
||||||
|
|
||||||
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
|
|
||||||
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck,int16_t dbType,int16_t tableType);
|
|
||||||
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
|
|
||||||
|
|
||||||
void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDbInfo *pDB, SStrToken *pIgExists);
|
|
||||||
|
|
||||||
void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctInfo *pAcctInfo);
|
|
||||||
void setCreateUserSql(SSqlInfo *pInfo, SStrToken *pName, SStrToken *pPasswd);
|
|
||||||
void setKillSql(SSqlInfo *pInfo, int32_t type, SStrToken *ip);
|
|
||||||
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken* pPwd, SStrToken *pPrivilege);
|
|
||||||
|
|
||||||
void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
|
|
||||||
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
|
|
||||||
|
|
||||||
// prefix show db.tables;
|
|
||||||
void setDbName(SStrToken *pCpxName, SStrToken *pDb);
|
|
||||||
|
|
||||||
tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType);
|
|
||||||
|
|
||||||
tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
|
|
||||||
|
|
||||||
void tSqlSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
|
|
||||||
|
|
||||||
void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type);
|
|
||||||
|
|
||||||
void *ParseAlloc(void *(*mallocProc)(size_t));
|
void *ParseAlloc(void *(*mallocProc)(size_t));
|
||||||
|
|
||||||
enum {
|
/**
|
||||||
TSQL_NODE_TYPE_EXPR = 0x1,
|
*
|
||||||
TSQL_NODE_TYPE_ID = 0x2,
|
* @param str sql string
|
||||||
TSQL_NODE_TYPE_VALUE = 0x4,
|
* @return sql ast
|
||||||
};
|
*/
|
||||||
|
SSqlInfo qSqlParse(const char *str);
|
||||||
#define NON_ARITHMEIC_EXPR 0
|
|
||||||
#define NORMAL_ARITHMETIC 1
|
|
||||||
#define AGG_ARIGHTMEIC 2
|
|
||||||
|
|
||||||
SSqlInfo qSQLParse(const char *str);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,10 @@ STSBuf* tsBufClone(STSBuf* pTSBuf);
|
||||||
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id);
|
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id);
|
||||||
|
|
||||||
void tsBufFlush(STSBuf* pTSBuf);
|
void tsBufFlush(STSBuf* pTSBuf);
|
||||||
|
|
||||||
void tsBufResetPos(STSBuf* pTSBuf);
|
void tsBufResetPos(STSBuf* pTSBuf);
|
||||||
STSElem tsBufGetElem(STSBuf* pTSBuf);
|
|
||||||
|
|
||||||
bool tsBufNextPos(STSBuf* pTSBuf);
|
bool tsBufNextPos(STSBuf* pTSBuf);
|
||||||
|
|
||||||
|
STSElem tsBufGetElem(STSBuf* pTSBuf);
|
||||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag);
|
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag);
|
||||||
|
|
||||||
STSCursor tsBufGetCursor(STSBuf* pTSBuf);
|
STSCursor tsBufGetCursor(STSBuf* pTSBuf);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
|
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
|
||||||
|
|
||||||
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
||||||
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
|
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!(sq)))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
|
||||||
|
|
||||||
int32_t getOutputInterResultBufSize(SQuery* pQuery);
|
int32_t getOutputInterResultBufSize(SQuery* pQuery);
|
||||||
|
|
||||||
|
@ -44,22 +44,18 @@ void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot);
|
||||||
bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot);
|
bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot);
|
||||||
void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow, int16_t type);
|
void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow, int16_t type);
|
||||||
|
|
||||||
SResultRowCellInfo* getResultCell(SQueryRuntimeEnv* pRuntimeEnv, const SResultRow* pRow, int32_t index);
|
SResultRowCellInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset);
|
||||||
|
|
||||||
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
|
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
|
||||||
assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size);
|
assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size);
|
||||||
return pResultRowInfo->pResult[slot];
|
return pResultRowInfo->pResult[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SResultRow *pResult,
|
static FORCE_INLINE char *getPosInResultPage(SQuery *pQuery, tFilePage* page, int32_t rowOffset, int16_t offset) {
|
||||||
tFilePage* page) {
|
assert(rowOffset >= 0 && pQuery != NULL);
|
||||||
assert(pResult != NULL && pRuntimeEnv != NULL);
|
|
||||||
|
|
||||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
int32_t numOfRows = (int32_t)GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pQuery->topBotQuery, pQuery->stableQuery);
|
||||||
|
return ((char *)page->data) + rowOffset + offset * numOfRows;
|
||||||
int32_t realRowId = (int32_t)(pResult->rowId * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pRuntimeEnv->topBotQuery, pRuntimeEnv->stableQuery));
|
|
||||||
return ((char *)page->data) + pRuntimeEnv->offset[columnIndex] * pRuntimeEnv->numOfRowsPerPage +
|
|
||||||
pQuery->pExpr1[columnIndex].bytes * realRowId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
|
bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
|
||||||
|
@ -74,8 +70,6 @@ void* destroyResultRowPool(SResultRowPool* p);
|
||||||
int32_t getNumOfAllocatedResultRows(SResultRowPool* p);
|
int32_t getNumOfAllocatedResultRows(SResultRowPool* p);
|
||||||
int32_t getNumOfUsedResultRows(SResultRowPool* p);
|
int32_t getNumOfUsedResultRows(SResultRowPool* p);
|
||||||
|
|
||||||
bool isPointInterpoQuery(SQuery *pQuery);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SArray* pResult; // SArray<SResPair>
|
SArray* pResult; // SArray<SResPair>
|
||||||
int32_t colId;
|
int32_t colId;
|
||||||
|
@ -85,12 +79,14 @@ void interResToBinary(SBufferWriter* bw, SArray* pRes, int32_t tagLen);
|
||||||
SArray* interResFromBinary(const char* data, int32_t len);
|
SArray* interResFromBinary(const char* data, int32_t len);
|
||||||
void freeInterResult(void* param);
|
void freeInterResult(void* param);
|
||||||
|
|
||||||
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo, int32_t offset);
|
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo);
|
||||||
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
|
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
|
||||||
|
bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo);
|
||||||
bool hasRemainData(SGroupResInfo* pGroupResInfo);
|
bool hasRemainData(SGroupResInfo* pGroupResInfo);
|
||||||
|
|
||||||
bool incNextGroup(SGroupResInfo* pGroupResInfo);
|
bool incNextGroup(SGroupResInfo* pGroupResInfo);
|
||||||
int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo);
|
int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo);
|
||||||
|
|
||||||
int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQInfo *pQInfo);
|
int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t* offset);
|
||||||
|
|
||||||
#endif // TDENGINE_QUERYUTIL_H
|
#endif // TDENGINE_QUERYUTIL_H
|
||||||
|
|
|
@ -92,11 +92,11 @@ cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
|
||||||
|
|
||||||
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
|
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
|
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd ::= SHOW CREATE DATABASE ids(X). {
|
cmd ::= SHOW CREATE DATABASE ids(X). {
|
||||||
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
|
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd ::= SHOW dbPrefix(X) TABLES. {
|
cmd ::= SHOW dbPrefix(X) TABLES. {
|
||||||
|
@ -113,19 +113,19 @@ cmd ::= SHOW dbPrefix(X) STABLES. {
|
||||||
|
|
||||||
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
|
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
|
||||||
SStrToken token;
|
SStrToken token;
|
||||||
setDbName(&token, &X);
|
tSetDbName(&token, &X);
|
||||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
|
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd ::= SHOW dbPrefix(X) VGROUPS. {
|
cmd ::= SHOW dbPrefix(X) VGROUPS. {
|
||||||
SStrToken token;
|
SStrToken token;
|
||||||
setDbName(&token, &X);
|
tSetDbName(&token, &X);
|
||||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
|
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
|
cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
|
||||||
SStrToken token;
|
SStrToken token;
|
||||||
setDbName(&token, &X);
|
tSetDbName(&token, &X);
|
||||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &Y);
|
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,26 +144,26 @@ cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z). {
|
||||||
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_DEFAULT, -1); }
|
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_DEFAULT, -1); }
|
||||||
cmd ::= DROP TOPIC ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_TOPIC, -1); }
|
cmd ::= DROP TOPIC ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_TOPIC, -1); }
|
||||||
|
|
||||||
cmd ::= DROP DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
|
cmd ::= DROP DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
|
||||||
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
|
cmd ::= DROP USER ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
|
||||||
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
|
cmd ::= DROP ACCOUNT ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
|
||||||
|
|
||||||
/////////////////////////////////THE USE STATEMENT//////////////////////////////////////////
|
/////////////////////////////////THE USE STATEMENT//////////////////////////////////////////
|
||||||
cmd ::= USE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_USE_DB, 1, &X);}
|
cmd ::= USE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &X);}
|
||||||
|
|
||||||
/////////////////////////////////THE DESCRIBE STATEMENT/////////////////////////////////////
|
/////////////////////////////////THE DESCRIBE STATEMENT/////////////////////////////////////
|
||||||
cmd ::= DESCRIBE ids(X) cpxName(Y). {
|
cmd ::= DESCRIBE ids(X) cpxName(Y). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
|
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
|
/////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
|
||||||
cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); }
|
cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); }
|
||||||
cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);}
|
cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);}
|
||||||
cmd ::= ALTER DNODE ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); }
|
cmd ::= ALTER DNODE ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); }
|
||||||
cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); }
|
cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); }
|
||||||
cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
|
cmd ::= ALTER LOCAL ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
|
||||||
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); }
|
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); }
|
||||||
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
|
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
|
||||||
cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
|
cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ ifnotexists(X) ::= . { X.n = 0;}
|
||||||
|
|
||||||
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
||||||
//create option for dnode/db/user/account
|
//create option for dnode/db/user/account
|
||||||
cmd ::= CREATE DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
|
cmd ::= CREATE DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
|
||||||
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
|
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
|
||||||
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
|
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
|
||||||
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
|
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
|
||||||
|
@ -299,17 +299,17 @@ alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.parti
|
||||||
%type typename {TAOS_FIELD}
|
%type typename {TAOS_FIELD}
|
||||||
typename(A) ::= ids(X). {
|
typename(A) ::= ids(X). {
|
||||||
X.type = 0;
|
X.type = 0;
|
||||||
tSqlSetColumnType (&A, &X);
|
tSetColumnType (&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
//define binary type, e.g., binary(10), nchar(10)
|
//define binary type, e.g., binary(10), nchar(10)
|
||||||
typename(A) ::= ids(X) LP signed(Y) RP. {
|
typename(A) ::= ids(X) LP signed(Y) RP. {
|
||||||
if (Y <= 0) {
|
if (Y <= 0) {
|
||||||
X.type = 0;
|
X.type = 0;
|
||||||
tSqlSetColumnType(&A, &X);
|
tSetColumnType(&A, &X);
|
||||||
} else {
|
} else {
|
||||||
X.type = -Y; // negative value of name length
|
X.type = -Y; // negative value of name length
|
||||||
tSqlSetColumnType(&A, &X);
|
tSetColumnType(&A, &X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ typename(A) ::= ids(X) LP signed(Y) RP. {
|
||||||
typename(A) ::= ids(X) UNSIGNED(Z). {
|
typename(A) ::= ids(X) UNSIGNED(Z). {
|
||||||
X.type = 0;
|
X.type = 0;
|
||||||
X.n = ((Z.z + Z.n) - X.z);
|
X.n = ((Z.z + Z.n) - X.z);
|
||||||
tSqlSetColumnType (&A, &X);
|
tSetColumnType (&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type signed {int64_t}
|
%type signed {int64_t}
|
||||||
|
@ -331,10 +331,10 @@ cmd ::= CREATE TABLE create_stable_args. {}
|
||||||
cmd ::= CREATE STABLE create_stable_args. {}
|
cmd ::= CREATE STABLE create_stable_args. {}
|
||||||
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
|
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
|
||||||
|
|
||||||
%type create_table_list{SCreateTableSQL*}
|
%type create_table_list{SCreateTableSql*}
|
||||||
%destructor create_table_list{destroyCreateTableSql($$);}
|
%destructor create_table_list{destroyCreateTableSql($$);}
|
||||||
create_table_list(A) ::= create_from_stable(Z). {
|
create_table_list(A) ::= create_from_stable(Z). {
|
||||||
SCreateTableSQL* pCreateTable = calloc(1, sizeof(SCreateTableSQL));
|
SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql));
|
||||||
pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));
|
pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));
|
||||||
|
|
||||||
taosArrayPush(pCreateTable->childTableInfo, &Z);
|
taosArrayPush(pCreateTable->childTableInfo, &Z);
|
||||||
|
@ -347,9 +347,9 @@ create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
|
||||||
A = X;
|
A = X;
|
||||||
}
|
}
|
||||||
|
|
||||||
%type create_table_args{SCreateTableSQL*}
|
%type create_table_args{SCreateTableSql*}
|
||||||
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
|
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
|
||||||
A = tSetCreateSqlElems(X, NULL, NULL, TSQL_CREATE_TABLE);
|
A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE);
|
||||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
V.n += Z.n;
|
V.n += Z.n;
|
||||||
|
@ -357,9 +357,9 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create super table
|
// create super table
|
||||||
%type create_stable_args{SCreateTableSQL*}
|
%type create_stable_args{SCreateTableSql*}
|
||||||
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
|
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
|
||||||
A = tSetCreateSqlElems(X, Y, NULL, TSQL_CREATE_STABLE);
|
A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE);
|
||||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
V.n += Z.n;
|
V.n += Z.n;
|
||||||
|
@ -389,7 +389,7 @@ tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(SSt
|
||||||
// create stream
|
// create stream
|
||||||
// create table table_name as select count(*) from super_table_name interval(time)
|
// create table table_name as select count(*) from super_table_name interval(time)
|
||||||
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
|
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
|
||||||
A = tSetCreateSqlElems(NULL, NULL, S, TSQL_CREATE_STREAM);
|
A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM);
|
||||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
V.n += Z.n;
|
V.n += Z.n;
|
||||||
|
@ -405,7 +405,7 @@ columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(T
|
||||||
// The information used for a column is the name and type of column:
|
// The information used for a column is the name and type of column:
|
||||||
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
||||||
column(A) ::= ids(X) typename(Y). {
|
column(A) ::= ids(X) typename(Y). {
|
||||||
tSqlSetColumnInfo(&A, &X, &Y);
|
tSetColumnInfo(&A, &X, &Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type tagitemlist {SArray*}
|
%type tagitemlist {SArray*}
|
||||||
|
@ -450,37 +450,37 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). {
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////// The SELECT statement /////////////////////////////////
|
//////////////////////// The SELECT statement /////////////////////////////////
|
||||||
%type select {SQuerySQL*}
|
%type select {SQuerySqlNode*}
|
||||||
%destructor select {doDestroyQuerySql($$);}
|
%destructor select {destroyQuerySqlNode($$);}
|
||||||
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). {
|
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) session_option(H) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). {
|
||||||
A = tSetQuerySqlElems(&T, W, X, Y, P, Z, &K, &S, F, &L, &G);
|
A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &S, F, &L, &G);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select(A) ::= LP select(B) RP. {A = B;}
|
||||||
|
|
||||||
%type union {SSubclauseInfo*}
|
%type union {SSubclauseInfo*}
|
||||||
%destructor union {destroyAllSelectClause($$);}
|
%destructor union {destroyAllSelectClause($$);}
|
||||||
|
|
||||||
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
|
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
|
||||||
union(Y) ::= LP union(X) RP. { Y = X; }
|
|
||||||
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, X); }
|
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, X); }
|
||||||
union(Y) ::= union(Z) UNION ALL LP select(X) RP. { Y = appendSelectClause(Z, X); }
|
|
||||||
|
|
||||||
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
|
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
|
||||||
|
|
||||||
// Support for the SQL exprssion without from & where subclauses, e.g.,
|
// Support for the SQL exprssion without from & where subclauses, e.g.,
|
||||||
// select current_database(),
|
// select current_database()
|
||||||
// select server_version(), select client_version(),
|
// select server_version()
|
||||||
// select server_state();
|
// select client_version()
|
||||||
|
// select server_state()
|
||||||
select(A) ::= SELECT(T) selcollist(W). {
|
select(A) ::= SELECT(T) selcollist(W). {
|
||||||
A = tSetQuerySqlElems(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// selcollist is a list of expressions that are to become the return
|
// selcollist is a list of expressions that are to become the return
|
||||||
// values of the SELECT statement. The "*" in statements like
|
// values of the SELECT statement. The "*" in statements like
|
||||||
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
|
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
|
||||||
%type selcollist {tSQLExprList*}
|
%type selcollist {SArray*}
|
||||||
%destructor selcollist {tSqlExprListDestroy($$);}
|
%destructor selcollist {tSqlExprListDestroy($$);}
|
||||||
|
|
||||||
%type sclp {tSQLExprList*}
|
%type sclp {SArray*}
|
||||||
%destructor sclp {tSqlExprListDestroy($$);}
|
%destructor sclp {tSqlExprListDestroy($$);}
|
||||||
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
||||||
sclp(A) ::= . {A = 0;}
|
sclp(A) ::= . {A = 0;}
|
||||||
|
@ -489,13 +489,12 @@ selcollist(A) ::= sclp(P) distinct(Z) expr(X) as(Y). {
|
||||||
}
|
}
|
||||||
|
|
||||||
selcollist(A) ::= sclp(P) STAR. {
|
selcollist(A) ::= sclp(P) STAR. {
|
||||||
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
|
tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL);
|
||||||
A = tSqlExprListAppend(P, pNode, 0, 0);
|
A = tSqlExprListAppend(P, pNode, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An option "AS <id>" phrase that can follow one of the expressions that
|
// An option "AS <id>" phrase that can follow one of the expressions that
|
||||||
// define the result set, or one of the tables in the FROM clause.
|
// define the result set, or one of the tables in the FROM clause.
|
||||||
//
|
|
||||||
%type as {SStrToken}
|
%type as {SStrToken}
|
||||||
as(X) ::= AS ids(Y). { X = Y; }
|
as(X) ::= AS ids(Y). { X = Y; }
|
||||||
as(X) ::= ids(Y). { X = Y; }
|
as(X) ::= ids(Y). { X = Y; }
|
||||||
|
@ -506,39 +505,36 @@ distinct(X) ::= DISTINCT(Y). { X = Y; }
|
||||||
distinct(X) ::= . { X.n = 0;}
|
distinct(X) ::= . { X.n = 0;}
|
||||||
|
|
||||||
// A complete FROM clause.
|
// A complete FROM clause.
|
||||||
%type from {SArray*}
|
%type from {SFromInfo*}
|
||||||
// current not support query from no-table
|
|
||||||
from(A) ::= FROM tablelist(X). {A = X;}
|
from(A) ::= FROM tablelist(X). {A = X;}
|
||||||
|
from(A) ::= FROM LP union(Y) RP. {A = Y;}
|
||||||
|
|
||||||
%type tablelist {SArray*}
|
%type tablelist {SArray*}
|
||||||
tablelist(A) ::= ids(X) cpxName(Y). {
|
tablelist(A) ::= ids(X) cpxName(Y). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
A = tVariantListAppendToken(NULL, &X, -1);
|
A = setTableNameList(NULL, &X, NULL);
|
||||||
A = tVariantListAppendToken(A, &X, -1); // table alias name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
|
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
toTSDBType(Z.type);
|
toTSDBType(Z.type);
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
A = tVariantListAppendToken(NULL, &X, -1);
|
A = setTableNameList(NULL, &X, &Z);
|
||||||
A = tVariantListAppendToken(A, &Z, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
X.n += Z.n;
|
X.n += Z.n;
|
||||||
A = tVariantListAppendToken(Y, &X, -1);
|
A = setTableNameList(Y, &X, NULL);
|
||||||
A = tVariantListAppendToken(A, &X, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
toTSDBType(F.type);
|
toTSDBType(F.type);
|
||||||
X.n += Z.n;
|
X.n += Z.n;
|
||||||
A = tVariantListAppendToken(Y, &X, -1);
|
|
||||||
A = tVariantListAppendToken(A, &F, -1);
|
A = setTableNameList(Y, &X, &F);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
|
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
|
||||||
|
@ -546,10 +542,18 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
||||||
tmvar(A) ::= VARIABLE(X). {A = X;}
|
tmvar(A) ::= VARIABLE(X). {A = X;}
|
||||||
|
|
||||||
%type interval_opt {SIntervalVal}
|
%type interval_opt {SIntervalVal}
|
||||||
interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.offset.z = NULL; N.offset.type = 0;}
|
interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0;}
|
||||||
interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(O) RP. {N.interval = E; N.offset = O;}
|
interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X;}
|
||||||
interval_opt(N) ::= . {memset(&N, 0, sizeof(N));}
|
interval_opt(N) ::= . {memset(&N, 0, sizeof(N));}
|
||||||
|
|
||||||
|
%type session_option {SSessionWindowVal}
|
||||||
|
session_option(X) ::= . {X.col.n = 0; X.gap.n = 0;}
|
||||||
|
session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. {
|
||||||
|
V.n += Z.n;
|
||||||
|
X.col = V;
|
||||||
|
X.gap = Y;
|
||||||
|
}
|
||||||
|
|
||||||
%type fill_opt {SArray*}
|
%type fill_opt {SArray*}
|
||||||
%destructor fill_opt {taosArrayDestroy($$);}
|
%destructor fill_opt {taosArrayDestroy($$);}
|
||||||
fill_opt(N) ::= . { N = 0; }
|
fill_opt(N) ::= . { N = 0; }
|
||||||
|
@ -622,7 +626,7 @@ grouplist(A) ::= item(X). {
|
||||||
}
|
}
|
||||||
|
|
||||||
//having clause, ignore the input condition in having
|
//having clause, ignore the input condition in having
|
||||||
%type having_opt {tSQLExpr*}
|
%type having_opt {tSqlExpr*}
|
||||||
%destructor having_opt {tSqlExprDestroy($$);}
|
%destructor having_opt {tSqlExprDestroy($$);}
|
||||||
having_opt(A) ::=. {A = 0;}
|
having_opt(A) ::=. {A = 0;}
|
||||||
having_opt(A) ::= HAVING expr(X). {A = X;}
|
having_opt(A) ::= HAVING expr(X). {A = X;}
|
||||||
|
@ -644,7 +648,7 @@ slimit_opt(A) ::= SLIMIT signed(X) SOFFSET signed(Y).
|
||||||
slimit_opt(A) ::= SLIMIT signed(X) COMMA signed(Y).
|
slimit_opt(A) ::= SLIMIT signed(X) COMMA signed(Y).
|
||||||
{A.limit = Y; A.offset = X;}
|
{A.limit = Y; A.offset = X;}
|
||||||
|
|
||||||
%type where_opt {tSQLExpr*}
|
%type where_opt {tSqlExpr*}
|
||||||
%destructor where_opt {tSqlExprDestroy($$);}
|
%destructor where_opt {tSqlExprDestroy($$);}
|
||||||
|
|
||||||
where_opt(A) ::= . {A = 0;}
|
where_opt(A) ::= . {A = 0;}
|
||||||
|
@ -652,25 +656,25 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
|
||||||
|
|
||||||
/////////////////////////// Expression Processing /////////////////////////////
|
/////////////////////////// Expression Processing /////////////////////////////
|
||||||
//
|
//
|
||||||
%type expr {tSQLExpr*}
|
%type expr {tSqlExpr*}
|
||||||
%destructor expr {tSqlExprDestroy($$);}
|
%destructor expr {tSqlExprDestroy($$);}
|
||||||
|
|
||||||
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->token.z = X.z; A->token.n = (Z.z - X.z + 1);}
|
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->token.z = X.z; A->token.n = (Z.z - X.z + 1);}
|
||||||
|
|
||||||
expr(A) ::= ID(X). { A = tSqlExprIdValueCreate(&X, TK_ID);}
|
expr(A) ::= ID(X). { A = tSqlExprCreateIdValue(&X, TK_ID);}
|
||||||
expr(A) ::= ID(X) DOT ID(Y). { X.n += (1+Y.n); A = tSqlExprIdValueCreate(&X, TK_ID);}
|
expr(A) ::= ID(X) DOT ID(Y). { X.n += (1+Y.n); A = tSqlExprCreateIdValue(&X, TK_ID);}
|
||||||
expr(A) ::= ID(X) DOT STAR(Y). { X.n += (1+Y.n); A = tSqlExprIdValueCreate(&X, TK_ALL);}
|
expr(A) ::= ID(X) DOT STAR(Y). { X.n += (1+Y.n); A = tSqlExprCreateIdValue(&X, TK_ALL);}
|
||||||
|
|
||||||
expr(A) ::= INTEGER(X). { A = tSqlExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= INTEGER(X). { A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
|
||||||
expr(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
|
||||||
expr(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
|
||||||
expr(A) ::= FLOAT(X). { A = tSqlExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= FLOAT(X). { A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
|
||||||
expr(A) ::= MINUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= MINUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
|
||||||
expr(A) ::= PLUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= PLUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
|
||||||
expr(A) ::= STRING(X). { A = tSqlExprIdValueCreate(&X, TK_STRING);}
|
expr(A) ::= STRING(X). { A = tSqlExprCreateIdValue(&X, TK_STRING);}
|
||||||
expr(A) ::= NOW(X). { A = tSqlExprIdValueCreate(&X, TK_NOW); }
|
expr(A) ::= NOW(X). { A = tSqlExprCreateIdValue(&X, TK_NOW); }
|
||||||
expr(A) ::= VARIABLE(X). { A = tSqlExprIdValueCreate(&X, TK_VARIABLE);}
|
expr(A) ::= VARIABLE(X). { A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
|
||||||
expr(A) ::= BOOL(X). { A = tSqlExprIdValueCreate(&X, TK_BOOL);}
|
expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
|
||||||
|
|
||||||
// ordinary functions: min(x), max(x), top(k, 20)
|
// ordinary functions: min(x), max(x), top(k, 20)
|
||||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
|
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
|
||||||
|
@ -690,7 +694,7 @@ expr(A) ::= expr(X) GE expr(Y). {A = tSqlExprCreate(X, Y, TK_GE);}
|
||||||
expr(A) ::= expr(X) NE expr(Y). {A = tSqlExprCreate(X, Y, TK_NE);}
|
expr(A) ::= expr(X) NE expr(Y). {A = tSqlExprCreate(X, Y, TK_NE);}
|
||||||
expr(A) ::= expr(X) EQ expr(Y). {A = tSqlExprCreate(X, Y, TK_EQ);}
|
expr(A) ::= expr(X) EQ expr(Y). {A = tSqlExprCreate(X, Y, TK_EQ);}
|
||||||
|
|
||||||
expr(A) ::= expr(X) BETWEEN expr(Y) AND expr(Z). { tSQLExpr* X2 = tSqlExprClone(X); A = tSqlExprCreate(tSqlExprCreate(X, Y, TK_GE), tSqlExprCreate(X2, Z, TK_LE), TK_AND);}
|
expr(A) ::= expr(X) BETWEEN expr(Y) AND expr(Z). { tSqlExpr* X2 = tSqlExprClone(X); A = tSqlExprCreate(tSqlExprCreate(X, Y, TK_GE), tSqlExprCreate(X2, Z, TK_LE), TK_AND);}
|
||||||
|
|
||||||
expr(A) ::= expr(X) AND expr(Y). {A = tSqlExprCreate(X, Y, TK_AND);}
|
expr(A) ::= expr(X) AND expr(Y). {A = tSqlExprCreate(X, Y, TK_AND);}
|
||||||
expr(A) ::= expr(X) OR expr(Y). {A = tSqlExprCreate(X, Y, TK_OR); }
|
expr(A) ::= expr(X) OR expr(Y). {A = tSqlExprCreate(X, Y, TK_OR); }
|
||||||
|
@ -706,12 +710,12 @@ expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
|
||||||
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
|
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
|
||||||
|
|
||||||
//in expression
|
//in expression
|
||||||
expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSQLExpr*)Y, TK_IN); }
|
expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); }
|
||||||
|
|
||||||
%type exprlist {tSQLExprList*}
|
%type exprlist {SArray*}
|
||||||
%destructor exprlist {tSqlExprListDestroy($$);}
|
%destructor exprlist {tSqlExprListDestroy($$);}
|
||||||
|
|
||||||
%type expritem {tSQLExpr*}
|
%type expritem {tSqlExpr*}
|
||||||
%destructor expritem {tSqlExprDestroy($$);}
|
%destructor expritem {tSqlExprDestroy($$);}
|
||||||
|
|
||||||
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
|
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
|
||||||
|
@ -720,12 +724,12 @@ expritem(A) ::= expr(X). {A = X;}
|
||||||
expritem(A) ::= . {A = 0;}
|
expritem(A) ::= . {A = 0;}
|
||||||
|
|
||||||
///////////////////////////////////reset query cache//////////////////////////////////////
|
///////////////////////////////////reset query cache//////////////////////////////////////
|
||||||
cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
|
cmd ::= RESET QUERY CACHE. { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
|
||||||
|
|
||||||
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
|
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
|
||||||
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
||||||
X.n += F.n;
|
X.n += F.n;
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,14 +739,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
|
||||||
toTSDBType(A.type);
|
toTSDBType(A.type);
|
||||||
SArray* K = tVariantListAppendToken(NULL, &A, -1);
|
SArray* K = tVariantListAppendToken(NULL, &A, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
||||||
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||||
|
@ -751,7 +755,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||||
toTSDBType(Y.type);
|
toTSDBType(Y.type);
|
||||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -764,7 +768,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
|
||||||
toTSDBType(Z.type);
|
toTSDBType(Z.type);
|
||||||
A = tVariantListAppendToken(A, &Z, -1);
|
A = tVariantListAppendToken(A, &Z, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,7 +779,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
|
||||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||||
A = tVariantListAppend(A, &Z, -1);
|
A = tVariantListAppend(A, &Z, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +787,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
|
||||||
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
|
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
|
||||||
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
||||||
X.n += F.n;
|
X.n += F.n;
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,14 +797,14 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
|
||||||
toTSDBType(A.type);
|
toTSDBType(A.type);
|
||||||
SArray* K = tVariantListAppendToken(NULL, &A, -1);
|
SArray* K = tVariantListAppendToken(NULL, &A, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
||||||
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||||
|
@ -809,7 +813,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||||
toTSDBType(Y.type);
|
toTSDBType(Y.type);
|
||||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,7 +826,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
|
||||||
toTSDBType(Z.type);
|
toTSDBType(Z.type);
|
||||||
A = tVariantListAppendToken(A, &Z, -1);
|
A = tVariantListAppendToken(A, &Z, -1);
|
||||||
|
|
||||||
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
|
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
|
||||||
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -834,7 +838,6 @@ cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); s
|
||||||
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
|
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
|
||||||
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
|
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
|
||||||
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
|
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
|
||||||
COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF
|
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT
|
||||||
SPREAD TWA INTERP LAST_ROW RATE IRATE SUM_RATE SUM_IRATE AVG_RATE AVG_IRATE TBID NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT
|
|
||||||
METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO VALUES.
|
METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO VALUES.
|
||||||
|