Merge remote-tracking branch 'upstream/develop' into odbc2
This commit is contained in:
commit
64e3e94466
|
@ -42,15 +42,15 @@ def pre_test(){
|
|||
cd ${WKC}
|
||||
git checkout develop
|
||||
git reset --hard HEAD~10 >/dev/null
|
||||
git pull
|
||||
git pull >/dev/null
|
||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||
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'
|
||||
find ${WKC}/tests/pytest -name \'*\'.sql -exec rm -rf {} \\;
|
||||
cd ${WK}
|
||||
git reset --hard HEAD~10
|
||||
git checkout develop
|
||||
git pull
|
||||
git checkout develop
|
||||
git pull >/dev/null
|
||||
cd ${WK}
|
||||
export TZ=Asia/Harbin
|
||||
date
|
||||
|
|
39
README.md
39
README.md
|
@ -160,39 +160,42 @@ mkdir debug && cd debug
|
|||
cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
# Quick Run
|
||||
|
||||
# Quick Run
|
||||
To quickly start a TDengine server after building, run the command below in terminal:
|
||||
```bash
|
||||
./build/bin/taosd -c test/cfg
|
||||
```
|
||||
In another terminal, use the TDengine shell to connect the server:
|
||||
```bash
|
||||
./build/bin/taos -c test/cfg
|
||||
```
|
||||
option "-c test/cfg" specifies the system configuration file directory.
|
||||
|
||||
# Installing
|
||||
|
||||
After building successfully, TDengine can be installed by:
|
||||
```bash
|
||||
make install
|
||||
sudo make install
|
||||
```
|
||||
Users can find more information about directories installed on the system in the [directory and files](https://www.taosdata.com/en/documentation/administrator/#Directory-and-Files) section. It should be noted that installing from source code does not configure service management for TDengine.
|
||||
|
||||
Users can find more information about directories installed on the system in the [directory and files](https://www.taosdata.com/en/documentation/administrator/#Directory-and-Files) section. Since version 2.0, installing from source code will also configure service management for TDengine.
|
||||
Users can also choose to [install from packages](https://www.taosdata.com/en/getting-started/#Install-from-Package) for it.
|
||||
|
||||
To start the service after installation, in a terminal, use:
|
||||
```cmd
|
||||
taosd
|
||||
```bash
|
||||
sudo systemctl start taosd
|
||||
```
|
||||
|
||||
Then users can use the [TDengine shell](https://www.taosdata.com/en/getting-started/#TDengine-Shell) to connect the TDengine server. In a terminal, use:
|
||||
```cmd
|
||||
```bash
|
||||
taos
|
||||
```
|
||||
|
||||
If TDengine shell connects the server successfully, welcome messages and version info are printed. Otherwise, an error message is shown.
|
||||
|
||||
## Quick Run
|
||||
|
||||
If you don't want to run TDengine as a service, you can run it in current shell. For example, to quickly start a TDengine server after building, run the command below in terminal:
|
||||
```bash
|
||||
./build/bin/taosd -c test/cfg
|
||||
```
|
||||
|
||||
In another terminal, use the TDengine shell to connect the server:
|
||||
```bash
|
||||
./build/bin/taos -c test/cfg
|
||||
```
|
||||
|
||||
option "-c test/cfg" specifies the system configuration file directory.
|
||||
|
||||
# Try TDengine
|
||||
It is easy to run SQL commands from TDengine shell which is the same as other SQL databases.
|
||||
```sql
|
||||
|
|
|
@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
|
|||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||
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 ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||
|
|
|
@ -145,7 +145,7 @@ TDengine 建议用数据采集点的名字(如上表中的D1001)来做表名。
|
|||
|
||||
在TDengine的设计里,**表用来代表一个具体的数据采集点,超级表用来代表一组相同类型的数据采集点集合**。当为某个具体数据采集点创建表时,用户使用超级表的定义做模板,同时指定该具体采集点(表)的标签值。与传统的关系型数据库相比,表(一个数据采集点)是带有静态标签的,而且这些标签可以事后增加、删除、修改。**一张超级表包含有多张表,这些表具有相同的时序数据schema,但带有不同的标签值**。
|
||||
|
||||
当对多个具有相同数据类型的数据采集点进行聚合操作时,TDengine将先把满足标签过滤条件的表从超级表的中查找出来,然后再扫描这些表的时序数据,进行聚合操作,这样能将需要扫描的数据集大幅减少,从而大幅提高聚合计算的性能。
|
||||
当对多个具有相同数据类型的数据采集点进行聚合操作时,TDengine会先把满足标签过滤条件的表从超级表中找出来,然后再扫描这些表的时序数据,进行聚合操作,这样需要扫描的数据集会大幅减少,从而显著提高聚合计算的性能。
|
||||
|
||||
## <a class="anchor" id="cluster"></a>集群与基本逻辑单元
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ Memory Size = maxVgroupsPerDb * (blocks * cache + 10MB) + numOfTables * (tagSize
|
|||
|
||||
示例:假设是 4 核机器,cache 是缺省大小 16M, blocks 是缺省值 6,假设有 10 万张表,标签总长度是 256 字节,则总的内存需求为:4 \* (16 \* 6 + 10) + 100000 \* (0.25 + 0.5) / 1000 = 499M。
|
||||
|
||||
注意:从这个公式计算得到的内存容量,应理解为系统的“必要需求”,而不是“内存总数”。在实际运行的生产系统中,由于操作系统缓存、资源管理调度等方面的需要,内存规划应当在计算结果的基础上保留一定冗余,以维持系统状态和系统性能的稳定性。
|
||||
|
||||
实际运行的系统往往会根据数据特点的不同,将数据存放在不同的 DB 里。因此做规划时,也需要考虑。
|
||||
|
||||
如果内存充裕,可以加大 Blocks 的配置,这样更多数据将保存在内存里,提高查询速度。
|
||||
|
|
|
@ -125,7 +125,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
```mysql
|
||||
ALTER DATABASE db_name CACHELAST 0;
|
||||
```
|
||||
CACHELAST 参数控制是否在内存中缓存数据子表的 last_row。缺省值为 0,取值范围 [0, 1]。其中 0 表示不启用、1 表示启用。(从 2.0.11 版本开始支持)
|
||||
CACHELAST 参数控制是否在内存中缓存数据子表的 last_row。缺省值为 0,取值范围 [0, 1]。其中 0 表示不启用、1 表示启用。(从 2.0.11 版本开始支持,修改后需要重启服务器生效。)
|
||||
|
||||
**Tips**: 以上所有参数修改后都可以用show databases来确认是否修改成功。
|
||||
|
||||
|
@ -331,7 +331,8 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
```mysql
|
||||
INSERT INTO tb_name VALUES (field1_value1, ...) (field1_value2, ...) ...;
|
||||
```
|
||||
向表tb_name中插入多条记录
|
||||
向表tb_name中插入多条记录
|
||||
**注意**:在使用“插入多条记录”方式写入数据时,不能把第一列的时间戳取值都设为now,否则会导致语句中的多条记录使用相同的时间戳,于是就可能出现相互覆盖以致这些数据行无法全部被正确保存。
|
||||
|
||||
- **按指定的列插入多条记录**
|
||||
```mysql
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
## 1. TDengine2.0之前的版本升级到2.0及以上的版本应该注意什么?☆☆☆
|
||||
|
||||
2.0版本在之前版本的基础上,进行了完全的重构,配置文件和数据文件是不兼容的。在升级之前务必进行如下操作:
|
||||
2.0版在之前版本的基础上,进行了完全的重构,配置文件和数据文件是不兼容的。在升级之前务必进行如下操作:
|
||||
|
||||
1. 删除配置文件,执行 <code> sudo rm -rf /etc/taos/taos.cfg </code>
|
||||
2. 删除日志文件,执行 <code> sudo rm -rf /var/log/taos/ </code>
|
||||
3. 确保数据已经不再需要的前提下,删除数据文件,执行 <code> sudo rm -rf /var/lib/taos/ </code>
|
||||
4. 安装最新稳定版本的TDengine
|
||||
5. 如果数据需要迁移数据或者数据文件损坏,请联系涛思数据官方技术支持团队,进行协助解决
|
||||
1. 删除配置文件,执行 `sudo rm -rf /etc/taos/taos.cfg`
|
||||
2. 删除日志文件,执行 `sudo rm -rf /var/log/taos/`
|
||||
3. 确保数据已经不再需要的前提下,删除数据文件,执行 `sudo rm -rf /var/lib/taos/`
|
||||
4. 安装最新稳定版本的 TDengine
|
||||
5. 如果需要迁移数据或者数据文件损坏,请联系涛思数据官方技术支持团队,进行协助解决
|
||||
|
||||
## 2. Windows平台下JDBCDriver找不到动态链接库,怎么办?
|
||||
|
||||
|
|
|
@ -213,10 +213,10 @@ fi
|
|||
|
||||
if echo $osinfo | grep -qwi "ubuntu" ; then
|
||||
# echo "this is ubuntu system"
|
||||
${csudo} rm -f /var/lib/dpkg/info/tdengine* || :
|
||||
${csudo} dpkg --force-all -P tdengine || :
|
||||
elif echo $osinfo | grep -qwi "debian" ; then
|
||||
# echo "this is debian system"
|
||||
${csudo} rm -f /var/lib/dpkg/info/tdengine* || :
|
||||
${csudo} dpkg --force-all -P tdengine || :
|
||||
elif echo $osinfo | grep -qwi "centos" ; then
|
||||
# echo "this is centos system"
|
||||
${csudo} rpm -e --noscripts tdengine || :
|
||||
|
|
|
@ -425,7 +425,7 @@ static bool bnMonitorVgroups() {
|
|||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextVgroup(pIter, &pVgroup);
|
||||
if (pVgroup == NULL) break;
|
||||
if (pVgroup == NULL || pVgroup->pDb == NULL) break;
|
||||
|
||||
int32_t dbReplica = pVgroup->pDb->cfg.replications;
|
||||
int32_t vgReplica = pVgroup->numOfVnodes;
|
||||
|
@ -721,4 +721,4 @@ int32_t bnAlterDnode(struct SDnodeObj *pSrcDnode, int32_t vnodeId, int32_t dnode
|
|||
mnodeDecDnodeRef(pDestDnode);
|
||||
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -481,15 +481,19 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
|
|||
case TSDB_DATA_TYPE_BOOL:
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i]));
|
||||
break;
|
||||
|
|
|
@ -281,7 +281,7 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
|
|||
}
|
||||
|
||||
static void tscAsyncResultCallback(SSchedMsg *pMsg) {
|
||||
SSqlObj* pSql = pMsg->ahandle;
|
||||
SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pMsg->ahandle);
|
||||
if (pSql == NULL || pSql->signature != pSql) {
|
||||
tscDebug("%p SqlObj is freed, not add into queue async res", pSql);
|
||||
return;
|
||||
|
@ -292,23 +292,26 @@ static void tscAsyncResultCallback(SSchedMsg *pMsg) {
|
|||
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
if (pSql->fp == NULL || pSql->fetchFp == NULL){
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
}
|
||||
|
||||
pSql->fp = pSql->fetchFp;
|
||||
(*pSql->fp)(pSql->param, pSql, pRes->code);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
}
|
||||
|
||||
void tscAsyncResultOnError(SSqlObj* pSql) {
|
||||
SSchedMsg schedMsg = {0};
|
||||
schedMsg.fp = tscAsyncResultCallback;
|
||||
schedMsg.ahandle = pSql;
|
||||
schedMsg.ahandle = (void *)pSql->self;
|
||||
schedMsg.thandle = (void *)1;
|
||||
schedMsg.msg = 0;
|
||||
taosScheduleTask(tscQhandle, &schedMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tscSendMsgToServer(SSqlObj *pSql);
|
||||
|
||||
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||
|
|
|
@ -394,7 +394,7 @@ static int32_t tsCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start
|
|||
|
||||
TSKEY k = *(TSKEY *)start;
|
||||
|
||||
if (k == 0) {
|
||||
if (k == INT64_MIN) {
|
||||
if (pDataBlocks->tsSource == TSDB_USE_CLI_TS) {
|
||||
return -1;
|
||||
} else if (pDataBlocks->tsSource == -1) {
|
||||
|
@ -1360,7 +1360,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
|
||||
SSqlInfo SQLInfo = qSqlParse(pSql->sqlstr);
|
||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||
if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) {
|
||||
tscResetSqlCmd(pCmd, true);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -520,7 +520,7 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
assert(pVgroupInfo->vgroups[vgIndex].vgId > 0 && vgIndex < pTableMetaInfo->vgroupList->numOfVgroups);
|
||||
|
||||
pRetrieveMsg->header.vgId = htonl(pVgroupInfo->vgroups[vgIndex].vgId);
|
||||
tscDebug("%p build fetch msg from vgId:%d, vgIndex:%d", pSql, pVgroupInfo->vgroups[vgIndex].vgId, vgIndex);
|
||||
tscDebug("%p build fetch msg from vgId:%d, vgIndex:%d, qhandle:%" PRIX64, pSql, pVgroupInfo->vgroups[vgIndex].vgId, vgIndex, pSql->res.qhandle);
|
||||
} else {
|
||||
int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables);
|
||||
assert(vgIndex >= 0 && vgIndex < numOfVgroups);
|
||||
|
@ -528,12 +528,12 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, vgIndex);
|
||||
|
||||
pRetrieveMsg->header.vgId = htonl(pTableIdList->vgInfo.vgId);
|
||||
tscDebug("%p build fetch msg from vgId:%d, vgIndex:%d", pSql, pTableIdList->vgInfo.vgId, vgIndex);
|
||||
tscDebug("%p build fetch msg from vgId:%d, vgIndex:%d, qhandle:%" PRIX64, pSql, pTableIdList->vgInfo.vgId, vgIndex, pSql->res.qhandle);
|
||||
}
|
||||
} else {
|
||||
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
pRetrieveMsg->header.vgId = htonl(pTableMeta->vgId);
|
||||
tscDebug("%p build fetch msg from only one vgroup, vgId:%d", pSql, pTableMeta->vgId);
|
||||
tscDebug("%p build fetch msg from only one vgroup, vgId:%d, qhandle:%" PRIX64, pSql, pTableMeta->vgId, pSql->res.qhandle);
|
||||
}
|
||||
|
||||
pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg);
|
||||
|
@ -1350,7 +1350,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SSqlCmd *pCmd = &(pSql->cmd);
|
||||
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg);
|
||||
|
||||
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
|
||||
SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo;
|
||||
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
|
||||
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
|
||||
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN);
|
||||
|
@ -1359,7 +1359,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (pCreateTableInfo->pSelect != NULL) {
|
||||
size += (pCreateTableInfo->pSelect->selectToken.n + 1);
|
||||
size += (pCreateTableInfo->pSelect->sqlstr.n + 1);
|
||||
}
|
||||
|
||||
return size + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||
|
@ -1417,7 +1417,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateMsg->tableName);
|
||||
assert(code == 0);
|
||||
|
||||
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
|
||||
SCreateTableSql *pCreateTable = pInfo->pCreateTableInfo;
|
||||
|
||||
pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0;
|
||||
pCreateMsg->numOfColumns = htons(pCmd->numOfCols);
|
||||
|
@ -1440,11 +1440,11 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
pMsg = (char *)pSchema;
|
||||
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);
|
||||
pCreateMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
|
||||
pMsg += pQuerySql->selectToken.n + 1;
|
||||
strncpy(pMsg, pQuerySql->sqlstr.z, pQuerySql->sqlstr.n + 1);
|
||||
pCreateMsg->sqlLen = htons(pQuerySql->sqlstr.n + 1);
|
||||
pMsg += pQuerySql->sqlstr.n + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1159,7 +1159,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
|||
}
|
||||
|
||||
SSqlExpr* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t resColId, int16_t interSize, bool isTagCol) {
|
||||
int16_t size, int16_t resColId, int16_t interSize, bool isTagCol) {
|
||||
SSqlExpr* pExpr = doCreateSqlExpr(pQueryInfo, functionId, pColIndex, type, size, resColId, interSize, isTagCol);
|
||||
taosArrayPush(pQueryInfo->exprList, &pExpr);
|
||||
return pExpr;
|
||||
|
|
|
@ -283,12 +283,37 @@ typedef struct {
|
|||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
|
||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||
#define dataColsTKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, 0))
|
||||
#define dataColsKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, 0))
|
||||
#define dataColsTKeyLast(pCols) \
|
||||
(((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, (pCols)->numOfRows - 1))
|
||||
#define dataColsKeyLast(pCols) \
|
||||
(((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, (pCols)->numOfRows - 1))
|
||||
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
|
||||
if (pCols->numOfRows) {
|
||||
return dataColsTKeyAt(pCols, 0);
|
||||
} else {
|
||||
return TKEY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
void tdResetDataCols(SDataCols *pCols);
|
||||
|
|
|
@ -41,41 +41,46 @@ static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, co
|
|||
|
||||
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:{
|
||||
int8_t* p = (int8_t*) dest;
|
||||
int8_t* pSrc = (int8_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:{
|
||||
int16_t* p = (int16_t*) dest;
|
||||
int16_t* pSrc = (int16_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
int32_t* p = (int32_t*) dest;
|
||||
int32_t* pSrc = (int32_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
int64_t* p = (int64_t*) dest;
|
||||
int64_t* pSrc = (int64_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) dest;
|
||||
|
@ -84,7 +89,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
|
|||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) dest;
|
||||
|
@ -93,7 +98,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
|
|||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
|
|||
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
||||
POST_BUILD
|
||||
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
|
||||
COMMENT "build jdbc driver")
|
||||
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>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.21</version>
|
||||
<version>2.0.22</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JDBCDriver</name>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.21</version>
|
||||
<version>2.0.22</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>JDBCDriver</name>
|
||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||
|
@ -102,6 +102,8 @@
|
|||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/TSDBJNIConnectorTest.java</exclude>
|
||||
<exclude>**/UnsignedNumberJniTest.java</exclude>
|
||||
<exclude>**/DatetimeBefore1970Test.java</exclude>
|
||||
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||
<exclude>**/AuthenticationTest.java</exclude>
|
||||
|
|
|
@ -12,7 +12,7 @@ public abstract class AbstractDriver implements Driver {
|
|||
hostProp.required = false;
|
||||
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.description = "Port";
|
||||
|
||||
|
@ -40,11 +40,11 @@ public abstract class AbstractDriver implements Driver {
|
|||
protected Properties parseURL(String url, Properties defaults) {
|
||||
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
||||
|
||||
// parse properties
|
||||
// parse properties in url
|
||||
int beginningOfSlashes = url.indexOf("//");
|
||||
int index = url.indexOf("?");
|
||||
if (index != -1) {
|
||||
String paramString = url.substring(index + 1, url.length());
|
||||
String paramString = url.substring(index + 1);
|
||||
url = url.substring(0, index);
|
||||
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
||||
while (queryParams.hasMoreElements()) {
|
||||
|
@ -68,6 +68,7 @@ public abstract class AbstractDriver implements Driver {
|
|||
String dbProductName = url.substring(0, beginningOfSlashes);
|
||||
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PRODUCT_NAME,dbProductName);
|
||||
// parse dbname
|
||||
url = url.substring(beginningOfSlashes + 2);
|
||||
int indexOfSlash = url.indexOf("/");
|
||||
|
|
|
@ -29,12 +29,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
|||
public abstract boolean getBoolean(int columnIndex) throws SQLException;
|
||||
|
||||
@Override
|
||||
public byte getByte(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
public abstract byte getByte(int columnIndex) throws SQLException;
|
||||
|
||||
@Override
|
||||
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 {
|
||||
if (isClosed())
|
||||
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);
|
||||
|
||||
} else {
|
||||
// not match
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("the sql is not complete!"));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -189,7 +188,7 @@ public class SavedPreparedStatement {
|
|||
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", 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
|
||||
|
@ -212,7 +211,7 @@ public class SavedPreparedStatement {
|
|||
return;
|
||||
}
|
||||
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE,errorMsg);
|
||||
}
|
||||
|
||||
public void addBatch() {
|
||||
|
|
|
@ -16,16 +16,11 @@ package com.taosdata.jdbc;
|
|||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
// JNI_ERROR_NUMBER
|
||||
public static final int JNI_SUCCESS = 0;
|
||||
public static final int JNI_TDENGINE_ERROR = -1;
|
||||
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_FETCH_END = -6;
|
||||
public static final int JNI_OUT_OF_MEMORY = -7;
|
||||
|
||||
public static final int TSDB_DATA_TYPE_NULL = 0;
|
||||
// TSDB Data Types
|
||||
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_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_TIMESTAMP = 9;
|
||||
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 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 {
|
||||
switch (taosType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NULL:
|
||||
return Types.NULL;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return Types.BOOLEAN;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||
return Types.TINYINT;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
return Types.SMALLINT;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||
return Types.INTEGER;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
return Types.BIGINT;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
|
@ -99,13 +83,42 @@ public abstract class TSDBConstants {
|
|||
case TSDBConstants.TSDB_DATA_TYPE_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 {
|
||||
switch (jdbcType){
|
||||
case Types.NULL:
|
||||
return TSDBConstants.TSDB_DATA_TYPE_NULL;
|
||||
case Types.BOOLEAN:
|
||||
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
|
||||
case Types.TINYINT:
|
||||
|
@ -130,22 +143,31 @@ public abstract class TSDBConstants {
|
|||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||
}
|
||||
|
||||
static {
|
||||
DATATYPE_MAP = new HashMap<>();
|
||||
DATATYPE_MAP.put(0, "NULL");
|
||||
DATATYPE_MAP.put(1, "BOOL");
|
||||
DATATYPE_MAP.put(2, "TINYINT");
|
||||
DATATYPE_MAP.put(3, "SMALLINT");
|
||||
DATATYPE_MAP.put(4, "INT");
|
||||
DATATYPE_MAP.put(5, "BIGINT");
|
||||
DATATYPE_MAP.put(6, "FLOAT");
|
||||
DATATYPE_MAP.put(7, "DOUBLE");
|
||||
DATATYPE_MAP.put(8, "BINARY");
|
||||
DATATYPE_MAP.put(9, "TIMESTAMP");
|
||||
DATATYPE_MAP.put(10, "NCHAR");
|
||||
public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException {
|
||||
switch (jdbcType){
|
||||
case Types.BOOLEAN:
|
||||
return "BOOL";
|
||||
case Types.TINYINT:
|
||||
return "TINYINT";
|
||||
case Types.SMALLINT:
|
||||
return "SMALLINT";
|
||||
case Types.INTEGER:
|
||||
return "INT";
|
||||
case Types.BIGINT:
|
||||
return "BIGINT";
|
||||
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://";
|
||||
|
||||
/**
|
||||
* PRODUCT_NAME
|
||||
*/
|
||||
public static final String PROPERTY_KEY_PRODUCT_NAME = "productName";
|
||||
/**
|
||||
* Key used to retrieve the host value from the properties instance passed to
|
||||
* the driver.
|
||||
|
@ -96,38 +100,34 @@ public class TSDBDriver extends AbstractDriver {
|
|||
static {
|
||||
try {
|
||||
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
||||
} catch (SQLException E) {
|
||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!"));
|
||||
} catch (SQLException e) {
|
||||
throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||
|
||||
if (!acceptsURL(url))
|
||||
return null;
|
||||
|
||||
Properties props = null;
|
||||
if ((props = parseURL(url, info)) == null) {
|
||||
Properties props = parseURL(url, info);
|
||||
if (props == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
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));
|
||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
||||
return newConn;
|
||||
return new TSDBConnection(props, this.dbMetaData);
|
||||
} catch (SQLWarning sqlWarning) {
|
||||
sqlWarning.printStackTrace();
|
||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
||||
return newConn;
|
||||
return new TSDBConnection(props, this.dbMetaData);
|
||||
} catch (SQLException sqlEx) {
|
||||
throw sqlEx;
|
||||
} catch (Exception ex) {
|
||||
SQLException sqlEx = new SQLException("SQLException:" + ex.toString());
|
||||
sqlEx.initCause(ex);
|
||||
throw sqlEx;
|
||||
throw new SQLException("SQLException:" + ex.toString(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,8 @@ public class TSDBDriver extends AbstractDriver {
|
|||
*/
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||
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 {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.taosdata.jdbc;
|
|||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.util.HashMap;
|
||||
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_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_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_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "invalid sql for executeUpdate: (?)");
|
||||
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_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_SUBSCRIBE_FAILED, "failed to create subscription");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
|
||||
|
||||
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_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);
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -16,15 +16,20 @@ public class TSDBErrorNumbers {
|
|||
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x230a; //Database not specified or available
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x230b; //not a valid sql for executeUpdate: (SQL)
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE = 0x230c; //not a valid sql for execute: (SQL)
|
||||
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_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_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
|
||||
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_CONNECTION_NULL = 0x2354; // JNI connection is NULL
|
||||
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_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
|
||||
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_UNSUPPORTED_ENCODING);
|
||||
|
||||
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
|
||||
errorNumbers.add(ERROR_JNI_CONNECTION_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_FETCH_END);
|
||||
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
|
||||
|
||||
}
|
||||
|
||||
private TSDBErrorNumbers() {
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
/**
|
||||
* *************************************************************************
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* <p>
|
||||
* 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
|
||||
* 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
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* <p>
|
||||
* 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/>.
|
||||
**************************************************************************** */
|
||||
* ***************************************************************************
|
||||
*/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import com.taosdata.jdbc.utils.TaosInfo;
|
||||
|
@ -23,7 +24,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* JNI connector
|
||||
* */
|
||||
*/
|
||||
public class TSDBJNIConnector {
|
||||
private static volatile Boolean isInitialized = false;
|
||||
|
||||
|
@ -72,13 +73,13 @@ public class TSDBJNIConnector {
|
|||
if (!isInitialized) {
|
||||
initImp(configDir);
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
TaosGlobalConfig.setCharset(getTsCharset());
|
||||
|
|
|
@ -27,8 +27,8 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
|||
private final TSDBResultSetRowData rowData;
|
||||
private final TSDBResultSetBlockData blockData;
|
||||
|
||||
private boolean batchFetch = false;
|
||||
private boolean lastWasNull = false;
|
||||
private boolean batchFetch;
|
||||
private boolean lastWasNull;
|
||||
private boolean isClosed;
|
||||
|
||||
public void setBatchFetch(boolean batchFetch) {
|
||||
|
@ -86,7 +86,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
|||
if (rowData != null) {
|
||||
this.rowData.clear();
|
||||
}
|
||||
|
||||
int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
|
||||
if (code == TSDBConstants.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;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getString(colIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||
boolean res = false;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getBoolean(colIndex);
|
||||
}
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -155,91 +151,84 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
|||
byte res = 0;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return (byte) this.blockData.getInt(colIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public short getShort(int columnIndex) throws SQLException {
|
||||
short res = 0;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return (short) this.blockData.getInt(colIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getInt(int columnIndex) throws SQLException {
|
||||
int res = 0;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getInt(colIndex);
|
||||
}
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public long getLong(int columnIndex) throws SQLException {
|
||||
long res = 0L;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getLong(colIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public float getFloat(int columnIndex) throws SQLException {
|
||||
float res = 0;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
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 {
|
||||
double res = 0;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getDouble(colIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -255,15 +244,14 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
|||
Timestamp res = null;
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getTimestamp(colIndex);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.getTimestamp(columnIndex);
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
if (!lastWasNull) {
|
||||
res = this.rowData.getTimestamp(colIndex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public ResultSetMetaData getMetaData() throws SQLException {
|
||||
|
@ -274,12 +262,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
|||
public Object getObject(int columnIndex) throws SQLException {
|
||||
int colIndex = getTrueColumnIndex(columnIndex);
|
||||
|
||||
if (!this.getBatchFetch()) {
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
return this.rowData.get(colIndex);
|
||||
} else {
|
||||
if (this.getBatchFetch())
|
||||
return this.blockData.get(colIndex);
|
||||
}
|
||||
|
||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||
return this.rowData.get(colIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,468 +30,472 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
public class TSDBResultSetBlockData {
|
||||
private int numOfRows = 0;
|
||||
private int rowIndex = 0;
|
||||
|
||||
private List<ColumnMetaData> columnMetaDataList;
|
||||
private ArrayList<Object> colData = null;
|
||||
|
||||
public TSDBResultSetBlockData(List<ColumnMetaData> colMeta, int numOfCols) {
|
||||
this.columnMetaDataList = colMeta;
|
||||
this.colData = new ArrayList<Object>(numOfCols);
|
||||
}
|
||||
|
||||
public TSDBResultSetBlockData() {
|
||||
this.colData = new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
int size = this.colData.size();
|
||||
if (this.colData != null) {
|
||||
this.colData.clear();
|
||||
}
|
||||
|
||||
setNumOfCols(size);
|
||||
}
|
||||
|
||||
public int getNumOfRows() {
|
||||
return this.numOfRows;
|
||||
}
|
||||
|
||||
public void setNumOfRows(int numOfRows) {
|
||||
this.numOfRows = numOfRows;
|
||||
}
|
||||
|
||||
public int getNumOfCols() {
|
||||
return this.colData.size();
|
||||
}
|
||||
|
||||
public void setNumOfCols(int numOfCols) {
|
||||
this.colData = new ArrayList<Object>(numOfCols);
|
||||
this.colData.addAll(Collections.nCopies(numOfCols, null));
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return this.rowIndex < this.numOfRows;
|
||||
}
|
||||
|
||||
public boolean forward() {
|
||||
if (this.rowIndex > this.numOfRows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((++this.rowIndex) < this.numOfRows);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.rowIndex = 0;
|
||||
}
|
||||
|
||||
public void setBoolean(int col, boolean value) {
|
||||
colData.set(col, value);
|
||||
}
|
||||
|
||||
public void setByteArray(int col, int length, byte[] value) {
|
||||
try {
|
||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||
this.colData.set(col, sb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
||||
this.colData.set(col, ib);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||
this.colData.set(col, lb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||
this.colData.set(col, fb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
|
||||
this.colData.set(col, db);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||
this.colData.set(col, lb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class NullType {
|
||||
private static final byte NULL_BOOL_VAL = 0x2;
|
||||
private static final String NULL_STR = "null";
|
||||
|
||||
public String toString() {
|
||||
return NullType.NULL_STR;
|
||||
}
|
||||
|
||||
public static boolean isBooleanNull(byte val) {
|
||||
return val == NullType.NULL_BOOL_VAL;
|
||||
}
|
||||
|
||||
private static boolean isTinyIntNull(byte val) {
|
||||
return val == Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isSmallIntNull(short val) {
|
||||
return val == Short.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isIntNull(int val) {
|
||||
return val == Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isBigIntNull(long val) {
|
||||
return val == Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isFloatNull(float val) {
|
||||
return Float.isNaN(val);
|
||||
}
|
||||
|
||||
private static boolean isDoubleNull(double val) {
|
||||
return Double.isNaN(val);
|
||||
}
|
||||
|
||||
private static boolean isBinaryNull(byte[] val, int length) {
|
||||
if (length != Byte.BYTES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return val[0] == 0xFF;
|
||||
}
|
||||
|
||||
private static boolean isNcharNull(byte[] val, int length) {
|
||||
if (length != Integer.BYTES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (val[0] & val[1] & val[2] & val[3]) == 0xFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The original type may not be a string type, but will be converted to by
|
||||
* calling this method
|
||||
*
|
||||
* @param col column index
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public String getString(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return new NullType().toString();
|
||||
}
|
||||
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public int getInt(int col) {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return ((Long) obj).intValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return ((Double) obj).intValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Integer.parseInt((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getBoolean(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return ((int) obj == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (((Long) obj) == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return (((Double) obj) == 0) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
if ("TRUE".compareToIgnoreCase((String) obj) == 0) {
|
||||
return Boolean.TRUE;
|
||||
} else if ("FALSE".compareToIgnoreCase((String) obj) == 0) {
|
||||
return Boolean.TRUE;
|
||||
} else {
|
||||
throw new SQLDataException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
public long getLong(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (long) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return ((Double) obj).longValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Long.parseLong((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Timestamp getTimestamp(int col) {
|
||||
try {
|
||||
return new Timestamp(getLong(col));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getDouble(int col) {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (long) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return (double) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Double.parseDouble((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object get(int col) {
|
||||
int fieldSize = this.columnMetaDataList.get(col).getColSize();
|
||||
|
||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
|
||||
byte val = bb.get(this.rowIndex);
|
||||
if (NullType.isBooleanNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (val == 0x0) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
|
||||
byte val = bb.get(this.rowIndex);
|
||||
if (NullType.isTinyIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||
ShortBuffer sb = (ShortBuffer) this.colData.get(col);
|
||||
short val = sb.get(this.rowIndex);
|
||||
if (NullType.isSmallIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
IntBuffer ib = (IntBuffer) this.colData.get(col);
|
||||
int val = ib.get(this.rowIndex);
|
||||
if (NullType.isIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||
LongBuffer lb = (LongBuffer) this.colData.get(col);
|
||||
long val = lb.get(this.rowIndex);
|
||||
if (NullType.isBigIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (long) val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||
FloatBuffer fb = (FloatBuffer) this.colData.get(col);
|
||||
float val = fb.get(this.rowIndex);
|
||||
if (NullType.isFloatNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
DoubleBuffer lb = (DoubleBuffer) this.colData.get(col);
|
||||
double val = lb.get(this.rowIndex);
|
||||
if (NullType.isDoubleNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
bb.position(fieldSize * this.rowIndex);
|
||||
|
||||
int length = bb.getShort();
|
||||
|
||||
byte[] dest = new byte[length];
|
||||
bb.get(dest, 0, length);
|
||||
if (NullType.isBinaryNull(dest, length)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new String(dest);
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
bb.position(fieldSize * this.rowIndex);
|
||||
|
||||
int length = bb.getShort();
|
||||
|
||||
byte[] dest = new byte[length];
|
||||
bb.get(dest, 0, length);
|
||||
if (NullType.isNcharNull(dest, length)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
String ss = TaosGlobalConfig.getCharset();
|
||||
return new String(dest, ss);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
private int numOfRows = 0;
|
||||
private int rowIndex = 0;
|
||||
|
||||
private List<ColumnMetaData> columnMetaDataList;
|
||||
private ArrayList<Object> colData = null;
|
||||
|
||||
public TSDBResultSetBlockData(List<ColumnMetaData> colMeta, int numOfCols) {
|
||||
this.columnMetaDataList = colMeta;
|
||||
this.colData = new ArrayList<Object>(numOfCols);
|
||||
}
|
||||
|
||||
public TSDBResultSetBlockData() {
|
||||
this.colData = new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
int size = this.colData.size();
|
||||
if (this.colData != null) {
|
||||
this.colData.clear();
|
||||
}
|
||||
|
||||
setNumOfCols(size);
|
||||
}
|
||||
|
||||
public int getNumOfRows() {
|
||||
return this.numOfRows;
|
||||
}
|
||||
|
||||
public void setNumOfRows(int numOfRows) {
|
||||
this.numOfRows = numOfRows;
|
||||
}
|
||||
|
||||
public int getNumOfCols() {
|
||||
return this.colData.size();
|
||||
}
|
||||
|
||||
public void setNumOfCols(int numOfCols) {
|
||||
this.colData = new ArrayList<Object>(numOfCols);
|
||||
this.colData.addAll(Collections.nCopies(numOfCols, null));
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return this.rowIndex < this.numOfRows;
|
||||
}
|
||||
|
||||
public boolean forward() {
|
||||
if (this.rowIndex > this.numOfRows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((++this.rowIndex) < this.numOfRows);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.rowIndex = 0;
|
||||
}
|
||||
|
||||
public void setBoolean(int col, boolean value) {
|
||||
colData.set(col, value);
|
||||
}
|
||||
|
||||
public void setByteArray(int col, int length, byte[] value) {
|
||||
try {
|
||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||
this.colData.set(col, sb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
||||
this.colData.set(col, ib);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||
this.colData.set(col, lb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||
this.colData.set(col, fb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
|
||||
this.colData.set(col, db);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||
this.colData.set(col, lb);
|
||||
break;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.colData.set(col, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class NullType {
|
||||
private static final byte NULL_BOOL_VAL = 0x2;
|
||||
private static final String NULL_STR = "null";
|
||||
|
||||
public String toString() {
|
||||
return NullType.NULL_STR;
|
||||
}
|
||||
|
||||
public static boolean isBooleanNull(byte val) {
|
||||
return val == NullType.NULL_BOOL_VAL;
|
||||
}
|
||||
|
||||
private static boolean isTinyIntNull(byte val) {
|
||||
return val == Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isSmallIntNull(short val) {
|
||||
return val == Short.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isIntNull(int val) {
|
||||
return val == Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isBigIntNull(long val) {
|
||||
return val == Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isFloatNull(float val) {
|
||||
return Float.isNaN(val);
|
||||
}
|
||||
|
||||
private static boolean isDoubleNull(double val) {
|
||||
return Double.isNaN(val);
|
||||
}
|
||||
|
||||
private static boolean isBinaryNull(byte[] val, int length) {
|
||||
if (length != Byte.BYTES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return val[0] == 0xFF;
|
||||
}
|
||||
|
||||
private static boolean isNcharNull(byte[] val, int length) {
|
||||
if (length != Integer.BYTES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (val[0] & val[1] & val[2] & val[3]) == 0xFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The original type may not be a string type, but will be converted to by
|
||||
* calling this method
|
||||
*
|
||||
* @param col column index
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public String getString(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return new NullType().toString();
|
||||
}
|
||||
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public int getInt(int col) {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return ((Long) obj).intValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return ((Double) obj).intValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Integer.parseInt((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getBoolean(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return ((int) obj == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (((Long) obj) == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return (((Double) obj) == 0) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
if ("TRUE".compareToIgnoreCase((String) obj) == 0) {
|
||||
return Boolean.TRUE;
|
||||
} else if ("FALSE".compareToIgnoreCase((String) obj) == 0) {
|
||||
return Boolean.TRUE;
|
||||
} else {
|
||||
throw new SQLDataException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
public long getLong(int col) throws SQLException {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (long) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return ((Double) obj).longValue();
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Long.parseLong((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Timestamp getTimestamp(int col) {
|
||||
try {
|
||||
return new Timestamp(getLong(col));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getDouble(int col) {
|
||||
Object obj = get(col);
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = this.columnMetaDataList.get(col).getColType();
|
||||
switch (type) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
return (int) obj;
|
||||
}
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
return (long) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
return (double) obj;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
return Double.parseDouble((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object get(int col) {
|
||||
int fieldSize = this.columnMetaDataList.get(col).getColSize();
|
||||
|
||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
|
||||
byte val = bb.get(this.rowIndex);
|
||||
if (NullType.isBooleanNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (val == 0x0) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
|
||||
byte val = bb.get(this.rowIndex);
|
||||
if (NullType.isTinyIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||
ShortBuffer sb = (ShortBuffer) this.colData.get(col);
|
||||
short val = sb.get(this.rowIndex);
|
||||
if (NullType.isSmallIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||
IntBuffer ib = (IntBuffer) this.colData.get(col);
|
||||
int val = ib.get(this.rowIndex);
|
||||
if (NullType.isIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||
LongBuffer lb = (LongBuffer) this.colData.get(col);
|
||||
long val = lb.get(this.rowIndex);
|
||||
if (NullType.isBigIntNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (long) val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||
FloatBuffer fb = (FloatBuffer) this.colData.get(col);
|
||||
float val = fb.get(this.rowIndex);
|
||||
if (NullType.isFloatNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||
DoubleBuffer lb = (DoubleBuffer) this.colData.get(col);
|
||||
double val = lb.get(this.rowIndex);
|
||||
if (NullType.isDoubleNull(val)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
bb.position(fieldSize * this.rowIndex);
|
||||
|
||||
int length = bb.getShort();
|
||||
|
||||
byte[] dest = new byte[length];
|
||||
bb.get(dest, 0, length);
|
||||
if (NullType.isBinaryNull(dest, length)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new String(dest);
|
||||
}
|
||||
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||
bb.position(fieldSize * this.rowIndex);
|
||||
|
||||
int length = bb.getShort();
|
||||
|
||||
byte[] dest = new byte[length];
|
||||
bb.get(dest, 0, length);
|
||||
if (NullType.isNcharNull(dest, length)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
String ss = TaosGlobalConfig.getCharset();
|
||||
return new String(dest, ss);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,34 +126,12 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
|
|||
|
||||
public int getColumnType(int column) throws SQLException {
|
||||
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
||||
switch (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);
|
||||
return TSDBConstants.taosType2JdbcType(meta.getColType());
|
||||
}
|
||||
|
||||
public String getColumnTypeName(int column) throws SQLException {
|
||||
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 {
|
||||
|
|
|
@ -14,208 +14,322 @@
|
|||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class TSDBResultSetRowData {
|
||||
private ArrayList<Object> data = null;
|
||||
private int colSize = 0;
|
||||
private ArrayList<Object> data = null;
|
||||
private int colSize = 0;
|
||||
|
||||
public TSDBResultSetRowData(int colSize) {
|
||||
this.setColSize(colSize);
|
||||
}
|
||||
public TSDBResultSetRowData(int colSize) {
|
||||
this.setColSize(colSize);
|
||||
}
|
||||
|
||||
public TSDBResultSetRowData() {
|
||||
this.data = new ArrayList<>();
|
||||
this.setColSize(0);
|
||||
}
|
||||
public TSDBResultSetRowData() {
|
||||
this.data = new ArrayList<>();
|
||||
this.setColSize(0);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if(this.data != null) {
|
||||
this.data.clear();
|
||||
}
|
||||
if (this.colSize == 0) {
|
||||
return;
|
||||
}
|
||||
this.data = new ArrayList<>(colSize);
|
||||
this.data.addAll(Collections.nCopies(this.colSize, null));
|
||||
}
|
||||
public void clear() {
|
||||
if (this.data != null) {
|
||||
this.data.clear();
|
||||
}
|
||||
if (this.colSize == 0) {
|
||||
return;
|
||||
}
|
||||
this.data = new ArrayList<>(colSize);
|
||||
this.data.addAll(Collections.nCopies(this.colSize, null));
|
||||
}
|
||||
|
||||
public boolean wasNull(int col) {
|
||||
return data.get(col) == null;
|
||||
}
|
||||
public boolean wasNull(int col) {
|
||||
return data.get(col) == null;
|
||||
}
|
||||
|
||||
public void setBoolean(int col, boolean value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setBoolean(int col, boolean value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public boolean getBoolean(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
public boolean getBoolean(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
|
||||
switch(srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj) == 1.0? Boolean.TRUE:Boolean.FALSE;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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_BIGINT: return ((Long) obj) == 1L? Boolean.TRUE:Boolean.FALSE;
|
||||
}
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return (Boolean) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
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_BIGINT:
|
||||
return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
public void setByte(int col, byte value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setByte(int col, byte value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public void setShort(int col, short value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setShort(int col, short value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public void setInt(int col, int value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setInt(int col, int value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public int getInt(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
public int getInt(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
|
||||
switch(srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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_BIGINT: return ((Long) obj).intValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj);
|
||||
}
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return ((Float) obj).intValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
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_BIGINT:
|
||||
return ((Long) obj).intValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
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;
|
||||
}
|
||||
|
||||
public void setLong(int col, long value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setLong(int col, long value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public long getLong(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
public long getLong(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
|
||||
switch(srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).longValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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_BIGINT: return (Long) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj);
|
||||
}
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return ((Float) obj).longValue();
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
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_BIGINT:
|
||||
return (Long) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
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;
|
||||
}
|
||||
|
||||
public void setFloat(int col, float value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setFloat(int col, float value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public float getFloat(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
public float getFloat(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
|
||||
switch(srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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_BIGINT: return (Long) obj;
|
||||
}
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return (Float) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
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_BIGINT:
|
||||
return (Long) obj;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setDouble(int col, double value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setDouble(int col, double value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public double getDouble(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
public double getDouble(int col, int srcType) throws SQLException {
|
||||
Object obj = data.get(col);
|
||||
|
||||
switch(srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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_BIGINT: return (Long) obj;
|
||||
}
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return (Float) obj;
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
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_BIGINT:
|
||||
return (Long) obj;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setString(int col, String value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
public void setString(int col, String value) {
|
||||
data.set(col, value);
|
||||
}
|
||||
|
||||
public void setByteArray(int col, byte[] value) {
|
||||
public void setByteArray(int col, byte[] value) {
|
||||
try {
|
||||
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The original type may not be a string type, but will be converted to by calling this method
|
||||
* @param col column index
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public String getString(int col, int srcType) throws SQLException {
|
||||
if (srcType == TSDBConstants.TSDB_DATA_TYPE_BINARY || srcType == TSDBConstants.TSDB_DATA_TYPE_NCHAR) {
|
||||
return (String) data.get(col);
|
||||
} else {
|
||||
return String.valueOf(data.get(col));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The original type may not be a string type, but will be converted to by calling this method
|
||||
*
|
||||
* @param col column index
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public String getString(int col, int srcType) throws SQLException {
|
||||
switch (srcType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
return (String) data.get(col);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimestamp(int col, long ts) {
|
||||
data.set(col, ts);
|
||||
}
|
||||
public void setTimestamp(int col, long ts) {
|
||||
data.set(col, ts);
|
||||
}
|
||||
|
||||
public Timestamp getTimestamp(int col) {
|
||||
return new Timestamp((Long) data.get(col));
|
||||
}
|
||||
public Timestamp getTimestamp(int col) {
|
||||
return new Timestamp((Long) data.get(col));
|
||||
}
|
||||
|
||||
public Object get(int col) {
|
||||
return data.get(col);
|
||||
}
|
||||
public Object get(int col) {
|
||||
return data.get(col);
|
||||
}
|
||||
|
||||
public int getColSize() {
|
||||
return colSize;
|
||||
}
|
||||
public int getColSize() {
|
||||
return colSize;
|
||||
}
|
||||
|
||||
public void setColSize(int colSize) {
|
||||
this.colSize = colSize;
|
||||
this.clear();
|
||||
}
|
||||
public void setColSize(int colSize) {
|
||||
this.colSize = colSize;
|
||||
this.clear();
|
||||
}
|
||||
|
||||
public ArrayList<Object> getData() {
|
||||
return data;
|
||||
}
|
||||
public ArrayList<Object> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(ArrayList<Object> data) {
|
||||
this.data = (ArrayList<Object>) data.clone();
|
||||
}
|
||||
public void setData(ArrayList<Object> data) {
|
||||
this.data = (ArrayList<Object>) data.clone();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@ public class TSDBStatement extends AbstractStatement {
|
|||
this.connector.freeResultSet(pSql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||
}
|
||||
|
||||
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
|
||||
res.setBatchFetch(this.connection.getBatchFetch());
|
||||
return res;
|
||||
|
|
|
@ -21,27 +21,23 @@ public class TSDBSubscribe {
|
|||
private final long id;
|
||||
|
||||
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
|
||||
if (null != connecter) {
|
||||
this.connecter = connecter;
|
||||
this.id = id;
|
||||
} else {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
if (connecter == null)
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||
|
||||
this.connecter = connecter;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* consume
|
||||
*
|
||||
*/
|
||||
public TSDBResultSet consume() throws SQLException {
|
||||
if (this.connecter.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
if (this.connecter.isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||
|
||||
long resultSetPointer = this.connecter.consume(this.id);
|
||||
|
||||
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) {
|
||||
return null;
|
||||
} else {
|
||||
|
@ -56,9 +52,9 @@ public class TSDBSubscribe {
|
|||
* @throws SQLException
|
||||
*/
|
||||
public void close(boolean keepProgress) throws SQLException {
|
||||
if (this.connecter.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
if (this.connecter.isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||
|
||||
this.connecter.unsubscribe(this.id, keepProgress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ public class RestfulConnection extends AbstractConnection {
|
|||
public Statement createStatement() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
;
|
||||
|
||||
return new RestfulStatement(this, database);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ package com.taosdata.jdbc.rs;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.taosdata.jdbc.AbstractDriver;
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import com.taosdata.jdbc.*;
|
||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -21,15 +19,16 @@ public class RestfulDriver extends AbstractDriver {
|
|||
try {
|
||||
DriverManager.registerDriver(new RestfulDriver());
|
||||
} 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
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
// throw SQLException if url is null
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
||||
if (url == null || url.trim().isEmpty() || url.trim().replaceAll("\\s", "").isEmpty())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||
|
||||
// return null if url is not be accepted
|
||||
if (!acceptsURL(url))
|
||||
return null;
|
||||
|
@ -61,14 +60,20 @@ public class RestfulDriver extends AbstractDriver {
|
|||
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
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.startsWith(URL_PREFIX);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||
return url.length() > 0 && url.trim().length() > 0 && url.startsWith(URL_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.taosdata.jdbc.TSDBErrorNumbers;
|
|||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||
private volatile boolean isClosed;
|
||||
|
@ -17,8 +16,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
|
||||
private final String database;
|
||||
private final Statement statement;
|
||||
// private final JSONObject resultJson;
|
||||
// data
|
||||
private ArrayList<ArrayList<Object>> resultSet;
|
||||
private final ArrayList<ArrayList<Object>> resultSet;
|
||||
// meta
|
||||
private ArrayList<String> columnNames;
|
||||
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 {
|
||||
this.database = database;
|
||||
this.statement = statement;
|
||||
// this.resultJson = resultJson;
|
||||
|
||||
// column metadata
|
||||
JSONArray columnMeta = resultJson.getJSONArray("column_meta");
|
||||
columnNames = new ArrayList<>();
|
||||
|
@ -39,10 +41,11 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
|
||||
JSONArray col = columnMeta.getJSONArray(colIndex);
|
||||
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);
|
||||
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);
|
||||
|
||||
|
@ -53,105 +56,50 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
ArrayList row = new ArrayList();
|
||||
JSONArray jsonRow = data.getJSONArray(rowIndex);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
JSONArray head = resultJson.getJSONArray("head");
|
||||
for (int i = 0; i < head.size(); i++) {
|
||||
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:
|
||||
private Object parseColumnData(JSONArray row, int colIndex, int taosType) {
|
||||
switch (taosType) {
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||
return row.getBoolean(colIndex);
|
||||
case Types.TINYINT:
|
||||
case Types.SMALLINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||
return row.getByte(colIndex);
|
||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||
return row.getShort(colIndex);
|
||||
case Types.INTEGER:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||
return row.getInteger(colIndex);
|
||||
case Types.BIGINT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||
return row.getBigInteger(colIndex);
|
||||
case Types.FLOAT:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||
return row.getFloat(colIndex);
|
||||
case Types.DOUBLE:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||
return row.getDouble(colIndex);
|
||||
case Types.TIMESTAMP:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||
return new Timestamp(row.getDate(colIndex).getTime());
|
||||
case Types.BINARY:
|
||||
case Types.NCHAR:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||
default:
|
||||
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 {
|
||||
String name;
|
||||
int type;
|
||||
int length;
|
||||
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.type = type;
|
||||
this.length = length;
|
||||
this.note = note;
|
||||
this.taos_type = taos_type;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,53 +132,119 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
public String getString(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||
|
||||
if (columnIndex > resultSet.get(pos).size()) {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + 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());
|
||||
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return resultSet.get(pos).get(columnIndex).toString();
|
||||
Object value = resultSet.get(pos).get(columnIndex);
|
||||
return value == null ? null : value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(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);
|
||||
int result = getInt(columnIndex);
|
||||
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
|
||||
public short getShort(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);
|
||||
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
|
||||
public int getInt(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);
|
||||
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
|
||||
public long getLong(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);
|
||||
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
|
||||
public float getFloat(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);
|
||||
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
@ -239,6 +253,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
public double getDouble(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);
|
||||
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
||||
|
@ -246,12 +262,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
|||
|
||||
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
||||
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();
|
||||
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;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.WrapperImpl;
|
||||
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
@ -8,7 +9,7 @@ import java.sql.Timestamp;
|
|||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||
public class RestfulResultSetMetaData extends WrapperImpl implements ResultSetMetaData {
|
||||
|
||||
private final String database;
|
||||
private ArrayList<RestfulResultSet.Field> fields;
|
||||
|
@ -20,6 +21,10 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
public ArrayList<RestfulResultSet.Field> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() throws SQLException {
|
||||
return fields.size();
|
||||
|
@ -134,8 +139,8 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public String getColumnTypeName(int column) throws SQLException {
|
||||
int type = fields.get(column - 1).type;
|
||||
return TSDBConstants.jdbcType2TaosTypeName(type);
|
||||
int taos_type = fields.get(column - 1).taos_type;
|
||||
return TSDBConstants.taosType2JdbcTypeName(taos_type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,18 +185,4 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
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.JSONObject;
|
||||
import com.taosdata.jdbc.AbstractStatement;
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.TSDBError;
|
||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class RestfulStatement extends AbstractStatement {
|
||||
|
||||
|
@ -30,39 +27,6 @@ public class RestfulStatement extends AbstractStatement {
|
|||
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
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
|
@ -75,9 +39,8 @@ public class RestfulStatement extends AbstractStatement {
|
|||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
||||
// if (this.database == null || this.database.isEmpty())
|
||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
// if (this.database != null && !this.database.trim().replaceAll("\\s","").isEmpty())
|
||||
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
||||
|
@ -93,10 +56,8 @@ public class RestfulStatement extends AbstractStatement {
|
|||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
||||
// if (this.database == null || this.database.isEmpty())
|
||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
// if (this.database != null && !this.database.trim().replaceAll("\\s", "").isEmpty())
|
||||
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
||||
|
@ -148,24 +109,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject resultJson = JSON.parseObject(result);
|
||||
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.affectedRows = 0;
|
||||
return resultSet;
|
||||
}
|
||||
|
@ -177,7 +123,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
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.affectedRows = checkJsonResultSet(jsonObject);
|
||||
|
|
|
@ -15,12 +15,12 @@ public class TSDBJNIConnectorTest {
|
|||
public void test() {
|
||||
try {
|
||||
// init
|
||||
TSDBJNIConnector.init(null, null, null, null);
|
||||
TSDBJNIConnector.init("/etc/taos/taos.cfg", null, null, null);
|
||||
// connect
|
||||
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
|
||||
long pSql = connector.executeQuery("show variables");
|
||||
long pSql = connector.executeQuery("select * from unsign_jni.us_table");
|
||||
if (connector.isUpdateQuery(pSql)) {
|
||||
connector.freeResultSet(pSql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||
|
@ -29,13 +29,13 @@ public class TSDBJNIConnectorTest {
|
|||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
|
||||
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) {
|
||||
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) {
|
||||
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();
|
||||
// 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);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
@Test
|
||||
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
|
||||
|
|
|
@ -222,7 +222,7 @@ static void *dnodeProcessVWriteQueue(void *wparam) {
|
|||
dnodeSendRpcVWriteRsp(pVnode, pWrite, pWrite->code);
|
||||
} else {
|
||||
if (qtype == TAOS_QTYPE_FWD) {
|
||||
vnodeConfirmForward(pVnode, pWrite->pHead.version, 0);
|
||||
vnodeConfirmForward(pVnode, pWrite->pHead.version, 0, pWrite->pHead.msgType != TSDB_MSG_TYPE_SUBMIT);
|
||||
}
|
||||
if (pWrite->rspRet.rsp) {
|
||||
rpcFreeCont(pWrite->rspRet.rsp);
|
||||
|
|
|
@ -28,7 +28,7 @@ typedef void* qinfo_t;
|
|||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo);
|
||||
int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo, uint64_t *qId);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -88,9 +88,10 @@ void* qOpenQueryMgmt(int32_t vgId);
|
|||
void qQueryMgmtNotifyClosed(void* pExecutor);
|
||||
void qQueryMgmtReOpen(void *pExecutor);
|
||||
void qCleanupQueryMgmt(void* pExecutor);
|
||||
void** qRegisterQInfo(void* pMgmt, uint64_t qInfo);
|
||||
void** qRegisterQInfo(void* pMgmt, uint64_t qId, uint64_t qInfo);
|
||||
void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
||||
void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||
bool checkQIdEqual(void *qHandle, uint64_t qId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0612) //"Invalid information to create table")
|
||||
#define TSDB_CODE_TDB_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0613) //"No available disk")
|
||||
#define TSDB_CODE_TDB_MESSED_MSG TAOS_DEF_ERROR_CODE(0, 0x0614) //"TSDB messed message")
|
||||
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615) //"TSDB invalid tag value")
|
||||
|
||||
// query
|
||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) //"Invalid handle")
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "tdataformat.h"
|
||||
#include "tname.h"
|
||||
#include "hash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -172,10 +174,32 @@ typedef struct STsdbQueryCond {
|
|||
int32_t type; // data block load type:
|
||||
} STsdbQueryCond;
|
||||
|
||||
typedef struct STableData STableData;
|
||||
typedef struct {
|
||||
T_REF_DECLARE()
|
||||
SRWLatch latch;
|
||||
TSKEY keyFirst;
|
||||
TSKEY keyLast;
|
||||
int64_t numOfRows;
|
||||
int32_t maxTables;
|
||||
STableData **tData;
|
||||
SList * actList;
|
||||
SList * extraBuffList;
|
||||
SList * bufBlockList;
|
||||
int64_t pointsAdd; // TODO
|
||||
int64_t storageAdd; // TODO
|
||||
} SMemTable;
|
||||
|
||||
typedef struct {
|
||||
SMemTable* mem;
|
||||
SMemTable* imem;
|
||||
SMemTable mtable;
|
||||
SMemTable* omem;
|
||||
} SMemSnapshot;
|
||||
|
||||
typedef struct SMemRef {
|
||||
int32_t ref;
|
||||
void * mem;
|
||||
void * imem;
|
||||
int32_t ref;
|
||||
SMemSnapshot snapshot;
|
||||
} SMemRef;
|
||||
|
||||
typedef struct SDataBlockInfo {
|
||||
|
|
|
@ -79,6 +79,9 @@ typedef void (*FStopSyncFile)(int32_t vgId, uint64_t fversion);
|
|||
// get file version
|
||||
typedef int32_t (*FGetVersion)(int32_t vgId, uint64_t *fver, uint64_t *vver);
|
||||
|
||||
// reset version
|
||||
typedef int32_t (*FResetVersion)(int32_t vgId, uint64_t fver);
|
||||
|
||||
typedef int32_t (*FSendFile)(void *tsdb, SOCKET socketFd);
|
||||
typedef int32_t (*FRecvFile)(void *tsdb, SOCKET socketFd);
|
||||
|
||||
|
@ -96,6 +99,7 @@ typedef struct {
|
|||
FStartSyncFile startSyncFileFp;
|
||||
FStopSyncFile stopSyncFileFp;
|
||||
FGetVersion getVersionFp;
|
||||
FResetVersion resetVersionFp;
|
||||
FSendFile sendFileFp;
|
||||
FRecvFile recvFileFp;
|
||||
} SSyncInfo;
|
||||
|
@ -108,8 +112,8 @@ void syncCleanUp();
|
|||
int64_t syncStart(const SSyncInfo *);
|
||||
void syncStop(int64_t rid);
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg *);
|
||||
int32_t syncForwardToPeer(int64_t rid, void *pHead, void *mhandle, int32_t qtype);
|
||||
void syncConfirmForward(int64_t rid, uint64_t version, int32_t code);
|
||||
int32_t syncForwardToPeer(int64_t rid, void *pHead, void *mhandle, int32_t qtype, bool force);
|
||||
void syncConfirmForward(int64_t rid, uint64_t version, int32_t code, bool force);
|
||||
void syncRecover(int64_t rid); // recover from other nodes:
|
||||
int32_t syncGetNodesRole(int64_t rid, SNodesRole *);
|
||||
|
||||
|
|
|
@ -197,13 +197,11 @@
|
|||
#define TK_PREV 178
|
||||
#define TK_LINEAR 179
|
||||
#define TK_IMPORT 180
|
||||
#define TK_METRIC 181
|
||||
#define TK_TBNAME 182
|
||||
#define TK_JOIN 183
|
||||
#define TK_METRICS 184
|
||||
#define TK_INSERT 185
|
||||
#define TK_INTO 186
|
||||
#define TK_VALUES 187
|
||||
#define TK_TBNAME 181
|
||||
#define TK_JOIN 182
|
||||
#define TK_INSERT 183
|
||||
#define TK_INTO 184
|
||||
#define TK_VALUES 185
|
||||
|
||||
|
||||
#define TK_SPACE 300
|
||||
|
|
|
@ -65,6 +65,7 @@ void walFsync(twalh, bool forceFsync);
|
|||
int32_t walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
||||
int32_t walGetWalFile(twalh, char *fileName, int64_t *fileId);
|
||||
uint64_t walGetVersion(twalh);
|
||||
void walResetVersion(twalh, uint64_t newVer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ void vnodeFreeFromWQueue(void *pVnode, SVWriteMsg *pWrite);
|
|||
int32_t vnodeProcessWrite(void *pVnode, void *pHead, int32_t qtype, void *pRspRet);
|
||||
|
||||
// vnodeSync
|
||||
void vnodeConfirmForward(void *pVnode, uint64_t version, int32_t code);
|
||||
void vnodeConfirmForward(void *pVnode, uint64_t version, int32_t code, bool force);
|
||||
|
||||
// vnodeRead
|
||||
int32_t vnodeWriteToRQueue(void *pVnode, void *pCont, int32_t contLen, int8_t qtype, void *rparam);
|
||||
|
|
|
@ -36,6 +36,7 @@ ELSEIF (TD_DARWIN)
|
|||
LIST(APPEND SRC ./src/shellDarwin.c)
|
||||
LIST(APPEND SRC ./src/shellCommand.c)
|
||||
LIST(APPEND SRC ./src/shellImport.c)
|
||||
LIST(APPEND SRC ./src/shellCheck.c)
|
||||
ADD_EXECUTABLE(shell ${SRC})
|
||||
# linking with dylib
|
||||
TARGET_LINK_LIBRARIES(shell taos)
|
||||
|
|
|
@ -51,6 +51,7 @@ typedef struct SShellArguments {
|
|||
char file[TSDB_FILENAME_LEN];
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
int threadNum;
|
||||
int check;
|
||||
char* commands;
|
||||
int abort;
|
||||
int port;
|
||||
|
@ -71,6 +72,7 @@ void read_history();
|
|||
void write_history();
|
||||
void source_file(TAOS* con, char* fptr);
|
||||
void source_dir(TAOS* con, SShellArguments* args);
|
||||
void shellCheck(TAOS* con, SShellArguments* args);
|
||||
void get_history_path(char* history);
|
||||
void cleanup_handler(void* arg);
|
||||
void exitShell();
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#define _XOPEN_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
#include "os.h"
|
||||
#include "shell.h"
|
||||
#include "shellCommand.h"
|
||||
#include "tglobal.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define SHELL_SQL_LEN 1024
|
||||
static int32_t tbNum = 0;
|
||||
static int32_t tbMallocNum = 0;
|
||||
static char ** tbNames = NULL;
|
||||
static int32_t checkedNum = 0;
|
||||
static int32_t errorNum = 0;
|
||||
|
||||
typedef struct {
|
||||
pthread_t threadID;
|
||||
int threadIndex;
|
||||
int totalThreads;
|
||||
void * taos;
|
||||
char * db;
|
||||
} ShellThreadObj;
|
||||
|
||||
static int32_t shellUseDb(TAOS *con, char *db) {
|
||||
if (db == NULL) {
|
||||
fprintf(stdout, "no dbname input\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char sql[SHELL_SQL_LEN] = {0};
|
||||
snprintf(sql, SHELL_SQL_LEN, "use %s", db);
|
||||
|
||||
TAOS_RES *pSql = taos_query(con, sql);
|
||||
int32_t code = taos_errno(pSql);
|
||||
if (code != 0) {
|
||||
fprintf(stdout, "failed to execute sql:%s since %s", sql, taos_errstr(pSql));
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t shellShowTables(TAOS *con, char *db) {
|
||||
char sql[SHELL_SQL_LEN] = {0};
|
||||
snprintf(sql, SHELL_SQL_LEN, "show %s.tables", db);
|
||||
|
||||
TAOS_RES *pSql = taos_query(con, sql);
|
||||
int32_t code = taos_errno(pSql);
|
||||
|
||||
if (code != 0) {
|
||||
fprintf(stdout, "failed to execute sql:%s since %s\n", sql, taos_errstr(pSql));
|
||||
} else {
|
||||
TAOS_ROW row;
|
||||
while ((row = taos_fetch_row(pSql))) {
|
||||
int32_t tbIndex = tbNum++;
|
||||
if (tbMallocNum < tbNum) {
|
||||
tbMallocNum = (tbMallocNum * 2 + 1);
|
||||
tbNames = realloc(tbNames, tbMallocNum * sizeof(char *));
|
||||
if (tbNames == NULL) {
|
||||
fprintf(stdout, "failed to malloc tablenames, num:%d\n", tbMallocNum);
|
||||
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tbNames[tbIndex] = malloc(TSDB_TABLE_NAME_LEN);
|
||||
strncpy(tbNames[tbIndex], (const char *)row[0], TSDB_TABLE_NAME_LEN);
|
||||
if (tbIndex % 100000 == 0 && tbIndex != 0) {
|
||||
fprintf(stdout, "%d tablenames fetched\n", tbIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
|
||||
fprintf(stdout, "total %d tablenames fetched, over\n", tbNum);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void shellFreeTbnames() {
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
free(tbNames[i]);
|
||||
}
|
||||
free(tbNames);
|
||||
}
|
||||
|
||||
static void *shellCheckThreadFp(void *arg) {
|
||||
ShellThreadObj *pThread = (ShellThreadObj *)arg;
|
||||
|
||||
int32_t interval = tbNum / pThread->totalThreads + 1;
|
||||
int32_t start = pThread->threadIndex * interval;
|
||||
int32_t end = (pThread->threadIndex + 1) * interval;
|
||||
|
||||
if (end > tbNum) end = tbNum + 1;
|
||||
|
||||
char file[32] = {0};
|
||||
snprintf(file, 32, "tb%d.txt", pThread->threadIndex);
|
||||
|
||||
FILE *fp = fopen(file, "w");
|
||||
if (!fp) {
|
||||
fprintf(stdout, "failed to open %s, reason:%s", file, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char sql[SHELL_SQL_LEN];
|
||||
for (int32_t t = start; t < end; ++t) {
|
||||
char *tbname = tbNames[t];
|
||||
if (tbname == NULL) break;
|
||||
|
||||
snprintf(sql, SHELL_SQL_LEN, "select * from %s limit 1", tbname);
|
||||
|
||||
TAOS_RES *pSql = taos_query(pThread->taos, sql);
|
||||
int32_t code = taos_errno(pSql);
|
||||
if (code != 0) {
|
||||
int32_t len = snprintf(sql, SHELL_SQL_LEN, "drop table %s.%s;\n", pThread->db, tbname);
|
||||
fwrite(sql, 1, len, fp);
|
||||
atomic_add_fetch_32(&errorNum, 1);
|
||||
}
|
||||
|
||||
int32_t cnum = atomic_add_fetch_32(&checkedNum, 1);
|
||||
if (cnum % 5000 == 0 && cnum != 0) {
|
||||
fprintf(stdout, "%d tables checked\n", cnum);
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
fsync(fileno(fp));
|
||||
fclose(fp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void shellRunCheckThreads(TAOS *con, SShellArguments *args) {
|
||||
pthread_attr_t thattr;
|
||||
ShellThreadObj *threadObj = (ShellThreadObj *)calloc(args->threadNum, sizeof(ShellThreadObj));
|
||||
for (int t = 0; t < args->threadNum; ++t) {
|
||||
ShellThreadObj *pThread = threadObj + t;
|
||||
pThread->threadIndex = t;
|
||||
pThread->totalThreads = args->threadNum;
|
||||
pThread->taos = con;
|
||||
pThread->db = args->database;
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&(pThread->threadID), &thattr, shellCheckThreadFp, (void *)pThread) != 0) {
|
||||
fprintf(stderr, "ERROR: thread:%d failed to start\n", pThread->threadIndex);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = 0; t < args->threadNum; ++t) {
|
||||
pthread_join(threadObj[t].threadID, NULL);
|
||||
}
|
||||
|
||||
for (int t = 0; t < args->threadNum; ++t) {
|
||||
taos_close(threadObj[t].taos);
|
||||
}
|
||||
free(threadObj);
|
||||
}
|
||||
|
||||
void shellCheck(TAOS *con, SShellArguments *args) {
|
||||
int64_t start = taosGetTimestampMs();
|
||||
|
||||
if (shellUseDb(con, args->database) != 0) {
|
||||
shellFreeTbnames();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shellShowTables(con, args->database) != 0) {
|
||||
shellFreeTbnames();
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stdout, "total %d tables will be checked by %d threads\n", tbNum, args->threadNum);
|
||||
shellRunCheckThreads(con, args);
|
||||
|
||||
int64_t end = taosGetTimestampMs();
|
||||
fprintf(stdout, "total %d tables checked, failed:%d, time spent %.2f seconds\n", checkedNum, errorNum,
|
||||
(end - start) / 1000.0);
|
||||
}
|
|
@ -121,6 +121,12 @@ TAOS *shellInit(SShellArguments *args) {
|
|||
taos_close(con);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (args->check != 0) {
|
||||
shellCheck(con, args);
|
||||
taos_close(con);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
return con;
|
||||
|
@ -412,7 +418,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
|||
#ifdef WINDOWS
|
||||
if (tt < 0) tt = 0;
|
||||
#endif
|
||||
if (tt < 0 && ms != 0) {
|
||||
if (tt <= 0 && ms < 0) {
|
||||
tt--;
|
||||
if (precision == TSDB_TIME_PRECISION_MICRO) {
|
||||
ms += 1000000;
|
||||
|
|
|
@ -45,6 +45,7 @@ static struct argp_option options[] = {
|
|||
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
||||
{"directory", 'D', "DIRECTORY", 0, "Use multi-thread to import all SQL files in the directory separately."},
|
||||
{"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."},
|
||||
{"check", 'k', "CHECK", 0, "Check tables."},
|
||||
{"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."},
|
||||
{"timezone", 't', "TIMEZONE", 0, "Time zone of the shell, default is local."},
|
||||
{"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync."},
|
||||
|
@ -130,6 +131,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||
return -1;
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
arguments->check = atoi(arg);
|
||||
break;
|
||||
case 'd':
|
||||
arguments->database = arg;
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
"filetype": "insert",
|
||||
"cfgdir": "/etc/taos",
|
||||
"host": "127.0.0.1",
|
||||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"thread_count": 4,
|
||||
"thread_count_create_tbl": 4,
|
||||
"result_file": "./insert_res.txt",
|
||||
"confirm_parameter_prompt": "no",
|
||||
"insert_interval": 1000,
|
||||
"num_of_records_per_req": 100,
|
||||
"max_sql_len": 1024000,
|
||||
"databases": [{
|
||||
"dbinfo": {
|
||||
"name": "db",
|
||||
"drop": "yes",
|
||||
"replica": 1,
|
||||
"days": 10,
|
||||
"cache": 16,
|
||||
"blocks": 8,
|
||||
"precision": "ms",
|
||||
"keep": 365,
|
||||
"minRows": 100,
|
||||
"maxRows": 4096,
|
||||
"comp":2,
|
||||
"walLevel":1,
|
||||
"cachelast":0,
|
||||
"quorum":1,
|
||||
"fsync":3000,
|
||||
"update": 0
|
||||
},
|
||||
"super_tables": [{
|
||||
"name": "stb",
|
||||
"child_table_exists":"no",
|
||||
"childtable_count": 100,
|
||||
"childtable_prefix": "stb_",
|
||||
"auto_create_table": "no",
|
||||
"data_source": "rand",
|
||||
"insert_mode": "taosc",
|
||||
"insert_rows": 1000,
|
||||
"multi_thread_write_one_tbl": "no",
|
||||
"rows_per_tbl": 20,
|
||||
"max_sql_len": 1024000,
|
||||
"disorder_ratio": 0,
|
||||
"disorder_range": 1000,
|
||||
"timestamp_step": 1,
|
||||
"start_timestamp": "2020-10-01 00:00:00.000",
|
||||
"sample_format": "csv",
|
||||
"sample_file": "./sample.csv",
|
||||
"tags_file": "",
|
||||
"columns": [{"type": "INT"}],
|
||||
"tags": [{"type": "TINYINT", "count":1}]
|
||||
}]
|
||||
}]
|
||||
}
|
|
@ -1,60 +1,57 @@
|
|||
{
|
||||
"filetype": "insert",
|
||||
"cfgdir": "/etc/taos",
|
||||
"host": "127.0.0.1",
|
||||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"thread_count": 4,
|
||||
"thread_count_create_tbl": 4,
|
||||
"result_file": "./insert_res.txt",
|
||||
"filetype": "insert",
|
||||
"cfgdir": "/etc/taos",
|
||||
"host": "127.0.0.1",
|
||||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"thread_count": 4,
|
||||
"thread_count_create_tbl": 4,
|
||||
"result_file": "./insert_res.txt",
|
||||
"confirm_parameter_prompt": "no",
|
||||
"insert_interval": 0,
|
||||
"num_of_records_per_req": 100,
|
||||
"max_sql_len": 1024000,
|
||||
"databases": [{
|
||||
"dbinfo": {
|
||||
"name": "db",
|
||||
"drop": "yes",
|
||||
"replica": 1,
|
||||
"days": 10,
|
||||
"cache": 16,
|
||||
"blocks": 8,
|
||||
"precision": "ms",
|
||||
"keep": 365,
|
||||
"minRows": 100,
|
||||
"maxRows": 4096,
|
||||
"comp":2,
|
||||
"walLevel":1,
|
||||
"cachelast":0,
|
||||
"quorum":1,
|
||||
"fsync":3000,
|
||||
"update": 0
|
||||
},
|
||||
"super_tables": [{
|
||||
"name": "stb",
|
||||
"databases": [{
|
||||
"dbinfo": {
|
||||
"name": "db",
|
||||
"drop": "yes",
|
||||
"replica": 1,
|
||||
"days": 10,
|
||||
"cache": 16,
|
||||
"blocks": 8,
|
||||
"precision": "ms",
|
||||
"keep": 365,
|
||||
"minRows": 100,
|
||||
"maxRows": 4096,
|
||||
"comp":2,
|
||||
"walLevel":1,
|
||||
"cachelast":0,
|
||||
"quorum":1,
|
||||
"fsync":3000,
|
||||
"update": 0
|
||||
},
|
||||
"super_tables": [{
|
||||
"name": "stb",
|
||||
"child_table_exists":"no",
|
||||
"childtable_count": 100,
|
||||
"childtable_prefix": "stb_",
|
||||
"auto_create_table": "no",
|
||||
"data_source": "rand",
|
||||
"insert_mode": "taosc",
|
||||
"childtable_limit": 33,
|
||||
"childtable_offset": 33,
|
||||
"insert_rows": 1000,
|
||||
"multi_thread_write_one_tbl": "no",
|
||||
"number_of_tbl_in_one_sql": 0,
|
||||
"rows_per_tbl": 100,
|
||||
"max_sql_len": 1024000,
|
||||
"disorder_ratio": 0,
|
||||
"disorder_range": 1000,
|
||||
"timestamp_step": 1,
|
||||
"start_timestamp": "2020-10-01 00:00:00.000",
|
||||
"sample_format": "csv",
|
||||
"sample_file": "./sample.csv",
|
||||
"tags_file": "",
|
||||
"columns": [{"type": "INT"}, {"type": "DOUBLE", "count":10}, {"type": "BINARY", "len": 16, "count":3}, {"type": "BINARY", "len": 32, "count":6}],
|
||||
"tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}]
|
||||
}]
|
||||
}]
|
||||
"childtable_count": 10000,
|
||||
"childtable_prefix": "stb_",
|
||||
"auto_create_table": "no",
|
||||
"data_source": "rand",
|
||||
"insert_mode": "taosc",
|
||||
"insert_rows": 100000,
|
||||
"multi_thread_write_one_tbl": "no",
|
||||
"rows_per_tbl": 0,
|
||||
"max_sql_len": 1024000,
|
||||
"disorder_ratio": 0,
|
||||
"disorder_range": 1000,
|
||||
"timestamp_step": 1,
|
||||
"start_timestamp": "2020-10-01 00:00:00.000",
|
||||
"sample_format": "csv",
|
||||
"sample_file": "./sample.csv",
|
||||
"tags_file": "",
|
||||
"columns": [{"type": "INT"}, {"type": "DOUBLE", "count":10}, {"type": "BINARY", "len": 16, "count":3}, {"type": "BINARY", "len": 32, "count":6}],
|
||||
"tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}]
|
||||
}]
|
||||
}]
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -44,7 +44,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
|
|||
void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle);
|
||||
int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_t *sid);
|
||||
|
||||
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
||||
int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCheck);
|
||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
||||
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle);
|
||||
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||
|
|
|
@ -552,7 +552,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow) {
|
|||
|
||||
int32_t code = (*pTable->fpInsert)(pRow);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->name,
|
||||
sdbError("vgId:1, sdb:%s, failed to perform insert action for key:%s, remove it", pTable->name,
|
||||
sdbGetRowStr(pTable, pRow->pObj));
|
||||
sdbDeleteHash(pTable, pRow);
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *
|
|||
if (pRow != NULL) {
|
||||
// forward to peers
|
||||
pRow->processedCount = 0;
|
||||
int32_t syncCode = syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC);
|
||||
int32_t syncCode = syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC, false);
|
||||
if (syncCode <= 0) pRow->processedCount = 1;
|
||||
|
||||
if (syncCode < 0) {
|
||||
|
@ -700,7 +700,7 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *
|
|||
actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version);
|
||||
|
||||
// even it is WAL/FWD, it shall be called to update version in sync
|
||||
syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC);
|
||||
syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC, false);
|
||||
|
||||
// from wal or forward msg, row not created, should add into hash
|
||||
if (action == SDB_ACTION_INSERT) {
|
||||
|
@ -1119,7 +1119,7 @@ static void *sdbWorkerFp(void *pWorker) {
|
|||
sdbConfirmForward(1, pRow, pRow->code);
|
||||
} else {
|
||||
if (qtype == TAOS_QTYPE_FWD) {
|
||||
syncConfirmForward(tsSdbMgmt.sync, pRow->pHead.version, pRow->code);
|
||||
syncConfirmForward(tsSdbMgmt.sync, pRow->pHead.version, pRow->code, false);
|
||||
}
|
||||
sdbFreeFromQueue(pRow);
|
||||
}
|
||||
|
|
|
@ -108,10 +108,12 @@ static int32_t mnodeChildTableActionDestroy(SSdbRow *pRow) {
|
|||
|
||||
static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||
SCTableObj *pTable = pRow->pObj;
|
||||
int32_t code = 0;
|
||||
|
||||
SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId);
|
||||
code = -1;
|
||||
}
|
||||
|
||||
SDbObj *pDb = NULL;
|
||||
|
@ -119,6 +121,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
|||
pDb = mnodeGetDb(pVgroup->dbName);
|
||||
if (pDb == NULL) {
|
||||
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
|
||||
code = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +130,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
|||
pAcct = mnodeGetAcct(pDb->acct);
|
||||
if (pAcct == NULL) {
|
||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
|
||||
code = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,6 +143,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
|||
if (pAcct) pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1);
|
||||
} else {
|
||||
mError("table:%s:%p, correspond stable not found suid:%" PRIu64, pTable->info.tableId, pTable, pTable->suid);
|
||||
code = -1;
|
||||
}
|
||||
} else {
|
||||
grantAdd(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1);
|
||||
|
@ -146,18 +151,31 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
|||
}
|
||||
|
||||
if (pDb) mnodeAddTableIntoDb(pDb);
|
||||
if (pVgroup) mnodeAddTableIntoVgroup(pVgroup, pTable);
|
||||
if (pVgroup) {
|
||||
if (mnodeAddTableIntoVgroup(pVgroup, pTable, pRow->pMsg == NULL) != 0) {
|
||||
mError("table:%s, vgId:%d tid:%d, failed to perform insert action, uid:%" PRIu64 " suid:%" PRIu64,
|
||||
pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||
code = -1;
|
||||
}
|
||||
}
|
||||
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
mnodeDecDbRef(pDb);
|
||||
mnodeDecAcctRef(pAcct);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
if (code == 0) {
|
||||
mTrace("table:%s, vgId:%d tid:%d, perform insert action, uid:%" PRIu64 " suid:%" PRIu64, pTable->info.tableId,
|
||||
pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
|
||||
SCTableObj *pTable = pRow->pObj;
|
||||
if (pTable->vgId == 0) {
|
||||
mError("table:%s, vgId:%d tid:%d, failed to perform delete action, uid:%" PRIu64 " suid:%" PRIu64,
|
||||
pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
||||
}
|
||||
|
||||
|
@ -188,6 +206,8 @@ static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
|
|||
mnodeDecDbRef(pDb);
|
||||
mnodeDecAcctRef(pAcct);
|
||||
|
||||
mTrace("table:%s, vgId:%d tid:%d, perform delete action, uid:%" PRIu64 " suid:%" PRIu64, pTable->info.tableId,
|
||||
pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -399,13 +419,13 @@ static void mnodeAddTableIntoStable(SSTableObj *pStable, SCTableObj *pCtable) {
|
|||
|
||||
if (pStable->vgHash == NULL) {
|
||||
pStable->vgHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
mDebug("table:%s, create hash:%p", pStable->info.tableId, pStable->vgHash);
|
||||
mDebug("stable:%s, create vgId hash:%p", pStable->info.tableId, pStable->vgHash);
|
||||
}
|
||||
|
||||
if (pStable->vgHash != NULL) {
|
||||
if (taosHashGet(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId)) == NULL) {
|
||||
taosHashPut(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId), &pCtable->vgId, sizeof(pCtable->vgId));
|
||||
mDebug("table:%s, vgId:%d is put into stable hash:%p, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId,
|
||||
mDebug("stable:%s, vgId:%d is put into stable vgId hash:%p, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId,
|
||||
pStable->vgHash, taosHashGetSize(pStable->vgHash));
|
||||
}
|
||||
}
|
||||
|
@ -443,19 +463,21 @@ static int32_t mnodeSuperTableActionDestroy(SSdbRow *pRow) {
|
|||
|
||||
static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) {
|
||||
SSTableObj *pStable = pRow->pObj;
|
||||
SDbObj *pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||
SDbObj * pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||
if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) {
|
||||
mnodeAddSuperTableIntoDb(pDb);
|
||||
}
|
||||
mnodeDecDbRef(pDb);
|
||||
|
||||
taosHashPut(tsSTableUidHash, &pStable->uid, sizeof(int64_t), &pStable, sizeof(int64_t));
|
||||
|
||||
mTrace("stable:%s, perform insert action, uid:%" PRIu64, pStable->info.tableId, pStable->uid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
||||
SSTableObj *pStable = pRow->pObj;
|
||||
SDbObj *pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||
SDbObj * pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||
if (pDb != NULL) {
|
||||
mnodeRemoveSuperTableFromDb(pDb);
|
||||
mnodeDropAllChildTablesInStable((SSTableObj *)pStable);
|
||||
|
@ -463,6 +485,8 @@ static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
|||
mnodeDecDbRef(pDb);
|
||||
|
||||
taosHashRemove(tsSTableUidHash, &pStable->uid, sizeof(int64_t));
|
||||
|
||||
mTrace("stable:%s, perform delete action, uid:%" PRIu64, pStable->info.tableId, pStable->uid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1888,15 +1912,14 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
|||
pMsg->rpcMsg.handle);
|
||||
|
||||
if (pMsg->pBatchMasterMsg) {
|
||||
++pMsg->pBatchMasterMsg->successed;
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
||||
>= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||
}
|
||||
++pMsg->pBatchMasterMsg->successed;
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||
}
|
||||
|
||||
mnodeDestroySubMsg(pMsg);
|
||||
mnodeDestroySubMsg(pMsg);
|
||||
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
dnodeSendRpcMWriteRsp(pMsg, TSDB_CODE_SUCCESS);
|
||||
|
@ -1911,9 +1934,8 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
|||
if (pMsg->pBatchMasterMsg) {
|
||||
++pMsg->pBatchMasterMsg->received;
|
||||
pMsg->pBatchMasterMsg->code = code;
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
||||
>= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||
}
|
||||
|
||||
mnodeDestroySubMsg(pMsg);
|
||||
|
@ -2662,9 +2684,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
|
|||
|
||||
if (pMsg->pBatchMasterMsg) {
|
||||
++pMsg->pBatchMasterMsg->successed;
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
||||
>= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, rpcMsg->code);
|
||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, rpcMsg->code);
|
||||
}
|
||||
|
||||
mnodeDestroySubMsg(pMsg);
|
||||
|
|
|
@ -443,6 +443,7 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
|
|||
mDebug("msg:%p, app:%p db:%s, no enough sid in vgId:%d", pMsg, pMsg->rpcMsg.ahandle, pDb->name, pVgroup->vgId);
|
||||
continue;
|
||||
}
|
||||
mTrace("vgId:%d, alloc tid:%d", pVgroup->vgId, sid);
|
||||
|
||||
*pSid = sid;
|
||||
*ppVgroup = pVgroup;
|
||||
|
@ -507,6 +508,7 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
|
|||
pDb->vgListIndex = 0;
|
||||
pthread_mutex_unlock(&pDb->mutex);
|
||||
|
||||
mTrace("vgId:%d, alloc tid:%d", pVgroup->vgId, sid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -832,26 +834,37 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v
|
|||
return numOfRows;
|
||||
}
|
||||
|
||||
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable) {
|
||||
int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCheck) {
|
||||
int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
||||
if (pTable->tid > idPoolSize) {
|
||||
mnodeAllocVgroupIdPool(pVgroup);
|
||||
}
|
||||
|
||||
if (pTable->tid >= 1) {
|
||||
taosIdPoolMarkStatus(pVgroup->idPool, pTable->tid);
|
||||
pVgroup->numOfTables++;
|
||||
// The create vgroup message may be received later than the create table message
|
||||
// and the writing order in sdb is therefore uncertain
|
||||
// which will cause the reference count of the vgroup to be incorrect when restarting
|
||||
// mnodeIncVgroupRef(pVgroup);
|
||||
if (taosIdPoolMarkStatus(pVgroup->idPool, pTable->tid) || !needCheck) {
|
||||
pVgroup->numOfTables++;
|
||||
mTrace("table:%s, vgId:%d tid:%d, mark tid used, uid:%" PRIu64, pTable->info.tableId, pTable->vgId, pTable->tid,
|
||||
pTable->uid);
|
||||
// The create vgroup message may be received later than the create table message
|
||||
// and the writing order in sdb is therefore uncertain
|
||||
// which will cause the reference count of the vgroup to be incorrect when restarting
|
||||
// mnodeIncVgroupRef(pVgroup);
|
||||
} else {
|
||||
mError("table:%s, vgId:%d tid:%d, failed to mark tid, uid:%" PRIu64, pTable->info.tableId, pTable->vgId,
|
||||
pTable->tid, pTable->uid);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable) {
|
||||
if (pTable->tid >= 1) {
|
||||
taosFreeId(pVgroup->idPool, pTable->tid);
|
||||
pVgroup->numOfTables--;
|
||||
mTrace("table:%s, vgId:%d tid:%d, put tid back uid:%" PRIu64, pTable->info.tableId, pTable->vgId, pTable->tid,
|
||||
pTable->uid);
|
||||
// The create vgroup message may be received later than the create table message
|
||||
// and the writing order in sdb is therefore uncertain
|
||||
// which will cause the reference count of the vgroup to be incorrect when restarting
|
||||
|
|
|
@ -110,7 +110,7 @@ static void httpCleanupString(HttpString *str) {
|
|||
static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) {
|
||||
if (str->size == 0) {
|
||||
str->pos = 0;
|
||||
str->size = 64;
|
||||
str->size = len + 1;
|
||||
str->str = malloc(str->size);
|
||||
} else if (str->pos + len + 1 >= str->size) {
|
||||
str->size += len;
|
||||
|
@ -715,10 +715,12 @@ static int32_t httpParserOnVersion(HttpParser *parser, HTTP_PARSER_STATE state,
|
|||
|
||||
if (parser->method) {
|
||||
ok = httpOnRequestLine(parser, parser->method, parser->target, parser->version);
|
||||
/*
|
||||
if (parser->target) {
|
||||
free(parser->target);
|
||||
parser->target = NULL;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
httpClearString(&parser->str);
|
||||
|
|
|
@ -308,6 +308,7 @@ enum {
|
|||
|
||||
typedef struct SQInfo {
|
||||
void* signature;
|
||||
uint64_t qId;
|
||||
int32_t code; // error code to returned to client
|
||||
int64_t owner; // if it is in execution
|
||||
|
||||
|
@ -429,7 +430,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t nu
|
|||
|
||||
SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code);
|
||||
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, uint64_t *qId);
|
||||
int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQInfo *pQInfo, SQueryParam* param, bool isSTable);
|
||||
void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters);
|
||||
|
||||
|
|
|
@ -27,168 +27,6 @@ extern "C" {
|
|||
#include "tvariant.h"
|
||||
|
||||
#define ParseTOKENTYPE SStrToken
|
||||
extern char tTokenTypeSwitcher[13];
|
||||
|
||||
#define toTSDBType(x) \
|
||||
do { \
|
||||
if ((x) >= tListLen(tTokenTypeSwitcher)) { \
|
||||
(x) = TSDB_DATA_TYPE_BINARY; \
|
||||
} else { \
|
||||
(x) = tTokenTypeSwitcher[(x)]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct SLimitVal {
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimitVal;
|
||||
|
||||
typedef struct SOrderVal {
|
||||
uint32_t order;
|
||||
int32_t orderColId;
|
||||
} SOrderVal;
|
||||
|
||||
typedef struct tVariantListItem {
|
||||
tVariant pVar;
|
||||
uint8_t sortOrder;
|
||||
} tVariantListItem;
|
||||
|
||||
typedef struct SIntervalVal {
|
||||
SStrToken interval;
|
||||
SStrToken offset;
|
||||
} SIntervalVal;
|
||||
|
||||
typedef struct SSessionWindowVal {
|
||||
SStrToken col;
|
||||
SStrToken gap;
|
||||
} SSessionWindowVal;
|
||||
|
||||
typedef struct SQuerySQL {
|
||||
struct tSQLExprList *pSelection; // select clause
|
||||
SArray * from; // from clause SArray<tVariantListItem>
|
||||
struct tSQLExpr * pWhere; // where clause [optional]
|
||||
SArray * pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
|
||||
SArray * pSortOrder; // orderby [optional], SArray<tVariantListItem>
|
||||
SIntervalVal interval; // (interval, interval_offset) [optional]
|
||||
SSessionWindowVal sessionVal; // session window [optional]
|
||||
SStrToken sliding; // sliding window [optional]
|
||||
SLimitVal limit; // limit offset [optional]
|
||||
SLimitVal slimit; // group limit offset [optional]
|
||||
SArray * fillType; // fill type[optional], SArray<tVariantListItem>
|
||||
SStrToken selectToken; // sql string
|
||||
} SQuerySQL;
|
||||
|
||||
typedef struct SCreatedTableInfo {
|
||||
SStrToken name; // table name token
|
||||
SStrToken stableName; // super table name token , for using clause
|
||||
SArray *pTagNames; // create by using super table, tag name
|
||||
SArray *pTagVals; // create by using super table, tag value
|
||||
char *fullname; // table full name
|
||||
STagData tagdata; // true tag data, super table full name is in STagData
|
||||
int8_t igExist; // ignore if exists
|
||||
} SCreatedTableInfo;
|
||||
|
||||
typedef struct SCreateTableSQL {
|
||||
SStrToken name; // table name, create table [name] xxx
|
||||
int8_t type; // create normal table/from super table/ stream
|
||||
bool existCheck;
|
||||
|
||||
struct {
|
||||
SArray *pTagColumns; // SArray<TAOS_FIELD>
|
||||
SArray *pColumns; // SArray<TAOS_FIELD>
|
||||
} colInfo;
|
||||
|
||||
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
||||
SQuerySQL *pSelect;
|
||||
} SCreateTableSQL;
|
||||
|
||||
typedef struct SAlterTableInfo {
|
||||
SStrToken name;
|
||||
int16_t tableType;
|
||||
int16_t type;
|
||||
STagData tagData;
|
||||
SArray *pAddColumns; // SArray<TAOS_FIELD>
|
||||
SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
|
||||
} SAlterTableInfo;
|
||||
|
||||
typedef struct SCreateDbInfo {
|
||||
SStrToken dbname;
|
||||
int32_t replica;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t maxTablesPerVnode;
|
||||
int32_t numOfBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t minRowsPerBlock;
|
||||
int32_t maxRowsPerBlock;
|
||||
int32_t fsyncPeriod;
|
||||
int64_t commitTime;
|
||||
int32_t walLevel;
|
||||
int32_t quorum;
|
||||
int32_t compressionLevel;
|
||||
SStrToken precision;
|
||||
bool ignoreExists;
|
||||
int8_t update;
|
||||
int8_t cachelast;
|
||||
SArray *keep;
|
||||
int8_t dbType;
|
||||
int16_t partitions;
|
||||
} SCreateDbInfo;
|
||||
|
||||
typedef struct SCreateAcctInfo {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int32_t maxPointsPerSecond;
|
||||
int64_t maxStorage;
|
||||
int64_t maxQueryTime;
|
||||
int32_t maxConnections;
|
||||
SStrToken stat;
|
||||
} SCreateAcctInfo;
|
||||
|
||||
typedef struct SShowInfo {
|
||||
uint8_t showType;
|
||||
SStrToken prefix;
|
||||
SStrToken pattern;
|
||||
} SShowInfo;
|
||||
|
||||
typedef struct SUserInfo {
|
||||
SStrToken user;
|
||||
SStrToken passwd;
|
||||
SStrToken privilege;
|
||||
int16_t type;
|
||||
} SUserInfo;
|
||||
|
||||
typedef struct SMiscInfo {
|
||||
SArray *a; // SArray<SStrToken>
|
||||
bool existsCheck;
|
||||
int16_t dbType;
|
||||
int16_t tableType;
|
||||
SUserInfo user;
|
||||
union {
|
||||
SCreateDbInfo dbOpt;
|
||||
SCreateAcctInfo acctOpt;
|
||||
SShowInfo showOpt;
|
||||
SStrToken id;
|
||||
};
|
||||
} SMiscInfo;
|
||||
|
||||
typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
|
||||
SQuerySQL **pClause;
|
||||
int32_t numOfClause;
|
||||
} SSubclauseInfo;
|
||||
|
||||
typedef struct SSqlInfo {
|
||||
int32_t type;
|
||||
bool valid;
|
||||
SSubclauseInfo subclauseInfo;
|
||||
char msg[256];
|
||||
union {
|
||||
SCreateTableSQL *pCreateTableInfo;
|
||||
SAlterTableInfo *pAlterInfo;
|
||||
SMiscInfo *pMiscInfo;
|
||||
};
|
||||
} SSqlInfo;
|
||||
|
||||
#define NON_ARITHMEIC_EXPR 0
|
||||
#define NORMAL_ARITHMETIC 1
|
||||
|
@ -201,36 +39,278 @@ enum SQL_NODE_TYPE {
|
|||
SQL_NODE_EXPR = 4,
|
||||
};
|
||||
|
||||
typedef struct tSQLExpr {
|
||||
uint16_t type; // sql node type
|
||||
uint32_t tokenId; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
||||
enum SQL_NODE_FROM_TYPE {
|
||||
SQL_NODE_FROM_SUBQUERY = 1,
|
||||
SQL_NODE_FROM_NAMELIST = 2,
|
||||
};
|
||||
|
||||
extern char tTokenTypeSwitcher[13];
|
||||
|
||||
#define toTSDBType(x) \
|
||||
do { \
|
||||
if ((x) >= tListLen(tTokenTypeSwitcher)) { \
|
||||
(x) = TSDB_DATA_TYPE_BINARY; \
|
||||
} else { \
|
||||
(x) = tTokenTypeSwitcher[(x)]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0)
|
||||
#define TPARSER_SET_NONE_TOKEN(_t) ((_t).n = 0)
|
||||
|
||||
typedef struct SLimitVal {
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimitVal;
|
||||
|
||||
typedef struct SOrderVal {
|
||||
uint32_t order;
|
||||
int32_t orderColId;
|
||||
} SOrderVal;
|
||||
|
||||
typedef struct tVariantListItem {
|
||||
tVariant pVar;
|
||||
uint8_t sortOrder;
|
||||
} tVariantListItem;
|
||||
|
||||
typedef struct SIntervalVal {
|
||||
SStrToken interval;
|
||||
SStrToken offset;
|
||||
} SIntervalVal;
|
||||
|
||||
typedef struct SSessionWindowVal {
|
||||
SStrToken col;
|
||||
SStrToken gap;
|
||||
} 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 *pSortOrder; // orderby [optional], SArray<tVariantListItem>
|
||||
SArray *fillType; // fill type[optional], SArray<tVariantListItem>
|
||||
SIntervalVal interval; // (interval, interval_offset) [optional]
|
||||
SSessionWindowVal sessionVal; // session window [optional]
|
||||
SStrToken sliding; // sliding window [optional]
|
||||
SLimitVal limit; // limit offset [optional]
|
||||
SLimitVal slimit; // group limit offset [optional]
|
||||
SStrToken sqlstr; // sql string in select clause
|
||||
} SQuerySqlNode;
|
||||
|
||||
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 {
|
||||
SStrToken name; // table name token
|
||||
SStrToken stableName; // super table name token , for using clause
|
||||
SArray *pTagNames; // create by using super table, tag name
|
||||
SArray *pTagVals; // create by using super table, tag value
|
||||
char *fullname; // table full name
|
||||
STagData tagdata; // true tag data, super table full name is in STagData
|
||||
int8_t igExist; // ignore if exists
|
||||
} SCreatedTableInfo;
|
||||
|
||||
typedef struct SCreateTableSql {
|
||||
SStrToken name; // table name, create table [name] xxx
|
||||
int8_t type; // create normal table/from super table/ stream
|
||||
bool existCheck;
|
||||
|
||||
struct {
|
||||
SArray *pTagColumns; // SArray<TAOS_FIELD>
|
||||
SArray *pColumns; // SArray<TAOS_FIELD>
|
||||
} colInfo;
|
||||
|
||||
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
||||
SQuerySqlNode *pSelect;
|
||||
} SCreateTableSql;
|
||||
|
||||
typedef struct SAlterTableInfo {
|
||||
SStrToken name;
|
||||
int16_t tableType;
|
||||
int16_t type;
|
||||
STagData tagData;
|
||||
SArray *pAddColumns; // SArray<TAOS_FIELD>
|
||||
SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
|
||||
} SAlterTableInfo;
|
||||
|
||||
typedef struct SCreateDbInfo {
|
||||
SStrToken dbname;
|
||||
int32_t replica;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t maxTablesPerVnode;
|
||||
int32_t numOfBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t minRowsPerBlock;
|
||||
int32_t maxRowsPerBlock;
|
||||
int32_t fsyncPeriod;
|
||||
int64_t commitTime;
|
||||
int32_t walLevel;
|
||||
int32_t quorum;
|
||||
int32_t compressionLevel;
|
||||
SStrToken precision;
|
||||
bool ignoreExists;
|
||||
int8_t update;
|
||||
int8_t cachelast;
|
||||
SArray *keep;
|
||||
int8_t dbType;
|
||||
int16_t partitions;
|
||||
} SCreateDbInfo;
|
||||
|
||||
typedef struct SCreateAcctInfo {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int32_t maxPointsPerSecond;
|
||||
int64_t maxStorage;
|
||||
int64_t maxQueryTime;
|
||||
int32_t maxConnections;
|
||||
SStrToken stat;
|
||||
} SCreateAcctInfo;
|
||||
|
||||
typedef struct SShowInfo {
|
||||
uint8_t showType;
|
||||
SStrToken prefix;
|
||||
SStrToken pattern;
|
||||
} SShowInfo;
|
||||
|
||||
typedef struct SUserInfo {
|
||||
SStrToken user;
|
||||
SStrToken passwd;
|
||||
SStrToken privilege;
|
||||
int16_t type;
|
||||
} SUserInfo;
|
||||
|
||||
typedef struct SMiscInfo {
|
||||
SArray *a; // SArray<SStrToken>
|
||||
bool existsCheck;
|
||||
int16_t dbType;
|
||||
int16_t tableType;
|
||||
SUserInfo user;
|
||||
union {
|
||||
SCreateDbInfo dbOpt;
|
||||
SCreateAcctInfo acctOpt;
|
||||
SShowInfo showOpt;
|
||||
SStrToken id;
|
||||
};
|
||||
} SMiscInfo;
|
||||
|
||||
typedef struct SSqlInfo {
|
||||
int32_t type;
|
||||
bool valid;
|
||||
SSubclauseInfo subclauseInfo;
|
||||
char msg[256];
|
||||
union {
|
||||
SCreateTableSql *pCreateTableInfo;
|
||||
SAlterTableInfo *pAlterInfo;
|
||||
SMiscInfo *pMiscInfo;
|
||||
};
|
||||
} SSqlInfo;
|
||||
|
||||
typedef struct tSqlExpr {
|
||||
uint16_t type; // sql node type
|
||||
uint32_t tokenId; // TK_LE: less than(binary expr)
|
||||
|
||||
// the whole string of the function(col, param), while the function name is kept in token
|
||||
SStrToken operand;
|
||||
uint32_t functionId; // function id
|
||||
SStrToken operand;
|
||||
uint32_t functionId; // function id
|
||||
|
||||
SStrToken colInfo; // table column info
|
||||
tVariant value; // the use input value
|
||||
SStrToken token; // original sql expr string
|
||||
SStrToken colInfo; // table column info
|
||||
tVariant value; // the use input value
|
||||
SStrToken token; // original sql expr string
|
||||
|
||||
struct tSQLExpr *pLeft; // left child
|
||||
struct tSQLExpr *pRight; // right child
|
||||
struct tSQLExprList *pParam; // function parameters list
|
||||
} tSQLExpr;
|
||||
struct tSqlExpr *pLeft; // left child
|
||||
struct tSqlExpr *pRight; // right child
|
||||
struct SArray *pParam; // function parameters list
|
||||
} tSqlExpr;
|
||||
|
||||
// used in select clause. select <tSQLExprList> from xxx
|
||||
// used in select clause. select <SArray> from xxx
|
||||
typedef struct tSqlExprItem {
|
||||
tSQLExpr *pNode; // The list of expressions
|
||||
char * aliasName; // alias name, null-terminated string
|
||||
bool distinct;
|
||||
tSqlExpr *pNode; // The list of expressions
|
||||
char *aliasName; // alias name, null-terminated string
|
||||
bool distinct;
|
||||
} tSqlExprItem;
|
||||
|
||||
// todo refactor by using SArray
|
||||
typedef struct tSQLExprList {
|
||||
int32_t nExpr; /* Number of expressions on the list */
|
||||
int32_t nAlloc; /* Number of entries allocated below */
|
||||
tSqlExprItem *a; /* One entry for each expression */
|
||||
} tSQLExprList;
|
||||
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);
|
||||
|
||||
SFromInfo *setTableNameList(SFromInfo* pFromInfo, SStrToken *pName, SStrToken* pAlias);
|
||||
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);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -247,72 +327,19 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
|||
*/
|
||||
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);
|
||||
|
||||
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 *tSetQuerySqlNode(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *pSession,
|
||||
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);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mallocProc The parser allocator
|
||||
* @return
|
||||
*/
|
||||
void *ParseAlloc(void *(*mallocProc)(size_t));
|
||||
|
||||
SSqlInfo qSQLParse(const char *str);
|
||||
/**
|
||||
*
|
||||
* @param str sql string
|
||||
* @return sql ast
|
||||
*/
|
||||
SSqlInfo qSqlParse(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -92,11 +92,11 @@ cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
|
|||
|
||||
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
|
||||
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). {
|
||||
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
|
||||
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
|
||||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) TABLES. {
|
||||
|
@ -113,19 +113,19 @@ cmd ::= SHOW dbPrefix(X) STABLES. {
|
|||
|
||||
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
|
||||
SStrToken token;
|
||||
setDbName(&token, &X);
|
||||
tSetDbName(&token, &X);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
|
||||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) VGROUPS. {
|
||||
SStrToken token;
|
||||
setDbName(&token, &X);
|
||||
tSetDbName(&token, &X);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
|
||||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
|
||||
SStrToken token;
|
||||
setDbName(&token, &X);
|
||||
tSetDbName(&token, &X);
|
||||
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 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 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 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 ACCOUNT ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
|
||||
|
||||
/////////////////////////////////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/////////////////////////////////////
|
||||
cmd ::= DESCRIBE ids(X) cpxName(Y). {
|
||||
X.n += Y.n;
|
||||
setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
|
||||
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
|
||||
}
|
||||
|
||||
/////////////////////////////////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) 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) 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) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 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 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 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);}
|
||||
|
||||
|
@ -187,7 +187,7 @@ ifnotexists(X) ::= . { X.n = 0;}
|
|||
|
||||
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
||||
//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).
|
||||
{ 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);}
|
||||
|
@ -299,17 +299,17 @@ alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.parti
|
|||
%type typename {TAOS_FIELD}
|
||||
typename(A) ::= ids(X). {
|
||||
X.type = 0;
|
||||
tSqlSetColumnType (&A, &X);
|
||||
tSetColumnType (&A, &X);
|
||||
}
|
||||
|
||||
//define binary type, e.g., binary(10), nchar(10)
|
||||
typename(A) ::= ids(X) LP signed(Y) RP. {
|
||||
if (Y <= 0) {
|
||||
X.type = 0;
|
||||
tSqlSetColumnType(&A, &X);
|
||||
tSetColumnType(&A, &X);
|
||||
} else {
|
||||
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). {
|
||||
X.type = 0;
|
||||
X.n = ((Z.z + Z.n) - X.z);
|
||||
tSqlSetColumnType (&A, &X);
|
||||
tSetColumnType (&A, &X);
|
||||
}
|
||||
|
||||
%type signed {int64_t}
|
||||
|
@ -331,10 +331,10 @@ cmd ::= CREATE TABLE 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;}
|
||||
|
||||
%type create_table_list{SCreateTableSQL*}
|
||||
%type create_table_list{SCreateTableSql*}
|
||||
%destructor create_table_list{destroyCreateTableSql($$);}
|
||||
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));
|
||||
|
||||
taosArrayPush(pCreateTable->childTableInfo, &Z);
|
||||
|
@ -347,9 +347,9 @@ create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
|
|||
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. {
|
||||
A = tSetCreateSqlElems(X, NULL, NULL, TSQL_CREATE_TABLE);
|
||||
A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE);
|
||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
|
||||
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
|
||||
%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. {
|
||||
A = tSetCreateSqlElems(X, Y, NULL, TSQL_CREATE_STABLE);
|
||||
A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE);
|
||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
|
||||
V.n += Z.n;
|
||||
|
@ -389,7 +389,7 @@ tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(SSt
|
|||
// create stream
|
||||
// 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). {
|
||||
A = tSetCreateSqlElems(NULL, NULL, S, TSQL_CREATE_STREAM);
|
||||
A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM);
|
||||
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
|
||||
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:
|
||||
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
||||
column(A) ::= ids(X) typename(Y). {
|
||||
tSqlSetColumnInfo(&A, &X, &Y);
|
||||
tSetColumnInfo(&A, &X, &Y);
|
||||
}
|
||||
|
||||
%type tagitemlist {SArray*}
|
||||
|
@ -450,26 +450,26 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). {
|
|||
}
|
||||
|
||||
//////////////////////// The SELECT statement /////////////////////////////////
|
||||
%type select {SQuerySQL*}
|
||||
%destructor select {doDestroyQuerySql($$);}
|
||||
%type select {SQuerySqlNode*}
|
||||
%destructor select {destroyQuerySqlNode($$);}
|
||||
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 = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &S, F, &L, &G);
|
||||
}
|
||||
|
||||
select(A) ::= LP select(B) RP. {A = B;}
|
||||
|
||||
%type union {SSubclauseInfo*}
|
||||
%destructor union {destroyAllSelectClause($$);}
|
||||
|
||||
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 LP select(X) RP. { Y = appendSelectClause(Z, X); }
|
||||
|
||||
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
|
||||
|
||||
// Support for the SQL exprssion without from & where subclauses, e.g.,
|
||||
// select current_database(),
|
||||
// select server_version(), select client_version(),
|
||||
// select server_state();
|
||||
// select current_database()
|
||||
// select server_version()
|
||||
// select client_version()
|
||||
// select server_state()
|
||||
select(A) ::= SELECT(T) selcollist(W). {
|
||||
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
@ -477,10 +477,10 @@ select(A) ::= SELECT(T) selcollist(W). {
|
|||
// selcollist is a list of expressions that are to become the return
|
||||
// values of the SELECT statement. The "*" in statements like
|
||||
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
|
||||
%type selcollist {tSQLExprList*}
|
||||
%type selcollist {SArray*}
|
||||
%destructor selcollist {tSqlExprListDestroy($$);}
|
||||
|
||||
%type sclp {tSQLExprList*}
|
||||
%type sclp {SArray*}
|
||||
%destructor sclp {tSqlExprListDestroy($$);}
|
||||
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
||||
sclp(A) ::= . {A = 0;}
|
||||
|
@ -489,13 +489,12 @@ selcollist(A) ::= sclp(P) distinct(Z) expr(X) as(Y). {
|
|||
}
|
||||
|
||||
selcollist(A) ::= sclp(P) STAR. {
|
||||
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
|
||||
tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL);
|
||||
A = tSqlExprListAppend(P, pNode, 0, 0);
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
%type as {SStrToken}
|
||||
as(X) ::= AS 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;}
|
||||
|
||||
// A complete FROM clause.
|
||||
%type from {SArray*}
|
||||
// current not support query from no-table
|
||||
%type from {SFromInfo*}
|
||||
from(A) ::= FROM tablelist(X). {A = X;}
|
||||
from(A) ::= FROM LP union(Y) RP. {A = Y;}
|
||||
|
||||
%type tablelist {SArray*}
|
||||
tablelist(A) ::= ids(X) cpxName(Y). {
|
||||
toTSDBType(X.type);
|
||||
X.n += Y.n;
|
||||
A = tVariantListAppendToken(NULL, &X, -1);
|
||||
A = tVariantListAppendToken(A, &X, -1); // table alias name
|
||||
A = setTableNameList(NULL, &X, NULL);
|
||||
}
|
||||
|
||||
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
|
||||
toTSDBType(X.type);
|
||||
toTSDBType(Z.type);
|
||||
X.n += Y.n;
|
||||
A = tVariantListAppendToken(NULL, &X, -1);
|
||||
A = tVariantListAppendToken(A, &Z, -1);
|
||||
A = setTableNameList(NULL, &X, &Z);
|
||||
}
|
||||
|
||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
||||
toTSDBType(X.type);
|
||||
X.n += Z.n;
|
||||
A = tVariantListAppendToken(Y, &X, -1);
|
||||
A = tVariantListAppendToken(A, &X, -1);
|
||||
A = setTableNameList(Y, &X, NULL);
|
||||
}
|
||||
|
||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
||||
toTSDBType(X.type);
|
||||
toTSDBType(F.type);
|
||||
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"
|
||||
|
@ -630,7 +626,7 @@ grouplist(A) ::= item(X). {
|
|||
}
|
||||
|
||||
//having clause, ignore the input condition in having
|
||||
%type having_opt {tSQLExpr*}
|
||||
%type having_opt {tSqlExpr*}
|
||||
%destructor having_opt {tSqlExprDestroy($$);}
|
||||
having_opt(A) ::=. {A = 0;}
|
||||
having_opt(A) ::= HAVING expr(X). {A = X;}
|
||||
|
@ -652,7 +648,7 @@ slimit_opt(A) ::= SLIMIT signed(X) SOFFSET signed(Y).
|
|||
slimit_opt(A) ::= SLIMIT signed(X) COMMA signed(Y).
|
||||
{A.limit = Y; A.offset = X;}
|
||||
|
||||
%type where_opt {tSQLExpr*}
|
||||
%type where_opt {tSqlExpr*}
|
||||
%destructor where_opt {tSqlExprDestroy($$);}
|
||||
|
||||
where_opt(A) ::= . {A = 0;}
|
||||
|
@ -660,25 +656,25 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
|
|||
|
||||
/////////////////////////// Expression Processing /////////////////////////////
|
||||
//
|
||||
%type expr {tSQLExpr*}
|
||||
%type expr {tSqlExpr*}
|
||||
%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) ::= ID(X). { A = tSqlExprIdValueCreate(&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 STAR(Y). { X.n += (1+Y.n); A = tSqlExprIdValueCreate(&X, TK_ALL);}
|
||||
expr(A) ::= ID(X). { A = tSqlExprCreateIdValue(&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 = tSqlExprCreateIdValue(&X, TK_ALL);}
|
||||
|
||||
expr(A) ::= INTEGER(X). { A = tSqlExprIdValueCreate(&X, TK_INTEGER);}
|
||||
expr(A) ::= MINUS(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 = tSqlExprIdValueCreate(&X, TK_INTEGER);}
|
||||
expr(A) ::= FLOAT(X). { A = tSqlExprIdValueCreate(&X, TK_FLOAT);}
|
||||
expr(A) ::= MINUS(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 = tSqlExprIdValueCreate(&X, TK_FLOAT);}
|
||||
expr(A) ::= STRING(X). { A = tSqlExprIdValueCreate(&X, TK_STRING);}
|
||||
expr(A) ::= NOW(X). { A = tSqlExprIdValueCreate(&X, TK_NOW); }
|
||||
expr(A) ::= VARIABLE(X). { A = tSqlExprIdValueCreate(&X, TK_VARIABLE);}
|
||||
expr(A) ::= BOOL(X). { A = tSqlExprIdValueCreate(&X, TK_BOOL);}
|
||||
expr(A) ::= INTEGER(X). { A = tSqlExprCreateIdValue(&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 = tSqlExprCreateIdValue(&X, TK_INTEGER);}
|
||||
expr(A) ::= FLOAT(X). { A = tSqlExprCreateIdValue(&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 = tSqlExprCreateIdValue(&X, TK_FLOAT);}
|
||||
expr(A) ::= STRING(X). { A = tSqlExprCreateIdValue(&X, TK_STRING);}
|
||||
expr(A) ::= NOW(X). { A = tSqlExprCreateIdValue(&X, TK_NOW); }
|
||||
expr(A) ::= VARIABLE(X). { A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
|
||||
expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
|
||||
|
||||
// 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); }
|
||||
|
@ -698,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) 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) OR expr(Y). {A = tSqlExprCreate(X, Y, TK_OR); }
|
||||
|
@ -714,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); }
|
||||
|
||||
//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($$);}
|
||||
|
||||
%type expritem {tSQLExpr*}
|
||||
%type expritem {tSqlExpr*}
|
||||
%destructor expritem {tSqlExprDestroy($$);}
|
||||
|
||||
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
|
||||
|
@ -728,12 +724,12 @@ expritem(A) ::= expr(X). {A = X;}
|
|||
expritem(A) ::= . {A = 0;}
|
||||
|
||||
///////////////////////////////////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//////////////////////////////////
|
||||
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -743,14 +739,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
|
|||
toTSDBType(A.type);
|
||||
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);
|
||||
}
|
||||
|
||||
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
||||
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
||||
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);
|
||||
}
|
||||
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||
|
@ -759,7 +755,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
|||
toTSDBType(Y.type);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -772,7 +768,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
|
|||
toTSDBType(Z.type);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -783,7 +779,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
|
|||
SArray* A = tVariantListAppendToken(NULL, &Y, -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);
|
||||
}
|
||||
|
||||
|
@ -791,7 +787,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
|
|||
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
|
||||
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -801,14 +797,14 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
|
|||
toTSDBType(A.type);
|
||||
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);
|
||||
}
|
||||
|
||||
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
|
||||
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
|
||||
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);
|
||||
}
|
||||
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
||||
|
@ -817,7 +813,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
|||
toTSDBType(Y.type);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -830,7 +826,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
|
|||
toTSDBType(Z.type);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -842,6 +838,4 @@ 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
|
||||
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
|
||||
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT
|
||||
METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO VALUES.
|
||||
|