Merge from master into develop
This commit is contained in:
commit
45a0859a5f
|
@ -57,7 +57,7 @@ IF (TD_LINUX_64)
|
|||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ADD_DEFINITIONS(-D_TD_LINUX_64)
|
||||
MESSAGE(STATUS "linux64 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
ENDIF ()
|
||||
|
||||
|
@ -65,7 +65,7 @@ IF (TD_LINUX_32)
|
|||
ADD_DEFINITIONS(-D_TD_LINUX_32)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "linux32 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_ARM_64)
|
||||
|
@ -73,7 +73,7 @@ IF (TD_ARM_64)
|
|||
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "arm64 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_ARM_32)
|
||||
|
@ -81,7 +81,7 @@ IF (TD_ARM_32)
|
|||
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "arm32 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_MIPS_64)
|
||||
|
@ -89,7 +89,7 @@ IF (TD_MIPS_64)
|
|||
ADD_DEFINITIONS(-D_TD_MIPS_64)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "mips64 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_MIPS_32)
|
||||
|
@ -97,7 +97,7 @@ IF (TD_MIPS_32)
|
|||
ADD_DEFINITIONS(-D_TD_MIPS_32)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "mips32 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_APLHINE)
|
||||
|
@ -138,7 +138,7 @@ IF (TD_DARWIN_64)
|
|||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||
MESSAGE(STATUS "darwin64 is defined")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-Og")
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||
|
|
|
@ -32,6 +32,7 @@ ENDIF ()
|
|||
#
|
||||
|
||||
# Set compiler options
|
||||
SET(COMMON_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}")
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ PROJECT(TDengine)
|
|||
IF (DEFINED VERNUMBER)
|
||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||
ELSE ()
|
||||
SET(TD_VER_NUMBER "2.0.20.2")
|
||||
SET(TD_VER_NUMBER "2.1.0.0")
|
||||
ENDIF ()
|
||||
|
||||
IF (DEFINED VERCOMPATIBLE)
|
||||
|
|
|
@ -117,9 +117,9 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专
|
|||
## 常用工具
|
||||
|
||||
* [TDengine样例导入工具](https://www.taosdata.com/blog/2020/01/18/1166.html)
|
||||
* [TDengine性能对比测试工具](https://www.taosdata.com/blog/2020/01/18/1166.html)
|
||||
* [TDengine写入性能测试工具](https://www.taosdata.com/blog/2020/01/18/1166.html)
|
||||
* [IDEA数据库管理工具可视化使用TDengine](https://www.taosdata.com/blog/2020/08/27/1767.html)
|
||||
* [基于eletron开发的跨平台TDengine图形化管理工具](https://github.com/skye0207/TDengineGUI)
|
||||
* [基于Electron开发的跨平台TDengine图形化管理工具](https://github.com/skye0207/TDengineGUI)
|
||||
* [DataX,支持TDengine的离线数据采集/同步工具](https://github.com/wgzhao/DataX)(文档:[读取插件](https://github.com/wgzhao/DataX/blob/master/docs/src/main/sphinx/reader/tdenginereader.md)、[写入插件](https://github.com/wgzhao/DataX/blob/master/docs/src/main/sphinx/writer/tdenginewriter.md))
|
||||
|
||||
## TDengine与其他数据库的对比测试
|
||||
|
|
|
@ -0,0 +1,211 @@
|
|||
# 通过 Docker 快速体验 TDengine
|
||||
|
||||
虽然并不推荐在生产环境中通过 Docker 来部署 TDengine 服务,但 Docker 工具能够很好地屏蔽底层操作系统的环境差异,很适合在开发测试或初次体验时用于安装运行 TDengine 的工具集。特别是,借助 Docker,能够比较方便地在 Mac OSX 和 Windows 系统上尝试 TDengine,而无需安装虚拟机或额外租用 Linux 服务器。
|
||||
|
||||
下文通过 Step by Step 风格的介绍,讲解如何通过 Docker 快速建立 TDengine 的单节点运行环境,以支持开发和测试。
|
||||
|
||||
## 下载 Docker
|
||||
|
||||
Docker 工具自身的下载请参考 [Docker官网文档](https://docs.docker.com/get-docker/)。
|
||||
|
||||
安装完毕后可以在命令行终端查看 Docker 版本。如果版本号正常输出,则说明 Docker 环境已经安装成功。
|
||||
|
||||
```bash
|
||||
$ docker -v
|
||||
Docker version 20.10.5, build 55c4c88
|
||||
```
|
||||
|
||||
## 在 Docker 容器中运行 TDengine
|
||||
|
||||
1,使用命令拉取 TDengine 镜像,并使它在后台运行。
|
||||
|
||||
```bash
|
||||
$ docker run -d tdengine/tdengine
|
||||
cdf548465318c6fc2ad97813f89cc60006393392401cae58a27b15ca9171f316
|
||||
```
|
||||
|
||||
- **docker run**:通过 Docker 运行一个容器。
|
||||
- **-d**:让容器在后台运行。
|
||||
- **tdengine/tdengine**:拉取的 TDengine 官方发布的应用镜像。
|
||||
- **cdf548465318c6fc2ad97813f89cc60006393392401cae58a27b15ca9171f316**:这个返回的长字符是容器 ID,我们可以通过容器 ID 来查看对应的容器。
|
||||
|
||||
2,确认容器是否已经正确运行。
|
||||
|
||||
```bash
|
||||
$ docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS ···
|
||||
cdf548465318 tdengine/tdengine "taosd" 14 minutes ago Up 14 minutes ···
|
||||
```
|
||||
|
||||
- **docker ps**:列出所有正在运行状态的容器信息。
|
||||
- **CONTAINER ID**:容器 ID。
|
||||
- **IMAGE**:使用的镜像。
|
||||
- **COMMAND**:启动容器时运行的命令。
|
||||
- **CREATED**:容器创建时间。
|
||||
- **STATUS**:容器状态。UP 表示运行中。
|
||||
|
||||
3,进入 Docker 容器内,使用 TDengine。
|
||||
|
||||
```bash
|
||||
$ docker exec -it cdf548465318 /bin/bash
|
||||
root@cdf548465318:~/TDengine-server-2.0.13.0#
|
||||
```
|
||||
|
||||
- **docker exec**:通过 docker exec 命令进入容器,如果退出,容器不会停止。
|
||||
- **-i**:进入交互模式。
|
||||
- **-t**:指定一个终端。
|
||||
- **cdf548465318**:容器 ID,需要根据 docker ps 指令返回的值进行修改。
|
||||
- **/bin/bash**:载入容器后运行 bash 来进行交互。
|
||||
|
||||
4,进入容器后,执行 taos shell 客户端程序。
|
||||
|
||||
```bash
|
||||
$ root@cdf548465318:~/TDengine-server-2.0.13.0# taos
|
||||
|
||||
Welcome to the TDengine shell from Linux, Client Version:2.0.13.0
|
||||
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
|
||||
|
||||
taos>
|
||||
```
|
||||
|
||||
TDengine 终端成功连接服务端,打印出了欢迎消息和版本信息。如果失败,会有错误信息打印出来。
|
||||
|
||||
在 TDengine 终端中,可以通过 SQL 命令来创建/删除数据库、表、超级表等,并可以进行插入和查询操作。具体可以参考 [TAOS SQL 说明文档](https://www.taosdata.com/cn/documentation/taos-sql)。
|
||||
|
||||
## 通过 taosdemo 进一步了解 TDengine
|
||||
|
||||
1,接上面的步骤,先退出 TDengine 终端程序。
|
||||
|
||||
```bash
|
||||
$ taos> q
|
||||
root@cdf548465318:~/TDengine-server-2.0.13.0#
|
||||
```
|
||||
|
||||
2,在命令行界面执行 taosdemo。
|
||||
|
||||
```bash
|
||||
$ root@cdf548465318:~/TDengine-server-2.0.13.0# taosdemo
|
||||
###################################################################
|
||||
# Server IP: localhost:0
|
||||
# User: root
|
||||
# Password: taosdata
|
||||
# Use metric: true
|
||||
# Datatype of Columns: int int int int int int int float
|
||||
# Binary Length(If applicable): -1
|
||||
# Number of Columns per record: 3
|
||||
# Number of Threads: 10
|
||||
# Number of Tables: 10000
|
||||
# Number of Data per Table: 100000
|
||||
# Records/Request: 1000
|
||||
# Database name: test
|
||||
# Table prefix: t
|
||||
# Delete method: 0
|
||||
# Test time: 2021-04-13 02:05:20
|
||||
###################################################################
|
||||
```
|
||||
|
||||
回车后,该命令将新建一个数据库 test,并且自动创建一张超级表 meters,并以超级表 meters 为模版创建了 1 万张表,表名从 "t0" 到 "t9999"。每张表有 10 万条记录,每条记录有 f1,f2,f3 三个字段,时间戳 ts 字段从 "2017-07-14 10:40:00 000" 到 "2017-07-14 10:41:39 999"。每张表带有 areaid 和 loc 两个标签 TAG,areaid 被设置为 1 到 10,loc 被设置为 "beijing" 或 "shanghai"。
|
||||
|
||||
3,进入 TDengine 终端,查看 taosdemo 生成的数据。
|
||||
|
||||
- **进入命令行。**
|
||||
|
||||
```bash
|
||||
$ root@cdf548465318:~/TDengine-server-2.0.13.0# taos
|
||||
|
||||
Welcome to the TDengine shell from Linux, Client Version:2.0.13.0
|
||||
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
|
||||
|
||||
taos>
|
||||
```
|
||||
|
||||
- **查看数据库。**
|
||||
|
||||
```bash
|
||||
$ taos> show databases;
|
||||
name | created_time | ntables | vgroups | ···
|
||||
test | 2021-04-13 02:14:15.950 | 10000 | 6 | ···
|
||||
log | 2021-04-12 09:36:37.549 | 4 | 1 | ···
|
||||
|
||||
```
|
||||
|
||||
- **查看超级表。**
|
||||
|
||||
```bash
|
||||
$ taos> use test;
|
||||
Database changed.
|
||||
|
||||
$ taos> show stables;
|
||||
name | created_time | columns | tags | tables |
|
||||
=====================================================================================
|
||||
meters | 2021-04-13 02:14:15.955 | 4 | 2 | 10000 |
|
||||
Query OK, 1 row(s) in set (0.001737s)
|
||||
|
||||
```
|
||||
|
||||
- **查看表,限制输出十条。**
|
||||
|
||||
```bash
|
||||
$ taos> select * from test.t0 limit 10;
|
||||
ts | f1 | f2 | f3 |
|
||||
====================================================================
|
||||
2017-07-14 02:40:01.000 | 3 | 9 | 0 |
|
||||
2017-07-14 02:40:02.000 | 0 | 1 | 2 |
|
||||
2017-07-14 02:40:03.000 | 7 | 2 | 3 |
|
||||
2017-07-14 02:40:04.000 | 9 | 4 | 5 |
|
||||
2017-07-14 02:40:05.000 | 1 | 2 | 5 |
|
||||
2017-07-14 02:40:06.000 | 6 | 3 | 2 |
|
||||
2017-07-14 02:40:07.000 | 4 | 7 | 8 |
|
||||
2017-07-14 02:40:08.000 | 4 | 6 | 6 |
|
||||
2017-07-14 02:40:09.000 | 5 | 7 | 7 |
|
||||
2017-07-14 02:40:10.000 | 1 | 5 | 0 |
|
||||
Query OK, 10 row(s) in set (0.003638s)
|
||||
|
||||
```
|
||||
|
||||
- **查看 t0 表的标签值。**
|
||||
|
||||
```bash
|
||||
$ taos> select areaid, loc from test.t0;
|
||||
areaid | loc |
|
||||
===========================
|
||||
10 | shanghai |
|
||||
Query OK, 1 row(s) in set (0.002904s)
|
||||
|
||||
```
|
||||
|
||||
## 停止正在 Docker 中运行的 TDengine 服务
|
||||
|
||||
```bash
|
||||
$ docker stop cdf548465318
|
||||
cdf548465318
|
||||
```
|
||||
|
||||
- **docker stop**:通过 docker stop 停止指定的正在运行中的 docker 镜像。
|
||||
- **cdf548465318**:容器 ID,根据 docker ps 指令返回的结果进行修改。
|
||||
|
||||
## 编程开发时连接在 Docker 中的 TDengine
|
||||
|
||||
从 Docker 之外连接使用在 Docker 容器内运行的 TDengine 服务,有以下两个思路:
|
||||
|
||||
1,通过端口映射(-p),将容器内部开放的网络端口映射到宿主机的指定端口上。通过挂载本地目录(-v),可以实现宿主机与容器内部的数据同步,防止容器删除后,数据丢失。
|
||||
|
||||
```bash
|
||||
$ docker run -d -v /etc/taos:/etc/taos -p 6041:6041 tdengine/tdengine
|
||||
526aa188da767ae94b244226a2b2eec2b5f17dd8eff592893d9ec0cd0f3a1ccd
|
||||
|
||||
$ curl -u root:taosdata -d 'show databases' 127.0.0.1:6041/rest/sql
|
||||
{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep1,keep2,keep(D)","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","precision","status"],"data":[],"rows":0}
|
||||
```
|
||||
|
||||
- 第一条命令,启动一个运行了 TDengine 的 docker 容器,并且将容器的 6041 端口映射到宿主机的 6041 端口上。
|
||||
- 第二条命令,通过 RESTful 接口访问 TDengine,这时连接的是本机的 6041 端口,可见连接成功。
|
||||
|
||||
注意:在这个示例中,出于方便性考虑,只映射了 RESTful 需要的 6041 端口。如果希望以非 RESTful 方式连接 TDengine 服务,则需要映射从 6030 开始的共 11 个端口(完整的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))。在例子中,挂载本地目录也只是处理了配置文件所在的 /etc/taos 目录,而没有挂载数据存储目录。
|
||||
|
||||
2,直接通过 exec 命令,进入到 docker 容器中去做开发。也即,把程序代码放在 TDengine 服务端所在的同一个 Docker 容器中,连接容器本地的 TDengine 服务。
|
||||
|
||||
```bash
|
||||
$ docker exec -it 526aa188da /bin/bash
|
||||
```
|
||||
|
|
@ -10,7 +10,9 @@ TDengine软件分为服务器、客户端和报警模块三部分,目前2.0版
|
|||
|
||||
### 通过Docker容器运行
|
||||
|
||||
请参考[TDengine官方Docker镜像的发布、下载和使用](https://www.taosdata.com/blog/2020/05/13/1509.html)
|
||||
暂时不建议生产环境采用 Docker 来部署 TDengine 的客户端或服务端,但在开发环境下或初次尝试时,使用 Docker 方式部署是十分方便的。特别是,利用 Docker,可以方便地在 Mac OSX 和 Windows 环境下尝试 TDengine。
|
||||
|
||||
详细操作方法请参照 [通过Docker快速体验TDengine](https://www.taosdata.com/cn/documentation/getting-started/docker)。
|
||||
|
||||
### <a class="anchor" id="package-install"></a>通过安装包安装
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ TDengine 分布式架构的逻辑结构图如下:
|
|||
|
||||
**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。
|
||||
|
||||
**端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。(另外还可能有 RESTful、Arbitrator 所使用的端口,那样的话就一共是 13 个。)使用时,需要确保防火墙将这些端口打开,以备使用。每个数据节点可以配置不同的serverPort。
|
||||
**端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。(另外还可能有 RESTful、Arbitrator 所使用的端口,那样的话就一共是 13 个。)使用时,需要确保防火墙将这些端口打开,以备使用。每个数据节点可以配置不同的serverPort。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))
|
||||
|
||||
**集群对外连接:** TDengine集群可以容纳单个、多个甚至几千个数据节点。应用只需要向集群中任何一个数据节点发起连接即可,连接需要提供的网络参数是一数据节点的End Point(FQDN加配置的端口号)。通过命令行CLI启动应用taos时,可以通过选项-h来指定数据节点的FQDN, -P来指定其配置的端口号,如果端口不配置,将采用TDengine的系统配置参数serverPort。
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ TDengine 采用 SQL 作为查询语言。应用程序可以通过 C/C++, Java, G
|
|||
- 时间戳对齐的连接查询(Join Query: 隐式连接)操作
|
||||
- 多种聚合/计算函数: count, max, min, avg, sum, twa, stddev, leastsquares, top, bottom, first, last, percentile, apercentile, last_row, spread, diff等
|
||||
|
||||
例如:在TAOS Shell中,从表d1001中查询出vlotage > 215的记录,按时间降序排列,仅仅输出2条。
|
||||
例如:在TAOS Shell中,从表d1001中查询出voltage > 215的记录,按时间降序排列,仅仅输出2条。
|
||||
```mysql
|
||||
taos> select * from d1001 where voltage > 215 order by ts desc limit 2;
|
||||
ts | current | voltage | phase |
|
||||
|
|
|
@ -120,7 +120,7 @@ if (async) {
|
|||
}
|
||||
```
|
||||
|
||||
TDengine中的订阅既可以是同步的,也可以是异步的,上面的代码会根据从命令行获取的参数`async`的值来决定使用哪种方式。这里,同步的意思是用户程序要直接调用`taos_consume`来拉取数据,而异步则由API在内部的另一个线程中调用`taos_consume`,然后把拉取到的数据交给回调函数`subscribe_callback`去处理。
|
||||
TDengine中的订阅既可以是同步的,也可以是异步的,上面的代码会根据从命令行获取的参数`async`的值来决定使用哪种方式。这里,同步的意思是用户程序要直接调用`taos_consume`来拉取数据,而异步则由API在内部的另一个线程中调用`taos_consume`,然后把拉取到的数据交给回调函数`subscribe_callback`去处理。(注意,`subscribe_callback` 中不宜做较为耗时的操作,否则有可能导致客户端阻塞等不可控的问题。)
|
||||
|
||||
参数`taos`是一个已经建立好的数据库连接,在同步模式下无特殊要求。但在异步模式下,需要注意它不会被其它线程使用,否则可能导致不可预计的错误,因为回调函数在API的内部线程中被调用,而TDengine的部分API不是线程安全的。
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ TDengine 的 JDBC 驱动实现尽可能与关系型数据库驱动保持一致
|
|||
|
||||
* TDengine 目前不支持针对单条数据记录的删除操作。
|
||||
* 目前不支持事务操作。
|
||||
* 目前不支持表间的 union 操作。
|
||||
* 目前不支持嵌套查询(nested query)。
|
||||
* 对每个 Connection 的实例,至多只能有一个打开的 ResultSet 实例;如果在 ResultSet 还没关闭的情况下执行了新的查询,taos-jdbcdriver 会自动关闭上一个 ResultSet。
|
||||
|
||||
|
@ -447,7 +446,7 @@ Query OK, 1 row(s) in set (0.000141s)
|
|||
|
||||
|
||||
|
||||
## TAOS-JDBCDriver 版本以及支持的 TDengine 版本和 JDK 版本
|
||||
## <a class="anchor" id="version"></a>TAOS-JDBCDriver 版本以及支持的 TDengine 版本和 JDK 版本
|
||||
|
||||
| taos-jdbcdriver 版本 | TDengine 版本 | JDK 版本 |
|
||||
| -------------------- | ----------------- | -------- |
|
||||
|
|
|
@ -32,7 +32,7 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、
|
|||
|
||||
**Linux**
|
||||
|
||||
**1. 从涛思官网(https://www.taosdata.com/cn/all-downloads/)下载**
|
||||
**1. 从[涛思官网](https://www.taosdata.com/cn/all-downloads/)下载**
|
||||
|
||||
* X64硬件环境:TDengine-client-2.x.x.x-Linux-x64.tar.gz
|
||||
|
||||
|
@ -68,7 +68,7 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、
|
|||
|
||||
**Windows x64/x86**
|
||||
|
||||
**1. 从涛思官网(https://www.taosdata.com/cn/all-downloads/)下载 :**
|
||||
**1. 从[涛思官网](https://www.taosdata.com/cn/all-downloads/)下载 :**
|
||||
|
||||
* X64硬件环境:TDengine-client-2.X.X.X-Windows-x64.exe
|
||||
|
||||
|
@ -213,7 +213,7 @@ C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine
|
|||
|
||||
- `int taos_result_precision(TAOS_RES *res)`
|
||||
|
||||
返回结果集时间戳字段的精度,`0` 代表毫秒,`1` 代表微秒,`2` 代表纳秒。
|
||||
返回结果集时间戳字段的精度,`0` 代表毫秒,`1` 代表微秒。
|
||||
|
||||
- `TAOS_ROW taos_fetch_row(TAOS_RES *res)`
|
||||
|
||||
|
@ -349,7 +349,7 @@ TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时
|
|||
* param:是应用提供的用于回调的一个参数,回调时,提供给应用
|
||||
* callback: 第二个回调函数,会在连续查询自动停止时被调用。
|
||||
|
||||
返回值为NULL,表示创建成功,返回值不为空,表示成功。
|
||||
返回值为NULL,表示创建失败;返回值不为空,表示成功。
|
||||
|
||||
- `void taos_close_stream (TAOS_STREAM *tstr)`
|
||||
|
||||
|
@ -377,6 +377,7 @@ TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时
|
|||
* res:查询结果集,注意结果集中可能没有记录
|
||||
* param:调用 `taos_subscribe`时客户程序提供的附加参数
|
||||
* code:错误码
|
||||
**注意**:在这个回调函数里不可以做耗时过长的处理,尤其是对于返回的结果集中数据较多的情况,否则有可能导致客户端阻塞等异常状态。如果必须进行复杂计算,则建议在另外的线程中进行处理。
|
||||
|
||||
* `TAOS_RES *taos_consume(TAOS_SUB *tsub)`
|
||||
|
||||
|
@ -743,7 +744,7 @@ HTTP请求URL采用`sqlutc`时,返回结果集的时间戳将采用UTC时间
|
|||
|
||||
下面仅列出一些与RESTful接口有关的配置参数,其他系统参数请看配置文件里的说明。注意:配置修改后,需要重启taosd服务才能生效
|
||||
|
||||
- httpPort: 对外提供RESTful服务的端口号,默认绑定到6041
|
||||
- 对外提供RESTful服务的端口号,默认绑定到 6041(实际取值是 serverPort + 11,因此可以通过修改 serverPort 参数的设置来修改)
|
||||
- httpMaxThreads: 启动的线程数量,默认为2(2.0.17版本开始,默认值改为CPU核数的一半向下取整)
|
||||
- restfulRowLimit: 返回结果集(JSON格式)的最大条数,默认值为10240
|
||||
- httpEnableCompress: 是否支持压缩,默认不支持,目前TDengine仅支持gzip压缩格式
|
||||
|
|
|
@ -55,12 +55,11 @@ arbitrator ha.taosdata.com:6042
|
|||
| 4 | statusInterval | dnode向mnode报告状态时长 |
|
||||
| 5 | arbitrator | 系统中裁决器的end point |
|
||||
| 6 | timezone | 时区 |
|
||||
| 7 | locale | 系统区位信息及编码格式 |
|
||||
| 8 | charset | 字符集编码 |
|
||||
| 9 | balance | 是否启动负载均衡 |
|
||||
| 10 | maxTablesPerVnode | 每个vnode中能够创建的最大表个数 |
|
||||
| 11 | maxVgroupsPerDb | 每个DB中能够使用的最大vgroup个数 |
|
||||
| 7 | balance | 是否启动负载均衡 |
|
||||
| 8 | maxTablesPerVnode | 每个vnode中能够创建的最大表个数 |
|
||||
| 9 | maxVgroupsPerDb | 每个DB中能够使用的最大vgroup个数 |
|
||||
|
||||
备注:在 2.0.19.0 及更早的版本中,除以上 9 项参数外,dnode 加入集群时,还会要求 locale 和 charset 参数的取值也一致。
|
||||
|
||||
|
||||
## <a class="anchor" id="node-one"></a>启动第一个数据节点
|
||||
|
|
|
@ -100,8 +100,7 @@ taosd -C
|
|||
|
||||
- firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。
|
||||
- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。
|
||||
- serverPort:taosd启动后,对外服务的端口号,默认值为6030。
|
||||
- httpPort: RESTful服务使用的端口号,所有的HTTP请求(TCP)都需要向该接口发起查询/写入请求, 默认值为6041。
|
||||
- serverPort:taosd启动后,对外服务的端口号,默认值为6030。(RESTful服务使用的端口号是在此基础上+11,即默认值为6041。)
|
||||
- dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。
|
||||
- logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。
|
||||
- arbitrator:系统中裁决器的end point, 缺省值为空。
|
||||
|
@ -115,7 +114,7 @@ taosd -C
|
|||
- queryBufferSize: 为所有并发查询占用保留的内存大小。计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。单位为 MB(2.0.15 以前的版本中,此参数的单位是字节)。
|
||||
- ratioOfQueryCores: 设置查询线程的最大数量。最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。
|
||||
|
||||
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。
|
||||
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))
|
||||
|
||||
不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine提供如下存储相关的系统配置参数:
|
||||
|
||||
|
@ -150,7 +149,7 @@ TDengine集群中加入一个新的dnode时,涉及集群相关的一些参数
|
|||
- maxTablesPerVnode: 每个vnode中能够创建的最大表个数。默认值:1000000。
|
||||
- maxVgroupsPerDb: 每个数据库中能够使用的最大vgroup个数。
|
||||
- arbitrator: 系统中裁决器的end point,缺省为空。
|
||||
- timezone、locale、charset 的配置见客户端配置。
|
||||
- timezone、locale、charset 的配置见客户端配置。(2.0.20.0 及以上的版本里,集群中加入新节点已不要求 locale 和 charset 参数取值一致)
|
||||
|
||||
为方便调试,可通过SQL语句临时调整每个dnode的日志配置,系统重启后会失效:
|
||||
|
||||
|
@ -463,41 +462,41 @@ TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下
|
|||
|
||||
| 关键字列表 | | | | |
|
||||
| ---------- | ----------- | ------------ | ---------- | --------- |
|
||||
| ABLOCKS | CONNECTIONS | GT | MNODES | SLIDING |
|
||||
| ABORT | COPY | ID | MODULES | SLIMIT |
|
||||
| ACCOUNT | COUNT | IF | NCHAR | SMALLINT |
|
||||
| ACCOUNTS | CREATE | IGNORE | NE | SPREAD |
|
||||
| ADD | CTIME | IMMEDIATE | NONE | STABLE |
|
||||
| AFTER | DATABASE | IMPORT | NOT | STABLES |
|
||||
| ALL | DATABASES | IN | NOTNULL | STAR |
|
||||
| ALTER | DAYS | INITIALLY | NOW | STATEMENT |
|
||||
| AND | DEFERRED | INSERT | OF | STDDEV |
|
||||
| AS | DELIMITERS | INSTEAD | OFFSET | STREAM |
|
||||
| ASC | DESC | INTEGER | OR | STREAMS |
|
||||
| ATTACH | DESCRIBE | INTERVAL | ORDER | STRING |
|
||||
| AVG | DETACH | INTO | PASS | SUM |
|
||||
| BEFORE | DIFF | IP | PERCENTILE | TABLE |
|
||||
| BEGIN | DISTINCT | IS | PLUS | TABLES |
|
||||
| BETWEEN | DIVIDE | ISNULL | PRAGMA | TAG |
|
||||
| BIGINT | DNODE | JOIN | PREV | TAGS |
|
||||
| BINARY | DNODES | KEEP | PRIVILEGE | TBLOCKS |
|
||||
| BITAND | DOT | KEY | QUERIES | TBNAME |
|
||||
| BITNOT | DOUBLE | KILL | QUERY | TIMES |
|
||||
| BITOR | DROP | LAST | RAISE | TIMESTAMP |
|
||||
| BOOL | EACH | LE | REM | TINYINT |
|
||||
| BOTTOM | END | LEASTSQUARES | REPLACE | TOP |
|
||||
| BY | EQ | LIKE | REPLICA | TRIGGER |
|
||||
| CACHE | EXISTS | LIMIT | RESET | UMINUS |
|
||||
| CASCADE | EXPLAIN | LINEAR | RESTRICT | UPLUS |
|
||||
| CHANGE | FAIL | LOCAL | ROW | USE |
|
||||
| CLOG | FILL | LP | ROWS | USER |
|
||||
| CLUSTER | FIRST | LSHIFT | RP | USERS |
|
||||
| COLON | FLOAT | LT | RSHIFT | USING |
|
||||
| COLUMN | FOR | MATCH | SCORES | VALUES |
|
||||
| COMMA | FROM | MAX | SELECT | VARIABLE |
|
||||
| COMP | GE | METRIC | SEMI | VGROUPS |
|
||||
| CONCAT | GLOB | METRICS | SET | VIEW |
|
||||
| CONFIGS | GRANTS | MIN | SHOW | WAVG |
|
||||
| CONFLICT | GROUP | MINUS | SLASH | WHERE |
|
||||
| CONNECTION | | | | |
|
||||
| ABLOCKS | CONNECTIONS | HAVING | MODULES | SMALLINT |
|
||||
| ABORT | COPY | ID | NCHAR | SPREAD |
|
||||
| ACCOUNT | COUNT | IF | NE | STABLE |
|
||||
| ACCOUNTS | CREATE | IGNORE | NONE | STABLES |
|
||||
| ADD | CTIME | IMMEDIATE | NOT | STAR |
|
||||
| AFTER | DATABASE | IMPORT | NOTNULL | STATEMENT |
|
||||
| ALL | DATABASES | IN | NOW | STDDEV |
|
||||
| ALTER | DAYS | INITIALLY | OF | STREAM |
|
||||
| AND | DEFERRED | INSERT | OFFSET | STREAMS |
|
||||
| AS | DELIMITERS | INSTEAD | OR | STRING |
|
||||
| ASC | DESC | INTEGER | ORDER | SUM |
|
||||
| ATTACH | DESCRIBE | INTERVAL | PASS | TABLE |
|
||||
| AVG | DETACH | INTO | PERCENTILE | TABLES |
|
||||
| BEFORE | DIFF | IP | PLUS | TAG |
|
||||
| BEGIN | DISTINCT | IS | PRAGMA | TAGS |
|
||||
| BETWEEN | DIVIDE | ISNULL | PREV | TBLOCKS |
|
||||
| BIGINT | DNODE | JOIN | PRIVILEGE | TBNAME |
|
||||
| BINARY | DNODES | KEEP | QUERIES | TIMES |
|
||||
| BITAND | DOT | KEY | QUERY | TIMESTAMP |
|
||||
| BITNOT | DOUBLE | KILL | RAISE | TINYINT |
|
||||
| BITOR | DROP | LAST | REM | TOP |
|
||||
| BOOL | EACH | LE | REPLACE | TOPIC |
|
||||
| BOTTOM | END | LEASTSQUARES | REPLICA | TRIGGER |
|
||||
| BY | EQ | LIKE | RESET | UMINUS |
|
||||
| CACHE | EXISTS | LIMIT | RESTRICT | UNION |
|
||||
| CASCADE | EXPLAIN | LINEAR | ROW | UPLUS |
|
||||
| CHANGE | FAIL | LOCAL | ROWS | USE |
|
||||
| CLOG | FILL | LP | RP | USER |
|
||||
| CLUSTER | FIRST | LSHIFT | RSHIFT | USERS |
|
||||
| COLON | FLOAT | LT | SCORES | USING |
|
||||
| COLUMN | FOR | MATCH | SELECT | VALUES |
|
||||
| COMMA | FROM | MAX | SEMI | VARIABLE |
|
||||
| COMP | GE | METRIC | SET | VGROUPS |
|
||||
| CONCAT | GLOB | METRICS | SHOW | VIEW |
|
||||
| CONFIGS | GRANTS | MIN | SLASH | WAVG |
|
||||
| CONFLICT | GROUP | MINUS | SLIDING | WHERE |
|
||||
| CONNECTION | GT | MNODES | SLIMIT | |
|
||||
|
||||
|
|
|
@ -48,15 +48,15 @@ TDengine 缺省的时间戳是毫秒精度,但通过修改配置参数 enableM
|
|||
| 3 | BIGINT | 8 | 长整型,范围 [-2^63+1, 2^63-1], -2^63 用于 NULL |
|
||||
| 4 | FLOAT | 4 | 浮点型,有效位数 6-7,范围 [-3.4E38, 3.4E38] |
|
||||
| 5 | DOUBLE | 8 | 双精度浮点型,有效位数 15-16,范围 [-1.7E308, 1.7E308] |
|
||||
| 6 | BINARY | 自定义 | 用于记录 ASCII 型字符串。理论上,最长可以有 16374 字节,但由于每行数据最多 16K 字节,实际上限一般小于理论值。 binary 仅支持字符串输入,字符串两端使用单引号引用,否则英文全部自动转化为小写。使用时须指定大小,如 binary(20) 定义了最长为 20 个字符的字符串,每个字符占 1 byte 的存储空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\’`。 |
|
||||
| 6 | BINARY | 自定义 | 记录单字节字符串,建议只用于处理 ASCII 可见字符,中文等多字节字符需使用 nchar。理论上,最长可以有 16374 字节,但由于每行数据最多 16K 字节,实际上限一般小于理论值。binary 仅支持字符串输入,字符串两端需使用单引号引用。使用时须指定大小,如 binary(20) 定义了最长为 20 个单字节字符的字符串,每个字符占 1 byte 的存储空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\’`。 |
|
||||
| 7 | SMALLINT | 2 | 短整型, 范围 [-32767, 32767], -32768 用于 NULL |
|
||||
| 8 | TINYINT | 1 | 单字节整型,范围 [-127, 127], -128 用于 NULL |
|
||||
| 9 | BOOL | 1 | 布尔型,{true, false} |
|
||||
| 10 | NCHAR | 自定义 | 用于记录非 ASCII 型字符串,如中文字符。每个 nchar 字符占用 4 bytes 的存储空间。字符串两端使用单引号引用,字符串内的单引号需用转义字符 `\’`。nchar 使用时须指定字符串大小,类型为 nchar(10) 的列表示此列的字符串最多存储 10 个 nchar 字符,会固定占用 40 bytes 的空间。如果用户字符串长度超出声明长度,将会报错。 |
|
||||
| 10 | NCHAR | 自定义 | 记录包含多字节字符在内的字符串,如中文字符。每个 nchar 字符占用 4 bytes 的存储空间。字符串两端使用单引号引用,字符串内的单引号需用转义字符 `\’`。nchar 使用时须指定字符串大小,类型为 nchar(10) 的列表示此列的字符串最多存储 10 个 nchar 字符,会固定占用 40 bytes 的空间。如果用户字符串长度超出声明长度,将会报错。 |
|
||||
|
||||
**Tips**:
|
||||
1. TDengine 对 SQL 语句中的英文字符不区分大小写,自动转化为小写执行。因此用户大小写敏感的字符串及密码,需要使用单引号将字符串引起来。
|
||||
2. 应避免使用 BINARY 类型来保存非 ASCII 型的字符串,会很容易导致数据乱码等错误。正确的做法是使用 NCHAR 类型来保存中文字符。
|
||||
2. **注意**,虽然 Binary 类型在底层存储上支持字节型的二进制字符,但不同编程语言对二进制数据的处理方式并不保证一致,因此建议在 Binary 类型中只存储 ASCII 可见字符,而避免存储不可见字符。多字节的数据,例如中文字符,则需要使用 nchar 类型进行保存。如果强行使用 Binary 类型保存中文字符,虽然有时也能正常读写,但并不带有字符集信息,很容易出现数据乱码甚至数据损坏等情况。
|
||||
|
||||
## <a class="anchor" id="management"></a>数据库管理
|
||||
|
||||
|
@ -409,16 +409,12 @@ SELECT select_expr [, select_expr ...]
|
|||
[FILL fill_val]
|
||||
[GROUP BY col_list]
|
||||
[ORDER BY col_list { DESC | ASC }]
|
||||
[SLIMIT limit_val [, SOFFSET offset_val]]
|
||||
[LIMIT limit_val [, OFFSET offset_val]]
|
||||
[SLIMIT limit_val [SOFFSET offset_val]]
|
||||
[LIMIT limit_val [OFFSET offset_val]]
|
||||
[>> export_file];
|
||||
```
|
||||
|
||||
#### SELECT子句
|
||||
|
||||
一个选择子句可以是联合查询(UNION)和另一个查询的子查询(SUBQUERY)。
|
||||
|
||||
##### 通配符
|
||||
#### 通配符
|
||||
|
||||
通配符 * 可以用于代指全部列。对于普通表,结果中只有普通列。
|
||||
```mysql
|
||||
|
@ -470,7 +466,7 @@ Query OK, 1 row(s) in set (0.020443s)
|
|||
```
|
||||
|
||||
在使用SQL函数来进行查询过程中,部分SQL函数支持通配符操作。其中的区别在于:
|
||||
```count(\*)```函数只返回一列。```first```、```last```、```last_row```函数则是返回全部列。
|
||||
```count(*)```函数只返回一列。```first```、```last```、```last_row```函数则是返回全部列。
|
||||
|
||||
```mysql
|
||||
taos> SELECT COUNT(*) FROM d1001;
|
||||
|
@ -488,7 +484,7 @@ taos> SELECT FIRST(*) FROM d1001;
|
|||
Query OK, 1 row(s) in set (0.000849s)
|
||||
```
|
||||
|
||||
##### 标签列
|
||||
#### 标签列
|
||||
|
||||
从 2.0.14 版本开始,支持在普通表的查询中指定 _标签列_,且标签列的值会与普通列的数据一起返回。
|
||||
```mysql
|
||||
|
@ -622,12 +618,15 @@ taos> SELECT COUNT(tbname) FROM meters WHERE groupId > 2;
|
|||
Query OK, 1 row(s) in set (0.001091s)
|
||||
```
|
||||
|
||||
- 可以使用 * 返回所有列,或指定列名。可以对数字列进行四则运算,可以给输出的列取列名
|
||||
- WHERE 语句可以使用各种逻辑判断来过滤数字值,或使用通配符来过滤字符串
|
||||
- 可以使用 * 返回所有列,或指定列名。可以对数字列进行四则运算,可以给输出的列取列名。
|
||||
* 暂不支持含列名的四则运算表达式用于条件过滤算子(例如,不支持 `where a*2>6;`,但可以写 `where a>6/2;`)。
|
||||
* 暂不支持含列名的四则运算表达式作为 SQL 函数的应用对象(例如,不支持 `select min(2*a) from t;`,但可以写 `select 2*min(a) from t;`)。
|
||||
- WHERE 语句可以使用各种逻辑判断来过滤数字值,或使用通配符来过滤字符串。
|
||||
- 输出结果缺省按首列时间戳升序排序,但可以指定按降序排序( _c0 指首列时间戳)。使用 ORDER BY 对其他字段进行排序为非法操作。
|
||||
- 参数 LIMIT 控制输出条数,OFFSET 指定从第几条开始输出。LIMIT/OFFSET 对结果集的执行顺序在 ORDER BY 之后。
|
||||
- 参数 SLIMIT 控制由 GROUP BY 指令划分的每个分组中的输出条数。
|
||||
- 通过”>>"输出结果可以导出到指定文件
|
||||
* 在有 GROUP BY 子句的情况下,LIMIT 参数控制的是每个分组中至多允许输出的条数。
|
||||
- 参数 SLIMIT 控制由 GROUP BY 指令划分的分组中,至多允许输出几个分组的数据。
|
||||
- 通过 ">>" 输出结果可以导出到指定文件。
|
||||
|
||||
### 支持的条件过滤操作
|
||||
|
||||
|
@ -647,6 +646,27 @@ Query OK, 1 row(s) in set (0.001091s)
|
|||
2. 针对单一字段的过滤,如果是时间过滤条件,则一条语句中只支持设定一个;但针对其他的(普通)列或标签列,则可以使用 `OR` 关键字进行组合条件的查询过滤。例如:((value > 20 AND value < 30) OR (value < 12)) 。
|
||||
3. 从 2.0.17 版本开始,条件过滤开始支持 BETWEEN AND 语法,例如 `WHERE col2 BETWEEN 1.5 AND 3.25` 表示查询条件为“1.5 ≤ col2 ≤ 3.25”。
|
||||
|
||||
<!--
|
||||
### <a class="anchor" id="having"></a>GROUP BY 之后的 HAVING 过滤
|
||||
|
||||
从 2.0.20 版本开始,GROUP BY 之后允许再跟一个 HAVING 子句,对成组后的各组数据再做筛选。HAVING 子句可以使用聚合函数和选择函数作为过滤条件(但暂时不支持 LEASTSQUARES、TOP、BOTTOM、LAST_ROW)。
|
||||
|
||||
例如,如下语句只会输出 `AVG(f1) > 0` 的分组:
|
||||
```mysql
|
||||
SELECT AVG(f1), SPREAD(f1, f2, st2.f1) FROM st2 WHERE f1 > 0 GROUP BY f1 HAVING AVG(f1) > 0;
|
||||
```
|
||||
-->
|
||||
|
||||
### <a class="anchor" id="union"></a>UNION ALL 操作符
|
||||
|
||||
```mysql
|
||||
SELECT ...
|
||||
UNION ALL SELECT ...
|
||||
[UNION ALL SELECT ...]
|
||||
```
|
||||
|
||||
TDengine 支持 UNION ALL 操作符。也就是说,如果多个 SELECT 子句返回结果集的结构完全相同(列名、列类型、列数、顺序),那么可以通过 UNION ALL 把这些结果集合并到一起。目前只支持 UNION ALL 模式,也即在结果集的合并过程中是不去重的。
|
||||
|
||||
### SQL 示例
|
||||
|
||||
- 对于下面的例子,表tb1用以下语句创建
|
||||
|
@ -695,11 +715,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:应用全部字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)可以使用星号*来替代具体的字段,使用星号(*)返回全部记录数量。
|
||||
1)可以使用星号\*来替代具体的字段,使用星号(\*)返回全部记录数量。
|
||||
|
||||
2)针对同一表的(不包含NULL值)字段查询结果均相同。
|
||||
|
||||
|
@ -730,7 +750,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
适用于:**表、超级表**。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -757,7 +777,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表。
|
||||
适用于:**表**。
|
||||
|
||||
- **SUM**
|
||||
```mysql
|
||||
|
@ -769,7 +789,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
适用于:**表、超级表**。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -796,7 +816,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表。(从 2.0.15.1 版本开始,本函数也支持超级表)
|
||||
适用于:**表**。(从 2.0.15.1 版本开始,本函数也支持**超级表**)
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -819,7 +839,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
说明:自变量是时间戳,因变量是该列的值。
|
||||
|
||||
适用于:表。
|
||||
适用于:**表**。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -842,6 +862,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
taos> SELECT MIN(current), MIN(voltage) FROM meters;
|
||||
|
@ -867,6 +889,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
taos> SELECT MAX(current), MAX(voltage) FROM meters;
|
||||
|
@ -892,6 +916,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:所有字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)如果要返回各个列的首个(时间戳最小)非NULL值,可以使用FIRST(\*);
|
||||
|
@ -925,6 +951,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:所有字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)如果要返回各个列的最后(时间戳最大)一个非NULL值,可以使用LAST(\*);
|
||||
|
@ -950,12 +978,14 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
```mysql
|
||||
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明: 统计表/超级表中某列的值最大*k*个非NULL值。若多于k个列值并列最大,则返回时间戳小的。
|
||||
功能说明: 统计表/超级表中某列的值最大 *k* 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)*k*值取值范围1≤*k*≤100;
|
||||
|
@ -984,12 +1014,14 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
```mysql
|
||||
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最小*k*个非NULL值。若多于k个列值并列最小,则返回时间戳小的。
|
||||
功能说明:统计表/超级表中某列的值最小 *k* 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)*k*值取值范围1≤*k*≤100;
|
||||
|
@ -1023,6 +1055,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表**。
|
||||
|
||||
说明:*P*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。
|
||||
|
||||
示例:
|
||||
|
@ -1038,12 +1072,14 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
```mysql
|
||||
SELECT APERCENTILE(field_name, P) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的值百分比分位数,与PERCENTILE函数相似,但是返回近似结果。
|
||||
功能说明:统计表/超级表中某列的值百分比分位数,与PERCENTILE函数相似,但是返回近似结果。
|
||||
|
||||
返回结果数据类型: 双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:*P*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。推荐使用```APERCENTILE```函数,该函数性能远胜于```PERCENTILE```函数
|
||||
|
||||
```mysql
|
||||
|
@ -1058,12 +1094,14 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
```mysql
|
||||
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
||||
```
|
||||
功能说明:返回表(超级表)的最后一条记录。
|
||||
功能说明:返回表/超级表的最后一条记录。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:所有字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:与last函数不同,last_row不支持时间范围限制,强制返回最后一条记录。
|
||||
|
||||
示例:
|
||||
|
@ -1092,6 +1130,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表**。
|
||||
|
||||
说明:输出结果行数是范围内总行数减一,第一行没有结果输出。
|
||||
|
||||
示例:
|
||||
|
@ -1114,6 +1154,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:可用于TIMESTAMP字段,此时表示记录的时间覆盖范围。
|
||||
|
||||
示例:
|
||||
|
@ -1142,6 +1184,8 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:**表、超级表**。
|
||||
|
||||
说明:
|
||||
|
||||
1)支持两列或多列之间进行计算,可使用括号控制计算优先级;
|
||||
|
@ -1216,6 +1260,7 @@ SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), P
|
|||
- 列名最大长度为 64,最多允许 1024 列,最少需要 2 列,第一列必须是时间戳
|
||||
- 标签最多允许 128 个,可以 1 个,标签总长度不超过 16k 个字符
|
||||
- SQL 语句最大长度 65480 个字符,但可通过系统配置参数 maxSQLLength 修改,最长可配置为 1M
|
||||
- SELECT 语句的查询结果,最多允许返回 1024 列(语句中的函数调用可能也会占用一些列空间),超限时需要显式指定较少的返回数据列,以避免语句执行报错。
|
||||
- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制
|
||||
|
||||
## TAOS SQL其他约定
|
||||
|
|
|
@ -102,7 +102,7 @@ TDengine 目前尚不支持删除功能,未来根据用户需求可能会支
|
|||
|
||||
批量插入。每条写入语句可以一张表同时插入多条记录,也可以同时插入多张表的多条记录。
|
||||
|
||||
## 12. 最有效的写入数据的方法是什么?windows系统下插入的nchar类数据中的汉字被解析成了乱码如何解决?
|
||||
## 12. windows系统下插入的nchar类数据中的汉字被解析成了乱码如何解决?
|
||||
|
||||
Windows下插入nchar类的数据中如果有中文,请先确认系统的地区设置成了中国(在Control Panel里可以设置),这时cmd中的`taos`客户端应该已经可以正常工作了;如果是在IDE里开发Java应用,比如Eclipse, Intellij,请确认IDE里的文件编码为GBK(这是Java默认的编码类型),然后在生成Connection时,初始化客户端的配置,具体语句如下:
|
||||
```JAVA
|
||||
|
@ -166,3 +166,18 @@ TDengine 中时间戳的时区总是由客户端进行处理,而与服务端
|
|||
2. 如果在 taos.cfg 中设置了 timezone 参数,则客户端会以这个配置文件中的设置为准。
|
||||
3. 如果在 C/C++/Java/Python 等各种编程语言的 Connector Driver 中,在建立数据库连接时显式指定了 timezone,那么会以这个指定的时区设置为准。例如 Java Connector 的 JDBC URL 中就有 timezone 参数。
|
||||
4. 在书写 SQL 语句时,也可以直接使用 Unix 时间戳(例如 `1554984068000`)或带有时区的时间戳字符串,也即以 RFC 3339 格式(例如 `2013-04-12T15:52:01.123+08:00`)或 ISO-8601 格式(例如 `2013-04-12T15:52:01.123+0800`)来书写时间戳,此时这些时间戳的取值将不再受其他时区设置的影响。
|
||||
|
||||
## <a class="anchor" id="port"></a>19. TDengine 都会用到哪些网络端口?
|
||||
|
||||
在 TDengine 2.0 版本中,会用到以下这些网络端口(以默认端口 6030 为前提进行说明,如果修改了配置文件中的设置,那么这里列举的端口都会出现变化),管理员可以参考这里的信息调整防火墙设置:
|
||||
|
||||
| 协议 | 默认端口 | 用途说明 | 修改方法 |
|
||||
| --- | --------- | ------------------------------- | ------------------------------ |
|
||||
| TCP | 6030 | 客户端与服务端之间通讯。 | 由配置文件设置 serverPort 决定。 |
|
||||
| TCP | 6035 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
|
||||
| TCP | 6040 | 多节点集群的节点间数据同步。 | 随 serverPort 端口变化。 |
|
||||
| TCP | 6041 | 客户端与服务端之间的 RESTful 通讯。 | 随 serverPort 端口变化。 |
|
||||
| TCP | 6042 | Arbitrator 的服务端口。 | 因 Arbitrator 启动参数设置变化。 |
|
||||
| TCP | 6060 | 企业版内 Monitor 服务的网络端口。 | |
|
||||
| UDP | 6030-6034 | 客户端与服务端之间通讯。 | 随 serverPort 端口变化。 |
|
||||
| UDP | 6035-6039 | 多节点集群的节点间通讯。 | 随 serverPort 端口变化。 |
|
||||
|
|
|
@ -97,7 +97,7 @@ go build -o bin/taosimport app/main.go
|
|||
|
||||
是否保存统计信息到 tdengine 的 statistic 表中,1 是,0 否, 默认 0。
|
||||
|
||||
* -savetb int
|
||||
* -savetb string
|
||||
|
||||
当 save 为 1 时保存统计信息的表名, 默认 statistic。
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -17,47 +16,55 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
dataimport "github.com/taosdata/TDengine/importSampleData/import"
|
||||
dataImport "github.com/taosdata/TDengine/importSampleData/import"
|
||||
|
||||
_ "github.com/taosdata/driver-go/taosSql"
|
||||
)
|
||||
|
||||
const (
|
||||
TIMESTAMP = "timestamp"
|
||||
DATETIME = "datetime"
|
||||
MILLISECOND = "millisecond"
|
||||
DEFAULT_STARTTIME int64 = -1
|
||||
DEFAULT_INTERVAL int64 = 1 * 1000
|
||||
DEFAULT_DELAY int64 = -1
|
||||
DEFAULT_STATISTIC_TABLE = "statistic"
|
||||
// 主键类型必须为 timestamp
|
||||
TIMESTAMP = "timestamp"
|
||||
|
||||
JSON_FORMAT = "json"
|
||||
CSV_FORMAT = "csv"
|
||||
SUPERTABLE_PREFIX = "s_"
|
||||
SUBTABLE_PREFIX = "t_"
|
||||
// 样例数据中主键时间字段是 millisecond 还是 dateTime 格式
|
||||
DATETIME = "datetime"
|
||||
MILLISECOND = "millisecond"
|
||||
|
||||
DRIVER_NAME = "taosSql"
|
||||
STARTTIME_LAYOUT = "2006-01-02 15:04:05.000"
|
||||
INSERT_PREFIX = "insert into "
|
||||
DefaultStartTime int64 = -1
|
||||
DefaultInterval int64 = 1 * 1000 // 导入的记录时间间隔,该设置只会在指定 auto=1 之后生效,否则会根据样例数据自动计算间隔时间。单位为毫秒,默认 1000。
|
||||
DefaultDelay int64 = -1 //
|
||||
|
||||
// 当 save 为 1 时保存统计信息的表名, 默认 statistic。
|
||||
DefaultStatisticTable = "statistic"
|
||||
|
||||
// 样例数据文件格式,可以是 json 或 csv
|
||||
JsonFormat = "json"
|
||||
CsvFormat = "csv"
|
||||
|
||||
SuperTablePrefix = "s_" // 超级表前缀
|
||||
SubTablePrefix = "t_" // 子表前缀
|
||||
|
||||
DriverName = "taosSql"
|
||||
StartTimeLayout = "2006-01-02 15:04:05.000"
|
||||
InsertPrefix = "insert into "
|
||||
)
|
||||
|
||||
var (
|
||||
cfg string
|
||||
cases string
|
||||
hnum int
|
||||
vnum int
|
||||
thread int
|
||||
batch int
|
||||
auto int
|
||||
starttimestr string
|
||||
interval int64
|
||||
host string
|
||||
port int
|
||||
user string
|
||||
password string
|
||||
dropdb int
|
||||
db string
|
||||
dbparam string
|
||||
cfg string // 导入配置文件路径,包含样例数据文件相关描述及对应 TDengine 配置信息。默认使用 config/cfg.toml
|
||||
cases string // 需要导入的场景名称,该名称可从 -cfg 指定的配置文件中 [usecase] 查看,可同时导入多个场景,中间使用逗号分隔,如:sensor_info,camera_detection,默认为 sensor_info
|
||||
hnum int // 需要将样例数据进行横向扩展的倍数,假设原有样例数据包含 1 张子表 t_0 数据,指定 hnum 为 2 时会根据原有表名创建 t、t_1 两张子表。默认为 100。
|
||||
vnum int // 需要将样例数据进行纵向扩展的次数,如果设置为 0 代表将历史数据导入至当前时间后持续按照指定间隔导入。默认为 1000,表示将样例数据在时间轴上纵向复制1000 次
|
||||
thread int // 执行导入数据的线程数目,默认为 10
|
||||
batch int // 执行导入数据时的批量大小,默认为 100。批量是指一次写操作时,包含多少条记录
|
||||
auto int // 是否自动生成样例数据中的主键时间戳,1 是,0 否, 默认 0
|
||||
startTimeStr string // 导入的记录开始时间,格式为 "yyyy-MM-dd HH:mm:ss.SSS",不设置会使用样例数据中最小时间,设置后会忽略样例数据中的主键时间,会按照指定的 start 进行导入。如果 auto 为 1,则必须设置 start,默认为空
|
||||
interval int64 // 导入的记录时间间隔,该设置只会在指定 auto=1 之后生效,否则会根据样例数据自动计算间隔时间。单位为毫秒,默认 1000
|
||||
host string // 导入的 TDengine 服务器 IP,默认为 127.0.0.1
|
||||
port int // 导入的 TDengine 服务器端口,默认为 6030
|
||||
user string // 导入的 TDengine 用户名,默认为 root
|
||||
password string // 导入的 TDengine 用户密码,默认为 taosdata
|
||||
dropdb int // 导入数据之前是否删除数据库,1 是,0 否, 默认 0
|
||||
db string // 导入的 TDengine 数据库名称,默认为 test_yyyyMMdd
|
||||
dbparam string // 当指定的数据库不存在时,自动创建数据库时可选项配置参数,如 days 10 cache 16000 ablocks 4,默认为空
|
||||
|
||||
dataSourceName string
|
||||
startTime int64
|
||||
|
@ -72,10 +79,10 @@ var (
|
|||
lastStaticTime time.Time
|
||||
lastTotalRows int64
|
||||
timeTicker *time.Ticker
|
||||
delay int64 // default 10 milliseconds
|
||||
tick int64
|
||||
save int
|
||||
saveTable string
|
||||
delay int64 // 当 vnum 设置为 0 时持续导入的时间间隔,默认为所有场景中最小记录间隔时间的一半,单位 ms。
|
||||
tick int64 // 打印统计信息的时间间隔,默认 2000 ms。
|
||||
save int // 是否保存统计信息到 tdengine 的 statistic 表中,1 是,0 否, 默认 0。
|
||||
saveTable string // 当 save 为 1 时保存统计信息的表名, 默认 statistic。
|
||||
)
|
||||
|
||||
type superTableConfig struct {
|
||||
|
@ -83,7 +90,7 @@ type superTableConfig struct {
|
|||
endTime int64
|
||||
cycleTime int64
|
||||
avgInterval int64
|
||||
config dataimport.CaseConfig
|
||||
config dataImport.CaseConfig
|
||||
}
|
||||
|
||||
type scaleTableInfo struct {
|
||||
|
@ -92,14 +99,14 @@ type scaleTableInfo struct {
|
|||
insertRows int64
|
||||
}
|
||||
|
||||
type tableRows struct {
|
||||
tableName string // tableName
|
||||
value string // values(...)
|
||||
}
|
||||
//type tableRows struct {
|
||||
// tableName string // tableName
|
||||
// value string // values(...)
|
||||
//}
|
||||
|
||||
type dataRows struct {
|
||||
rows []map[string]interface{}
|
||||
config dataimport.CaseConfig
|
||||
config dataImport.CaseConfig
|
||||
}
|
||||
|
||||
func (rows dataRows) Len() int {
|
||||
|
@ -107,9 +114,9 @@ func (rows dataRows) Len() int {
|
|||
}
|
||||
|
||||
func (rows dataRows) Less(i, j int) bool {
|
||||
itime := getPrimaryKey(rows.rows[i][rows.config.Timestamp])
|
||||
jtime := getPrimaryKey(rows.rows[j][rows.config.Timestamp])
|
||||
return itime < jtime
|
||||
iTime := getPrimaryKey(rows.rows[i][rows.config.Timestamp])
|
||||
jTime := getPrimaryKey(rows.rows[j][rows.config.Timestamp])
|
||||
return iTime < jTime
|
||||
}
|
||||
|
||||
func (rows dataRows) Swap(i, j int) {
|
||||
|
@ -123,26 +130,26 @@ func getPrimaryKey(value interface{}) int64 {
|
|||
}
|
||||
|
||||
func init() {
|
||||
parseArg() //parse argument
|
||||
parseArg() // parse argument
|
||||
|
||||
if db == "" {
|
||||
//db = "go"
|
||||
// 导入的 TDengine 数据库名称,默认为 test_yyyyMMdd
|
||||
db = fmt.Sprintf("test_%s", time.Now().Format("20060102"))
|
||||
}
|
||||
|
||||
if auto == 1 && len(starttimestr) == 0 {
|
||||
if auto == 1 && len(startTimeStr) == 0 {
|
||||
log.Fatalf("startTime must be set when auto is 1, the format is \"yyyy-MM-dd HH:mm:ss.SSS\" ")
|
||||
}
|
||||
|
||||
if len(starttimestr) != 0 {
|
||||
t, err := time.ParseInLocation(STARTTIME_LAYOUT, strings.TrimSpace(starttimestr), time.Local)
|
||||
if len(startTimeStr) != 0 {
|
||||
t, err := time.ParseInLocation(StartTimeLayout, strings.TrimSpace(startTimeStr), time.Local)
|
||||
if err != nil {
|
||||
log.Fatalf("param startTime %s error, %s\n", starttimestr, err)
|
||||
log.Fatalf("param startTime %s error, %s\n", startTimeStr, err)
|
||||
}
|
||||
|
||||
startTime = t.UnixNano() / 1e6 // as millisecond
|
||||
} else {
|
||||
startTime = DEFAULT_STARTTIME
|
||||
startTime = DefaultStartTime
|
||||
}
|
||||
|
||||
dataSourceName = fmt.Sprintf("%s:%s@/tcp(%s:%d)/", user, password, host, port)
|
||||
|
@ -154,9 +161,9 @@ func init() {
|
|||
|
||||
func main() {
|
||||
|
||||
importConfig := dataimport.LoadConfig(cfg)
|
||||
importConfig := dataImport.LoadConfig(cfg)
|
||||
|
||||
var caseMinumInterval int64 = -1
|
||||
var caseMinInterval int64 = -1
|
||||
|
||||
for _, userCase := range strings.Split(cases, ",") {
|
||||
caseConfig, ok := importConfig.UserCases[userCase]
|
||||
|
@ -168,7 +175,7 @@ func main() {
|
|||
|
||||
checkUserCaseConfig(userCase, &caseConfig)
|
||||
|
||||
//read file as map array
|
||||
// read file as map array
|
||||
fileRows := readFile(caseConfig)
|
||||
log.Printf("case [%s] sample data file contains %d rows.\n", userCase, len(fileRows.rows))
|
||||
|
||||
|
@ -177,31 +184,31 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
_, exists := superTableConfigMap[caseConfig.Stname]
|
||||
_, exists := superTableConfigMap[caseConfig.StName]
|
||||
if !exists {
|
||||
superTableConfigMap[caseConfig.Stname] = &superTableConfig{config: caseConfig}
|
||||
superTableConfigMap[caseConfig.StName] = &superTableConfig{config: caseConfig}
|
||||
} else {
|
||||
log.Fatalf("the stname of case %s already exist.\n", caseConfig.Stname)
|
||||
log.Fatalf("the stname of case %s already exist.\n", caseConfig.StName)
|
||||
}
|
||||
|
||||
var start, cycleTime, avgInterval int64 = getSuperTableTimeConfig(fileRows)
|
||||
|
||||
// set super table's startTime, cycleTime and avgInterval
|
||||
superTableConfigMap[caseConfig.Stname].startTime = start
|
||||
superTableConfigMap[caseConfig.Stname].avgInterval = avgInterval
|
||||
superTableConfigMap[caseConfig.Stname].cycleTime = cycleTime
|
||||
superTableConfigMap[caseConfig.StName].startTime = start
|
||||
superTableConfigMap[caseConfig.StName].cycleTime = cycleTime
|
||||
superTableConfigMap[caseConfig.StName].avgInterval = avgInterval
|
||||
|
||||
if caseMinumInterval == -1 || caseMinumInterval > avgInterval {
|
||||
caseMinumInterval = avgInterval
|
||||
if caseMinInterval == -1 || caseMinInterval > avgInterval {
|
||||
caseMinInterval = avgInterval
|
||||
}
|
||||
|
||||
startStr := time.Unix(0, start*int64(time.Millisecond)).Format(STARTTIME_LAYOUT)
|
||||
startStr := time.Unix(0, start*int64(time.Millisecond)).Format(StartTimeLayout)
|
||||
log.Printf("case [%s] startTime %s(%d), average dataInterval %d ms, cycleTime %d ms.\n", userCase, startStr, start, avgInterval, cycleTime)
|
||||
}
|
||||
|
||||
if DEFAULT_DELAY == delay {
|
||||
if DefaultDelay == delay {
|
||||
// default delay
|
||||
delay = caseMinumInterval / 2
|
||||
delay = caseMinInterval / 2
|
||||
if delay < 1 {
|
||||
delay = 1
|
||||
}
|
||||
|
@ -218,7 +225,7 @@ func main() {
|
|||
createSuperTable(superTableConfigMap)
|
||||
log.Printf("create %d superTable ,used %d ms.\n", superTableNum, time.Since(start)/1e6)
|
||||
|
||||
//create sub table
|
||||
// create sub table
|
||||
start = time.Now()
|
||||
createSubTable(subTableMap)
|
||||
log.Printf("create %d times of %d subtable ,all %d tables, used %d ms.\n", hnum, len(subTableMap), len(scaleTableMap), time.Since(start)/1e6)
|
||||
|
@ -278,7 +285,7 @@ func staticSpeed() {
|
|||
defer connection.Close()
|
||||
|
||||
if save == 1 {
|
||||
connection.Exec("use " + db)
|
||||
_, _ = connection.Exec("use " + db)
|
||||
_, err := connection.Exec("create table if not exists " + saveTable + "(ts timestamp, speed int)")
|
||||
if err != nil {
|
||||
log.Fatalf("create %s Table error: %s\n", saveTable, err)
|
||||
|
@ -294,12 +301,12 @@ func staticSpeed() {
|
|||
total := getTotalRows(successRows)
|
||||
currentSuccessRows := total - lastTotalRows
|
||||
|
||||
speed := currentSuccessRows * 1e9 / int64(usedTime)
|
||||
speed := currentSuccessRows * 1e9 / usedTime
|
||||
log.Printf("insert %d rows, used %d ms, speed %d rows/s", currentSuccessRows, usedTime/1e6, speed)
|
||||
|
||||
if save == 1 {
|
||||
insertSql := fmt.Sprintf("insert into %s values(%d, %d)", saveTable, currentTime.UnixNano()/1e6, speed)
|
||||
connection.Exec(insertSql)
|
||||
_, _ = connection.Exec(insertSql)
|
||||
}
|
||||
|
||||
lastStaticTime = currentTime
|
||||
|
@ -327,12 +334,13 @@ func getSuperTableTimeConfig(fileRows dataRows) (start, cycleTime, avgInterval i
|
|||
} else {
|
||||
|
||||
// use the sample data primary timestamp
|
||||
sort.Sort(fileRows) // sort the file data by the primarykey
|
||||
sort.Sort(fileRows) // sort the file data by the primaryKey
|
||||
minTime := getPrimaryKey(fileRows.rows[0][fileRows.config.Timestamp])
|
||||
maxTime := getPrimaryKey(fileRows.rows[len(fileRows.rows)-1][fileRows.config.Timestamp])
|
||||
|
||||
start = minTime // default startTime use the minTime
|
||||
if DEFAULT_STARTTIME != startTime {
|
||||
// 设置了start时间的话 按照start来
|
||||
if DefaultStartTime != startTime {
|
||||
start = startTime
|
||||
}
|
||||
|
||||
|
@ -350,31 +358,21 @@ func getSuperTableTimeConfig(fileRows dataRows) (start, cycleTime, avgInterval i
|
|||
return
|
||||
}
|
||||
|
||||
func createStatisticTable() {
|
||||
connection := getConnection()
|
||||
defer connection.Close()
|
||||
|
||||
_, err := connection.Exec("create table if not exist " + db + "." + saveTable + "(ts timestamp, speed int)")
|
||||
if err != nil {
|
||||
log.Fatalf("createStatisticTable error: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func createSubTable(subTableMaps map[string]*dataRows) {
|
||||
|
||||
connection := getConnection()
|
||||
defer connection.Close()
|
||||
|
||||
connection.Exec("use " + db)
|
||||
_, _ = connection.Exec("use " + db)
|
||||
|
||||
createTablePrefix := "create table if not exists "
|
||||
var buffer bytes.Buffer
|
||||
for subTableName := range subTableMaps {
|
||||
|
||||
superTableName := getSuperTableName(subTableMaps[subTableName].config.Stname)
|
||||
tagValues := subTableMaps[subTableName].rows[0] // the first rows values as tags
|
||||
superTableName := getSuperTableName(subTableMaps[subTableName].config.StName)
|
||||
firstRowValues := subTableMaps[subTableName].rows[0] // the first rows values as tags
|
||||
|
||||
buffers := bytes.Buffer{}
|
||||
// create table t using supertTable tags(...);
|
||||
// create table t using superTable tags(...);
|
||||
for i := 0; i < hnum; i++ {
|
||||
tableName := getScaleSubTableName(subTableName, i)
|
||||
|
||||
|
@ -384,21 +382,21 @@ func createSubTable(subTableMaps map[string]*dataRows) {
|
|||
}
|
||||
scaleTableNames = append(scaleTableNames, tableName)
|
||||
|
||||
buffers.WriteString(createTablePrefix)
|
||||
buffers.WriteString(tableName)
|
||||
buffers.WriteString(" using ")
|
||||
buffers.WriteString(superTableName)
|
||||
buffers.WriteString(" tags(")
|
||||
buffer.WriteString(createTablePrefix)
|
||||
buffer.WriteString(tableName)
|
||||
buffer.WriteString(" using ")
|
||||
buffer.WriteString(superTableName)
|
||||
buffer.WriteString(" tags(")
|
||||
for _, tag := range subTableMaps[subTableName].config.Tags {
|
||||
tagValue := fmt.Sprintf("%v", tagValues[strings.ToLower(tag.Name)])
|
||||
buffers.WriteString("'" + tagValue + "'")
|
||||
buffers.WriteString(",")
|
||||
tagValue := fmt.Sprintf("%v", firstRowValues[strings.ToLower(tag.Name)])
|
||||
buffer.WriteString("'" + tagValue + "'")
|
||||
buffer.WriteString(",")
|
||||
}
|
||||
buffers.Truncate(buffers.Len() - 1)
|
||||
buffers.WriteString(")")
|
||||
buffer.Truncate(buffer.Len() - 1)
|
||||
buffer.WriteString(")")
|
||||
|
||||
createTableSql := buffers.String()
|
||||
buffers.Reset()
|
||||
createTableSql := buffer.String()
|
||||
buffer.Reset()
|
||||
|
||||
//log.Printf("create table: %s\n", createTableSql)
|
||||
_, err := connection.Exec(createTableSql)
|
||||
|
@ -420,7 +418,7 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) {
|
|||
if err != nil {
|
||||
log.Fatalf("drop database error: %s\n", err)
|
||||
}
|
||||
log.Printf("dropDb: %s\n", dropDbSql)
|
||||
log.Printf("dropdb: %s\n", dropDbSql)
|
||||
}
|
||||
|
||||
createDbSql := "create database if not exists " + db + " " + dbparam
|
||||
|
@ -431,7 +429,7 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) {
|
|||
}
|
||||
log.Printf("createDb: %s\n", createDbSql)
|
||||
|
||||
connection.Exec("use " + db)
|
||||
_, _ = connection.Exec("use " + db)
|
||||
|
||||
prefix := "create table if not exists "
|
||||
var buffer bytes.Buffer
|
||||
|
@ -464,7 +462,7 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) {
|
|||
createSql := buffer.String()
|
||||
buffer.Reset()
|
||||
|
||||
//log.Printf("supertable: %s\n", createSql)
|
||||
//log.Printf("superTable: %s\n", createSql)
|
||||
_, err = connection.Exec(createSql)
|
||||
if err != nil {
|
||||
log.Fatalf("create supertable error: %s\n", err)
|
||||
|
@ -473,15 +471,15 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) {
|
|||
|
||||
}
|
||||
|
||||
func getScaleSubTableName(subTableName string, hnum int) string {
|
||||
if hnum == 0 {
|
||||
func getScaleSubTableName(subTableName string, hNum int) string {
|
||||
if hNum == 0 {
|
||||
return subTableName
|
||||
}
|
||||
return fmt.Sprintf("%s_%d", subTableName, hnum)
|
||||
return fmt.Sprintf("%s_%d", subTableName, hNum)
|
||||
}
|
||||
|
||||
func getSuperTableName(stname string) string {
|
||||
return SUPERTABLE_PREFIX + stname
|
||||
func getSuperTableName(stName string) string {
|
||||
return SuperTablePrefix + stName
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -499,7 +497,7 @@ func normalizationData(fileRows dataRows, minTime int64) int64 {
|
|||
|
||||
row[fileRows.config.Timestamp] = getPrimaryKey(row[fileRows.config.Timestamp]) - minTime
|
||||
|
||||
subTableName := getSubTableName(tableValue, fileRows.config.Stname)
|
||||
subTableName := getSubTableName(tableValue, fileRows.config.StName)
|
||||
|
||||
value, ok := subTableMap[subTableName]
|
||||
if !ok {
|
||||
|
@ -527,7 +525,7 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int
|
|||
continue
|
||||
}
|
||||
|
||||
subTableName := getSubTableName(tableValue, fileRows.config.Stname)
|
||||
subTableName := getSubTableName(tableValue, fileRows.config.StName)
|
||||
|
||||
value, ok := currSubTableMap[subTableName]
|
||||
if !ok {
|
||||
|
@ -543,7 +541,7 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int
|
|||
|
||||
}
|
||||
|
||||
var maxRows, tableRows int = 0, 0
|
||||
var maxRows, tableRows = 0, 0
|
||||
for tableName := range currSubTableMap {
|
||||
tableRows = len(currSubTableMap[tableName].rows)
|
||||
subTableMap[tableName] = currSubTableMap[tableName] // add to global subTableMap
|
||||
|
@ -556,7 +554,7 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int
|
|||
}
|
||||
|
||||
func getSubTableName(subTableValue string, superTableName string) string {
|
||||
return SUBTABLE_PREFIX + subTableValue + "_" + superTableName
|
||||
return SubTablePrefix + subTableValue + "_" + superTableName
|
||||
}
|
||||
|
||||
func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []int64) {
|
||||
|
@ -564,25 +562,25 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i
|
|||
defer connection.Close()
|
||||
defer wg.Done()
|
||||
|
||||
connection.Exec("use " + db) // use db
|
||||
_, _ = connection.Exec("use " + db) // use db
|
||||
|
||||
log.Printf("thread-%d start insert into [%d, %d) subtables.\n", threadIndex, start, end)
|
||||
|
||||
num := 0
|
||||
subTables := scaleTableNames[start:end]
|
||||
var buffer bytes.Buffer
|
||||
for {
|
||||
var currSuccessRows int64
|
||||
var appendRows int
|
||||
var lastTableName string
|
||||
|
||||
buffers := bytes.Buffer{}
|
||||
buffers.WriteString(INSERT_PREFIX)
|
||||
buffer.WriteString(InsertPrefix)
|
||||
|
||||
for _, tableName := range subTables {
|
||||
|
||||
subTableInfo := subTableMap[scaleTableMap[tableName].subTableName]
|
||||
subTableRows := int64(len(subTableInfo.rows))
|
||||
superTableConf := superTableConfigMap[subTableInfo.config.Stname]
|
||||
superTableConf := superTableConfigMap[subTableInfo.config.StName]
|
||||
|
||||
tableStartTime := superTableConf.startTime
|
||||
var tableEndTime int64
|
||||
|
@ -605,40 +603,35 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i
|
|||
// append
|
||||
|
||||
if lastTableName != tableName {
|
||||
buffers.WriteString(tableName)
|
||||
buffers.WriteString(" values")
|
||||
buffer.WriteString(tableName)
|
||||
buffer.WriteString(" values")
|
||||
}
|
||||
lastTableName = tableName
|
||||
|
||||
buffers.WriteString("(")
|
||||
buffers.WriteString(fmt.Sprintf("%v", currentTime))
|
||||
buffers.WriteString(",")
|
||||
buffer.WriteString("(")
|
||||
buffer.WriteString(fmt.Sprintf("%v", currentTime))
|
||||
buffer.WriteString(",")
|
||||
|
||||
// fieldNum := len(subTableInfo.config.Fields)
|
||||
for _, field := range subTableInfo.config.Fields {
|
||||
buffers.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)]))
|
||||
buffers.WriteString(",")
|
||||
// if( i != fieldNum -1){
|
||||
|
||||
// }
|
||||
buffer.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)]))
|
||||
buffer.WriteString(",")
|
||||
}
|
||||
|
||||
buffers.Truncate(buffers.Len() - 1)
|
||||
buffers.WriteString(") ")
|
||||
buffer.Truncate(buffer.Len() - 1)
|
||||
buffer.WriteString(") ")
|
||||
|
||||
appendRows++
|
||||
insertRows++
|
||||
if appendRows == batch {
|
||||
// executebatch
|
||||
insertSql := buffers.String()
|
||||
connection.Exec("use " + db)
|
||||
// executeBatch
|
||||
insertSql := buffer.String()
|
||||
affectedRows := executeBatchInsert(insertSql, connection)
|
||||
|
||||
successRows[threadIndex] += affectedRows
|
||||
currSuccessRows += affectedRows
|
||||
|
||||
buffers.Reset()
|
||||
buffers.WriteString(INSERT_PREFIX)
|
||||
buffer.Reset()
|
||||
buffer.WriteString(InsertPrefix)
|
||||
lastTableName = ""
|
||||
appendRows = 0
|
||||
}
|
||||
|
@ -654,15 +647,14 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i
|
|||
|
||||
// left := len(rows)
|
||||
if appendRows > 0 {
|
||||
// executebatch
|
||||
insertSql := buffers.String()
|
||||
connection.Exec("use " + db)
|
||||
// executeBatch
|
||||
insertSql := buffer.String()
|
||||
affectedRows := executeBatchInsert(insertSql, connection)
|
||||
|
||||
successRows[threadIndex] += affectedRows
|
||||
currSuccessRows += affectedRows
|
||||
|
||||
buffers.Reset()
|
||||
buffer.Reset()
|
||||
}
|
||||
|
||||
// log.Printf("thread-%d finished insert %d rows, used %d ms.", threadIndex, currSuccessRows, time.Since(threadStartTime)/1e6)
|
||||
|
@ -688,65 +680,10 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i
|
|||
|
||||
}
|
||||
|
||||
func buildSql(rows []tableRows) string {
|
||||
|
||||
var lastTableName string
|
||||
|
||||
buffers := bytes.Buffer{}
|
||||
|
||||
for i, row := range rows {
|
||||
if i == 0 {
|
||||
lastTableName = row.tableName
|
||||
buffers.WriteString(INSERT_PREFIX)
|
||||
buffers.WriteString(row.tableName)
|
||||
buffers.WriteString(" values")
|
||||
buffers.WriteString(row.value)
|
||||
continue
|
||||
}
|
||||
|
||||
if lastTableName == row.tableName {
|
||||
buffers.WriteString(row.value)
|
||||
} else {
|
||||
buffers.WriteString(" ")
|
||||
buffers.WriteString(row.tableName)
|
||||
buffers.WriteString(" values")
|
||||
buffers.WriteString(row.value)
|
||||
lastTableName = row.tableName
|
||||
}
|
||||
}
|
||||
|
||||
inserSql := buffers.String()
|
||||
return inserSql
|
||||
}
|
||||
|
||||
func buildRow(tableName string, currentTime int64, subTableInfo *dataRows, currentRow map[string]interface{}) tableRows {
|
||||
|
||||
tableRows := tableRows{tableName: tableName}
|
||||
|
||||
buffers := bytes.Buffer{}
|
||||
|
||||
buffers.WriteString("(")
|
||||
buffers.WriteString(fmt.Sprintf("%v", currentTime))
|
||||
buffers.WriteString(",")
|
||||
|
||||
for _, field := range subTableInfo.config.Fields {
|
||||
buffers.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)]))
|
||||
buffers.WriteString(",")
|
||||
}
|
||||
|
||||
buffers.Truncate(buffers.Len() - 1)
|
||||
buffers.WriteString(")")
|
||||
|
||||
insertSql := buffers.String()
|
||||
tableRows.value = insertSql
|
||||
|
||||
return tableRows
|
||||
}
|
||||
|
||||
func executeBatchInsert(insertSql string, connection *sql.DB) int64 {
|
||||
result, error := connection.Exec(insertSql)
|
||||
if error != nil {
|
||||
log.Printf("execute insertSql %s error, %s\n", insertSql, error)
|
||||
result, err := connection.Exec(insertSql)
|
||||
if err != nil {
|
||||
log.Printf("execute insertSql %s error, %s\n", insertSql, err)
|
||||
return 0
|
||||
}
|
||||
affected, _ := result.RowsAffected()
|
||||
|
@ -754,7 +691,6 @@ func executeBatchInsert(insertSql string, connection *sql.DB) int64 {
|
|||
affected = 0
|
||||
}
|
||||
return affected
|
||||
// return 0
|
||||
}
|
||||
|
||||
func getFieldValue(fieldValue interface{}) string {
|
||||
|
@ -762,7 +698,7 @@ func getFieldValue(fieldValue interface{}) string {
|
|||
}
|
||||
|
||||
func getConnection() *sql.DB {
|
||||
db, err := sql.Open(DRIVER_NAME, dataSourceName)
|
||||
db, err := sql.Open(DriverName, dataSourceName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -773,19 +709,11 @@ func getSubTableNameValue(suffix interface{}) string {
|
|||
return fmt.Sprintf("%v", suffix)
|
||||
}
|
||||
|
||||
func hash(s string) int {
|
||||
v := int(crc32.ChecksumIEEE([]byte(s)))
|
||||
if v < 0 {
|
||||
return -v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func readFile(config dataimport.CaseConfig) dataRows {
|
||||
func readFile(config dataImport.CaseConfig) dataRows {
|
||||
fileFormat := strings.ToLower(config.Format)
|
||||
if fileFormat == JSON_FORMAT {
|
||||
if fileFormat == JsonFormat {
|
||||
return readJSONFile(config)
|
||||
} else if fileFormat == CSV_FORMAT {
|
||||
} else if fileFormat == CsvFormat {
|
||||
return readCSVFile(config)
|
||||
}
|
||||
|
||||
|
@ -793,7 +721,7 @@ func readFile(config dataimport.CaseConfig) dataRows {
|
|||
return dataRows{}
|
||||
}
|
||||
|
||||
func readCSVFile(config dataimport.CaseConfig) dataRows {
|
||||
func readCSVFile(config dataImport.CaseConfig) dataRows {
|
||||
var rows dataRows
|
||||
f, err := os.Open(config.FilePath)
|
||||
if err != nil {
|
||||
|
@ -813,7 +741,7 @@ func readCSVFile(config dataimport.CaseConfig) dataRows {
|
|||
line := strings.ToLower(string(lineBytes))
|
||||
titles := strings.Split(line, config.Separator)
|
||||
if len(titles) < 3 {
|
||||
// need suffix、 primarykey and at least one other field
|
||||
// need suffix、 primaryKey and at least one other field
|
||||
log.Printf("the first line of file %s should be title row, and at least 3 field.\n", config.FilePath)
|
||||
return rows
|
||||
}
|
||||
|
@ -848,7 +776,7 @@ func readCSVFile(config dataimport.CaseConfig) dataRows {
|
|||
}
|
||||
|
||||
// if the primary key valid
|
||||
primaryKeyValue := getPrimaryKeyMillisec(config.Timestamp, config.TimestampType, config.TimestampTypeFormat, dataMap)
|
||||
primaryKeyValue := getPrimaryKeyMilliSec(config.Timestamp, config.TimestampType, config.TimestampTypeFormat, dataMap)
|
||||
if primaryKeyValue == -1 {
|
||||
log.Printf("the Timestamp[%s] of line %d is not valid, will filtered.\n", config.Timestamp, lineNum)
|
||||
continue
|
||||
|
@ -861,7 +789,7 @@ func readCSVFile(config dataimport.CaseConfig) dataRows {
|
|||
return rows
|
||||
}
|
||||
|
||||
func readJSONFile(config dataimport.CaseConfig) dataRows {
|
||||
func readJSONFile(config dataImport.CaseConfig) dataRows {
|
||||
|
||||
var rows dataRows
|
||||
f, err := os.Open(config.FilePath)
|
||||
|
@ -899,7 +827,7 @@ func readJSONFile(config dataimport.CaseConfig) dataRows {
|
|||
continue
|
||||
}
|
||||
|
||||
primaryKeyValue := getPrimaryKeyMillisec(config.Timestamp, config.TimestampType, config.TimestampTypeFormat, line)
|
||||
primaryKeyValue := getPrimaryKeyMilliSec(config.Timestamp, config.TimestampType, config.TimestampTypeFormat, line)
|
||||
if primaryKeyValue == -1 {
|
||||
log.Printf("the Timestamp[%s] of line %d is not valid, will filtered.\n", config.Timestamp, lineNum)
|
||||
continue
|
||||
|
@ -916,7 +844,7 @@ func readJSONFile(config dataimport.CaseConfig) dataRows {
|
|||
/**
|
||||
* get primary key as millisecond , otherwise return -1
|
||||
*/
|
||||
func getPrimaryKeyMillisec(key string, valueType string, valueFormat string, line map[string]interface{}) int64 {
|
||||
func getPrimaryKeyMilliSec(key string, valueType string, valueFormat string, line map[string]interface{}) int64 {
|
||||
if !existMapKeyAndNotEmpty(key, line) {
|
||||
return -1
|
||||
}
|
||||
|
@ -971,13 +899,13 @@ func existMapKeyAndNotEmpty(key string, maps map[string]interface{}) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func checkUserCaseConfig(caseName string, caseConfig *dataimport.CaseConfig) {
|
||||
func checkUserCaseConfig(caseName string, caseConfig *dataImport.CaseConfig) {
|
||||
|
||||
if len(caseConfig.Stname) == 0 {
|
||||
if len(caseConfig.StName) == 0 {
|
||||
log.Fatalf("the stname of case %s can't be empty\n", caseName)
|
||||
}
|
||||
|
||||
caseConfig.Stname = strings.ToLower(caseConfig.Stname)
|
||||
caseConfig.StName = strings.ToLower(caseConfig.StName)
|
||||
|
||||
if len(caseConfig.Tags) == 0 {
|
||||
log.Fatalf("the tags of case %s can't be empty\n", caseName)
|
||||
|
@ -1029,24 +957,24 @@ func checkUserCaseConfig(caseName string, caseConfig *dataimport.CaseConfig) {
|
|||
}
|
||||
|
||||
func parseArg() {
|
||||
flag.StringVar(&cfg, "cfg", "config/cfg.toml", "configuration file which describes usecase and data format.")
|
||||
flag.StringVar(&cases, "cases", "sensor_info", "usecase for dataset to be imported. Multiple choices can be separated by comma, for example, -cases sensor_info,camera_detection.")
|
||||
flag.StringVar(&cfg, "cfg", "config/cfg.toml", "configuration file which describes useCase and data format.")
|
||||
flag.StringVar(&cases, "cases", "sensor_info", "useCase for dataset to be imported. Multiple choices can be separated by comma, for example, -cases sensor_info,camera_detection.")
|
||||
flag.IntVar(&hnum, "hnum", 100, "magnification factor of the sample tables. For example, if hnum is 100 and in the sample data there are 10 tables, then 10x100=1000 tables will be created in the database.")
|
||||
flag.IntVar(&vnum, "vnum", 1000, "copies of the sample records in each table. If set to 0,this program will never stop simulating and importing data even if the timestamp has passed current time.")
|
||||
flag.Int64Var(&delay, "delay", DEFAULT_DELAY, "the delay time interval(millisecond) to continue generating data when vnum set 0.")
|
||||
flag.Int64Var(&delay, "delay", DefaultDelay, "the delay time interval(millisecond) to continue generating data when vnum set 0.")
|
||||
flag.Int64Var(&tick, "tick", 2000, "the tick time interval(millisecond) to print statistic info.")
|
||||
flag.IntVar(&save, "save", 0, "whether to save the statistical info into 'statistic' table. 0 is disabled and 1 is enabled.")
|
||||
flag.StringVar(&saveTable, "savetb", DEFAULT_STATISTIC_TABLE, "the table to save 'statistic' info when save set 1.")
|
||||
flag.StringVar(&saveTable, "savetb", DefaultStatisticTable, "the table to save 'statistic' info when save set 1.")
|
||||
flag.IntVar(&thread, "thread", 10, "number of threads to import data.")
|
||||
flag.IntVar(&batch, "batch", 100, "rows of records in one import batch.")
|
||||
flag.IntVar(&auto, "auto", 0, "whether to use the starttime and interval specified by users when simulating the data. 0 is disabled and 1 is enabled.")
|
||||
flag.StringVar(&starttimestr, "start", "", "the starting timestamp of simulated data, in the format of yyyy-MM-dd HH:mm:ss.SSS. If not specified, the ealiest timestamp in the sample data will be set as the starttime.")
|
||||
flag.Int64Var(&interval, "interval", DEFAULT_INTERVAL, "time inteval between two consecutive records, in the unit of millisecond. Only valid when auto is 1.")
|
||||
flag.IntVar(&auto, "auto", 0, "whether to use the startTime and interval specified by users when simulating the data. 0 is disabled and 1 is enabled.")
|
||||
flag.StringVar(&startTimeStr, "start", "", "the starting timestamp of simulated data, in the format of yyyy-MM-dd HH:mm:ss.SSS. If not specified, the earliest timestamp in the sample data will be set as the startTime.")
|
||||
flag.Int64Var(&interval, "interval", DefaultInterval, "time interval between two consecutive records, in the unit of millisecond. Only valid when auto is 1.")
|
||||
flag.StringVar(&host, "host", "127.0.0.1", "tdengine server ip.")
|
||||
flag.IntVar(&port, "port", 6030, "tdengine server port.")
|
||||
flag.StringVar(&user, "user", "root", "user name to login into the database.")
|
||||
flag.StringVar(&password, "password", "taosdata", "the import tdengine user password")
|
||||
flag.IntVar(&dropdb, "dropdb", 0, "whether to drop the existing datbase. 1 is yes and 0 otherwise.")
|
||||
flag.IntVar(&dropdb, "dropdb", 0, "whether to drop the existing database. 1 is yes and 0 otherwise.")
|
||||
flag.StringVar(&db, "db", "", "name of the database to store data.")
|
||||
flag.StringVar(&dbparam, "dbparam", "", "database configurations when it is created.")
|
||||
|
||||
|
@ -1066,7 +994,7 @@ func printArg() {
|
|||
fmt.Println("-thread:", thread)
|
||||
fmt.Println("-batch:", batch)
|
||||
fmt.Println("-auto:", auto)
|
||||
fmt.Println("-start:", starttimestr)
|
||||
fmt.Println("-start:", startTimeStr)
|
||||
fmt.Println("-interval:", interval)
|
||||
fmt.Println("-host:", host)
|
||||
fmt.Println("-port", port)
|
||||
|
|
|
@ -899,103 +899,103 @@ devid,location,color,devgroup,ts,temperature,humidity
|
|||
8, haerbing, yellow, 2, 1575129697000, 31, 16.321497
|
||||
8, haerbing, yellow, 2, 1575129698000, 25, 15.864515
|
||||
8, haerbing, yellow, 2, 1575129699000, 25, 16.492443
|
||||
9, sijiazhuang, blue, 0, 1575129600000, 23, 16.002889
|
||||
9, sijiazhuang, blue, 0, 1575129601000, 26, 17.034610
|
||||
9, sijiazhuang, blue, 0, 1575129602000, 29, 12.892319
|
||||
9, sijiazhuang, blue, 0, 1575129603000, 34, 15.321807
|
||||
9, sijiazhuang, blue, 0, 1575129604000, 29, 12.562642
|
||||
9, sijiazhuang, blue, 0, 1575129605000, 32, 17.190246
|
||||
9, sijiazhuang, blue, 0, 1575129606000, 19, 15.361774
|
||||
9, sijiazhuang, blue, 0, 1575129607000, 26, 15.022364
|
||||
9, sijiazhuang, blue, 0, 1575129608000, 31, 14.837084
|
||||
9, sijiazhuang, blue, 0, 1575129609000, 25, 11.554289
|
||||
9, sijiazhuang, blue, 0, 1575129610000, 21, 15.313973
|
||||
9, sijiazhuang, blue, 0, 1575129611000, 27, 18.621783
|
||||
9, sijiazhuang, blue, 0, 1575129612000, 31, 18.018101
|
||||
9, sijiazhuang, blue, 0, 1575129613000, 23, 14.421450
|
||||
9, sijiazhuang, blue, 0, 1575129614000, 28, 10.833142
|
||||
9, sijiazhuang, blue, 0, 1575129615000, 33, 18.169837
|
||||
9, sijiazhuang, blue, 0, 1575129616000, 21, 18.772730
|
||||
9, sijiazhuang, blue, 0, 1575129617000, 24, 18.893146
|
||||
9, sijiazhuang, blue, 0, 1575129618000, 24, 10.290187
|
||||
9, sijiazhuang, blue, 0, 1575129619000, 23, 17.393345
|
||||
9, sijiazhuang, blue, 0, 1575129620000, 30, 12.949215
|
||||
9, sijiazhuang, blue, 0, 1575129621000, 19, 19.267621
|
||||
9, sijiazhuang, blue, 0, 1575129622000, 33, 14.831735
|
||||
9, sijiazhuang, blue, 0, 1575129623000, 21, 14.711125
|
||||
9, sijiazhuang, blue, 0, 1575129624000, 16, 17.168485
|
||||
9, sijiazhuang, blue, 0, 1575129625000, 17, 16.426433
|
||||
9, sijiazhuang, blue, 0, 1575129626000, 19, 13.879050
|
||||
9, sijiazhuang, blue, 0, 1575129627000, 21, 18.308168
|
||||
9, sijiazhuang, blue, 0, 1575129628000, 17, 10.845681
|
||||
9, sijiazhuang, blue, 0, 1575129629000, 20, 10.238272
|
||||
9, sijiazhuang, blue, 0, 1575129630000, 19, 19.424976
|
||||
9, sijiazhuang, blue, 0, 1575129631000, 31, 13.885909
|
||||
9, sijiazhuang, blue, 0, 1575129632000, 15, 19.264740
|
||||
9, sijiazhuang, blue, 0, 1575129633000, 30, 12.460645
|
||||
9, sijiazhuang, blue, 0, 1575129634000, 27, 17.608036
|
||||
9, sijiazhuang, blue, 0, 1575129635000, 25, 13.493812
|
||||
9, sijiazhuang, blue, 0, 1575129636000, 19, 10.955939
|
||||
9, sijiazhuang, blue, 0, 1575129637000, 24, 11.956587
|
||||
9, sijiazhuang, blue, 0, 1575129638000, 15, 19.141381
|
||||
9, sijiazhuang, blue, 0, 1575129639000, 24, 14.801530
|
||||
9, sijiazhuang, blue, 0, 1575129640000, 17, 14.347318
|
||||
9, sijiazhuang, blue, 0, 1575129641000, 29, 14.803237
|
||||
9, sijiazhuang, blue, 0, 1575129642000, 28, 10.342297
|
||||
9, sijiazhuang, blue, 0, 1575129643000, 29, 19.368282
|
||||
9, sijiazhuang, blue, 0, 1575129644000, 31, 17.491654
|
||||
9, sijiazhuang, blue, 0, 1575129645000, 18, 13.161736
|
||||
9, sijiazhuang, blue, 0, 1575129646000, 17, 16.067354
|
||||
9, sijiazhuang, blue, 0, 1575129647000, 18, 13.736465
|
||||
9, sijiazhuang, blue, 0, 1575129648000, 23, 19.103276
|
||||
9, sijiazhuang, blue, 0, 1575129649000, 29, 16.075892
|
||||
9, sijiazhuang, blue, 0, 1575129650000, 21, 10.728566
|
||||
9, sijiazhuang, blue, 0, 1575129651000, 15, 18.921849
|
||||
9, sijiazhuang, blue, 0, 1575129652000, 24, 16.914709
|
||||
9, sijiazhuang, blue, 0, 1575129653000, 19, 13.501651
|
||||
9, sijiazhuang, blue, 0, 1575129654000, 19, 13.538347
|
||||
9, sijiazhuang, blue, 0, 1575129655000, 16, 13.261095
|
||||
9, sijiazhuang, blue, 0, 1575129656000, 32, 16.315746
|
||||
9, sijiazhuang, blue, 0, 1575129657000, 27, 16.400939
|
||||
9, sijiazhuang, blue, 0, 1575129658000, 24, 13.321819
|
||||
9, sijiazhuang, blue, 0, 1575129659000, 27, 19.070181
|
||||
9, sijiazhuang, blue, 0, 1575129660000, 27, 13.040922
|
||||
9, sijiazhuang, blue, 0, 1575129661000, 32, 10.872530
|
||||
9, sijiazhuang, blue, 0, 1575129662000, 28, 16.428657
|
||||
9, sijiazhuang, blue, 0, 1575129663000, 32, 13.883854
|
||||
9, sijiazhuang, blue, 0, 1575129664000, 33, 14.299554
|
||||
9, sijiazhuang, blue, 0, 1575129665000, 30, 16.445130
|
||||
9, sijiazhuang, blue, 0, 1575129666000, 15, 18.059404
|
||||
9, sijiazhuang, blue, 0, 1575129667000, 21, 12.348847
|
||||
9, sijiazhuang, blue, 0, 1575129668000, 32, 13.315378
|
||||
9, sijiazhuang, blue, 0, 1575129669000, 17, 15.689507
|
||||
9, sijiazhuang, blue, 0, 1575129670000, 22, 15.591808
|
||||
9, sijiazhuang, blue, 0, 1575129671000, 27, 16.386065
|
||||
9, sijiazhuang, blue, 0, 1575129672000, 25, 10.564803
|
||||
9, sijiazhuang, blue, 0, 1575129673000, 20, 12.276544
|
||||
9, sijiazhuang, blue, 0, 1575129674000, 26, 15.828786
|
||||
9, sijiazhuang, blue, 0, 1575129675000, 18, 12.236420
|
||||
9, sijiazhuang, blue, 0, 1575129676000, 15, 19.439522
|
||||
9, sijiazhuang, blue, 0, 1575129677000, 19, 19.831531
|
||||
9, sijiazhuang, blue, 0, 1575129678000, 22, 17.115744
|
||||
9, sijiazhuang, blue, 0, 1575129679000, 29, 19.879456
|
||||
9, sijiazhuang, blue, 0, 1575129680000, 34, 10.207136
|
||||
9, sijiazhuang, blue, 0, 1575129681000, 16, 17.633523
|
||||
9, sijiazhuang, blue, 0, 1575129682000, 15, 14.227873
|
||||
9, sijiazhuang, blue, 0, 1575129683000, 34, 12.027768
|
||||
9, sijiazhuang, blue, 0, 1575129684000, 22, 11.376610
|
||||
9, sijiazhuang, blue, 0, 1575129685000, 21, 11.711299
|
||||
9, sijiazhuang, blue, 0, 1575129686000, 33, 14.281126
|
||||
9, sijiazhuang, blue, 0, 1575129687000, 31, 10.895302
|
||||
9, sijiazhuang, blue, 0, 1575129688000, 31, 13.971350
|
||||
9, sijiazhuang, blue, 0, 1575129689000, 15, 15.262790
|
||||
9, sijiazhuang, blue, 0, 1575129690000, 23, 12.440568
|
||||
9, sijiazhuang, blue, 0, 1575129691000, 32, 19.731267
|
||||
9, sijiazhuang, blue, 0, 1575129692000, 22, 10.518092
|
||||
9, sijiazhuang, blue, 0, 1575129693000, 34, 17.863021
|
||||
9, sijiazhuang, blue, 0, 1575129694000, 28, 11.478909
|
||||
9, sijiazhuang, blue, 0, 1575129695000, 16, 15.075524
|
||||
9, sijiazhuang, blue, 0, 1575129696000, 16, 10.292127
|
||||
9, sijiazhuang, blue, 0, 1575129697000, 22, 13.716012
|
||||
9, sijiazhuang, blue, 0, 1575129698000, 32, 10.906551
|
||||
9, sijiazhuang, blue, 0, 1575129699000, 19, 18.386868
|
||||
9, shijiazhuang, blue, 0, 1575129600000, 23, 16.002889
|
||||
9, shijiazhuang, blue, 0, 1575129601000, 26, 17.034610
|
||||
9, shijiazhuang, blue, 0, 1575129602000, 29, 12.892319
|
||||
9, shijiazhuang, blue, 0, 1575129603000, 34, 15.321807
|
||||
9, shijiazhuang, blue, 0, 1575129604000, 29, 12.562642
|
||||
9, shijiazhuang, blue, 0, 1575129605000, 32, 17.190246
|
||||
9, shijiazhuang, blue, 0, 1575129606000, 19, 15.361774
|
||||
9, shijiazhuang, blue, 0, 1575129607000, 26, 15.022364
|
||||
9, shijiazhuang, blue, 0, 1575129608000, 31, 14.837084
|
||||
9, shijiazhuang, blue, 0, 1575129609000, 25, 11.554289
|
||||
9, shijiazhuang, blue, 0, 1575129610000, 21, 15.313973
|
||||
9, shijiazhuang, blue, 0, 1575129611000, 27, 18.621783
|
||||
9, shijiazhuang, blue, 0, 1575129612000, 31, 18.018101
|
||||
9, shijiazhuang, blue, 0, 1575129613000, 23, 14.421450
|
||||
9, shijiazhuang, blue, 0, 1575129614000, 28, 10.833142
|
||||
9, shijiazhuang, blue, 0, 1575129615000, 33, 18.169837
|
||||
9, shijiazhuang, blue, 0, 1575129616000, 21, 18.772730
|
||||
9, shijiazhuang, blue, 0, 1575129617000, 24, 18.893146
|
||||
9, shijiazhuang, blue, 0, 1575129618000, 24, 10.290187
|
||||
9, shijiazhuang, blue, 0, 1575129619000, 23, 17.393345
|
||||
9, shijiazhuang, blue, 0, 1575129620000, 30, 12.949215
|
||||
9, shijiazhuang, blue, 0, 1575129621000, 19, 19.267621
|
||||
9, shijiazhuang, blue, 0, 1575129622000, 33, 14.831735
|
||||
9, shijiazhuang, blue, 0, 1575129623000, 21, 14.711125
|
||||
9, shijiazhuang, blue, 0, 1575129624000, 16, 17.168485
|
||||
9, shijiazhuang, blue, 0, 1575129625000, 17, 16.426433
|
||||
9, shijiazhuang, blue, 0, 1575129626000, 19, 13.879050
|
||||
9, shijiazhuang, blue, 0, 1575129627000, 21, 18.308168
|
||||
9, shijiazhuang, blue, 0, 1575129628000, 17, 10.845681
|
||||
9, shijiazhuang, blue, 0, 1575129629000, 20, 10.238272
|
||||
9, shijiazhuang, blue, 0, 1575129630000, 19, 19.424976
|
||||
9, shijiazhuang, blue, 0, 1575129631000, 31, 13.885909
|
||||
9, shijiazhuang, blue, 0, 1575129632000, 15, 19.264740
|
||||
9, shijiazhuang, blue, 0, 1575129633000, 30, 12.460645
|
||||
9, shijiazhuang, blue, 0, 1575129634000, 27, 17.608036
|
||||
9, shijiazhuang, blue, 0, 1575129635000, 25, 13.493812
|
||||
9, shijiazhuang, blue, 0, 1575129636000, 19, 10.955939
|
||||
9, shijiazhuang, blue, 0, 1575129637000, 24, 11.956587
|
||||
9, shijiazhuang, blue, 0, 1575129638000, 15, 19.141381
|
||||
9, shijiazhuang, blue, 0, 1575129639000, 24, 14.801530
|
||||
9, shijiazhuang, blue, 0, 1575129640000, 17, 14.347318
|
||||
9, shijiazhuang, blue, 0, 1575129641000, 29, 14.803237
|
||||
9, shijiazhuang, blue, 0, 1575129642000, 28, 10.342297
|
||||
9, shijiazhuang, blue, 0, 1575129643000, 29, 19.368282
|
||||
9, shijiazhuang, blue, 0, 1575129644000, 31, 17.491654
|
||||
9, shijiazhuang, blue, 0, 1575129645000, 18, 13.161736
|
||||
9, shijiazhuang, blue, 0, 1575129646000, 17, 16.067354
|
||||
9, shijiazhuang, blue, 0, 1575129647000, 18, 13.736465
|
||||
9, shijiazhuang, blue, 0, 1575129648000, 23, 19.103276
|
||||
9, shijiazhuang, blue, 0, 1575129649000, 29, 16.075892
|
||||
9, shijiazhuang, blue, 0, 1575129650000, 21, 10.728566
|
||||
9, shijiazhuang, blue, 0, 1575129651000, 15, 18.921849
|
||||
9, shijiazhuang, blue, 0, 1575129652000, 24, 16.914709
|
||||
9, shijiazhuang, blue, 0, 1575129653000, 19, 13.501651
|
||||
9, shijiazhuang, blue, 0, 1575129654000, 19, 13.538347
|
||||
9, shijiazhuang, blue, 0, 1575129655000, 16, 13.261095
|
||||
9, shijiazhuang, blue, 0, 1575129656000, 32, 16.315746
|
||||
9, shijiazhuang, blue, 0, 1575129657000, 27, 16.400939
|
||||
9, shijiazhuang, blue, 0, 1575129658000, 24, 13.321819
|
||||
9, shijiazhuang, blue, 0, 1575129659000, 27, 19.070181
|
||||
9, shijiazhuang, blue, 0, 1575129660000, 27, 13.040922
|
||||
9, shijiazhuang, blue, 0, 1575129661000, 32, 10.872530
|
||||
9, shijiazhuang, blue, 0, 1575129662000, 28, 16.428657
|
||||
9, shijiazhuang, blue, 0, 1575129663000, 32, 13.883854
|
||||
9, shijiazhuang, blue, 0, 1575129664000, 33, 14.299554
|
||||
9, shijiazhuang, blue, 0, 1575129665000, 30, 16.445130
|
||||
9, shijiazhuang, blue, 0, 1575129666000, 15, 18.059404
|
||||
9, shijiazhuang, blue, 0, 1575129667000, 21, 12.348847
|
||||
9, shijiazhuang, blue, 0, 1575129668000, 32, 13.315378
|
||||
9, shijiazhuang, blue, 0, 1575129669000, 17, 15.689507
|
||||
9, shijiazhuang, blue, 0, 1575129670000, 22, 15.591808
|
||||
9, shijiazhuang, blue, 0, 1575129671000, 27, 16.386065
|
||||
9, shijiazhuang, blue, 0, 1575129672000, 25, 10.564803
|
||||
9, shijiazhuang, blue, 0, 1575129673000, 20, 12.276544
|
||||
9, shijiazhuang, blue, 0, 1575129674000, 26, 15.828786
|
||||
9, shijiazhuang, blue, 0, 1575129675000, 18, 12.236420
|
||||
9, shijiazhuang, blue, 0, 1575129676000, 15, 19.439522
|
||||
9, shijiazhuang, blue, 0, 1575129677000, 19, 19.831531
|
||||
9, shijiazhuang, blue, 0, 1575129678000, 22, 17.115744
|
||||
9, shijiazhuang, blue, 0, 1575129679000, 29, 19.879456
|
||||
9, shijiazhuang, blue, 0, 1575129680000, 34, 10.207136
|
||||
9, shijiazhuang, blue, 0, 1575129681000, 16, 17.633523
|
||||
9, shijiazhuang, blue, 0, 1575129682000, 15, 14.227873
|
||||
9, shijiazhuang, blue, 0, 1575129683000, 34, 12.027768
|
||||
9, shijiazhuang, blue, 0, 1575129684000, 22, 11.376610
|
||||
9, shijiazhuang, blue, 0, 1575129685000, 21, 11.711299
|
||||
9, shijiazhuang, blue, 0, 1575129686000, 33, 14.281126
|
||||
9, shijiazhuang, blue, 0, 1575129687000, 31, 10.895302
|
||||
9, shijiazhuang, blue, 0, 1575129688000, 31, 13.971350
|
||||
9, shijiazhuang, blue, 0, 1575129689000, 15, 15.262790
|
||||
9, shijiazhuang, blue, 0, 1575129690000, 23, 12.440568
|
||||
9, shijiazhuang, blue, 0, 1575129691000, 32, 19.731267
|
||||
9, shijiazhuang, blue, 0, 1575129692000, 22, 10.518092
|
||||
9, shijiazhuang, blue, 0, 1575129693000, 34, 17.863021
|
||||
9, shijiazhuang, blue, 0, 1575129694000, 28, 11.478909
|
||||
9, shijiazhuang, blue, 0, 1575129695000, 16, 15.075524
|
||||
9, shijiazhuang, blue, 0, 1575129696000, 16, 10.292127
|
||||
9, shijiazhuang, blue, 0, 1575129697000, 22, 13.716012
|
||||
9, shijiazhuang, blue, 0, 1575129698000, 32, 10.906551
|
||||
9, shijiazhuang, blue, 0, 1575129699000, 19, 18.386868
|
|
|
@ -0,0 +1,8 @@
|
|||
module github.com/taosdata/TDengine/importSampleData
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/pelletier/go-toml v1.9.0 // indirect
|
||||
github.com/taosdata/driver-go v0.0.0-20210415143420-d99751356e28 // indirect
|
||||
)
|
|
@ -14,23 +14,23 @@ var (
|
|||
once sync.Once
|
||||
)
|
||||
|
||||
// Config inclue all scene import config
|
||||
// Config include all scene import config
|
||||
type Config struct {
|
||||
UserCases map[string]CaseConfig
|
||||
}
|
||||
|
||||
// CaseConfig include the sample data config and tdengine config
|
||||
type CaseConfig struct {
|
||||
Format string
|
||||
FilePath string
|
||||
Separator string
|
||||
Stname string
|
||||
SubTableName string
|
||||
Timestamp string
|
||||
TimestampType string
|
||||
TimestampTypeFormat string
|
||||
Tags []FieldInfo
|
||||
Fields []FieldInfo
|
||||
Format string
|
||||
FilePath string
|
||||
Separator string
|
||||
StName string
|
||||
SubTableName string
|
||||
Timestamp string
|
||||
TimestampType string
|
||||
TimestampTypeFormat string
|
||||
Tags []FieldInfo
|
||||
Fields []FieldInfo
|
||||
}
|
||||
|
||||
// FieldInfo is field or tag info
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
name: tdengine
|
||||
base: core18
|
||||
version: '2.0.20.2'
|
||||
|
||||
version: '2.1.0.0'
|
||||
icon: snap/gui/t-dengine.svg
|
||||
summary: an open-source big data platform designed and optimized for IoT.
|
||||
description: |
|
||||
|
@ -72,7 +73,7 @@ parts:
|
|||
- usr/bin/taosd
|
||||
- usr/bin/taos
|
||||
- usr/bin/taosdemo
|
||||
- usr/lib/libtaos.so.2.0.20.2
|
||||
- usr/lib/libtaos.so.2.1.0.0
|
||||
- usr/lib/libtaos.so.1
|
||||
- usr/lib/libtaos.so
|
||||
|
||||
|
|
|
@ -44,23 +44,15 @@ typedef struct SLocalMerger {
|
|||
int32_t numOfCompleted;
|
||||
int32_t numOfVnode;
|
||||
SLoserTreeInfo * pLoserTree;
|
||||
char * prevRowOfInput;
|
||||
tFilePage * pResultBuf;
|
||||
int32_t nResultBufSize;
|
||||
tFilePage * pTempBuffer;
|
||||
struct SQLFunctionCtx *pCtx;
|
||||
int32_t rowSize; // size of each intermediate result.
|
||||
bool hasPrevRow; // cannot be released
|
||||
bool hasUnprocessedRow;
|
||||
tOrderDescriptor * pDesc;
|
||||
SColumnModel * resColModel;
|
||||
SColumnModel* finalModel;
|
||||
tExtMemBuffer ** pExtMemBuffer; // disk-based buffer
|
||||
SFillInfo* pFillInfo; // interpolation support structure
|
||||
char* pFinalRes; // result data after interpo
|
||||
tFilePage* discardData;
|
||||
bool discard;
|
||||
int32_t offset; // limit offset value
|
||||
bool orderPrjOnSTable; // projection query on stable
|
||||
} SLocalMerger;
|
||||
|
||||
|
@ -94,7 +86,7 @@ void tscCreateLocalMerger(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrde
|
|||
|
||||
void tscDestroyLocalMerger(SSqlObj *pSql);
|
||||
|
||||
int32_t tscDoLocalMerge(SSqlObj *pSql);
|
||||
//int32_t tscDoLocalMerge(SSqlObj *pSql);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -85,15 +85,13 @@ typedef struct SMergeTsCtx {
|
|||
int8_t compared;
|
||||
}SMergeTsCtx;
|
||||
|
||||
|
||||
typedef struct SVgroupTableInfo {
|
||||
SVgroupInfo vgInfo;
|
||||
SArray* itemList; //SArray<STableIdInfo>
|
||||
SArray *itemList; // SArray<STableIdInfo>
|
||||
} SVgroupTableInfo;
|
||||
|
||||
static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
||||
static FORCE_INLINE SQueryInfo* tscGetQueryInfo(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
||||
assert(pCmd != NULL && subClauseIndex >= 0);
|
||||
|
||||
if (pCmd->pQueryInfo == NULL || subClauseIndex >= pCmd->numOfClause) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -101,6 +99,8 @@ static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t sub
|
|||
return pCmd->pQueryInfo[subClauseIndex];
|
||||
}
|
||||
|
||||
SQueryInfo* tscGetActiveQueryInfo(SSqlCmd* pCmd);
|
||||
|
||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta);
|
||||
void tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf);
|
||||
|
@ -129,7 +129,13 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
|
|||
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
||||
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
|
||||
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
|
||||
bool tscIsTopbotQuery(SQueryInfo* pQueryInfo);
|
||||
bool tscIsTopBotQuery(SQueryInfo* pQueryInfo);
|
||||
bool hasTagValOutput(SQueryInfo* pQueryInfo);
|
||||
bool timeWindowInterpoRequired(SQueryInfo *pQueryInfo);
|
||||
bool isStabledev(SQueryInfo* pQueryInfo);
|
||||
bool isTsCompQuery(SQueryInfo* pQueryInfo);
|
||||
bool isSimpleAggregate(SQueryInfo* pQueryInfo);
|
||||
bool isBlockDistQuery(SQueryInfo* pQueryInfo);
|
||||
int32_t tscGetTopbotQueryParam(SQueryInfo* pQueryInfo);
|
||||
|
||||
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||
|
@ -143,7 +149,7 @@ bool tscQueryTags(SQueryInfo* pQueryInfo);
|
|||
bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo);
|
||||
|
||||
SSqlExpr* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
|
||||
SExprInfo* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
|
||||
SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType);
|
||||
|
||||
int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SStrToken* pzTableName, SSqlObj* pSql);
|
||||
|
@ -175,27 +181,29 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes)
|
|||
|
||||
int32_t tscGetResRowLength(SArray* pExprList);
|
||||
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
SExprInfo* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t resColId, int16_t interSize, bool isTagCol);
|
||||
|
||||
SSqlExpr* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
SExprInfo* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t resColId, int16_t interSize, bool isTagCol);
|
||||
|
||||
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
SExprInfo* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
int16_t size);
|
||||
size_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
|
||||
void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
|
||||
void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t uid);
|
||||
|
||||
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
||||
SExprInfo* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
||||
int32_t tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
||||
void tscSqlExprAssign(SExprInfo* dst, const SExprInfo* src);
|
||||
void tscSqlExprInfoDestroy(SArray* pExprInfo);
|
||||
|
||||
SColumn* tscColumnClone(const SColumn* src);
|
||||
bool tscColumnExists(SArray* pColumnList, SColumnIndex* pColIndex);
|
||||
SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex);
|
||||
SArray* tscColumnListClone(const SArray* src, int16_t tableIndex);
|
||||
bool tscColumnExists(SArray* pColumnList, int32_t columnIndex, uint64_t uid);
|
||||
SColumn* tscColumnListInsert(SArray* pColumnList, int32_t columnIndex, uint64_t uid, SSchema* pSchema);
|
||||
void tscColumnListDestroy(SArray* pColList);
|
||||
|
||||
void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo);
|
||||
|
||||
void tscDequoteAndTrimToken(SStrToken* pToken);
|
||||
int32_t tscValidateName(SStrToken* pToken);
|
||||
|
||||
|
@ -217,8 +225,11 @@ bool tscShouldBeFreed(SSqlObj* pSql);
|
|||
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
|
||||
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||
|
||||
SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||
SQueryInfo *tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex);
|
||||
void tscInitQueryInfo(SQueryInfo* pQueryInfo);
|
||||
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
||||
int32_t tscAddQueryInfo(SSqlCmd *pCmd);
|
||||
SQueryInfo *tscGetQueryInfo(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||
SQueryInfo *tscGetQueryInfoS(SSqlCmd *pCmd, int32_t subClauseIndex);
|
||||
|
||||
void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo);
|
||||
|
||||
|
@ -226,11 +237,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, SName* name, STableM
|
|||
SVgroupsInfo* vgroupList, SArray* pTagCols, SArray* pVgroupTables);
|
||||
|
||||
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo);
|
||||
int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
|
||||
|
||||
void tscInitQueryInfo(SQueryInfo* pQueryInfo);
|
||||
|
||||
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
||||
void tscFreeVgroupTableInfo(SArray* pVgroupTables);
|
||||
SArray* tscVgroupTableInfoDup(SArray* pVgroupTables);
|
||||
void tscRemoveVgroupTableGroup(SArray* pVgroupTable, int32_t index);
|
||||
|
@ -242,6 +249,8 @@ int tscGetTableMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool creat
|
|||
|
||||
void tscResetForNextRetrieve(SSqlRes* pRes);
|
||||
void tscDoQuery(SSqlObj* pSql);
|
||||
void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo);
|
||||
void doExecuteQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo);
|
||||
|
||||
SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *pInfo);
|
||||
void* tscVgroupInfoClear(SVgroupsInfo *pInfo);
|
||||
|
@ -275,7 +284,7 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex);
|
|||
int16_t tscGetJoinTagColIdByUid(STagCond* pTagCond, uint64_t uid);
|
||||
int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId);
|
||||
|
||||
void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex);
|
||||
void tscPrintSelNodeList(SSqlObj* pSql, int32_t subClauseIndex);
|
||||
|
||||
bool hasMoreVnodesToTry(SSqlObj *pSql);
|
||||
bool hasMoreClauseToTry(SSqlObj* pSql);
|
||||
|
@ -300,7 +309,10 @@ CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta);
|
|||
uint32_t tscGetTableMetaMaxSize();
|
||||
int32_t tscCreateTableMetaFromCChildMeta(STableMeta* pChild, const char* name, void* buf);
|
||||
STableMeta* tscTableMetaDup(STableMeta* pTableMeta);
|
||||
int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr);
|
||||
|
||||
void tsCreateSQLFunctionCtx(SQueryInfo* pQueryInfo, SQLFunctionCtx* pCtx, SSchema* pSchema);
|
||||
void* createQueryInfoFromQueryNode(SQueryInfo* pQueryInfo, SExprInfo* pExprs, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage);
|
||||
|
||||
void* malloc_throw(size_t size);
|
||||
void* calloc_throw(size_t nmemb, size_t size);
|
||||
|
|
|
@ -35,6 +35,7 @@ extern "C" {
|
|||
#include "qExecutor.h"
|
||||
#include "qSqlparser.h"
|
||||
#include "qTsbuf.h"
|
||||
#include "qUtil.h"
|
||||
#include "tcmdtype.h"
|
||||
|
||||
// forward declaration
|
||||
|
@ -97,12 +98,22 @@ typedef struct STableMetaInfo {
|
|||
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||
} STableMetaInfo;
|
||||
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
int16_t tableIndex;
|
||||
int16_t columnIndex;
|
||||
} SColumnIndex;
|
||||
|
||||
typedef struct SColumn {
|
||||
uint64_t tableUid;
|
||||
int32_t columnIndex;
|
||||
SColumnInfo info;
|
||||
} SColumn;
|
||||
|
||||
typedef struct SInternalField {
|
||||
TAOS_FIELD field;
|
||||
bool visible;
|
||||
SExprInfo *pExpr;
|
||||
} SInternalField;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
|
@ -110,43 +121,6 @@ typedef struct SFieldInfo {
|
|||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SColumn {
|
||||
SColumnIndex colIndex;
|
||||
int32_t numOfFilters;
|
||||
SColumnFilterInfo *filterInfo;
|
||||
} SColumn;
|
||||
|
||||
/* the structure for sql function in select clause */
|
||||
typedef struct SSqlExpr {
|
||||
char aliasName[TSDB_COL_NAME_LEN]; // as aliasName
|
||||
SColIndex colInfo;
|
||||
uint64_t uid; // refactor use the pointer
|
||||
int16_t functionId; // function id in aAgg array
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
int32_t interBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
int32_t offset; // sub result column value of arithmetic expression.
|
||||
int16_t resColId; // result column id
|
||||
SColumn *pFilter; // expr filter
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SExprFilter {
|
||||
tSqlExpr *pExpr; //used for having parse
|
||||
SSqlExpr *pSqlExpr;
|
||||
SArray *fp;
|
||||
SColumn *pFilters; //having filter info
|
||||
}SExprFilter;
|
||||
|
||||
typedef struct SInternalField {
|
||||
TAOS_FIELD field;
|
||||
bool visible;
|
||||
SExprInfo *pArithExprInfo;
|
||||
SSqlExpr *pSqlExpr;
|
||||
SExprFilter *pFieldFilters;
|
||||
} SInternalField;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
|
@ -161,7 +135,7 @@ typedef struct SJoinNode {
|
|||
} SJoinNode;
|
||||
|
||||
typedef struct SJoinInfo {
|
||||
bool hasJoin;
|
||||
bool hasJoin;
|
||||
SJoinNode* joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
} SJoinInfo;
|
||||
|
||||
|
@ -230,13 +204,14 @@ typedef struct SQueryInfo {
|
|||
SInterval interval; // tumble time window
|
||||
SSessionWindow sessionWindow; // session time window
|
||||
|
||||
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
||||
SSqlGroupbyExpr groupbyExpr; // groupby tags info
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SArray * exprList; // SArray<SSqlExpr*>
|
||||
SArray * exprList; // SArray<SExprInfo*>
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
STagCond tagCond;
|
||||
|
||||
SOrderVal order;
|
||||
int16_t fillType; // final result fill type
|
||||
int16_t numOfTables;
|
||||
|
@ -255,7 +230,15 @@ typedef struct SQueryInfo {
|
|||
int32_t round; // 0/1/....
|
||||
int32_t bufLen;
|
||||
char* buf;
|
||||
int32_t havingFieldNum;
|
||||
SQInfo* pQInfo; // global merge operator
|
||||
SArray* pDSOperator; // data source operator
|
||||
SArray* pPhyOperator; // physical query execution plan
|
||||
SQueryAttr* pQueryAttr; // query object
|
||||
|
||||
struct SQueryInfo *sibling; // sibling
|
||||
SArray *pUpstream; // SArray<struct SQueryInfo>
|
||||
struct SQueryInfo *pDownstream;
|
||||
int32_t havingFieldNum;
|
||||
} SQueryInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -270,8 +253,6 @@ typedef struct {
|
|||
};
|
||||
|
||||
uint32_t insertType; // TODO remove it
|
||||
int32_t clauseIndex; // index of multiple subclause query
|
||||
|
||||
char * curSql; // current sql, resume position of sql after parsing paused
|
||||
int8_t parseFinished;
|
||||
char reserve2[3]; // fix bus error on arm32
|
||||
|
@ -281,22 +262,26 @@ typedef struct {
|
|||
uint32_t allocSize;
|
||||
char * payload;
|
||||
int32_t payloadLen;
|
||||
|
||||
SQueryInfo **pQueryInfo;
|
||||
int32_t numOfClause;
|
||||
int32_t clauseIndex; // index of multiple subclause query
|
||||
SQueryInfo *active; // current active query info
|
||||
|
||||
int32_t batchSize; // for parameter ('?') binding and batch processing
|
||||
int32_t numOfParams;
|
||||
|
||||
int8_t dataSourceType; // load data from file or not
|
||||
char reserve4[3]; // fix bus error on arm32
|
||||
char reserve4[3]; // fix bus error on arm32
|
||||
int8_t submitSchema; // submit block is built with table schema
|
||||
char reserve5[3]; // fix bus error on arm32
|
||||
char reserve5[3]; // fix bus error on arm32
|
||||
STagData tagData; // NOTE: pTagData->data is used as a variant length array
|
||||
|
||||
SName **pTableNameList; // all involved tableMeta list of current insert sql statement.
|
||||
int32_t numOfTables;
|
||||
|
||||
SHashObj *pTableBlockHashList; // data block for each table
|
||||
SArray *pDataBlocks; // SArray<STableDataBlocks*>. Merged submit block for each vgroup
|
||||
SArray *pDataBlocks; // SArray<STableDataBlocks*>. Merged submit block for each vgroup
|
||||
} SSqlCmd;
|
||||
|
||||
typedef struct SResRec {
|
||||
|
@ -439,7 +424,7 @@ void tscInitMsgsFp();
|
|||
int tsParseSql(SSqlObj *pSql, bool initial);
|
||||
|
||||
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet);
|
||||
int tscProcessSql(SSqlObj *pSql);
|
||||
int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo);
|
||||
|
||||
int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex);
|
||||
void tscAsyncResultOnError(SSqlObj *pSql);
|
||||
|
@ -454,6 +439,9 @@ void tscRestoreFuncForSTableQuery(SQueryInfo *pQueryInfo);
|
|||
|
||||
int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
|
||||
void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo);
|
||||
void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBlock);
|
||||
|
||||
void handleDownstreamOperator(SSqlRes* pRes, SQueryInfo* pQueryInfo);
|
||||
void destroyTableNameList(SSqlCmd* pCmd);
|
||||
|
||||
void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta);
|
||||
|
@ -501,47 +489,6 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
|
|||
|
||||
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
|
||||
|
||||
static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex, int32_t offset) {
|
||||
SInternalField* pInfo = (SInternalField*) TARRAY_GET_ELEM(pFieldInfo->internalField, columnIndex);
|
||||
|
||||
int32_t type = pInfo->field.type;
|
||||
int32_t bytes = pInfo->field.bytes;
|
||||
|
||||
char* pData = pRes->data + (int32_t)(offset * pRes->numOfRows + bytes * pRes->row);
|
||||
UNUSED(pData);
|
||||
|
||||
// user defined constant value output columns
|
||||
if (pInfo->pSqlExpr != NULL && TSDB_COL_IS_UD_COL(pInfo->pSqlExpr->colInfo.flag)) {
|
||||
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
|
||||
pData = pInfo->pSqlExpr->param[1].pz;
|
||||
pRes->length[columnIndex] = pInfo->pSqlExpr->param[1].nLen;
|
||||
pRes->tsrow[columnIndex] = (pInfo->pSqlExpr->param[1].nType == TSDB_DATA_TYPE_NULL) ? NULL : (unsigned char*)pData;
|
||||
} else {
|
||||
assert(bytes == tDataTypes[type].bytes);
|
||||
|
||||
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)&pInfo->pSqlExpr->param[1].i64;
|
||||
pRes->length[columnIndex] = bytes;
|
||||
}
|
||||
} else {
|
||||
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
|
||||
int32_t realLen = varDataLen(pData);
|
||||
assert(realLen <= bytes - VARSTR_HEADER_SIZE);
|
||||
|
||||
pRes->tsrow[columnIndex] = (isNull(pData, type)) ? NULL : (unsigned char*)((tstr *)pData)->data;
|
||||
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor
|
||||
*(pData + realLen + VARSTR_HEADER_SIZE) = 0;
|
||||
}
|
||||
|
||||
pRes->length[columnIndex] = realLen;
|
||||
} else {
|
||||
assert(bytes == tDataTypes[type].bytes);
|
||||
|
||||
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)pData;
|
||||
pRes->length[columnIndex] = bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int32_t sentinel;
|
||||
extern SHashObj *tscVgroupMap;
|
||||
extern SHashObj *tscTableMetaInfo;
|
||||
|
|
|
@ -69,7 +69,8 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, __async_cb_func_t fp, void* para
|
|||
return;
|
||||
}
|
||||
|
||||
tscDoQuery(pSql);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
executeQuery(pSql, pQueryInfo);
|
||||
}
|
||||
|
||||
// TODO return the correct error code to client in tscQueueAsyncError
|
||||
|
@ -179,7 +180,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
|
|||
if (pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE) {
|
||||
tscFetchDatablockForSubquery(pSql);
|
||||
} else {
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,8 +194,8 @@ static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOf
|
|||
tscProcessAsyncRetrieveImpl(param, tres, numOfRows, tscAsyncFetchRowsProxy);
|
||||
}
|
||||
|
||||
void taos_fetch_rows_a(TAOS_RES *taosa, __async_cb_func_t fp, void *param) {
|
||||
SSqlObj *pSql = (SSqlObj *)taosa;
|
||||
void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) {
|
||||
SSqlObj *pSql = (SSqlObj *)tres;
|
||||
if (pSql == NULL || pSql->signature != pSql) {
|
||||
tscError("sql object is NULL");
|
||||
tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED);
|
||||
|
@ -206,18 +207,16 @@ void taos_fetch_rows_a(TAOS_RES *taosa, __async_cb_func_t fp, void *param) {
|
|||
|
||||
// user-defined callback function is stored in fetchFp
|
||||
pSql->fetchFp = fp;
|
||||
pSql->fp = tscAsyncFetchRowsProxy;
|
||||
pSql->fp = tscAsyncFetchRowsProxy;
|
||||
pSql->param = param;
|
||||
|
||||
if (pRes->qId == 0) {
|
||||
tscError("qhandle is NULL");
|
||||
tscError("qhandle is invalid");
|
||||
pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE;
|
||||
pSql->param = param;
|
||||
|
||||
tscAsyncResultOnError(pSql);
|
||||
return;
|
||||
}
|
||||
|
||||
pSql->param = param;
|
||||
tscResetForNextRetrieve(pRes);
|
||||
|
||||
// handle the sub queries of join query
|
||||
|
@ -255,8 +254,9 @@ void taos_fetch_rows_a(TAOS_RES *taosa, __async_cb_func_t fp, void *param) {
|
|||
if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
|
||||
SQueryInfo* pQueryInfo1 = tscGetActiveQueryInfo(&pSql->cmd);
|
||||
tscBuildAndSendRequest(pSql, pQueryInfo1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ static int32_t updateMetaBeforeRetryQuery(SSqlObj* pSql, STableMetaInfo* pTableM
|
|||
|
||||
SSchema *pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
SSqlExpr *pExpr = &(tscSqlExprGet(pQueryInfo, i)->base);
|
||||
pExpr->uid = pTableMetaInfo->pTableMeta->id.uid;
|
||||
|
||||
if (pExpr->colInfo.colIndex >= 0) {
|
||||
|
@ -344,7 +344,7 @@ static int32_t updateMetaBeforeRetryQuery(SSqlObj* pSql, STableMetaInfo* pTableM
|
|||
// validate the table columns information
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pQueryInfo->colList); ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
|
||||
if (pCol->colIndex.columnIndex >= numOfCols) {
|
||||
if (pCol->columnIndex >= numOfCols) {
|
||||
return pSql->retryReason;
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
tscDebug("0x%"PRIx64" get %s successfully", pSql->self, msg);
|
||||
if (pSql->pStream == NULL) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
|
||||
// check if it is a sub-query of super table query first, if true, enter another routine
|
||||
if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, (TSDB_QUERY_TYPE_STABLE_SUBQUERY|TSDB_QUERY_TYPE_SUBQUERY|TSDB_QUERY_TYPE_TAG_FILTER_QUERY))) {
|
||||
|
@ -396,8 +396,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
goto _error;
|
||||
}
|
||||
|
||||
// tscProcessSql can add error into async res
|
||||
tscProcessSql(pSql);
|
||||
// tscBuildAndSendRequest can add error into async res
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else { // continue to process normal async query
|
||||
|
@ -428,9 +428,9 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
goto _error;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
} else { // in all other cases, simple retry
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
|
@ -447,21 +447,29 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
}
|
||||
|
||||
if (pCmd->insertType == TSDB_QUERY_TYPE_STMT_INSERT) {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else {
|
||||
assert(code == TSDB_CODE_SUCCESS);
|
||||
assert(code == TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
(*pSql->fp)(pSql->param, pSql, code);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT)) {
|
||||
if (pCmd->dataSourceType == DATA_FROM_DATA_FILE) {
|
||||
tscImportDataFromFile(pSql);
|
||||
} else {
|
||||
tscHandleMultivnodeInsert(pSql);
|
||||
}
|
||||
} else {
|
||||
SQueryInfo* pQueryInfo1 = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
executeQuery(pSql, pQueryInfo1);
|
||||
}
|
||||
|
||||
// proceed to invoke the tscDoQuery();
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +506,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
return;
|
||||
}
|
||||
|
||||
tscDoQuery(pSql);
|
||||
// tscDoQuery(pSql);
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
// one column for each row
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||
|
@ -154,14 +154,14 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
|
||||
pSql->cmd.numOfCols = numOfCols;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE};
|
||||
tstrncpy(f.name, "Field", sizeof(f.name));
|
||||
|
||||
SInternalField* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
(TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE, -1000, (TSDB_COL_NAME_LEN - 1), false);
|
||||
|
||||
rowLen += ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE);
|
||||
|
@ -171,7 +171,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
tstrncpy(f.name, "Type", sizeof(f.name));
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, (int16_t)(typeColLength + VARSTR_HEADER_SIZE),
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, (int16_t)(typeColLength + VARSTR_HEADER_SIZE),
|
||||
-1000, typeColLength, false);
|
||||
|
||||
rowLen += typeColLength + VARSTR_HEADER_SIZE;
|
||||
|
@ -181,7 +181,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
tstrncpy(f.name, "Length", sizeof(f.name));
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t),
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t),
|
||||
-1000, sizeof(int32_t), false);
|
||||
|
||||
rowLen += sizeof(int32_t);
|
||||
|
@ -191,7 +191,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
tstrncpy(f.name, "Note", sizeof(f.name));
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, (int16_t)(noteColLength + VARSTR_HEADER_SIZE),
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, (int16_t)(noteColLength + VARSTR_HEADER_SIZE),
|
||||
-1000, noteColLength, false);
|
||||
|
||||
rowLen += noteColLength + VARSTR_HEADER_SIZE;
|
||||
|
@ -199,7 +199,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
}
|
||||
|
||||
static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
assert(tscGetMetaInfo(pQueryInfo, 0)->pTableMeta != NULL);
|
||||
|
||||
|
@ -389,7 +389,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
|
|||
SColumnIndex index = {0};
|
||||
pSql->cmd.numOfCols = 2;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
TAOS_FIELD f;
|
||||
|
@ -404,7 +404,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
|
|||
}
|
||||
|
||||
SInternalField* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, f.bytes, -1000, f.bytes - VARSTR_HEADER_SIZE, false);
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, f.bytes, -1000, f.bytes - VARSTR_HEADER_SIZE, false);
|
||||
|
||||
rowLen += f.bytes;
|
||||
|
||||
|
@ -417,7 +417,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
|
|||
}
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||
(int16_t)(ddlLen + VARSTR_HEADER_SIZE), -1000, ddlLen, false);
|
||||
|
||||
rowLen += ddlLen + VARSTR_HEADER_SIZE;
|
||||
|
@ -427,7 +427,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const
|
|||
static int32_t tscSCreateSetValueToResObj(SSqlObj *pSql, int32_t rowLen, const char *tableName, const char *ddl) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
int32_t numOfRows = 1;
|
||||
if (strlen(ddl) == 0) {
|
||||
|
||||
|
@ -444,7 +444,7 @@ static int32_t tscSCreateSetValueToResObj(SSqlObj *pSql, int32_t rowLen, const c
|
|||
return 0;
|
||||
}
|
||||
static int32_t tscSCreateBuildResult(SSqlObj *pSql, BuildType type, const char *str, const char *result) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
int32_t rowLen = tscSCreateBuildResultFields(pSql, type, result);
|
||||
|
||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||
|
@ -552,7 +552,7 @@ static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||
|
@ -606,7 +606,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
|
|||
}
|
||||
|
||||
static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||
|
||||
|
@ -633,7 +633,7 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName,
|
|||
}
|
||||
static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||
char *result = ddl;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||
|
||||
|
@ -674,7 +674,7 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
|
|||
}
|
||||
|
||||
static int32_t tscProcessShowCreateTable(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
assert(pTableMetaInfo->pTableMeta != NULL);
|
||||
|
||||
|
@ -700,7 +700,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
|
@ -727,7 +727,7 @@ static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) {
|
|||
return TSDB_CODE_TSC_ACTION_IN_PROGRESS;
|
||||
}
|
||||
static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
pExpr->resBytes = TSDB_USER_LEN + TSDB_DATA_TYPE_BINARY;
|
||||
|
@ -754,7 +754,7 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
|||
extractDBName(pSql->pTscObj->db, db);
|
||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||
|
@ -781,7 +781,7 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
|||
|
||||
static int32_t tscProcessServerVer(SSqlObj *pSql) {
|
||||
const char* v = pSql->pTscObj->sversion;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||
|
@ -804,7 +804,7 @@ static int32_t tscProcessServerVer(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
static int32_t tscProcessClientVer(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||
|
@ -856,7 +856,7 @@ static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
|||
return pSql->res.code;
|
||||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
|
||||
int32_t val = 1;
|
||||
|
@ -870,7 +870,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
|||
|
||||
pCmd->numOfCols = 1;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
@ -882,7 +882,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
|||
tscInitResObjForLocalQuery(pSql, 1, (int32_t)valueLength);
|
||||
|
||||
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, 0);
|
||||
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
pInfo->pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||
|
||||
memcpy(pRes->data, val, pInfo->field.bytes);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
|
|||
} else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) {
|
||||
// do nothing
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
useconds = tsosStr2int64(pToken->z);
|
||||
useconds = taosStr2int64(pToken->z);
|
||||
} else {
|
||||
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -740,7 +740,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
const int32_t STABLE_INDEX = 1;
|
||||
|
||||
SSqlCmd * pCmd = &pSql->cmd;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
|
||||
char *sql = *sqlstr;
|
||||
|
||||
|
@ -821,6 +821,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
index = 0;
|
||||
sToken = tStrGetToken(sql, &index, false);
|
||||
if (sToken.type != TK_TAGS && sToken.type != TK_LP) {
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
|
||||
}
|
||||
|
||||
|
@ -833,6 +834,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
char* end = NULL;
|
||||
code = parseBoundColumns(pCmd, &spd, pTagSchema, sql, &end);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -850,11 +852,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
sql += index;
|
||||
|
||||
if (sToken.type != TK_LP) {
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "( is expected", sToken.z);
|
||||
}
|
||||
|
||||
SKVRowBuilder kvRowBuilder = {0};
|
||||
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -867,6 +871,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
|
||||
if (TK_ILLEGAL == sToken.type) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
|
@ -884,6 +889,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
code = tsParseOneColumn(pSchema, &sToken, tagVal, pCmd->payload, &sql, false, tinfo.precision);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
tscDestroyBoundColumnInfo(&spd);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1093,7 +1099,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
|||
int32_t totalNum = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
assert(pQueryInfo != NULL);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = (pQueryInfo->numOfTables == 0)? tscAddEmptyMetaInfo(pQueryInfo):tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
@ -1313,7 +1319,7 @@ int tsInsertInitialCheck(SSqlObj *pSql) {
|
|||
pCmd->count = 0;
|
||||
pCmd->command = TSDB_SQL_INSERT;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoS(pCmd, pCmd->clauseIndex);
|
||||
|
||||
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT | pCmd->insertType);
|
||||
|
||||
|
@ -1403,7 +1409,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
|
|||
return code;
|
||||
}
|
||||
|
||||
return tscProcessSql(pSql);
|
||||
return tscBuildAndSendRequest(pSql, NULL);
|
||||
}
|
||||
|
||||
typedef struct SImportFileSupport {
|
||||
|
@ -1549,6 +1555,7 @@ void tscImportDataFromFile(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE && strlen(pCmd->payload) != 0);
|
||||
pCmd->active = pCmd->pQueryInfo[0];
|
||||
|
||||
SImportFileSupport *pSupporter = calloc(1, sizeof(SImportFileSupport));
|
||||
SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL);
|
||||
|
|
|
@ -815,7 +815,7 @@ static int insertStmtExecute(STscStmt* stmt) {
|
|||
pRes->numOfRows = 0;
|
||||
pRes->numOfTotal = 0;
|
||||
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
|
||||
// wait for the callback function to post the semaphore
|
||||
tsem_wait(&pSql->rspSem);
|
||||
|
|
|
@ -249,8 +249,8 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
|
|||
pQdesc->stime = htobe64(pSql->stime);
|
||||
pQdesc->queryId = htonl(pSql->queryId);
|
||||
//pQdesc->useconds = htobe64(pSql->res.useconds);
|
||||
pQdesc->useconds = htobe64(now - pSql->stime); // use local time instead of sever rsp elapsed time
|
||||
pQdesc->qHandle = htobe64(pSql->res.qId);
|
||||
pQdesc->useconds = htobe64(now - pSql->stime);
|
||||
pQdesc->qId = htobe64(pSql->res.qId);
|
||||
|
||||
pHeartbeat->numOfQueries++;
|
||||
pQdesc++;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,6 +24,7 @@
|
|||
#include "tsclient.h"
|
||||
#include "ttimer.h"
|
||||
#include "tlockfree.h"
|
||||
#include "qPlan.h"
|
||||
|
||||
int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
|
||||
|
||||
|
@ -269,7 +270,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
|
|||
assert(pHB->self == pObj->hbrid);
|
||||
|
||||
pHB->retry = 0;
|
||||
int32_t code = tscProcessSql(pHB);
|
||||
int32_t code = tscBuildAndSendRequest(pHB, NULL);
|
||||
taosReleaseRef(tscObjRef, pObj->hbrid);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -334,7 +335,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
return;
|
||||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
if (pQueryInfo != NULL && pQueryInfo->type == TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
tscDebug("0x%"PRIx64" sqlObj needs to be released or DB connection is closed, cmd:%d type:%d, pObj:%p signature:%p",
|
||||
pSql->self, pCmd->command, pQueryInfo->type, pObj, pObj->signature);
|
||||
|
@ -457,19 +458,16 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
(*pSql->fp)(pSql->param, pSql, rpcMsg->code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (shouldFree) { // in case of table-meta/vgrouplist query, automatically free it
|
||||
taosRemoveRef(tscObjRef, handle);
|
||||
tscDebug("0x%"PRIx64" sqlObj is automatically freed", pSql->self);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscObjRef, handle);
|
||||
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
}
|
||||
|
||||
int doProcessSql(SSqlObj *pSql) {
|
||||
int doBuildAndSendMsg(SSqlObj *pSql) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
|
@ -501,13 +499,16 @@ int doProcessSql(SSqlObj *pSql) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int tscProcessSql(SSqlObj *pSql) {
|
||||
int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo) {
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
uint32_t type = 0;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
if (pQueryInfo == NULL) {
|
||||
pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
}
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = NULL;
|
||||
|
||||
if (pQueryInfo != NULL) {
|
||||
|
@ -532,15 +533,16 @@ int tscProcessSql(SSqlObj *pSql) {
|
|||
return (*tscProcessMsgRsp[pCmd->command])(pSql);
|
||||
}
|
||||
|
||||
return doProcessSql(pSql);
|
||||
return doBuildAndSendMsg(pSql);
|
||||
}
|
||||
|
||||
int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
pRetrieveMsg->free = htons(pQueryInfo->type);
|
||||
pRetrieveMsg->qId = htobe64(pSql->res.qId);
|
||||
SQueryInfo *pQueryInfo = tscGetActiveQueryInfo(&pSql->cmd);
|
||||
|
||||
pRetrieveMsg->free = htons(pQueryInfo->type);
|
||||
pRetrieveMsg->qId = htobe64(pSql->res.qId);
|
||||
|
||||
// todo valid the vgroupId at the client side
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
@ -579,7 +581,7 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
||||
|
||||
char* pMsg = pSql->cmd.payload;
|
||||
|
@ -618,12 +620,12 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
const static int32_t MIN_QUERY_MSG_PKT_SIZE = TSDB_MAX_BYTES_PER_ROW * 5;
|
||||
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, clauseIndex);
|
||||
|
||||
int32_t srcColListSize = (int32_t)(taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo));
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
int32_t exprSize = (int32_t)(sizeof(SSqlFuncMsg) * numOfExprs * 2);
|
||||
int32_t exprSize = (int32_t)(sizeof(SSqlExpr) * numOfExprs * 2);
|
||||
|
||||
int32_t tsBufSize = (pQueryInfo->tsBuf != NULL) ? pQueryInfo->tsBuf->fileSize : 0;
|
||||
int32_t sqlLen = (int32_t) strlen(pSql->sqlstr) + 1;
|
||||
|
@ -647,8 +649,8 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen;
|
||||
}
|
||||
|
||||
static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg, int32_t *succeed) {
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, 0);
|
||||
static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, char *pMsg,
|
||||
int32_t *succeed) {
|
||||
TSKEY dfltKey = htobe64(pQueryMsg->window.skey);
|
||||
|
||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
|
@ -727,318 +729,214 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
// TODO refactor
|
||||
static int32_t serializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) {
|
||||
// append the filter information after the basic column information
|
||||
for (int32_t f = 0; f < numOfFilters; ++f) {
|
||||
SColumnFilterInfo *pColFilter = &pColFilters[f];
|
||||
|
||||
SColumnFilterInfo *pFilterMsg = (SColumnFilterInfo *)(*pMsg);
|
||||
pFilterMsg->filterstr = htons(pColFilter->filterstr);
|
||||
|
||||
(*pMsg) += sizeof(SColumnFilterInfo);
|
||||
|
||||
if (pColFilter->filterstr) {
|
||||
pFilterMsg->len = htobe64(pColFilter->len);
|
||||
memcpy(*pMsg, (void *)pColFilter->pz, (size_t)(pColFilter->len + 1));
|
||||
(*pMsg) += (pColFilter->len + 1); // append the additional filter binary info
|
||||
} else {
|
||||
pFilterMsg->lowerBndi = htobe64(pColFilter->lowerBndi);
|
||||
pFilterMsg->upperBndi = htobe64(pColFilter->upperBndi);
|
||||
}
|
||||
|
||||
pFilterMsg->lowerRelOptr = htons(pColFilter->lowerRelOptr);
|
||||
pFilterMsg->upperRelOptr = htons(pColFilter->upperRelOptr);
|
||||
|
||||
if (pColFilter->lowerRelOptr == TSDB_RELATION_INVALID && pColFilter->upperRelOptr == TSDB_RELATION_INVALID) {
|
||||
tscError("invalid filter info");
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t serializeSqlExpr(SSqlExpr* pExpr, STableMetaInfo* pTableMetaInfo, char** pMsg, int64_t id, bool validateColumn) {
|
||||
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
|
||||
// the queried table has been removed and a new table with the same name has already been created already
|
||||
// return error msg
|
||||
if (pExpr->uid != pTableMeta->id.uid) {
|
||||
tscError("0x%"PRIx64" table has already been destroyed", id);
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
||||
}
|
||||
|
||||
if (validateColumn && !tscValidateColumnId(pTableMetaInfo, pExpr->colInfo.colId, pExpr->numOfParams)) {
|
||||
tscError("0x%"PRIx64" table schema is not matched with parsed sql", id);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
assert(pExpr->resColId < 0);
|
||||
SSqlExpr* pSqlExpr = (SSqlExpr *)(*pMsg);
|
||||
|
||||
SColIndex* pIndex = &pSqlExpr->colInfo;
|
||||
|
||||
pIndex->colId = htons(pExpr->colInfo.colId);
|
||||
pIndex->colIndex = htons(pExpr->colInfo.colIndex);
|
||||
pIndex->flag = htons(pExpr->colInfo.flag);
|
||||
pSqlExpr->uid = htobe64(pExpr->uid);
|
||||
pSqlExpr->colType = htons(pExpr->colType);
|
||||
pSqlExpr->colBytes = htons(pExpr->colBytes);
|
||||
pSqlExpr->resType = htons(pExpr->resType);
|
||||
pSqlExpr->resBytes = htons(pExpr->resBytes);
|
||||
pSqlExpr->functionId = htons(pExpr->functionId);
|
||||
pSqlExpr->numOfParams = htons(pExpr->numOfParams);
|
||||
pSqlExpr->resColId = htons(pExpr->resColId);
|
||||
pSqlExpr->flist.numOfFilters = htons(pExpr->flist.numOfFilters);
|
||||
|
||||
(*pMsg) += sizeof(SSqlExpr);
|
||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) { // todo add log
|
||||
pSqlExpr->param[j].nType = htons((uint16_t)pExpr->param[j].nType);
|
||||
pSqlExpr->param[j].nLen = htons(pExpr->param[j].nLen);
|
||||
|
||||
if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy((*pMsg), pExpr->param[j].pz, pExpr->param[j].nLen);
|
||||
(*pMsg) += pExpr->param[j].nLen;
|
||||
} else {
|
||||
pSqlExpr->param[j].i64 = htobe64(pExpr->param[j].i64);
|
||||
}
|
||||
}
|
||||
|
||||
serializeColFilterInfo(pExpr->flist.filterInfo, pExpr->flist.numOfFilters, pMsg);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t size = tscEstimateQueryMsgSize(pSql, pCmd->clauseIndex);
|
||||
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
|
||||
tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self);
|
||||
tscError("%p failed to malloc for query msg", pSql);
|
||||
return TSDB_CODE_TSC_INVALID_SQL; // todo add test for this
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetActiveQueryInfo(pCmd);
|
||||
|
||||
SQueryAttr query = {{0}};
|
||||
tscCreateQueryFromQueryInfo(pQueryInfo, &query, pSql);
|
||||
|
||||
SArray* tableScanOperator = createTableScanPlan(&query);
|
||||
SArray* queryOperator = createExecOperatorPlan(&query);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
|
||||
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
|
||||
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo) && !tscQueryBlockInfo(pQueryInfo)) {
|
||||
tscError("0x%"PRIx64" illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", pSql->self, (uint64_t)numOfSrcCols,
|
||||
tscGetNumOfColumns(pTableMeta));
|
||||
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
if (pQueryInfo->interval.interval < 0) {
|
||||
tscError("0x%"PRIx64" illegal value of aggregation time interval in query msg: %" PRId64, pSql->self, (int64_t)pQueryInfo->interval.interval);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
if (pQueryInfo->groupbyExpr.numOfGroupCols < 0) {
|
||||
tscError("0x%"PRIx64" illegal value of numOfGroupCols in query msg: %d", pSql->self, pQueryInfo->groupbyExpr.numOfGroupCols);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pCmd->payload;
|
||||
tstrncpy(pQueryMsg->version, version, tListLen(pQueryMsg->version));
|
||||
|
||||
int32_t numOfTags = (int32_t)taosArrayGetSize(pTableMetaInfo->tagColList);
|
||||
int32_t numOfTags = query.numOfTags;
|
||||
int32_t sqlLen = (int32_t) strlen(pSql->sqlstr);
|
||||
|
||||
if (pQueryInfo->order.order == TSDB_ORDER_ASC) {
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->window.skey);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.ekey);
|
||||
if (taosArrayGetSize(tableScanOperator) == 0) {
|
||||
pQueryMsg->tableScanOperator = htonl(-1);
|
||||
} else {
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->window.ekey);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.skey);
|
||||
int32_t* tablescanOp = taosArrayGet(tableScanOperator, 0);
|
||||
pQueryMsg->tableScanOperator = htonl(*tablescanOp);
|
||||
}
|
||||
|
||||
pQueryMsg->order = htons(pQueryInfo->order.order);
|
||||
pQueryMsg->orderColId = htons(pQueryInfo->order.orderColId);
|
||||
pQueryMsg->fillType = htons(pQueryInfo->fillType);
|
||||
pQueryMsg->limit = htobe64(pQueryInfo->limit.limit);
|
||||
pQueryMsg->offset = htobe64(pQueryInfo->limit.offset);
|
||||
pQueryMsg->numOfCols = htons((int16_t)taosArrayGetSize(pQueryInfo->colList));
|
||||
pQueryMsg->interval.interval = htobe64(pQueryInfo->interval.interval);
|
||||
pQueryMsg->interval.sliding = htobe64(pQueryInfo->interval.sliding);
|
||||
pQueryMsg->interval.offset = htobe64(pQueryInfo->interval.offset);
|
||||
pQueryMsg->interval.intervalUnit = pQueryInfo->interval.intervalUnit;
|
||||
pQueryMsg->interval.slidingUnit = pQueryInfo->interval.slidingUnit;
|
||||
pQueryMsg->interval.offsetUnit = pQueryInfo->interval.offsetUnit;
|
||||
pQueryMsg->window.skey = htobe64(query.window.skey);
|
||||
pQueryMsg->window.ekey = htobe64(query.window.ekey);
|
||||
|
||||
pQueryMsg->order = htons(query.order.order);
|
||||
pQueryMsg->orderColId = htons(query.order.orderColId);
|
||||
pQueryMsg->fillType = htons(query.fillType);
|
||||
pQueryMsg->limit = htobe64(query.limit.limit);
|
||||
pQueryMsg->offset = htobe64(query.limit.offset);
|
||||
pQueryMsg->numOfCols = htons(query.numOfCols);
|
||||
|
||||
pQueryMsg->interval.interval = htobe64(query.interval.interval);
|
||||
pQueryMsg->interval.sliding = htobe64(query.interval.sliding);
|
||||
pQueryMsg->interval.offset = htobe64(query.interval.offset);
|
||||
pQueryMsg->interval.intervalUnit = query.interval.intervalUnit;
|
||||
pQueryMsg->interval.slidingUnit = query.interval.slidingUnit;
|
||||
pQueryMsg->interval.offsetUnit = query.interval.offsetUnit;
|
||||
|
||||
pQueryMsg->stableQuery = query.stableQuery;
|
||||
pQueryMsg->topBotQuery = query.topBotQuery;
|
||||
pQueryMsg->groupbyColumn = query.groupbyColumn;
|
||||
pQueryMsg->hasTagResults = query.hasTagResults;
|
||||
pQueryMsg->timeWindowInterpo = query.timeWindowInterpo;
|
||||
pQueryMsg->queryBlockDist = query.queryBlockDist;
|
||||
pQueryMsg->stabledev = query.stabledev;
|
||||
pQueryMsg->tsCompQuery = query.tsCompQuery;
|
||||
pQueryMsg->simpleAgg = query.simpleAgg;
|
||||
pQueryMsg->pointInterpQuery = query.pointInterpQuery;
|
||||
pQueryMsg->needReverseScan = query.needReverseScan;
|
||||
|
||||
pQueryMsg->numOfTags = htonl(numOfTags);
|
||||
pQueryMsg->sqlstrLen = htonl(sqlLen);
|
||||
pQueryMsg->sw.gap = htobe64(query.sw.gap);
|
||||
pQueryMsg->sw.primaryColId = htonl(PRIMARYKEY_TIMESTAMP_COL_INDEX);
|
||||
|
||||
pQueryMsg->secondStageOutput = htonl(query.numOfExpr2);
|
||||
pQueryMsg->numOfOutput = htons((int16_t)query.numOfOutput); // this is the stage one output column number
|
||||
|
||||
pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols);
|
||||
pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType);
|
||||
pQueryMsg->tbnameCondLen = htonl(pQueryInfo->tagCond.tbnameCond.len);
|
||||
pQueryMsg->numOfTags = htonl(numOfTags);
|
||||
pQueryMsg->queryType = htonl(pQueryInfo->type);
|
||||
pQueryMsg->vgroupLimit = htobe64(pQueryInfo->vgroupLimit);
|
||||
pQueryMsg->sqlstrLen = htonl(sqlLen);
|
||||
pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen);
|
||||
pQueryMsg->sw.gap = htobe64(pQueryInfo->sessionWindow.gap);
|
||||
pQueryMsg->sw.primaryColId = htonl(PRIMARYKEY_TIMESTAMP_COL_INDEX);
|
||||
|
||||
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
pQueryMsg->numOfOutput = htons((int16_t)numOfOutput); // this is the stage one output column number
|
||||
|
||||
// set column list ids
|
||||
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
|
||||
char *pMsg = (char *)(pQueryMsg->colList) + numOfCols * sizeof(SColumnInfo);
|
||||
SSchema *pSchema = tscGetTableSchema(pTableMeta);
|
||||
|
||||
char *pMsg = (char *)(pQueryMsg->tableCols) + numOfCols * sizeof(SColumnInfo);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
|
||||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
SColumnInfo *pCol = &query.tableCols[i];
|
||||
|
||||
if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || !isValidDataType(pColSchema->type)) {
|
||||
char n[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameExtractFullName(&pTableMetaInfo->name, n);
|
||||
|
||||
|
||||
tscError("0x%"PRIx64" tid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s",
|
||||
pSql->self, pTableMeta->id.tid, pTableMeta->id.uid, n, tscGetNumOfColumns(pTableMeta), pCol->colIndex.columnIndex,
|
||||
pColSchema->name);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
pQueryMsg->colList[i].colId = htons(pColSchema->colId);
|
||||
pQueryMsg->colList[i].bytes = htons(pColSchema->bytes);
|
||||
pQueryMsg->colList[i].type = htons(pColSchema->type);
|
||||
pQueryMsg->colList[i].numOfFilters = htons(pCol->numOfFilters);
|
||||
pQueryMsg->tableCols[i].colId = htons(pCol->colId);
|
||||
pQueryMsg->tableCols[i].bytes = htons(pCol->bytes);
|
||||
pQueryMsg->tableCols[i].type = htons(pCol->type);
|
||||
pQueryMsg->tableCols[i].flist.numOfFilters = htons(pCol->flist.numOfFilters);
|
||||
|
||||
// append the filter information after the basic column information
|
||||
for (int32_t f = 0; f < pCol->numOfFilters; ++f) {
|
||||
SColumnFilterInfo *pColFilter = &pCol->filterInfo[f];
|
||||
serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg);
|
||||
}
|
||||
|
||||
SColumnFilterInfo *pFilterMsg = (SColumnFilterInfo *)pMsg;
|
||||
pFilterMsg->filterstr = htons(pColFilter->filterstr);
|
||||
|
||||
pMsg += sizeof(SColumnFilterInfo);
|
||||
|
||||
if (pColFilter->filterstr) {
|
||||
pFilterMsg->len = htobe64(pColFilter->len);
|
||||
memcpy(pMsg, (void *)pColFilter->pz, (size_t)(pColFilter->len + 1));
|
||||
pMsg += (pColFilter->len + 1); // append the additional filter binary info
|
||||
} else {
|
||||
pFilterMsg->lowerBndi = htobe64(pColFilter->lowerBndi);
|
||||
pFilterMsg->upperBndi = htobe64(pColFilter->upperBndi);
|
||||
}
|
||||
|
||||
pFilterMsg->lowerRelOptr = htons(pColFilter->lowerRelOptr);
|
||||
pFilterMsg->upperRelOptr = htons(pColFilter->upperRelOptr);
|
||||
|
||||
if (pColFilter->lowerRelOptr == TSDB_RELATION_INVALID && pColFilter->upperRelOptr == TSDB_RELATION_INVALID) {
|
||||
tscError("invalid filter info");
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
for (int32_t i = 0; i < query.numOfOutput; ++i) {
|
||||
code = serializeSqlExpr(&query.pExpr1[i].base, pTableMetaInfo, &pMsg, pSql->self, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
SSqlFuncMsg *pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
for (int32_t i = 0; i < tscSqlExprNumOfExprs(pQueryInfo); ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
// the queried table has been removed and a new table with the same name has already been created already
|
||||
// return error msg
|
||||
if (pExpr->uid != pTableMeta->id.uid) {
|
||||
tscError("0x%"PRIx64" table has already been destroyed", pSql->self);
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
||||
for (int32_t i = 0; i < query.numOfExpr2; ++i) {
|
||||
code = serializeSqlExpr(&query.pExpr2[i].base, pTableMetaInfo, &pMsg, pSql->self, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!tscValidateColumnId(pTableMetaInfo, pExpr->colInfo.colId, pExpr->numOfParams)) {
|
||||
tscError("0x%"PRIx64" table schema is not matched with parsed sql", pSql->self);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
assert(pExpr->resColId < 0);
|
||||
|
||||
pSqlFuncExpr->colInfo.colId = htons(pExpr->colInfo.colId);
|
||||
pSqlFuncExpr->colInfo.colIndex = htons(pExpr->colInfo.colIndex);
|
||||
pSqlFuncExpr->colInfo.flag = htons(pExpr->colInfo.flag);
|
||||
|
||||
if (TSDB_COL_IS_UD_COL(pExpr->colInfo.flag)) {
|
||||
pSqlFuncExpr->colType = htons(pExpr->resType);
|
||||
pSqlFuncExpr->colBytes = htons(pExpr->resBytes);
|
||||
} else if (pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
SSchema *s = tGetTbnameColumnSchema();
|
||||
|
||||
pSqlFuncExpr->colType = htons(s->type);
|
||||
pSqlFuncExpr->colBytes = htons(s->bytes);
|
||||
} else if (pExpr->colInfo.colId == TSDB_BLOCK_DIST_COLUMN_INDEX) {
|
||||
SSchema s = tGetBlockDistColumnSchema();
|
||||
|
||||
pSqlFuncExpr->colType = htons(s.type);
|
||||
pSqlFuncExpr->colBytes = htons(s.bytes);
|
||||
} else {
|
||||
SSchema* s = tscGetColumnSchemaById(pTableMeta, pExpr->colInfo.colId);
|
||||
pSqlFuncExpr->colType = htons(s->type);
|
||||
pSqlFuncExpr->colBytes = htons(s->bytes);
|
||||
}
|
||||
|
||||
pSqlFuncExpr->functionId = htons(pExpr->functionId);
|
||||
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
|
||||
pSqlFuncExpr->resColId = htons(pExpr->resColId);
|
||||
if (pTableMeta->tableType != TSDB_SUPER_TABLE && pExpr->pFilter && pExpr->pFilter->numOfFilters > 0) {
|
||||
pSqlFuncExpr->filterNum = htonl(pExpr->pFilter->numOfFilters);
|
||||
} else {
|
||||
pSqlFuncExpr->filterNum = 0;
|
||||
}
|
||||
|
||||
pMsg += sizeof(SSqlFuncMsg);
|
||||
|
||||
if (pSqlFuncExpr->filterNum) {
|
||||
pMsg += sizeof(SColumnFilterInfo) * pExpr->pFilter->numOfFilters;
|
||||
|
||||
// append the filter information after the basic column information
|
||||
for (int32_t f = 0; f < pExpr->pFilter->numOfFilters; ++f) {
|
||||
SColumnFilterInfo *pColFilter = &pExpr->pFilter->filterInfo[f];
|
||||
|
||||
SColumnFilterInfo *pFilterMsg = &pSqlFuncExpr->filterInfo[f];
|
||||
pFilterMsg->filterstr = htons(pColFilter->filterstr);
|
||||
|
||||
if (pColFilter->filterstr) {
|
||||
pFilterMsg->len = htobe64(pColFilter->len);
|
||||
memcpy(pMsg, (void *)pColFilter->pz, (size_t)(pColFilter->len + 1));
|
||||
pMsg += (pColFilter->len + 1); // append the additional filter binary info
|
||||
} else {
|
||||
pFilterMsg->lowerBndi = htobe64(pColFilter->lowerBndi);
|
||||
pFilterMsg->upperBndi = htobe64(pColFilter->upperBndi);
|
||||
}
|
||||
|
||||
pFilterMsg->lowerRelOptr = htons(pColFilter->lowerRelOptr);
|
||||
pFilterMsg->upperRelOptr = htons(pColFilter->upperRelOptr);
|
||||
|
||||
if (pColFilter->lowerRelOptr == TSDB_RELATION_INVALID && pColFilter->upperRelOptr == TSDB_RELATION_INVALID) {
|
||||
tscError("invalid filter info");
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) { // todo add log
|
||||
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
||||
pSqlFuncExpr->arg[j].argBytes = htons(pExpr->param[j].nLen);
|
||||
|
||||
if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
|
||||
pMsg += pExpr->param[j].nLen;
|
||||
} else {
|
||||
pSqlFuncExpr->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64);
|
||||
}
|
||||
}
|
||||
|
||||
pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
}
|
||||
|
||||
size_t output = tscNumOfFields(pQueryInfo);
|
||||
|
||||
if (tscIsSecondStageQuery(pQueryInfo)) {
|
||||
pQueryMsg->secondStageOutput = htonl((int32_t) output);
|
||||
|
||||
SSqlFuncMsg *pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
|
||||
|
||||
for (int32_t i = 0; i < output; ++i) {
|
||||
SInternalField* pField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i);
|
||||
SSqlExpr *pExpr = pField->pSqlExpr;
|
||||
|
||||
// this should be switched to projection query
|
||||
if (pExpr != NULL) {
|
||||
// the queried table has been removed and a new table with the same name has already been created already
|
||||
// return error msg
|
||||
if (pExpr->uid != pTableMeta->id.uid) {
|
||||
tscError("0x%"PRIx64" table has already been destroyed", pSql->self);
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
||||
}
|
||||
|
||||
if (!tscValidateColumnId(pTableMetaInfo, pExpr->colInfo.colId, pExpr->numOfParams)) {
|
||||
tscError("0x%"PRIx64" table schema is not matched with parsed sql", pSql->self);
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
pSqlFuncExpr1->numOfParams = 0; // no params for projection query
|
||||
pSqlFuncExpr1->functionId = htons(TSDB_FUNC_PRJ);
|
||||
pSqlFuncExpr1->colInfo.colId = htons(pExpr->resColId);
|
||||
pSqlFuncExpr1->colInfo.flag = htons(TSDB_COL_NORMAL);
|
||||
|
||||
bool assign = false;
|
||||
for (int32_t f = 0; f < tscSqlExprNumOfExprs(pQueryInfo); ++f) {
|
||||
SSqlExpr *pe = tscSqlExprGet(pQueryInfo, f);
|
||||
if (pe == pExpr) {
|
||||
pSqlFuncExpr1->colInfo.colIndex = htons(f);
|
||||
pSqlFuncExpr1->colType = htons(pe->resType);
|
||||
pSqlFuncExpr1->colBytes = htons(pe->resBytes);
|
||||
assign = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(assign);
|
||||
pMsg += sizeof(SSqlFuncMsg);
|
||||
pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
|
||||
} else {
|
||||
assert(pField->pArithExprInfo != NULL);
|
||||
SExprInfo* pExprInfo = pField->pArithExprInfo;
|
||||
|
||||
pSqlFuncExpr1->colInfo.colId = htons(pExprInfo->base.colInfo.colId);
|
||||
pSqlFuncExpr1->functionId = htons(pExprInfo->base.functionId);
|
||||
pSqlFuncExpr1->numOfParams = htons(pExprInfo->base.numOfParams);
|
||||
pMsg += sizeof(SSqlFuncMsg);
|
||||
|
||||
for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
||||
// todo add log
|
||||
pSqlFuncExpr1->arg[j].argType = htons((uint16_t)pExprInfo->base.arg[j].argType);
|
||||
pSqlFuncExpr1->arg[j].argBytes = htons(pExprInfo->base.arg[j].argBytes);
|
||||
|
||||
if (pExprInfo->base.arg[j].argType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy(pMsg, pExprInfo->base.arg[j].argValue.pz, pExprInfo->base.arg[j].argBytes);
|
||||
pMsg += pExprInfo->base.arg[j].argBytes;
|
||||
} else {
|
||||
pSqlFuncExpr1->arg[j].argValue.i64 = htobe64(pExprInfo->base.arg[j].argValue.i64);
|
||||
}
|
||||
}
|
||||
|
||||
pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pQueryMsg->secondStageOutput = 0;
|
||||
}
|
||||
|
||||
int32_t succeed = 1;
|
||||
|
||||
|
||||
// serialize the table info (sid, uid, tags)
|
||||
pMsg = doSerializeTableInfo(pQueryMsg, pSql, pMsg, &succeed);
|
||||
pMsg = doSerializeTableInfo(pQueryMsg, pSql, pTableMetaInfo, pMsg, &succeed);
|
||||
if (succeed == 0) {
|
||||
return TSDB_CODE_TSC_APP_ERROR;
|
||||
code = TSDB_CODE_TSC_APP_ERROR;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
SSqlGroupbyExpr *pGroupbyExpr = &pQueryInfo->groupbyExpr;
|
||||
SSqlGroupbyExpr *pGroupbyExpr = query.pGroupbyExpr;
|
||||
if (pGroupbyExpr->numOfGroupCols > 0) {
|
||||
pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex);
|
||||
pQueryMsg->orderType = htons(pGroupbyExpr->orderType);
|
||||
|
||||
for (int32_t j = 0; j < pGroupbyExpr->numOfGroupCols; ++j) {
|
||||
SColIndex* pCol = taosArrayGet(pGroupbyExpr->columnInfo, j);
|
||||
|
||||
|
||||
*((int16_t *)pMsg) = htons(pCol->colId);
|
||||
pMsg += sizeof(pCol->colId);
|
||||
|
||||
|
@ -1047,48 +945,29 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
*((int16_t *)pMsg) += htons(pCol->flag);
|
||||
pMsg += sizeof(pCol->flag);
|
||||
|
||||
|
||||
memcpy(pMsg, pCol->name, tListLen(pCol->name));
|
||||
pMsg += tListLen(pCol->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
||||
for (int32_t i = 0; i < tscSqlExprNumOfExprs(pQueryInfo); ++i) {
|
||||
*((int64_t *)pMsg) = htobe64(pQueryInfo->fillVal[i]);
|
||||
pMsg += sizeof(pQueryInfo->fillVal[0]);
|
||||
if (query.fillType != TSDB_FILL_NONE) {
|
||||
for (int32_t i = 0; i < query.numOfOutput; ++i) {
|
||||
*((int64_t *)pMsg) = htobe64(query.fillVal[i]);
|
||||
pMsg += sizeof(query.fillVal[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfTags != 0) {
|
||||
int32_t numOfColumns = tscGetNumOfColumns(pTableMeta);
|
||||
int32_t numOfTagColumns = tscGetNumOfTags(pTableMeta);
|
||||
int32_t total = numOfTagColumns + numOfColumns;
|
||||
|
||||
pSchema = tscGetTableTagSchema(pTableMeta);
|
||||
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pTableMetaInfo->tagColList, i);
|
||||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
|
||||
if ((pCol->colIndex.columnIndex >= numOfTagColumns || pCol->colIndex.columnIndex < -1) ||
|
||||
(!isValidDataType(pColSchema->type))) {
|
||||
char n[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameExtractFullName(&pTableMetaInfo->name, n);
|
||||
if (query.numOfTags > 0) {
|
||||
for (int32_t i = 0; i < query.numOfTags; ++i) {
|
||||
SColumnInfo* pTag = &query.tagColList[i];
|
||||
|
||||
tscError("0x%"PRIx64" tid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s",
|
||||
pSql->self, pTableMeta->id.tid, pTableMeta->id.uid, n, total, numOfTagColumns, pCol->colIndex.columnIndex, pColSchema->name);
|
||||
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
SColumnInfo* pTagCol = (SColumnInfo*) pMsg;
|
||||
|
||||
pTagCol->colId = htons(pColSchema->colId);
|
||||
pTagCol->bytes = htons(pColSchema->bytes);
|
||||
pTagCol->type = htons(pColSchema->type);
|
||||
pTagCol->numOfFilters = 0;
|
||||
|
||||
pTagCol->colId = htons(pTag->colId);
|
||||
pTagCol->bytes = htons(pTag->bytes);
|
||||
pTagCol->type = htons(pTag->type);
|
||||
pTagCol->flist.numOfFilters = 0;
|
||||
|
||||
pMsg += sizeof(SColumnInfo);
|
||||
}
|
||||
}
|
||||
|
@ -1096,12 +975,12 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
// serialize tag column query condition
|
||||
if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0) {
|
||||
STagCond* pTagCond = &pQueryInfo->tagCond;
|
||||
|
||||
|
||||
SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid);
|
||||
if (pCond != NULL && pCond->cond != NULL) {
|
||||
pQueryMsg->tagCondLen = htons(pCond->len);
|
||||
memcpy(pMsg, pCond->cond, pCond->len);
|
||||
|
||||
|
||||
pMsg += pCond->len;
|
||||
}
|
||||
}
|
||||
|
@ -1118,21 +997,30 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
// compressed ts block
|
||||
pQueryMsg->tsOffset = htonl((int32_t)(pMsg - pCmd->payload));
|
||||
pQueryMsg->tsBuf.tsOffset = htonl((int32_t)(pMsg - pCmd->payload));
|
||||
|
||||
if (pQueryInfo->tsBuf != NULL) {
|
||||
// note: here used the index instead of actual vnode id.
|
||||
int32_t vnodeIndex = pTableMetaInfo->vgroupIndex;
|
||||
int32_t code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vnodeIndex, pMsg, &pQueryMsg->tsLen, &pQueryMsg->tsNumOfBlocks);
|
||||
code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vnodeIndex, pMsg, &pQueryMsg->tsBuf.tsLen, &pQueryMsg->tsBuf.tsNumOfBlocks);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
pMsg += pQueryMsg->tsLen;
|
||||
pMsg += pQueryMsg->tsBuf.tsLen;
|
||||
|
||||
pQueryMsg->tsOrder = htonl(pQueryInfo->tsBuf->tsOrder);
|
||||
pQueryMsg->tsLen = htonl(pQueryMsg->tsLen);
|
||||
pQueryMsg->tsNumOfBlocks = htonl(pQueryMsg->tsNumOfBlocks);
|
||||
pQueryMsg->tsBuf.tsOrder = htonl(pQueryInfo->tsBuf->tsOrder);
|
||||
pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen);
|
||||
pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks);
|
||||
}
|
||||
|
||||
int32_t numOfOperator = (int32_t) taosArrayGetSize(queryOperator);
|
||||
pQueryMsg->numOfOperator = htonl(numOfOperator);
|
||||
for(int32_t i = 0; i < numOfOperator; ++i) {
|
||||
int32_t *operator = taosArrayGet(queryOperator, i);
|
||||
*(int32_t*)pMsg = htonl(*operator);
|
||||
|
||||
pMsg += sizeof(int32_t);
|
||||
}
|
||||
|
||||
memcpy(pMsg, pSql->sqlstr, sqlLen);
|
||||
|
@ -1143,11 +1031,15 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
tscDebug("0x%"PRIx64" msg built success, len:%d bytes", pSql->self, msgLen);
|
||||
pCmd->payloadLen = msgLen;
|
||||
pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY;
|
||||
|
||||
|
||||
pQueryMsg->head.contLen = htonl(msgLen);
|
||||
assert(msgLen + minMsgSize() <= (int32_t)pCmd->allocSize);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_end:
|
||||
freeQueryAttr(&query);
|
||||
taosArrayDestroy(tableScanOperator);
|
||||
taosArrayDestroy(queryOperator);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
|
@ -1468,7 +1360,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SSchema *pSchema;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
// Reallocate the payload size
|
||||
|
@ -1537,7 +1429,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
pMsg = (char *)pSchema;
|
||||
if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql
|
||||
SQuerySqlNode *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
||||
SSqlNode *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
||||
|
||||
strncpy(pMsg, pQuerySql->sqlstr.z, pQuerySql->sqlstr.n + 1);
|
||||
pCreateMsg->sqlLen = htons(pQuerySql->sqlstr.n + 1);
|
||||
|
@ -1557,7 +1449,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
return minMsgSize() + sizeof(SAlterTableMsg) + sizeof(SSchema) * tscNumOfFields(pQueryInfo) + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||
}
|
||||
|
||||
|
@ -1566,7 +1458,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
int msgLen = 0;
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
|
@ -1615,7 +1507,7 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
|
|||
SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload;
|
||||
pCmd->payloadLen = htonl(pUpdateMsg->head.contLen);
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
STableMeta *pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
||||
|
||||
SNewVgroupInfo vgroupInfo = {.vgId = -1};
|
||||
|
@ -1651,7 +1543,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg*)pCmd->payload;
|
||||
pRetrieveMsg->qId = htobe64(pSql->res.qId);
|
||||
pRetrieveMsg->free = htons(pQueryInfo->type);
|
||||
|
@ -1675,7 +1567,7 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) {
|
|||
pRes->row = 0;
|
||||
pRes->rspType = 1;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
if (tscCreateResPointerInfo(pRes, pQueryInfo) != TSDB_CODE_SUCCESS) {
|
||||
return pRes->code;
|
||||
}
|
||||
|
@ -1723,16 +1615,32 @@ int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) {
|
|||
return code;
|
||||
}
|
||||
|
||||
pRes->code = tscDoLocalMerge(pSql);
|
||||
// global aggregation may be the upstream for parent query
|
||||
SQueryInfo *pQueryInfo = tscGetActiveQueryInfo(pCmd);
|
||||
if (pQueryInfo->pQInfo == NULL) {
|
||||
STableGroupInfo tableGroupInfo = {.numOfTables = 1, .pGroupList = taosArrayInit(1, POINTER_BYTES),};
|
||||
tableGroupInfo.map = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
|
||||
if (pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows > 0) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
tscCreateResPointerInfo(pRes, pQueryInfo);
|
||||
tscSetResRawPtr(pRes, pQueryInfo);
|
||||
STableKeyInfo tableKeyInfo = {.pTable = NULL, .lastKey = INT64_MIN};
|
||||
|
||||
SArray* group = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
taosArrayPush(group, &tableKeyInfo);
|
||||
taosArrayPush(tableGroupInfo.pGroupList, &group);
|
||||
|
||||
SExprInfo* list = calloc(tscSqlExprNumOfExprs(pQueryInfo), sizeof(SExprInfo));
|
||||
for(int32_t i = 0; i < tscSqlExprNumOfExprs(pQueryInfo); ++i) {
|
||||
SExprInfo* pExprInfo = tscSqlExprGet(pQueryInfo, i);
|
||||
list[i] = *pExprInfo;
|
||||
}
|
||||
|
||||
pQueryInfo->pQInfo = createQueryInfoFromQueryNode(pQueryInfo, list, &tableGroupInfo, NULL, NULL, pRes->pLocalMerger, MERGE_STAGE);
|
||||
}
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->completed = (pRes->numOfRows == 0);
|
||||
uint64_t localQueryId = 0;
|
||||
qTableQuery(pQueryInfo->pQInfo, &localQueryId);
|
||||
convertQueryResult(pRes, pQueryInfo);
|
||||
|
||||
handleDownstreamOperator(pRes, pQueryInfo);
|
||||
|
||||
code = pRes->code;
|
||||
if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||
|
@ -1780,7 +1688,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableInfoMsg *pInfoMsg = (STableInfoMsg *)pCmd->payload;
|
||||
|
@ -1850,7 +1758,7 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
char* pMsg = pCmd->payload;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
|
||||
SSTableVgroupMsg *pStableVgroupMsg = (SSTableVgroupMsg *)pMsg;
|
||||
pStableVgroupMsg->numOfTables = htonl(pQueryInfo->numOfTables);
|
||||
|
@ -2162,8 +2070,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
|||
|
||||
pInfo->vgroupList->numOfVgroups = pVgroupMsg->numOfVgroups;
|
||||
if (pInfo->vgroupList->numOfVgroups <= 0) {
|
||||
//tfree(pInfo->vgroupList);
|
||||
tscError("0x%"PRIx64" empty vgroup info", pSql->self);
|
||||
tscDebug("0x%"PRIx64" empty vgroup info, no corresponding tables for stable", pSql->self);
|
||||
} else {
|
||||
for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) {
|
||||
// just init, no need to lock
|
||||
|
@ -2213,7 +2120,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
|
@ -2245,15 +2152,16 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
|
||||
SColumnIndex index = {0};
|
||||
pSchema = pMetaMsg->schema;
|
||||
|
||||
|
||||
uint64_t uid = pTableMetaInfo->pTableMeta->id.uid;
|
||||
for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i, ++pSchema) {
|
||||
index.columnIndex = i;
|
||||
tscColumnListInsert(pQueryInfo->colList, &index);
|
||||
tscColumnListInsert(pQueryInfo->colList, i, uid, pSchema);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(pSchema->type, pSchema->name, pSchema->bytes);
|
||||
SInternalField* pInfo = tscFieldInfoAppend(pFieldInfo, &f);
|
||||
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pInfo->pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pTableSchema[i].type, pTableSchema[i].bytes, getNewResColId(pQueryInfo), pTableSchema[i].bytes, false);
|
||||
}
|
||||
|
||||
|
@ -2272,7 +2180,7 @@ static void createHbObj(STscObj* pObj) {
|
|||
|
||||
pSql->fp = tscProcessHeartBeatRsp;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoS(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
tfree(pSql);
|
||||
|
@ -2365,7 +2273,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
|
|||
taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
|
||||
tscDebug("0x%"PRIx64" remove table meta after drop table:%s, numOfRemain:%d", pSql->self, name, (int32_t) taosHashGetSize(tscTableMetaInfo));
|
||||
|
||||
pTableMetaInfo->pTableMeta = NULL;
|
||||
tfree(pTableMetaInfo->pTableMeta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2400,11 +2308,12 @@ int tscProcessShowCreateRsp(SSqlObj *pSql) {
|
|||
int tscProcessQueryRsp(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
SQueryTableRsp *pQuery = (SQueryTableRsp *)pRes->pRsp;
|
||||
pQuery->qId = htobe64(pQuery->qId);
|
||||
pRes->qId = pQuery->qId;
|
||||
SQueryTableRsp *pQueryAttr = (SQueryTableRsp *)pRes->pRsp;
|
||||
pQueryAttr->qId = htobe64(pQueryAttr->qId);
|
||||
|
||||
pRes->qId = pQueryAttr->qId;
|
||||
pRes->data = NULL;
|
||||
|
||||
tscResetForNextRetrieve(pRes);
|
||||
tscDebug("0x%"PRIx64" query rsp received, qId:0x%"PRIx64, pSql->self, pRes->qId);
|
||||
return 0;
|
||||
|
@ -2429,7 +2338,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
|||
pRes->completed = (pRetrieve->completed == 1);
|
||||
pRes->data = pRetrieve->data;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetActiveQueryInfo(pCmd);
|
||||
if (tscCreateResPointerInfo(pRes, pQueryInfo) != TSDB_CODE_SUCCESS) {
|
||||
return pRes->code;
|
||||
}
|
||||
|
@ -2443,6 +2352,8 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
|||
tscSetResRawPtr(pRes, pQueryInfo);
|
||||
}
|
||||
|
||||
handleDownstreamOperator(pRes, pQueryInfo);
|
||||
|
||||
if (pSql->pSubscription != NULL) {
|
||||
int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
|
||||
|
@ -2483,9 +2394,9 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn
|
|||
pNew->signature = pNew;
|
||||
pNew->cmd.command = TSDB_SQL_META;
|
||||
|
||||
tscAddSubqueryInfo(&pNew->cmd);
|
||||
tscAddQueryInfo(&pNew->cmd);
|
||||
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetailSafely(&pNew->cmd, 0);
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoS(&pNew->cmd, 0);
|
||||
|
||||
pNew->cmd.autoCreated = pSql->cmd.autoCreated; // create table if not exists
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen)) {
|
||||
|
@ -2519,7 +2430,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn
|
|||
|
||||
pSql->metaRid = pNew->self;
|
||||
|
||||
int32_t code = tscProcessSql(pNew);
|
||||
int32_t code = tscBuildAndSendRequest(pNew, NULL);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated
|
||||
}
|
||||
|
@ -2589,7 +2500,7 @@ int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool create
|
|||
int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
|
||||
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
|
@ -2613,7 +2524,7 @@ int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex) {
|
|||
}
|
||||
|
||||
static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, clauseIndex);
|
||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i);
|
||||
if (pTableMetaInfo->vgroupList == NULL) {
|
||||
|
@ -2640,13 +2551,13 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
pNew->cmd.command = TSDB_SQL_STABLEVGROUP;
|
||||
|
||||
// TODO TEST IT
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetailSafely(&pNew->cmd, 0);
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoS(&pNew->cmd, 0);
|
||||
if (pNewQueryInfo == NULL) {
|
||||
tscFreeSqlObj(pNew);
|
||||
return code;
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, clauseIndex);
|
||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||
STableMetaInfo *pMInfo = tscGetMetaInfo(pQueryInfo, i);
|
||||
STableMeta* pTableMeta = tscTableMetaDup(pMInfo->pTableMeta);
|
||||
|
@ -2670,7 +2581,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
|
||||
pNew->fp = tscTableMetaCallBack;
|
||||
pNew->param = (void *)pSql->self;
|
||||
code = tscProcessSql(pNew);
|
||||
code = tscBuildAndSendRequest(pNew, NULL);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
@ -2746,7 +2657,7 @@ void tscInitMsgsFp() {
|
|||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_TABLE] = tscProcessShowCreateRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
|
||||
|
||||
|
||||
tscKeepConn[TSDB_SQL_SHOW] = 1;
|
||||
tscKeepConn[TSDB_SQL_RETRIEVE] = 1;
|
||||
tscKeepConn[TSDB_SQL_SELECT] = 1;
|
||||
|
|
|
@ -191,7 +191,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
pSql->fp = syncConnCallback;
|
||||
pSql->param = pSql;
|
||||
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
tsem_wait(&pSql->rspSem);
|
||||
|
||||
if (pSql->res.code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -265,7 +265,7 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port,
|
|||
if (taos) *taos = pObj;
|
||||
|
||||
pSql->fetchFp = fp;
|
||||
pSql->res.code = tscProcessSql(pSql);
|
||||
pSql->res.code = tscBuildAndSendRequest(pSql, NULL);
|
||||
tscDebug("%p DB async connection is opening", taos);
|
||||
return pObj;
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ int taos_num_fields(TAOS_RES *res) {
|
|||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
int32_t num = 0;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
return num;
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -559,7 +559,7 @@ static bool tscKillQueryInDnode(SSqlObj* pSql) {
|
|||
return true;
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
|
||||
if ((pQueryInfo == NULL) || tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
return true;
|
||||
|
@ -578,7 +578,7 @@ static bool tscKillQueryInDnode(SSqlObj* pSql) {
|
|||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
tscDebug("0x%"PRIx64" send msg to dnode to free qhandle ASAP before free sqlObj, command:%s", pSql->self, sqlCmd[pCmd->command]);
|
||||
|
||||
tscProcessSql(pSql);
|
||||
tscBuildAndSendRequest(pSql, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -672,7 +672,7 @@ char *taos_get_client_info() { return version; }
|
|||
static void tscKillSTableQuery(SSqlObj *pSql) {
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
|
||||
if (!tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
return;
|
||||
|
@ -723,7 +723,7 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
// set the error code for master pSqlObj firstly
|
||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
|
||||
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
assert(pSql->rpcRid <= 0);
|
||||
|
@ -753,7 +753,7 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
|||
return true;
|
||||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
@ -932,7 +932,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
|||
int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
|
||||
char *str = (char *)tblNameList;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoS(pCmd, pCmd->clauseIndex);
|
||||
if (pQueryInfo == NULL) {
|
||||
pSql->res.code = terrno;
|
||||
return terrno;
|
||||
|
@ -1047,7 +1047,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
|
||||
/*
|
||||
* set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query.
|
||||
* If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql()
|
||||
* If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscBuildAndSendRequest()
|
||||
* to free connection, which may cause segment fault, when the parse phrase is not even successfully executed.
|
||||
*/
|
||||
pRes->qId = 0;
|
||||
|
@ -1060,7 +1060,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
|
||||
tscDoQuery(pSql);
|
||||
|
||||
tscDebug("0x%"PRIx64" load multi table meta result:%d %s pObj:%p", pSql->self, pRes->code, taos_errstr(pSql), pObj);
|
||||
tscDebug("0x%"PRIx64" load multi-table meta result:%d %s pObj:%p", pSql->self, pRes->code, taos_errstr(pSql), pObj);
|
||||
if ((code = pRes->code) != TSDB_CODE_SUCCESS) {
|
||||
tscFreeSqlObj(pSql);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ static int64_t getDelayValueAfterTimewindowClosed(SSqlStream* pStream, int64_t l
|
|||
|
||||
static bool isProjectStream(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_PRJ) {
|
||||
SExprInfo *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->base.functionId != TSDB_FUNC_PRJ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
|||
return;
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
|
@ -102,7 +102,7 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
|||
}
|
||||
|
||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo) && (pTableMetaInfo->pVgroupTables == NULL) && (pTableMetaInfo->vgroupList == NULL || pTableMetaInfo->vgroupList->numOfVgroups <= 0)) {
|
||||
tscDebug("%p empty vgroup list", pSql);
|
||||
tscDebug("0x%"PRIx64" empty vgroup list", pSql->self);
|
||||
pTableMetaInfo->vgroupList = tscVgroupInfoClear(pTableMetaInfo->vgroupList);
|
||||
code = TSDB_CODE_TSC_APP_ERROR;
|
||||
}
|
||||
|
@ -110,13 +110,13 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
|||
// failed to get table Meta or vgroup list, retry in 10sec.
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
tscTansformFuncForSTableQuery(pQueryInfo);
|
||||
tscDebug("0x%"PRIx64" stream:%p, start stream query on:%s", pSql->self, pStream, tNameGetTableName(&pTableMetaInfo->name));
|
||||
tscDebug("0x%"PRIx64" stream:%p started to query table:%s", pSql->self, pStream, tNameGetTableName(&pTableMetaInfo->name));
|
||||
|
||||
pQueryInfo->command = TSDB_SQL_SELECT;
|
||||
|
||||
|
||||
pSql->fp = tscProcessStreamQueryCallback;
|
||||
pSql->fetchFp = tscProcessStreamQueryCallback;
|
||||
tscDoQuery(pSql);
|
||||
executeQuery(pSql, pQueryInfo);
|
||||
tscIncStreamExecutionCount(pStream);
|
||||
} else {
|
||||
setRetryInfo(pStream, code);
|
||||
|
@ -138,8 +138,8 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
|||
|
||||
pStream->numOfRes = 0; // reset the numOfRes.
|
||||
SSqlObj *pSql = pStream->pSql;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
tscDebug("0x%"PRIx64" add into timer", pSql->self);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
tscDebug("0x%"PRIx64" timer launch query", pSql->self);
|
||||
|
||||
if (pStream->isProject) {
|
||||
/*
|
||||
|
@ -194,8 +194,8 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
SSqlStream *pStream = (SSqlStream *)param;
|
||||
if (tres == NULL || numOfRows < 0) {
|
||||
int64_t retryDelay = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision);
|
||||
tscError("0x%"PRIx64" stream:%p, query data failed, code:0x%08x, retry in %" PRId64 "ms", pStream->pSql->self, pStream, numOfRows,
|
||||
retryDelay);
|
||||
tscError("0x%"PRIx64" stream:%p, query data failed, code:0x%08x, retry in %" PRId64 "ms", pStream->pSql->self,
|
||||
pStream, numOfRows, retryDelay);
|
||||
|
||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||
|
||||
|
@ -207,7 +207,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
tfree(pTableMetaInfo->pTableMeta);
|
||||
|
||||
tscFreeSqlResult(pStream->pSql);
|
||||
tscFreeSubobj(pStream->pSql);
|
||||
tscFreeSubobj(pStream->pSql);
|
||||
tfree(pStream->pSql->pSubs);
|
||||
pStream->pSql->subState.numOfSub = 0;
|
||||
|
||||
|
@ -224,7 +224,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
static void tscStreamFillTimeGap(SSqlStream* pStream, TSKEY ts) {
|
||||
#if 0
|
||||
SSqlObj * pSql = pStream->pSql;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
if (pQueryInfo->fillType != TSDB_FILL_SET_VALUE && pQueryInfo->fillType != TSDB_FILL_NULL) {
|
||||
return;
|
||||
|
@ -267,13 +267,14 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
|
||||
if (pSql == NULL || numOfRows < 0) {
|
||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision);
|
||||
tscError("0x%"PRIx64" stream:%p, retrieve data failed, code:0x%08x, retry in %" PRId64 "ms", pSql->self, pStream, numOfRows, retryDelayTime);
|
||||
tscError("0x%"PRIx64" stream:%p, retrieve data failed, code:0x%08x, retry in %" PRId64 " ms", pSql->self, pStream, numOfRows, retryDelayTime);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
||||
return;
|
||||
}
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = pQueryInfo->pTableMetaInfo[0];
|
||||
|
||||
if (numOfRows > 0) { // when reaching here the first execution of stream computing is successful.
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
|
@ -313,6 +314,10 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
pStream->numOfRes);
|
||||
|
||||
tfree(pTableMetaInfo->pTableMeta);
|
||||
if (pQueryInfo->pQInfo != NULL) {
|
||||
qDestroyQueryInfo(pQueryInfo->pQInfo);
|
||||
pQueryInfo->pQInfo = NULL;
|
||||
}
|
||||
|
||||
tscFreeSqlResult(pSql);
|
||||
tscFreeSubobj(pSql);
|
||||
|
@ -345,10 +350,10 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
|
|||
return;
|
||||
}
|
||||
|
||||
tscDebug("0x%"PRIx64" stream:%p, next start at %" PRId64 ", in %" PRId64 "ms. delay:%" PRId64 "ms qrange %" PRId64 "-%" PRId64, pStream->pSql->self, pStream,
|
||||
tscDebug("0x%"PRIx64" stream:%p, next start at %" PRId64 "(ts window ekey), in %" PRId64 " ms. delay:%" PRId64 "ms qrange %" PRId64 "-%" PRId64, pStream->pSql->self, pStream,
|
||||
now + timer, timer, delay, pStream->stime, etime);
|
||||
} else {
|
||||
tscDebug("0x%"PRIx64" stream:%p, next start at %" PRId64 ", in %" PRId64 "ms. delay:%" PRId64 "ms qrange %" PRId64 "-%" PRId64, pStream->pSql->self, pStream,
|
||||
tscDebug("0x%"PRIx64" stream:%p, next start at %" PRId64 "(ts window ekey), in %" PRId64 " ms. delay:%" PRId64 "ms qrange %" PRId64 "-%" PRId64, pStream->pSql->self, pStream,
|
||||
pStream->stime, timer, delay, pStream->stime - pStream->interval.interval, pStream->stime - 1);
|
||||
}
|
||||
|
||||
|
@ -406,7 +411,6 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
|
|||
}
|
||||
} else {
|
||||
int64_t stime = taosTimeTruncate(pStream->stime - 1, &pStream->interval, pStream->precision);
|
||||
//int64_t stime = taosGetIntervalStartTimestamp(pStream->stime - 1, pStream->interval.interval, pStream->interval.interval, pStream->interval.intervalUnit, pStream->precision);
|
||||
if (stime >= pStream->etime) {
|
||||
tscDebug("0x%"PRIx64" stream:%p, stime:%" PRId64 " is larger than end time: %" PRId64 ", stop the stream", pStream->pSql->self, pStream,
|
||||
pStream->stime, pStream->etime);
|
||||
|
@ -440,7 +444,7 @@ static int32_t tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
|
|||
int64_t minIntervalTime =
|
||||
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
if (!pStream->isProject && pQueryInfo->interval.interval == 0) {
|
||||
sprintf(pSql->cmd.payload, "the interval value is 0");
|
||||
|
@ -490,7 +494,7 @@ static int32_t tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
|
|||
}
|
||||
|
||||
static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd, 0);
|
||||
|
||||
if (pStream->isProject) {
|
||||
// no data in table, flush all data till now to destination meter, 10sec delay
|
||||
|
@ -510,7 +514,7 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
|
|||
} else {
|
||||
return stime;
|
||||
}
|
||||
|
||||
|
||||
stime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
||||
} else {
|
||||
int64_t newStime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
||||
|
@ -552,7 +556,7 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
|
|||
return;
|
||||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||
|
||||
|
@ -628,14 +632,14 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
|||
|
||||
strtolower(pSql->sqlstr, sqlstr);
|
||||
|
||||
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
||||
registerSqlObj(pSql);
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s", pSql->self, pSql->sqlstr);
|
||||
tsem_init(&pSql->rspSem, 0, 0);
|
||||
|
||||
pSql->fp = tscCreateStream;
|
||||
pSql->fetchFp = tscCreateStream;
|
||||
|
||||
registerSqlObj(pSql);
|
||||
|
||||
int32_t code = tsParseSql(pSql, true);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
tscCreateStream(pStream, pSql, code);
|
||||
|
|
|
@ -284,7 +284,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
|||
}
|
||||
size_t numOfTables = taosArrayGetSize(tables);
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
SArray* progress = taosArrayInit(numOfTables, sizeof(SSubscriptionProgress));
|
||||
for( size_t i = 0; i < numOfTables; i++ ) {
|
||||
STidTags* tt = taosArrayGet( tables, i );
|
||||
|
@ -304,7 +304,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
|||
}
|
||||
taosArrayDestroy(tables);
|
||||
|
||||
TSDB_QUERY_SET_TYPE(tscGetQueryInfoDetail(pCmd, 0)->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY);
|
||||
TSDB_QUERY_SET_TYPE(tscGetQueryInfo(pCmd, 0)->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -487,11 +487,13 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
|||
if (pSql == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pSub->pSql->self != 0) {
|
||||
taosReleaseRef(tscObjRef, pSub->pSql->self);
|
||||
} else {
|
||||
tscFreeSqlObj(pSub->pSql);
|
||||
}
|
||||
|
||||
pSub->pSql = pSql;
|
||||
pSql->pSubscription = pSub;
|
||||
}
|
||||
|
@ -502,7 +504,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, 0);
|
||||
if (taosArrayGetSize(pSub->progress) > 0) { // fix crash in single table subscription
|
||||
|
||||
size_t size = taosArrayGetSize(pSub->progress);
|
||||
|
@ -555,7 +557,10 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
|||
pSql->fp = asyncCallback;
|
||||
pSql->fetchFp = asyncCallback;
|
||||
pSql->param = pSub;
|
||||
tscDoQuery(pSql);
|
||||
|
||||
pSql->cmd.active = pQueryInfo;
|
||||
executeQuery(pSql, pQueryInfo);
|
||||
|
||||
tsem_wait(&pSub->sem);
|
||||
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -15,10 +15,7 @@
|
|||
#ifndef _TD_DATA_FORMAT_H_
|
||||
#define _TD_DATA_FORMAT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "talgo.h"
|
||||
#include "ttype.h"
|
||||
#include "tutil.h"
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TAST_H
|
||||
#define TDENGINE_TAST_H
|
||||
#ifndef TDENGINE_TEXPR_H
|
||||
#define TDENGINE_TEXPR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -62,32 +62,32 @@ typedef struct tExprNode {
|
|||
uint8_t nodeType;
|
||||
union {
|
||||
struct {
|
||||
uint8_t optr; // filter operator
|
||||
uint8_t hasPK; // 0: do not contain primary filter, 1: contain
|
||||
void * info; // support filter operation on this expression only available for leaf node
|
||||
|
||||
uint8_t optr; // filter operator
|
||||
uint8_t hasPK; // 0: do not contain primary filter, 1: contain
|
||||
void *info; // support filter operation on this expression only available for leaf node
|
||||
struct tExprNode *pLeft; // left child pointer
|
||||
struct tExprNode *pRight; // right child pointer
|
||||
} _node;
|
||||
struct SSchema *pSchema;
|
||||
tVariant * pVal;
|
||||
|
||||
struct SSchema *pSchema;
|
||||
tVariant *pVal;
|
||||
};
|
||||
} tExprNode;
|
||||
|
||||
typedef struct SExprTraverseSupp {
|
||||
__result_filter_fn_t nodeFilterFn;
|
||||
__do_filter_suppl_fn_t setupInfoFn;
|
||||
void * pExtInfo;
|
||||
void *pExtInfo;
|
||||
} SExprTraverseSupp;
|
||||
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
||||
tExprNode* exprTreeFromTableName(const char* tbnameCond);
|
||||
tExprNode* exprdup(tExprNode* pTree);
|
||||
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
|
||||
bool exprTreeApplayFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
|
||||
bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
|
||||
|
||||
typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight,
|
||||
int32_t rightType, void *output, int32_t order);
|
||||
|
@ -99,4 +99,4 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TAST_H
|
||||
#endif // TDENGINE_TEXPR_H
|
||||
|
|
|
@ -44,6 +44,7 @@ extern int32_t tsDnodeId;
|
|||
// common
|
||||
extern int tsRpcTimer;
|
||||
extern int tsRpcMaxTime;
|
||||
extern int tsRpcForceTcp; // all commands go to tcp protocol if this is enabled
|
||||
extern int32_t tsMaxConnections;
|
||||
extern int32_t tsMaxShellConns;
|
||||
extern int32_t tsShellActivityTimer;
|
||||
|
|
|
@ -41,6 +41,35 @@ typedef struct SResPair {
|
|||
double avg;
|
||||
} SResPair;
|
||||
|
||||
// the structure for sql function in select clause
|
||||
typedef struct SSqlExpr {
|
||||
char aliasName[TSDB_COL_NAME_LEN]; // as aliasName
|
||||
SColIndex colInfo;
|
||||
|
||||
uint64_t uid; // refactor use the pointer
|
||||
|
||||
int16_t functionId; // function id in aAgg array
|
||||
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
int32_t interBytes; // inter result buffer size
|
||||
|
||||
int16_t colType; // table column type
|
||||
int16_t colBytes; // table column bytes
|
||||
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
int32_t offset; // sub result column value of arithmetic expression.
|
||||
int16_t resColId; // result column id
|
||||
|
||||
SColumnFilterList flist;
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SExprInfo {
|
||||
SSqlExpr base;
|
||||
struct tExprNode *pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
#define TSDB_DB_NAME_T 1
|
||||
#define TSDB_TABLE_NAME_T 2
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "texpr.h"
|
||||
#include "exception.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
|
@ -145,25 +146,25 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
|
|||
*pExpr = NULL;
|
||||
}
|
||||
|
||||
bool exprTreeApplayFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param) {
|
||||
bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param) {
|
||||
tExprNode *pLeft = pExpr->_node.pLeft;
|
||||
tExprNode *pRight = pExpr->_node.pRight;
|
||||
|
||||
//non-leaf nodes, recursively traverse the expression tree in the post-root order
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR && pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
|
||||
if (exprTreeApplayFilter(pLeft, pItem, param)) {
|
||||
if (exprTreeApplyFilter(pLeft, pItem, param)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// left child does not satisfy the query condition, try right child
|
||||
return exprTreeApplayFilter(pRight, pItem, param);
|
||||
return exprTreeApplyFilter(pRight, pItem, param);
|
||||
} else { // and
|
||||
if (!exprTreeApplayFilter(pLeft, pItem, param)) {
|
||||
if (!exprTreeApplyFilter(pLeft, pItem, param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return exprTreeApplayFilter(pRight, pItem, param);
|
||||
return exprTreeApplyFilter(pRight, pItem, param);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,3 +464,28 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
|
|||
CLEANUP_EXECUTE_TO(anchor, false);
|
||||
return expr;
|
||||
}
|
||||
|
||||
tExprNode* exprdup(tExprNode* pTree) {
|
||||
if (pTree == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tExprNode* pNode = calloc(1, sizeof(tExprNode));
|
||||
if (pTree->nodeType == TSQL_NODE_EXPR) {
|
||||
tExprNode* pLeft = exprdup(pTree->_node.pLeft);
|
||||
tExprNode* pRight = exprdup(pTree->_node.pRight);
|
||||
|
||||
pNode->nodeType = TSQL_NODE_EXPR;
|
||||
pNode->_node.pLeft = pLeft;
|
||||
pNode->_node.pRight = pRight;
|
||||
} else if (pTree->nodeType == TSQL_NODE_VALUE) {
|
||||
pNode->pVal = calloc(1, sizeof(tVariant));
|
||||
tVariantAssign(pNode->pVal, pTree->pVal);
|
||||
} else if (pTree->nodeType == TSQL_NODE_COL) {
|
||||
pNode->pSchema = calloc(1, sizeof(SSchema));
|
||||
*pNode->pSchema = *pTree->pSchema;
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ int32_t tsDnodeId = 0;
|
|||
// common
|
||||
int32_t tsRpcTimer = 1000;
|
||||
int32_t tsRpcMaxTime = 600; // seconds;
|
||||
int32_t tsRpcForceTcp = 0; //disable this, means query, show command use udp protocol as default
|
||||
int32_t tsMaxShellConns = 50000;
|
||||
int32_t tsMaxConnections = 5000;
|
||||
int32_t tsShellActivityTimer = 3; // second
|
||||
|
@ -625,6 +626,16 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "rpcForceTcp";
|
||||
cfg.ptr = &tsRpcForceTcp;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "rpcMaxTime";
|
||||
cfg.ptr = &tsRpcMaxTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
|
@ -921,7 +932,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = -1;
|
||||
cfg.maxValue = 10000000;
|
||||
cfg.maxValue = 100000000.0f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
|
|
@ -68,6 +68,7 @@ bool tscValidateTableNameLength(size_t len) {
|
|||
return len < TSDB_TABLE_NAME_LEN;
|
||||
}
|
||||
|
||||
// TODO refactor
|
||||
SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters) {
|
||||
if (numOfFilters == 0) {
|
||||
assert(src == NULL);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7a26c432f8b4203e42344ff3290b9b9b01b983d5
|
||||
Subproject commit 050667e5b4d0eafa5387e4283e713559b421203f
|
|
@ -1,5 +1,8 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.collect.RangeSet;
|
||||
import com.google.common.collect.TreeRangeSet;
|
||||
import com.taosdata.jdbc.TSDBError;
|
||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||
import com.taosdata.jdbc.utils.Utils;
|
||||
|
@ -10,6 +13,12 @@ import java.math.BigDecimal;
|
|||
import java.net.URL;
|
||||
import java.sql.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class RestfulPreparedStatement extends RestfulStatement implements PreparedStatement {
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public class Utils {
|
|||
*/
|
||||
private static String transformSql(String rawSql, Object[] paramArr, Map<Integer, Integer> placeholderPosition, RangeSet<Integer> clauseRangeSet) {
|
||||
String[] sqlArr = rawSql.split("\\?");
|
||||
|
||||
return IntStream.range(0, sqlArr.length).mapToObj(index -> {
|
||||
if (index == paramArr.length)
|
||||
return sqlArr[index];
|
||||
|
|
|
@ -345,6 +345,7 @@ public class InsertSpecialCharacterJniTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCase12() throws SQLException {
|
||||
final long now = System.currentTimeMillis();
|
||||
|
|
|
@ -158,7 +158,7 @@ static int32_t dnodeWriteCfg() {
|
|||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
fsync(fileno(fp));
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
|
|
@ -277,7 +277,7 @@ static int32_t dnodeWriteEps() {
|
|||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
fsync(fileno(fp));
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
|
|
@ -286,7 +286,7 @@ static int32_t dnodeWriteMInfos() {
|
|||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
fsync(fileno(fp));
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
|
|
@ -22,7 +22,6 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "osDef.h"
|
||||
#include "taos.h"
|
||||
|
||||
#define TSDB__packed
|
||||
|
@ -243,8 +242,9 @@ do { \
|
|||
#define TSDB_MAX_REPLICA 5
|
||||
|
||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||
#define TSDB_BLOCK_DIST_COLUMN_INDEX (-2)
|
||||
#define TSDB_UD_COLUMN_INDEX (-100)
|
||||
#define TSDB_BLOCK_DIST_COLUMN_INDEX (-2)
|
||||
#define TSDB_UD_COLUMN_INDEX (-1000)
|
||||
#define TSDB_RES_COL_ID (-5000)
|
||||
|
||||
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
||||
|
||||
|
@ -388,9 +388,10 @@ typedef enum {
|
|||
typedef enum {
|
||||
TSDB_SUPER_TABLE = 0, // super table
|
||||
TSDB_CHILD_TABLE = 1, // table created from super table
|
||||
TSDB_NORMAL_TABLE = 2, // ordinary table
|
||||
TSDB_STREAM_TABLE = 3, // table created from stream computing
|
||||
TSDB_TABLE_MAX = 4
|
||||
TSDB_NORMAL_TABLE = 2, // ordinary table
|
||||
TSDB_STREAM_TABLE = 3, // table created from stream computing
|
||||
TSDB_TEMP_TABLE = 4, // temp table created by nest query
|
||||
TSDB_TABLE_MAX = 5
|
||||
} ETableType;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -399,7 +399,6 @@ typedef struct SColIndex {
|
|||
char name[TSDB_COL_NAME_LEN]; // TODO remove it
|
||||
} SColIndex;
|
||||
|
||||
|
||||
typedef struct SColumnFilterInfo {
|
||||
int16_t lowerRelOptr;
|
||||
int16_t upperRelOptr;
|
||||
|
@ -421,42 +420,13 @@ typedef struct SColumnFilterInfo {
|
|||
};
|
||||
} SColumnFilterInfo;
|
||||
|
||||
/* sql function msg, to describe the message to vnode about sql function
|
||||
* operations in select clause */
|
||||
typedef struct SSqlFuncMsg {
|
||||
int16_t functionId;
|
||||
int16_t numOfParams;
|
||||
|
||||
int16_t resColId; // result column id, id of the current output column
|
||||
int16_t colType;
|
||||
int16_t colBytes;
|
||||
|
||||
SColIndex colInfo;
|
||||
struct ArgElem {
|
||||
int16_t argType;
|
||||
int16_t argBytes;
|
||||
union {
|
||||
double d;
|
||||
int64_t i64;
|
||||
char * pz;
|
||||
} argValue;
|
||||
} arg[3];
|
||||
|
||||
int32_t filterNum;
|
||||
SColumnFilterInfo filterInfo[];
|
||||
} SSqlFuncMsg;
|
||||
|
||||
|
||||
typedef struct SExprInfo {
|
||||
SColumnFilterInfo * pFilter;
|
||||
struct tExprNode* pExpr;
|
||||
int16_t bytes;
|
||||
int16_t type;
|
||||
int32_t interBytes;
|
||||
int64_t uid;
|
||||
SSqlFuncMsg base;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct SColumnFilterList {
|
||||
int16_t numOfFilters;
|
||||
union{
|
||||
int64_t placeholder;
|
||||
SColumnFilterInfo *filterInfo;
|
||||
};
|
||||
} SColumnFilterList;
|
||||
/*
|
||||
* for client side struct, we only need the column id, type, bytes are not necessary
|
||||
* But for data in vnode side, we need all the following information.
|
||||
|
@ -465,11 +435,7 @@ typedef struct SColumnInfo {
|
|||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
int16_t numOfFilters;
|
||||
union{
|
||||
int64_t placeholder;
|
||||
SColumnFilterInfo *filters;
|
||||
};
|
||||
SColumnFilterList flist;
|
||||
} SColumnInfo;
|
||||
|
||||
typedef struct STableIdInfo {
|
||||
|
@ -483,10 +449,29 @@ typedef struct STimeWindow {
|
|||
TSKEY ekey;
|
||||
} STimeWindow;
|
||||
|
||||
typedef struct {
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
} STsBufInfo;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char version[TSDB_VERSION_LEN];
|
||||
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo;// if the time window start/end required interpolation
|
||||
bool queryBlockDist; // if query data block distribution
|
||||
bool stabledev; // super table stddev query
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool simpleAgg;
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
bool needReverseScan; // need reverse scan
|
||||
|
||||
STimeWindow window;
|
||||
int32_t numOfTables;
|
||||
int16_t order;
|
||||
|
@ -509,14 +494,13 @@ typedef struct {
|
|||
int16_t fillType; // interpolate type
|
||||
uint64_t fillVal; // default value array list
|
||||
int32_t secondStageOutput;
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
STsBufInfo tsBuf; // tsBuf info
|
||||
int32_t numOfTags; // number of tags columns involved
|
||||
int32_t sqlstrLen; // sql query string
|
||||
int32_t prevResultLen; // previous result length
|
||||
SColumnInfo colList[];
|
||||
int32_t numOfOperator;
|
||||
int32_t tableScanOperator;// table scan operator. -1 means no scan operator
|
||||
SColumnInfo tableCols[];
|
||||
} SQueryTableMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -827,7 +811,7 @@ typedef struct {
|
|||
uint32_t queryId;
|
||||
int64_t useconds;
|
||||
int64_t stime;
|
||||
uint64_t qHandle;
|
||||
uint64_t qId;
|
||||
} SQueryDesc;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -221,7 +221,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t numOfTables;
|
||||
SArray * pGroupList;
|
||||
SArray *pGroupList;
|
||||
SHashObj *map; // speedup acquire the tableQueryInfo by table uid
|
||||
} STableGroupInfo;
|
||||
|
||||
|
|
|
@ -205,13 +205,6 @@
|
|||
#define TK_VALUES 186
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define TK_SPACE 300
|
||||
#define TK_COMMENT 301
|
||||
#define TK_ILLEGAL 302
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "taosdef.h"
|
||||
|
||||
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
|
||||
|
|
|
@ -142,7 +142,7 @@ static void *shellCheckThreadFp(void *arg) {
|
|||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
fsync(fileno(fp));
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -37,7 +37,7 @@ static struct argp_option options[] = {
|
|||
{"password", 'p', "PASSWORD", OPTION_ARG_OPTIONAL, "The password to use when connecting to the server."},
|
||||
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
|
||||
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
||||
{"user", 'A', "Auth", 0, "The user auth to use when connecting to the server."},
|
||||
{"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."},
|
||||
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
||||
{"dump-config", 'C', 0, 0, "Dump configuration."},
|
||||
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
||||
|
|
|
@ -68,12 +68,6 @@ enum TEST_MODE {
|
|||
INVAID_TEST
|
||||
};
|
||||
|
||||
enum QUERY_MODE {
|
||||
SYNC_QUERY_MODE, // 0
|
||||
ASYNC_QUERY_MODE, // 1
|
||||
INVALID_MODE
|
||||
};
|
||||
|
||||
#define MAX_SQL_SIZE 65536
|
||||
#define BUFFER_SIZE (65536*2)
|
||||
#define MAX_USERNAME_SIZE 64
|
||||
|
@ -118,8 +112,8 @@ typedef enum TALBE_EXISTS_EN {
|
|||
} TALBE_EXISTS_EN;
|
||||
|
||||
enum MODE {
|
||||
SYNC,
|
||||
ASYNC,
|
||||
SYNC_MODE,
|
||||
ASYNC_MODE,
|
||||
MODE_BUT
|
||||
};
|
||||
|
||||
|
@ -205,7 +199,7 @@ typedef struct SArguments_S {
|
|||
bool verbose_print;
|
||||
bool performance_print;
|
||||
char * output_file;
|
||||
uint32_t query_mode;
|
||||
bool async_mode;
|
||||
char * datatype[MAX_NUM_DATATYPE + 1];
|
||||
uint32_t len_of_binary;
|
||||
uint32_t num_of_CPR;
|
||||
|
@ -343,7 +337,7 @@ typedef struct SDbs_S {
|
|||
bool use_metric;
|
||||
bool insert_only;
|
||||
bool do_aggreFunc;
|
||||
bool queryMode;
|
||||
bool asyncMode;
|
||||
|
||||
uint32_t threadCount;
|
||||
uint32_t threadCountByCreateTbl;
|
||||
|
@ -360,7 +354,7 @@ typedef struct SpecifiedQueryInfo_S {
|
|||
uint64_t queryInterval; // 0: unlimit > 0 loop/s
|
||||
uint64_t concurrent;
|
||||
uint64_t sqlCount;
|
||||
uint32_t mode; // 0: sync, 1: async
|
||||
uint32_t asyncMode; // 0: sync, 1: async
|
||||
uint64_t subscribeInterval; // ms
|
||||
uint64_t queryTimes;
|
||||
int subscribeRestart;
|
||||
|
@ -375,7 +369,7 @@ typedef struct SuperQueryInfo_S {
|
|||
char sTblName[MAX_TB_NAME_SIZE+1];
|
||||
uint64_t queryInterval; // 0: unlimit > 0 loop/s
|
||||
uint32_t threadCnt;
|
||||
uint32_t mode; // 0: sync, 1: async
|
||||
uint32_t asyncMode; // 0: sync, 1: async
|
||||
uint64_t subscribeInterval; // ms
|
||||
int subscribeRestart;
|
||||
int subscribeKeepProgress;
|
||||
|
@ -777,7 +771,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
|
|||
errorPrint("%s", "\n\t-q need a number following!\nQuery mode -- 0: SYNC, 1: ASYNC. Default is SYNC.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
arguments->query_mode = atoi(argv[++i]);
|
||||
arguments->async_mode = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-T") == 0) {
|
||||
if ((argc == i+1)
|
||||
|| (!isStringNumber(argv[i+1]))) {
|
||||
|
@ -1646,7 +1640,7 @@ static void printfQueryMeta() {
|
|||
printf("concurrent: \033[33m%"PRIu64"\033[0m\n",
|
||||
g_queryInfo.specifiedQueryInfo.concurrent);
|
||||
printf("mod: \033[33m%s\033[0m\n",
|
||||
(g_queryInfo.specifiedQueryInfo.mode)?"async":"sync");
|
||||
(g_queryInfo.specifiedQueryInfo.asyncMode)?"async":"sync");
|
||||
printf("interval: \033[33m%"PRIu64"\033[0m\n",
|
||||
g_queryInfo.specifiedQueryInfo.subscribeInterval);
|
||||
printf("restart: \033[33m%d\033[0m\n",
|
||||
|
@ -1678,7 +1672,7 @@ static void printfQueryMeta() {
|
|||
g_queryInfo.superQueryInfo.queryTimes);
|
||||
|
||||
printf("mod: \033[33m%s\033[0m\n",
|
||||
(g_queryInfo.superQueryInfo.mode)?"async":"sync");
|
||||
(g_queryInfo.superQueryInfo.asyncMode)?"async":"sync");
|
||||
printf("interval: \033[33m%"PRIu64"\033[0m\n",
|
||||
g_queryInfo.superQueryInfo.subscribeInterval);
|
||||
printf("restart: \033[33m%d\033[0m\n",
|
||||
|
@ -4121,20 +4115,20 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
|
|||
g_queryInfo.specifiedQueryInfo.concurrent = 1;
|
||||
}
|
||||
|
||||
cJSON* mode = cJSON_GetObjectItem(specifiedQuery, "mode");
|
||||
if (mode && mode->type == cJSON_String
|
||||
&& mode->valuestring != NULL) {
|
||||
if (0 == strcmp("sync", mode->valuestring)) {
|
||||
g_queryInfo.specifiedQueryInfo.mode = SYNC_QUERY_MODE;
|
||||
} else if (0 == strcmp("async", mode->valuestring)) {
|
||||
g_queryInfo.specifiedQueryInfo.mode = ASYNC_QUERY_MODE;
|
||||
cJSON* specifiedAsyncMode = cJSON_GetObjectItem(specifiedQuery, "mode");
|
||||
if (specifiedAsyncMode && specifiedAsyncMode->type == cJSON_String
|
||||
&& specifiedAsyncMode->valuestring != NULL) {
|
||||
if (0 == strcmp("sync", specifiedAsyncMode->valuestring)) {
|
||||
g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE;
|
||||
} else if (0 == strcmp("async", specifiedAsyncMode->valuestring)) {
|
||||
g_queryInfo.specifiedQueryInfo.asyncMode = ASYNC_MODE;
|
||||
} else {
|
||||
errorPrint("%s() LN%d, failed to read json, query mode input error\n",
|
||||
errorPrint("%s() LN%d, failed to read json, async mode input error\n",
|
||||
__func__, __LINE__);
|
||||
goto PARSE_OVER;
|
||||
}
|
||||
} else {
|
||||
g_queryInfo.specifiedQueryInfo.mode = SYNC_QUERY_MODE;
|
||||
g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE;
|
||||
}
|
||||
|
||||
cJSON* interval = cJSON_GetObjectItem(specifiedQuery, "interval");
|
||||
|
@ -4281,20 +4275,20 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
|
|||
goto PARSE_OVER;
|
||||
}
|
||||
|
||||
cJSON* submode = cJSON_GetObjectItem(superQuery, "mode");
|
||||
if (submode && submode->type == cJSON_String
|
||||
&& submode->valuestring != NULL) {
|
||||
if (0 == strcmp("sync", submode->valuestring)) {
|
||||
g_queryInfo.superQueryInfo.mode = SYNC_QUERY_MODE;
|
||||
} else if (0 == strcmp("async", submode->valuestring)) {
|
||||
g_queryInfo.superQueryInfo.mode = ASYNC_QUERY_MODE;
|
||||
cJSON* superAsyncMode = cJSON_GetObjectItem(superQuery, "mode");
|
||||
if (superAsyncMode && superAsyncMode->type == cJSON_String
|
||||
&& superAsyncMode->valuestring != NULL) {
|
||||
if (0 == strcmp("sync", superAsyncMode->valuestring)) {
|
||||
g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE;
|
||||
} else if (0 == strcmp("async", superAsyncMode->valuestring)) {
|
||||
g_queryInfo.superQueryInfo.asyncMode = ASYNC_MODE;
|
||||
} else {
|
||||
errorPrint("%s() LN%d, failed to read json, query mode input error\n",
|
||||
errorPrint("%s() LN%d, failed to read json, async mode input error\n",
|
||||
__func__, __LINE__);
|
||||
goto PARSE_OVER;
|
||||
}
|
||||
} else {
|
||||
g_queryInfo.superQueryInfo.mode = SYNC_QUERY_MODE;
|
||||
g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE;
|
||||
}
|
||||
|
||||
cJSON* superInterval = cJSON_GetObjectItem(superQuery, "interval");
|
||||
|
@ -5748,10 +5742,10 @@ static void startMultiThreadInsertData(int threads, char* db_name,
|
|||
}
|
||||
*/
|
||||
tsem_init(&(t_info->lock_sem), 0, 0);
|
||||
if (SYNC == g_Dbs.queryMode) {
|
||||
pthread_create(pids + i, NULL, syncWrite, t_info);
|
||||
} else {
|
||||
if (ASYNC_MODE == g_Dbs.asyncMode) {
|
||||
pthread_create(pids + i, NULL, asyncWrite, t_info);
|
||||
} else {
|
||||
pthread_create(pids + i, NULL, syncWrite, t_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6455,7 +6449,7 @@ static TAOS_SUB* subscribeImpl(
|
|||
TAOS *taos, char *sql, char* topic, char* resultFileName) {
|
||||
TAOS_SUB* tsub = NULL;
|
||||
|
||||
if (ASYNC_QUERY_MODE == g_queryInfo.specifiedQueryInfo.mode) {
|
||||
if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) {
|
||||
tsub = taos_subscribe(taos,
|
||||
g_queryInfo.specifiedQueryInfo.subscribeRestart,
|
||||
topic, sql, subscribe_callback, (void*)resultFileName,
|
||||
|
@ -6540,7 +6534,7 @@ static void *superSubscribe(void *sarg) {
|
|||
TAOS_RES* res = NULL;
|
||||
while(1) {
|
||||
for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) {
|
||||
if (ASYNC_QUERY_MODE == g_queryInfo.superQueryInfo.mode) {
|
||||
if (ASYNC_MODE == g_queryInfo.superQueryInfo.asyncMode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -6629,7 +6623,7 @@ static void *specifiedSubscribe(void *sarg) {
|
|||
TAOS_RES* res = NULL;
|
||||
while(1) {
|
||||
for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) {
|
||||
if (ASYNC_QUERY_MODE == g_queryInfo.specifiedQueryInfo.mode) {
|
||||
if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -6852,7 +6846,7 @@ static void setParaFromArg(){
|
|||
g_Dbs.db[0].superTbls[0].childTblCount = g_args.num_of_tables;
|
||||
g_Dbs.threadCount = g_args.num_of_threads;
|
||||
g_Dbs.threadCountByCreateTbl = g_args.num_of_threads;
|
||||
g_Dbs.queryMode = g_args.query_mode;
|
||||
g_Dbs.asyncMode = g_args.async_mode;
|
||||
|
||||
g_Dbs.db[0].superTbls[0].autoCreateTable = PRE_CREATE_SUBTBL;
|
||||
g_Dbs.db[0].superTbls[0].childTblExists = TBL_NO_EXISTS;
|
||||
|
|
|
@ -344,7 +344,7 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
|
|||
|
||||
pShow->bytes[cols] = 24;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "qhandle");
|
||||
strcpy(pSchema[cols].name, "qid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
|
@ -420,7 +420,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v
|
|||
cols++;
|
||||
|
||||
char handleBuf[24] = {0};
|
||||
snprintf(handleBuf, tListLen(handleBuf), "%p", (void*)htobe64(pDesc->qHandle));
|
||||
snprintf(handleBuf, tListLen(handleBuf), "%"PRIu64, htobe64(pDesc->qId));
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, handleBuf, pShow->bytes[cols]);
|
||||
|
|
|
@ -123,7 +123,7 @@ static void mnodePrintUserAuth() {
|
|||
mnodeDecUserRef(pUser);
|
||||
}
|
||||
|
||||
fsync(fileno(fp));
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
ADD_SUBDIRECTORY(src/linux)
|
||||
ADD_SUBDIRECTORY(src/linux)
|
||||
ELSEIF (TD_DARWIN)
|
||||
ADD_SUBDIRECTORY(src/darwin)
|
||||
ELSEIF (TD_WINDOWS)
|
||||
|
|
|
@ -20,45 +20,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _TD_DARWIN_64
|
||||
#include "osDarwin.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_ARM_64
|
||||
#include "osArm64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_ARM_32
|
||||
#include "osArm32.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_MIPS_64
|
||||
#include "osMips64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_LINUX_64
|
||||
#include "osLinux64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_LINUX_32
|
||||
#include "osLinux32.h"
|
||||
#endif
|
||||
|
||||
#ifdef _ALPINE
|
||||
#include "osAlpine.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_NINGSI_60
|
||||
#include "osNingsi.h"
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#include "osWindows.h"
|
||||
#endif
|
||||
|
||||
#include "osInc.h"
|
||||
#include "osDef.h"
|
||||
#include "osAtomic.h"
|
||||
#include "osCommon.h"
|
||||
#include "osDir.h"
|
||||
#include "osFile.h"
|
||||
#include "osLz4.h"
|
||||
|
@ -67,6 +31,7 @@ extern "C" {
|
|||
#include "osRand.h"
|
||||
#include "osSemphone.h"
|
||||
#include "osSignal.h"
|
||||
#include "osSleep.h"
|
||||
#include "osSocket.h"
|
||||
#include "osString.h"
|
||||
#include "osSysinfo.h"
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_ALPINE_H
|
||||
#define TDENGINE_OS_ALPINE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
void error (int, int, const char *);
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_ARM32_H
|
||||
#define TDENGINE_OS_ARM32_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
|
||||
#define TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_ARM64_H
|
||||
#define TDENGINE_OS_ARM64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,7 +20,252 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_ATOMIC
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
|
||||
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
|
||||
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
|
||||
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
|
||||
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
|
||||
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
|
||||
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
|
||||
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
|
||||
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
|
||||
|
||||
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#else
|
||||
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#else
|
||||
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
|
||||
#endif
|
||||
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
|
||||
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
|
||||
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
|
||||
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
|
||||
|
||||
char interlocked_add_fetch_8(char volatile *ptr, char val);
|
||||
short interlocked_add_fetch_16(short volatile *ptr, short val);
|
||||
long interlocked_add_fetch_32(long volatile *ptr, long val);
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
|
||||
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_fetch_add_8 __sync_fetch_and_ad
|
||||
#define atomic_fetch_add_16 __sync_fetch_and_add
|
||||
#else
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_64
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_64
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_64
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_64
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_64
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_64
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
|
||||
#else
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_32
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_32
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_32
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_32
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_32
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_32
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
|
||||
#endif
|
||||
#elif defined(_TD_NINGSI_60)
|
||||
/*
|
||||
* type __sync_fetch_and_add (type *ptr, type value);
|
||||
* type __sync_fetch_and_sub (type *ptr, type value);
|
||||
* type __sync_fetch_and_or (type *ptr, type value);
|
||||
* type __sync_fetch_and_and (type *ptr, type value);
|
||||
* type __sync_fetch_and_xor (type *ptr, type value);
|
||||
* type __sync_fetch_and_nand (type *ptr, type value);
|
||||
* type __sync_add_and_fetch (type *ptr, type value);
|
||||
* type __sync_sub_and_fetch (type *ptr, type value);
|
||||
* type __sync_or_and_fetch (type *ptr, type value);
|
||||
* type __sync_and_and_fetch (type *ptr, type value);
|
||||
* type __sync_xor_and_fetch (type *ptr, type value);
|
||||
* type __sync_nand_and_fetch (type *ptr, type value);
|
||||
*
|
||||
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
|
||||
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
|
||||
* */
|
||||
|
||||
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
|
||||
#define atomic_store_8(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_16(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_32(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_64(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
|
||||
|
||||
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val );
|
||||
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val );
|
||||
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val );
|
||||
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val );
|
||||
void* atomic_exchange_ptr_impl( void **ptr, void *val );
|
||||
|
||||
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
|
||||
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
|
||||
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
|
||||
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
|
||||
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
|
||||
#else
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_DARWIN_H
|
||||
#define TDENGINE_OS_DARWIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <math.h>
|
||||
|
||||
#define TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
|
||||
#define TAOS_OS_FUNC_SEMPHONE
|
||||
typedef struct tsem_s *tsem_t;
|
||||
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
|
||||
int tsem_wait(tsem_t *sem);
|
||||
int tsem_post(tsem_t *sem);
|
||||
int tsem_destroy(tsem_t *sem);
|
||||
|
||||
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
#define TAOS_OS_FUNC_STRING_STR2INT64
|
||||
#define TAOS_OS_FUNC_SYSINFO
|
||||
#define TAOS_OS_FUNC_TIMER
|
||||
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
|
||||
// specific
|
||||
#define htobe64 htonll
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#if defined(MSG_NOSIGNAL)
|
||||
#undef MSG_NOSIGNAL
|
||||
#endif
|
||||
|
||||
#define MSG_NOSIGNAL 0
|
||||
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_PTHREAD_RWLOCK
|
||||
|
||||
int64_t tsosStr2int64(char *str);
|
||||
|
||||
#include "eok.h"
|
||||
|
||||
void taos_block_sigalrm(void);
|
||||
|
||||
#define TAOS_OS_DEF_EPOLL
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,17 +20,109 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
// specific
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#if defined(MSG_NOSIGNAL)
|
||||
#undef MSG_NOSIGNAL
|
||||
#endif
|
||||
|
||||
#define MSG_NOSIGNAL 0
|
||||
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_ALPINE)
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
void error (int, int, const char *);
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
char *stpcpy (char *dest, const char *src);
|
||||
char *stpncpy (char *dest, const char *src, size_t n);
|
||||
|
||||
// specific
|
||||
typedef int (*__compar_fn_t)(const void *, const void *);
|
||||
#define ssize_t int
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
#define strtok_r strtok_s
|
||||
#define snprintf _snprintf
|
||||
#define in_addr_t unsigned long
|
||||
#define socklen_t int
|
||||
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
char * strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||
char * strsep(char **stringp, const char *delim);
|
||||
char * getpass(const char *prefix);
|
||||
int flock(int fd, int option);
|
||||
char * strndup(const char *s, size_t n);
|
||||
int gettimeofday(struct timeval *ptv, void *pTimeZone);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
|
||||
#ifndef TCP_KEEPCNT
|
||||
#define TCP_KEEPCNT 0x1234
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPIDLE
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPINTVL
|
||||
#define TCP_KEEPINTVL 0x1234
|
||||
#endif
|
||||
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
#define SHUT_RD SD_RECEIVE
|
||||
#define SHUT_WR SD_SEND
|
||||
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_NB 2
|
||||
#define LOCK_UN 3
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int we_wordc;
|
||||
char *we_wordv[1];
|
||||
int we_offs;
|
||||
char wordPos[1025];
|
||||
} wordexp_t;
|
||||
int wordexp(char *words, wordexp_t *pwordexp, int flags);
|
||||
void wordfree(wordexp_t *pwordexp);
|
||||
|
||||
#define openlog(a, b, c)
|
||||
#define closelog()
|
||||
#define LOG_ERR 0
|
||||
#define LOG_INFO 1
|
||||
void syslog(int unused, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#ifndef WINDOWS
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
// #define WCHAR wchar_t
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
|
@ -113,6 +205,12 @@ extern "C" {
|
|||
#define threadlocal __declspec( thread )
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define PRIzu "ld"
|
||||
#else
|
||||
#define PRIzu "zu"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,13 +20,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
// TAOS_OS_FUNC_DIR
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int taosMkDir(const char *pathname, mode_t mode);
|
||||
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
|
||||
int32_t taosRename(char* oldName, char *newName);
|
||||
void taosRemoveDir(char *rootDir);
|
||||
int32_t taosMkDir(const char *pathname, mode_t mode);
|
||||
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
|
||||
int32_t taosRename(char *oldName, char *newName);
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _eok_h_fd274616_996c_400e_9023_ae70be881fa3_
|
||||
#define _eok_h_fd274616_996c_400e_9023_ae70be881fa3_
|
||||
#ifndef TDENGINE_OS_EOK_H
|
||||
#define TDENGINE_OS_EOK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
@ -22,50 +22,39 @@ extern "C" {
|
|||
|
||||
#include "osSocket.h"
|
||||
|
||||
int64_t taosReadImp(int32_t fd, void *buf, int64_t count);
|
||||
int64_t taosWriteImp(int32_t fd, void *buf, int64_t count);
|
||||
int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence);
|
||||
int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstPath);
|
||||
#define FD_VALID(x) ((x) > STDERR_FILENO)
|
||||
#define FD_INITIALIZER ((int32_t)-1)
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
typedef int32_t FileFd;
|
||||
typedef SOCKET SocketFd;
|
||||
#else
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#endif
|
||||
|
||||
int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
||||
int64_t taosWrite(FileFd fd, void *buf, int64_t count);
|
||||
|
||||
int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence);
|
||||
int32_t taosFtruncate(FileFd fd, int64_t length);
|
||||
int32_t taosFsync(FileFd fd);
|
||||
|
||||
int32_t taosRename(char* oldName, char *newName);
|
||||
int64_t taosCopy(char *from, char *to);
|
||||
|
||||
#define taosRead(fd, buf, count) taosReadImp(fd, buf, count)
|
||||
#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence)
|
||||
#define taosClose(fd) \
|
||||
{ \
|
||||
if (FD_VALID(fd)) { \
|
||||
close(fd); \
|
||||
fd = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
|
||||
// TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size);
|
||||
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size);
|
||||
int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size);
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int32_t factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL_TEST
|
||||
int64_t taosReadFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line);
|
||||
int64_t taosWriteFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line);
|
||||
int64_t taosLSeekRandomFail(int32_t fd, int64_t offset, int32_t whence, const char *file, uint32_t line);
|
||||
#undef taosRead
|
||||
#undef taosWrite
|
||||
#undef taosLSeek
|
||||
#define taosRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath);
|
||||
void taosClose(FileFd fd);
|
||||
|
||||
// TAOS_OS_FUNC_FILE_FTRUNCATE
|
||||
int32_t taosFtruncate(int32_t fd, int64_t length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_INC_H
|
||||
#define TDENGINE_OS_INC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
||||
#include <arpa/inet.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <stddef.h>
|
||||
#include <strings.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
#include <dispatch/dispatch.h>
|
||||
#include "osEok.h"
|
||||
#else
|
||||
#include <argp.h>
|
||||
#include <endian.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sendfile.h>
|
||||
|
||||
#if !(defined(_ALPINE))
|
||||
#include <error.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
#include "msvcProcess.h"
|
||||
#include "msvcDirect.h"
|
||||
#include "msvcFcntl.h"
|
||||
#include "msvcLibgen.h"
|
||||
#include "msvcStdio.h"
|
||||
#include "msvcUnistd.h"
|
||||
#include "msvcLibgen.h"
|
||||
#include "sys/msvcStat.h"
|
||||
#include "sys/msvcTypes.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_LINUX32_H
|
||||
#define TDENGINE_OS_LINUX32_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
|
||||
#define TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_LINUX64_H
|
||||
#define TDENGINE_OS_LINUX64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <poll.h>
|
||||
#ifndef _ALPINE
|
||||
#include <error.h>
|
||||
#endif
|
||||
#include <linux/sysctl.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,7 +20,22 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_LZ4
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
int32_t BUILDIN_CLZL(uint64_t val);
|
||||
int32_t BUILDIN_CLZ(uint32_t val);
|
||||
int32_t BUILDIN_CTZL(uint64_t val);
|
||||
int32_t BUILDIN_CTZ(uint32_t val);
|
||||
#elif defined (_TD_LINUX_32)
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#elif defined (_TD_ARM_32)
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#else
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
|
|
|
@ -23,26 +23,38 @@ extern "C" {
|
|||
#define POW2(x) ((x) * (x))
|
||||
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#else
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
|
|
|
@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c);
|
|||
#define tmalloc(size) malloc(size)
|
||||
#define tcalloc(num, size) calloc(num, size)
|
||||
#define trealloc(ptr, size) realloc(ptr, size)
|
||||
#define tstrdup(str) taosStrdupImp(str)
|
||||
#define tstrndup(str, size) taosStrndupImp(str, size)
|
||||
#define tgetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream)
|
||||
#define tfree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
|
@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c);
|
|||
#define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__)
|
||||
#define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__)
|
||||
#define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__)
|
||||
|
||||
// #undef tstrdup
|
||||
// #undef tstrndup
|
||||
// #undef tgetline
|
||||
// #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__)
|
||||
// #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
|
||||
// #define tgetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_MIPS64_H
|
||||
#define TDENGINE_OS_MIPS64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_NINGSI_H
|
||||
#define TDENGINE_OS_NINGSI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_ATOMIC
|
||||
/*
|
||||
* type __sync_fetch_and_add (type *ptr, type value);
|
||||
* type __sync_fetch_and_sub (type *ptr, type value);
|
||||
* type __sync_fetch_and_or (type *ptr, type value);
|
||||
* type __sync_fetch_and_and (type *ptr, type value);
|
||||
* type __sync_fetch_and_xor (type *ptr, type value);
|
||||
* type __sync_fetch_and_nand (type *ptr, type value);
|
||||
* type __sync_add_and_fetch (type *ptr, type value);
|
||||
* type __sync_sub_and_fetch (type *ptr, type value);
|
||||
* type __sync_or_and_fetch (type *ptr, type value);
|
||||
* type __sync_and_and_fetch (type *ptr, type value);
|
||||
* type __sync_xor_and_fetch (type *ptr, type value);
|
||||
* type __sync_nand_and_fetch (type *ptr, type value);
|
||||
*
|
||||
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
|
||||
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
|
||||
* */
|
||||
|
||||
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
|
||||
|
||||
#define atomic_store_8(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_16(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_32(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_64(ptr, val) (*(ptr)=(val))
|
||||
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
|
||||
|
||||
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val );
|
||||
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val );
|
||||
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val );
|
||||
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val );
|
||||
void* atomic_exchange_ptr_impl( void **ptr, void *val );
|
||||
|
||||
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
|
||||
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
|
||||
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
|
||||
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
|
||||
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,9 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_RAND
|
||||
uint32_t taosRand(void);
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
void taosRandStr(char* str, int32_t size);
|
||||
uint32_t taosSafeRand(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -20,7 +20,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE
|
||||
#if defined (_TD_DARWIN_64)
|
||||
typedef struct tsem_s *tsem_t;
|
||||
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
|
||||
int tsem_wait(tsem_t *sem);
|
||||
int tsem_post(tsem_t *sem);
|
||||
int tsem_destroy(tsem_t *sem);
|
||||
#else
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
int tsem_wait(tsem_t* sem);
|
||||
|
@ -28,7 +34,7 @@ extern "C" {
|
|||
#define tsem_destroy sem_destroy
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_OS_FUNC_PTHREAD_RWLOCK
|
||||
#if defined (_TD_DARWIN_64)
|
||||
#define pthread_rwlock_t pthread_mutex_t
|
||||
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
|
||||
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
|
||||
|
@ -43,7 +49,6 @@ extern "C" {
|
|||
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
int64_t taosGetSelfPthreadId();
|
||||
int64_t taosGetPthreadId(pthread_t thread);
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef SIGALRM
|
||||
|
@ -57,4 +55,4 @@ void taosDflSignal(int32_t signum);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TTIME_H
|
||||
#endif // TDENGINE_OS_SIGNAL_H
|
||||
|
|
|
@ -13,19 +13,17 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_COMMON_H
|
||||
#define TDENGINE_OS_COMMON_H
|
||||
#ifndef TDENGINE_OS_SLEEP_H
|
||||
#define TDENGINE_OS_SLEEP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_DEF_ZU
|
||||
#define PRIzu "zu"
|
||||
#endif
|
||||
void taosMsleep(int32_t ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -20,7 +20,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SOCKET_OP
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
|
||||
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
|
||||
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
|
||||
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
|
||||
#else
|
||||
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
|
@ -35,7 +42,21 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_DEF_EPOLL
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define TAOS_EPOLL_WAIT_TIME 100
|
||||
typedef SOCKET eventfd_t;
|
||||
#define eventfd(a, b) -1
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#ifndef EPOLLWAKEUP
|
||||
#define EPOLLWAKEUP (1u << 29)
|
||||
#endif
|
||||
#elif defined(_TD_DARWIN_64)
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#else
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
|
@ -59,21 +80,27 @@ extern "C" {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET
|
||||
int32_t taosSetNonblocking(SOCKET sock, int32_t on);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosBlockSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen);
|
||||
|
||||
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen);
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET_INET
|
||||
uint32_t taosInetAddr(char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt);
|
||||
|
||||
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
|
||||
#define htobe64 htonll
|
||||
#if defined(_TD_GO_DLL_)
|
||||
uint64_t htonll(uint64_t val);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
#define htobe64 htonll
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,35 +20,30 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_STRDUP
|
||||
#define taosStrdupImp(str) strdup(str)
|
||||
#define taosStrndupImp(str, size) strndup(str, size)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_GETLINE
|
||||
#define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream)
|
||||
#else
|
||||
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream);
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_WCHAR
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define tstrdup(str) _strdup(str)
|
||||
#define tstrndup(str, size) _strndup(str, size)
|
||||
int32_t tgetline(char **lineptr, size_t *n, FILE *stream);
|
||||
int32_t twcslen(const wchar_t *wcs);
|
||||
#else
|
||||
#define tstrdup(str) strdup(str)
|
||||
#define tstrndup(str, size) strndup(str, size)
|
||||
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
|
||||
#define twcslen wcslen
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0)
|
||||
|
||||
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
|
||||
int64_t tsosStr2int64(char *str);
|
||||
#endif
|
||||
int64_t taosStr2int64(char *str);
|
||||
|
||||
// USE_LIBICONV
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int *len);
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
char * taosCharsetReplace(char *charsetstr);
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO
|
||||
typedef struct {
|
||||
int64_t tsize;
|
||||
int64_t used;
|
||||
|
@ -28,20 +27,19 @@ typedef struct {
|
|||
} SysDiskSize;
|
||||
|
||||
int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize);
|
||||
void taosGetSystemInfo();
|
||||
bool taosGetProcIO(float *readKB, float *writeKB);
|
||||
bool taosGetBandSpeed(float *bandSpeedKb);
|
||||
void taosGetDisk();
|
||||
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ;
|
||||
bool taosGetProcMemory(float *memoryUsedMB) ;
|
||||
bool taosGetSysMemory(float *memoryUsedMB);
|
||||
void taosPrintOsInfo();
|
||||
int taosSystem(const char * cmd) ;
|
||||
void taosKillSystem();
|
||||
bool taosGetSystemUid(char *uid);
|
||||
char *taosGetCmdlineByPID(int pid);
|
||||
void taosGetSystemInfo();
|
||||
bool taosGetProcIO(float *readKB, float *writeKB);
|
||||
bool taosGetBandSpeed(float *bandSpeedKb);
|
||||
void taosGetDisk();
|
||||
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
|
||||
bool taosGetProcMemory(float *memoryUsedMB);
|
||||
bool taosGetSysMemory(float *memoryUsedMB);
|
||||
void taosPrintOsInfo();
|
||||
int taosSystem(const char *cmd);
|
||||
void taosKillSystem();
|
||||
bool taosGetSystemUid(char *uid);
|
||||
char * taosGetCmdlineByPID(int pid);
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO_CORE
|
||||
void taosSetCoreDump();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -23,9 +23,16 @@ extern "C" {
|
|||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIME_DEF
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#endif
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
|
||||
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||
|
@ -85,7 +92,7 @@ int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts);
|
|||
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit);
|
||||
|
||||
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth);
|
||||
void deltaToUtcInitOnce();
|
||||
void deltaToUtcInitOnce();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TAOS_OS_FUNC_TIMER
|
||||
void taosMsleep(int mseconds);
|
||||
int taosInitTimer(void (*callback)(int), int ms);
|
||||
void taosUninitTimer();
|
||||
|
||||
|
|
|
@ -1,352 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_WINDOWS_H
|
||||
#define TDENGINE_OS_WINDOWS_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <locale.h>
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include <conio.h>
|
||||
#include <math.h>
|
||||
#include "msvcProcess.h"
|
||||
#include "msvcDirect.h"
|
||||
#include "msvcFcntl.h"
|
||||
#include "msvcLibgen.h"
|
||||
#include "msvcStdio.h"
|
||||
#include "msvcUnistd.h"
|
||||
#include "msvcLibgen.h"
|
||||
#include "sys/msvcStat.h"
|
||||
#include "sys/msvcTypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_LZ4
|
||||
int32_t BUILDIN_CLZL(uint64_t val);
|
||||
int32_t BUILDIN_CLZ(uint32_t val);
|
||||
int32_t BUILDIN_CTZL(uint64_t val);
|
||||
int32_t BUILDIN_CTZ(uint32_t val);
|
||||
|
||||
#define TAOS_OS_FUNC_FILE
|
||||
#define TAOS_OS_FUNC_FILE_ISREG
|
||||
#define TAOS_OS_FUNC_FILE_ISDIR
|
||||
#define TAOS_OS_FUNC_FILE_ISLNK
|
||||
#define TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||
#define TAOS_OS_FUNC_FILE_FTRUNCATE
|
||||
|
||||
#define TAOS_OS_FUNC_DIR
|
||||
|
||||
#define TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
|
||||
|
||||
#define TAOS_OS_FUNC_SOCKET
|
||||
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
|
||||
#define TAOS_OS_FUNC_SOCKET_OP
|
||||
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
|
||||
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
|
||||
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
|
||||
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
|
||||
typedef SOCKET eventfd_t;
|
||||
#define eventfd(a, b) -1
|
||||
|
||||
#define TAOS_OS_DEF_EPOLL
|
||||
#define TAOS_EPOLL_WAIT_TIME 100
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
|
||||
#ifndef EPOLLWAKEUP
|
||||
#define EPOLLWAKEUP (1u << 29)
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_DEF_ZU
|
||||
#define PRIzu "ld"
|
||||
|
||||
#define TAOS_OS_FUNC_STRING_WCHAR
|
||||
int twcslen(const wchar_t *wcs);
|
||||
#define TAOS_OS_FUNC_STRING_GETLINE
|
||||
#define TAOS_OS_FUNC_STRING_STR2INT64
|
||||
#ifdef _TD_GO_DLL_
|
||||
int64_t tsosStr2int64(char *str);
|
||||
uint64_t htonll(uint64_t val);
|
||||
#else
|
||||
#define tsosStr2int64 _atoi64
|
||||
#endif
|
||||
#define TAOS_OS_FUNC_STRING_STRDUP
|
||||
#define taosStrdupImp(str) _strdup(str)
|
||||
#define taosStrndupImp(str, size) _strndup(str, size)
|
||||
|
||||
char *stpcpy (char *dest, const char *src);
|
||||
char *stpncpy (char *dest, const char *src, size_t n);
|
||||
|
||||
#define TAOS_OS_FUNC_SYSINFO
|
||||
|
||||
#define TAOS_OS_FUNC_TIME_DEF
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
#define MILLISECOND_PER_SECOND (1000i64)
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_TIMER_SLEEP
|
||||
#define TAOS_OS_FUNC_TIMER
|
||||
|
||||
// specific
|
||||
typedef int (*__compar_fn_t)(const void *, const void *);
|
||||
#define ssize_t int
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
#define strtok_r strtok_s
|
||||
#define snprintf _snprintf
|
||||
#define in_addr_t unsigned long
|
||||
#define socklen_t int
|
||||
#define htobe64 htonll
|
||||
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
char * strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||
char * strsep(char **stringp, const char *delim);
|
||||
char * getpass(const char *prefix);
|
||||
int flock(int fd, int option);
|
||||
int fsync(int filedes);
|
||||
char * strndup(const char *s, size_t n);
|
||||
int gettimeofday(struct timeval *ptv, void *pTimeZone);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
|
||||
#ifndef TCP_KEEPCNT
|
||||
#define TCP_KEEPCNT 0x1234
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPIDLE
|
||||
#define TCP_KEEPIDLE 0x1234
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPINTVL
|
||||
#define TCP_KEEPINTVL 0x1234
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//#if _MSC_VER >= 1900
|
||||
#define TAOS_OS_FUNC_SOCKET_INET
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
#define SHUT_RD SD_RECEIVE
|
||||
#define SHUT_WR SD_SEND
|
||||
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_NB 2
|
||||
#define LOCK_UN 3
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
#define TAOS_OS_FUNC_SIGNAL
|
||||
|
||||
typedef struct {
|
||||
int we_wordc;
|
||||
char *we_wordv[1];
|
||||
int we_offs;
|
||||
char wordPos[1025];
|
||||
} wordexp_t;
|
||||
int wordexp(char *words, wordexp_t *pwordexp, int flags);
|
||||
void wordfree(wordexp_t *pwordexp);
|
||||
|
||||
#define openlog(a, b, c)
|
||||
#define closelog()
|
||||
#define LOG_ERR 0
|
||||
#define LOG_INFO 1
|
||||
void syslog(int unused, const char *format, ...);
|
||||
|
||||
#define TAOS_OS_FUNC_ATOMIC
|
||||
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
|
||||
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
|
||||
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
|
||||
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
|
||||
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
|
||||
|
||||
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
|
||||
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
|
||||
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
|
||||
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
|
||||
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
|
||||
|
||||
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _WIN64
|
||||
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#else
|
||||
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
|
||||
#endif
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#else
|
||||
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
|
||||
#endif
|
||||
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
|
||||
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
|
||||
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
|
||||
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
|
||||
|
||||
char interlocked_add_fetch_8(char volatile *ptr, char val);
|
||||
short interlocked_add_fetch_16(short volatile *ptr, short val);
|
||||
long interlocked_add_fetch_32(long volatile *ptr, long val);
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
|
||||
|
||||
char interlocked_and_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_and_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_and_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_or_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_or_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_or_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
char interlocked_xor_fetch_8(char volatile* ptr, char val);
|
||||
short interlocked_xor_fetch_16(short volatile* ptr, short val);
|
||||
long interlocked_xor_fetch_32(long volatile* ptr, long val);
|
||||
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define atomic_fetch_add_8 __sync_fetch_and_ad
|
||||
#define atomic_fetch_add_16 __sync_fetch_and_add
|
||||
#else
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#endif
|
||||
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
|
||||
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
|
||||
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
|
||||
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
|
||||
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
|
||||
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
|
||||
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
|
||||
|
||||
#ifdef _WIN64
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_64
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_64
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_64
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_64
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_64
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_64
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
|
||||
#else
|
||||
#define atomic_add_fetch_ptr atomic_add_fetch_32
|
||||
#define atomic_fetch_add_ptr atomic_fetch_add_32
|
||||
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
|
||||
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
|
||||
#define atomic_and_fetch_ptr atomic_and_fetch_32
|
||||
#define atomic_fetch_and_ptr atomic_fetch_and_32
|
||||
#define atomic_or_fetch_ptr atomic_or_fetch_32
|
||||
#define atomic_fetch_or_ptr atomic_fetch_or_32
|
||||
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
|
||||
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,7 +0,0 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
TARGET_LINK_LIBRARIES(os m rt)
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* 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 _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
void osInit() {
|
||||
if (configDir[0] == 0) {
|
||||
strcpy(configDir, "/etc/taos");
|
||||
}
|
||||
|
||||
strcpy(tsVnodeDir, "");
|
||||
strcpy(tsDnodeDir, "");
|
||||
strcpy(tsMnodeDir, "");
|
||||
strcpy(tsDataDir, "/var/lib/taos");
|
||||
strcpy(tsLogDir, "/var/log/taos");
|
||||
strcpy(tsScriptDir, "/etc/taos");
|
||||
strcpy(tsOsName, "Linux");
|
||||
}
|
|
@ -2,4 +2,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
ADD_LIBRARY(osdarwin ${SRC})
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* 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 _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tulog.h"
|
||||
|
||||
int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) {
|
||||
int r = 0;
|
||||
if (offset) {
|
||||
r = fseek(in_file, *offset, SEEK_SET);
|
||||
if (r==-1) return -1;
|
||||
}
|
||||
off_t len = count;
|
||||
while (len>0) {
|
||||
char buf[1024*16];
|
||||
off_t n = sizeof(buf);
|
||||
if (len<n) n = len;
|
||||
size_t m = fread(buf, 1, n, in_file);
|
||||
if (m<n) {
|
||||
int e = ferror(in_file);
|
||||
if (e) return -1;
|
||||
}
|
||||
if (m==0) break;
|
||||
if (m!=fwrite(buf, 1, m, out_file)) {
|
||||
return -1;
|
||||
}
|
||||
len -= m;
|
||||
}
|
||||
return count - len;
|
||||
}
|
||||
|
||||
int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t* offset, int64_t count) {
|
||||
int r = 0;
|
||||
if (offset) {
|
||||
r = lseek(sfd, *offset, SEEK_SET);
|
||||
if (r==-1) return -1;
|
||||
}
|
||||
off_t len = count;
|
||||
while (len>0) {
|
||||
char buf[1024*16];
|
||||
off_t n = sizeof(buf);
|
||||
if (len<n) n = len;
|
||||
size_t m = read(sfd, buf, n);
|
||||
if (m==-1) return -1;
|
||||
if (m==0) break;
|
||||
size_t l = write(dfd, buf, m);
|
||||
if (l==-1) return -1;
|
||||
len -= l;
|
||||
}
|
||||
return count - len;
|
||||
}
|
||||
|
|
@ -18,9 +18,9 @@
|
|||
// https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere
|
||||
// experimentally, we follow log-and-crash here
|
||||
|
||||
#include "eok.h"
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "osEok.h"
|
||||
|
||||
#include <sys/event.h>
|
||||
|
||||
|
@ -415,8 +415,6 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) {
|
|||
static struct timespec do_timespec_diff(struct timespec *from, struct timespec *to);
|
||||
|
||||
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) {
|
||||
taos_block_sigalrm();
|
||||
|
||||
int e = 0;
|
||||
if (!events) {
|
||||
errno = EINVAL;
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#include <libproc.h>
|
||||
|
||||
// #define SEM_USE_PTHREAD
|
|
@ -22,7 +22,6 @@
|
|||
#include <errno.h>
|
||||
#include <libproc.h>
|
||||
|
||||
|
||||
static void taosGetSystemTimezone() {
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
if (cfg_timezone == NULL) return;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue