提交 6c0afb07 编写于 作者: A Alex Duan

Merge branch '2.4' of github.com:taosdata/TDengine into 2.4

...@@ -1853,3 +1853,24 @@ TDengine 中的表(列)名命名规则如下: ...@@ -1853,3 +1853,24 @@ TDengine 中的表(列)名命名规则如下:
```mysql ```mysql
select jtag->'key' from (select jtag from stable) where jtag->'key'>0 select jtag->'key' from (select jtag from stable) where jtag->'key'>0
``` ```
## 转义字符说明
- 转义字符表
| 字符序列 | **代表的字符** |
| :--------: | ------- |
| `\'` | 单引号' |
| `\"` | 双引号" |
| \n | 换行符 |
| \r | 回车符 |
| \t | tab符 |
| `\\` | 斜杠\ |
| `\%` | % 规则见下 |
| `\_` | _ 规则见下 |
- 转义字符使用规则
1. 标识符里有转义字符(数据库名、表名、列名)
1. 普通标识符: 直接提示错误的标识符,因为标识符规定必须是数字、字母和下划线,并且不能以数字开头。
2. 反引号``标识符: 保持原样,不转义
2. 数据里有转义字符
1. 遇到上面定义的转义字符会转义(%和_见下面说明),如果没有匹配的转义字符会忽略掉转义符\。
2. 对于%和_,因为在like里这两个字符是通配符,所以在模式匹配like里用`\%`和`\_`表示字符里本身的%和_,如果在like模式匹配上下文之外使用`\%`或`\_`,则它们的计算结果为字符串`\%`和`\_`,而不是%和_。
\ No newline at end of file
...@@ -1335,3 +1335,24 @@ Is not null supports all types of columns. Non-null expression is < > "" and onl ...@@ -1335,3 +1335,24 @@ Is not null supports all types of columns. Non-null expression is < > "" and onl
select jtag->'key' from (select jtag from stable) where jtag->'key'>0 select jtag->'key' from (select jtag from stable) where jtag->'key'>0
``` ```
## Escape character description
- Special Character Escape Sequences
| Escape Sequence | **Character Represented by Sequence** |
| :--------: | ------------------- |
| `\'` | A single quote (') character |
| `\"` | A double quote (") character |
| \n | A newline (linefeed) character |
| \r | A carriage return character |
| \t | A tab character |
| `\\` | A backslash (\) character |
| `\%` | A % character; see note following the table |
| `\_` | A _ character; see note following the table |
- Escape character usage rules
- The escape characters that in a identifier (database name, table name, column name)
1. Normal identifier: The wrong identifier is prompted directly, because the identifier must be numbers, letters and underscores, and cannot start with a number.
2. Backquote`` identifier: Keep it as it is.
- The escape characters that in a data
3. The escape character defined above will be escaped (% and _ see the description below). If there is no matching escape character, the escape character will be ignored.
4. The `\%` and `\_` sequences are used to search for literal instances of % and _ in pattern-matching contexts where they would otherwise be interpreted as wildcard characters.If you use `\%` or `\_` outside of pattern-matching contexts, they evaluate to the strings `\%` and `\_`, not to % and _.
\ No newline at end of file
...@@ -36,11 +36,11 @@ install_home_path="/usr/local/taos" ...@@ -36,11 +36,11 @@ install_home_path="/usr/local/taos"
mkdir -p ${pkg_dir}${install_home_path} mkdir -p ${pkg_dir}${install_home_path}
mkdir -p ${pkg_dir}${install_home_path}/bin mkdir -p ${pkg_dir}${install_home_path}/bin
mkdir -p ${pkg_dir}${install_home_path}/cfg mkdir -p ${pkg_dir}${install_home_path}/cfg
mkdir -p ${pkg_dir}${install_home_path}/connector #mkdir -p ${pkg_dir}${install_home_path}/connector
mkdir -p ${pkg_dir}${install_home_path}/driver mkdir -p ${pkg_dir}${install_home_path}/driver
mkdir -p ${pkg_dir}${install_home_path}/examples mkdir -p ${pkg_dir}${install_home_path}/examples
mkdir -p ${pkg_dir}${install_home_path}/include mkdir -p ${pkg_dir}${install_home_path}/include
mkdir -p ${pkg_dir}${install_home_path}/init.d #mkdir -p ${pkg_dir}${install_home_path}/init.d
mkdir -p ${pkg_dir}${install_home_path}/script mkdir -p ${pkg_dir}${install_home_path}/script
cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg
...@@ -51,7 +51,7 @@ if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then ...@@ -51,7 +51,7 @@ if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then
cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg || : cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg || :
fi fi
cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d #cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d
cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script
cp ${compile_dir}/../packaging/tools/preun.sh ${pkg_dir}${install_home_path}/script cp ${compile_dir}/../packaging/tools/preun.sh ${pkg_dir}${install_home_path}/script
cp ${compile_dir}/../packaging/tools/startPre.sh ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/../packaging/tools/startPre.sh ${pkg_dir}${install_home_path}/bin
...@@ -70,10 +70,10 @@ cp ${compile_dir}/../src/inc/taos.h ${pkg_dir}${install_home_pat ...@@ -70,10 +70,10 @@ cp ${compile_dir}/../src/inc/taos.h ${pkg_dir}${install_home_pat
cp ${compile_dir}/../src/inc/taosdef.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../src/inc/taosdef.h ${pkg_dir}${install_home_path}/include
cp ${compile_dir}/../src/inc/taoserror.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../src/inc/taoserror.h ${pkg_dir}${install_home_path}/include
cp -r ${top_dir}/tests/examples/* ${pkg_dir}${install_home_path}/examples cp -r ${top_dir}/tests/examples/* ${pkg_dir}${install_home_path}/examples
cp -r ${top_dir}/src/connector/python ${pkg_dir}${install_home_path}/connector #cp -r ${top_dir}/src/connector/python ${pkg_dir}${install_home_path}/connector
cp -r ${top_dir}/src/connector/go ${pkg_dir}${install_home_path}/connector #cp -r ${top_dir}/src/connector/go ${pkg_dir}${install_home_path}/connector
cp -r ${top_dir}/src/connector/nodejs ${pkg_dir}${install_home_path}/connector #cp -r ${top_dir}/src/connector/nodejs ${pkg_dir}${install_home_path}/connector
cp ${compile_dir}/build/lib/taos-jdbcdriver*.* ${pkg_dir}${install_home_path}/connector ||: #cp ${compile_dir}/build/lib/taos-jdbcdriver*.* ${pkg_dir}${install_home_path}/connector ||:
install_user_local_path="/usr/local" install_user_local_path="/usr/local"
......
...@@ -46,11 +46,11 @@ libfile="libtaos.so.%{_version}" ...@@ -46,11 +46,11 @@ libfile="libtaos.so.%{_version}"
# create install path, and cp file # create install path, and cp file
mkdir -p %{buildroot}%{homepath}/bin mkdir -p %{buildroot}%{homepath}/bin
mkdir -p %{buildroot}%{homepath}/cfg mkdir -p %{buildroot}%{homepath}/cfg
mkdir -p %{buildroot}%{homepath}/connector #mkdir -p %{buildroot}%{homepath}/connector
mkdir -p %{buildroot}%{homepath}/driver mkdir -p %{buildroot}%{homepath}/driver
mkdir -p %{buildroot}%{homepath}/examples mkdir -p %{buildroot}%{homepath}/examples
mkdir -p %{buildroot}%{homepath}/include mkdir -p %{buildroot}%{homepath}/include
mkdir -p %{buildroot}%{homepath}/init.d #mkdir -p %{buildroot}%{homepath}/init.d
mkdir -p %{buildroot}%{homepath}/script mkdir -p %{buildroot}%{homepath}/script
cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg
...@@ -60,7 +60,7 @@ fi ...@@ -60,7 +60,7 @@ fi
if [ -f %{_compiledir}/test/cfg/taosadapter.service ]; then if [ -f %{_compiledir}/test/cfg/taosadapter.service ]; then
cp %{_compiledir}/test/cfg/taosadapter.service %{buildroot}%{homepath}/cfg cp %{_compiledir}/test/cfg/taosadapter.service %{buildroot}%{homepath}/cfg
fi fi
cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d #cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d
cp %{_compiledir}/../packaging/tools/post.sh %{buildroot}%{homepath}/script cp %{_compiledir}/../packaging/tools/post.sh %{buildroot}%{homepath}/script
cp %{_compiledir}/../packaging/tools/preun.sh %{buildroot}%{homepath}/script cp %{_compiledir}/../packaging/tools/preun.sh %{buildroot}%{homepath}/script
cp %{_compiledir}/../packaging/tools/startPre.sh %{buildroot}%{homepath}/bin cp %{_compiledir}/../packaging/tools/startPre.sh %{buildroot}%{homepath}/bin
...@@ -75,10 +75,10 @@ cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driv ...@@ -75,10 +75,10 @@ cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driv
cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include
cp %{_compiledir}/../src/inc/taosdef.h %{buildroot}%{homepath}/include cp %{_compiledir}/../src/inc/taosdef.h %{buildroot}%{homepath}/include
cp %{_compiledir}/../src/inc/taoserror.h %{buildroot}%{homepath}/include cp %{_compiledir}/../src/inc/taoserror.h %{buildroot}%{homepath}/include
cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector #cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector
cp -r %{_compiledir}/../src/connector/go %{buildroot}%{homepath}/connector #cp -r %{_compiledir}/../src/connector/go %{buildroot}%{homepath}/connector
cp -r %{_compiledir}/../src/connector/nodejs %{buildroot}%{homepath}/connector #cp -r %{_compiledir}/../src/connector/nodejs %{buildroot}%{homepath}/connector
cp %{_compiledir}/build/lib/taos-jdbcdriver*.* %{buildroot}%{homepath}/connector ||: #cp %{_compiledir}/build/lib/taos-jdbcdriver*.* %{buildroot}%{homepath}/connector ||:
cp -r %{_compiledir}/../tests/examples/* %{buildroot}%{homepath}/examples cp -r %{_compiledir}/../tests/examples/* %{buildroot}%{homepath}/examples
if [ -f %{_compiledir}/build/bin/jemalloc-config ]; then if [ -f %{_compiledir}/build/bin/jemalloc-config ]; then
......
...@@ -170,11 +170,11 @@ function install_main_path() { ...@@ -170,11 +170,11 @@ function install_main_path() {
${csudo}mkdir -p ${install_main_dir} ${csudo}mkdir -p ${install_main_dir}
${csudo}mkdir -p ${install_main_dir}/cfg ${csudo}mkdir -p ${install_main_dir}/cfg
${csudo}mkdir -p ${install_main_dir}/bin ${csudo}mkdir -p ${install_main_dir}/bin
${csudo}mkdir -p ${install_main_dir}/connector # ${csudo}mkdir -p ${install_main_dir}/connector
${csudo}mkdir -p ${install_main_dir}/driver ${csudo}mkdir -p ${install_main_dir}/driver
${csudo}mkdir -p ${install_main_dir}/examples ${csudo}mkdir -p ${install_main_dir}/examples
${csudo}mkdir -p ${install_main_dir}/include ${csudo}mkdir -p ${install_main_dir}/include
${csudo}mkdir -p ${install_main_dir}/init.d # ${csudo}mkdir -p ${install_main_dir}/init.d
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
${csudo}mkdir -p ${nginx_dir} ${csudo}mkdir -p ${nginx_dir}
fi fi
...@@ -601,14 +601,14 @@ function install_service_on_sysvinit() { ...@@ -601,14 +601,14 @@ function install_service_on_sysvinit() {
sleep 1 sleep 1
if ((${os_type} == 1)); then if ((${os_type} == 1)); then
${csudo}cp -f ${script_dir}/init.d/${serverName}.deb ${install_main_dir}/init.d/${serverName} # ${csudo}cp -f ${script_dir}/init.d/${serverName}.deb ${install_main_dir}/init.d/${serverName}
${csudo}cp ${script_dir}/init.d/${serverName}.deb ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName} ${csudo}cp ${script_dir}/init.d/${serverName}.deb ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord # ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord
${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord
elif ((${os_type} == 2)); then elif ((${os_type} == 2)); then
${csudo}cp -f ${script_dir}/init.d/${serverName}.rpm ${install_main_dir}/init.d/${serverName} # ${csudo}cp -f ${script_dir}/init.d/${serverName}.rpm ${install_main_dir}/init.d/${serverName}
${csudo}cp ${script_dir}/init.d/${serverName}.rpm ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName} ${csudo}cp ${script_dir}/init.d/${serverName}.rpm ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord # ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord
${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord
fi fi
...@@ -804,9 +804,9 @@ function update_TDengine() { ...@@ -804,9 +804,9 @@ function update_TDengine() {
install_log install_log
install_header install_header
install_lib install_lib
if [ "$pagMode" != "lite" ]; then # if [ "$pagMode" != "lite" ]; then
install_connector # install_connector
fi # fi
install_examples install_examples
if [ -z $1 ]; then if [ -z $1 ]; then
install_bin install_bin
...@@ -887,9 +887,9 @@ function install_TDengine() { ...@@ -887,9 +887,9 @@ function install_TDengine() {
#install_avro lib #install_avro lib
#install_avro lib64 #install_avro lib64
if [ "$pagMode" != "lite" ]; then # if [ "$pagMode" != "lite" ]; then
install_connector # install_connector
fi # fi
install_examples install_examples
if [ -z $1 ]; then # install service and client if [ -z $1 ]; then # install service and client
...@@ -897,6 +897,7 @@ function install_TDengine() { ...@@ -897,6 +897,7 @@ function install_TDengine() {
install_bin install_bin
install_service install_service
install_taosadapter_service install_taosadapter_service
install_taosadapter_config
openresty_work=false openresty_work=false
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
......
...@@ -147,17 +147,17 @@ function install_main_path() { ...@@ -147,17 +147,17 @@ function install_main_path() {
${csudo}mkdir -p ${install_main_dir} ${csudo}mkdir -p ${install_main_dir}
${csudo}mkdir -p ${install_main_dir}/cfg ${csudo}mkdir -p ${install_main_dir}/cfg
${csudo}mkdir -p ${install_main_dir}/bin ${csudo}mkdir -p ${install_main_dir}/bin
${csudo}mkdir -p ${install_main_dir}/connector # ${csudo}mkdir -p ${install_main_dir}/connector
${csudo}mkdir -p ${install_main_dir}/driver ${csudo}mkdir -p ${install_main_dir}/driver
${csudo}mkdir -p ${install_main_dir}/examples ${csudo}mkdir -p ${install_main_dir}/examples
${csudo}mkdir -p ${install_main_dir}/include ${csudo}mkdir -p ${install_main_dir}/include
${csudo}mkdir -p ${install_main_dir}/init.d # ${csudo}mkdir -p ${install_main_dir}/init.d
else else
${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || : ${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || :
${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir} ${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir}
${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg ${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg
${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin ${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin
${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector # ${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector
${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver ${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver
${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples ${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples
${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include ${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include
...@@ -178,9 +178,15 @@ function install_bin() { ...@@ -178,9 +178,15 @@ function install_bin() {
${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || :
${csudo}rm -f ${bin_link_dir}/${uninstallScript} || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin ${csudo}cp -r ${binary_dir}/build/bin/taos ${install_main_dir}/bin || :
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin [ -f ${binary_dir}/build/bin/taosBenchmark ] && ${csudo}cp -r ${binary_dir}/build/bin/taosBenchmark ${install_main_dir}/bin || :
[ -f ${install_main_dir}/bin/taosBenchmark ] && ${csudo}ln -sf ${install_main_dir}/bin/taosBenchmark ${install_main_dir}/bin/taosdemo || :
[ -f ${binary_dir}/build/bin/taosdump ] && ${csudo}cp -r ${binary_dir}/build/bin/taosdump ${install_main_dir}/bin || :
[ -f ${binary_dir}/build/bin/taosadapter ] && ${csudo}cp -r ${binary_dir}/build/bin/taosadapter ${install_main_dir}/bin || :
${csudo}cp -r ${binary_dir}/build/bin/taosd ${install_main_dir}/bin || :
${csudo}cp -r ${binary_dir}/build/bin/tarbitrator ${install_main_dir}/bin || :
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin
${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin ${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin
${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin ${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin
${csudo}cp -r ${script_dir}/run_taosd.sh ${install_main_dir}/bin ${csudo}cp -r ${script_dir}/run_taosd.sh ${install_main_dir}/bin
...@@ -465,10 +471,10 @@ function install_service_on_sysvinit() { ...@@ -465,10 +471,10 @@ function install_service_on_sysvinit() {
# Install taosd service # Install taosd service
if ((${os_type} == 1)); then if ((${os_type} == 1)); then
${csudo}cp -f ${script_dir}/../deb/${serverName} ${install_main_dir}/init.d # ${csudo}cp -f ${script_dir}/../deb/${serverName} ${install_main_dir}/init.d
${csudo}cp ${script_dir}/../deb/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} ${csudo}cp ${script_dir}/../deb/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
elif ((${os_type} == 2)); then elif ((${os_type} == 2)); then
${csudo}cp -f ${script_dir}/../rpm/${serverName} ${install_main_dir}/init.d # ${csudo}cp -f ${script_dir}/../rpm/${serverName} ${install_main_dir}/init.d
${csudo}cp ${script_dir}/../rpm/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} ${csudo}cp ${script_dir}/../rpm/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
fi fi
...@@ -565,7 +571,7 @@ function update_TDengine() { ...@@ -565,7 +571,7 @@ function update_TDengine() {
install_log install_log
install_header install_header
install_lib install_lib
install_connector # install_connector
install_examples install_examples
install_bin install_bin
...@@ -605,7 +611,7 @@ function install_TDengine() { ...@@ -605,7 +611,7 @@ function install_TDengine() {
install_log install_log
install_header install_header
install_lib install_lib
install_connector # install_connector
install_examples install_examples
install_bin install_bin
......
...@@ -134,6 +134,15 @@ if [ -n "${taostools_bin_files}" ]; then ...@@ -134,6 +134,15 @@ if [ -n "${taostools_bin_files}" ]; then
echo -e "install-taostools.sh not found" echo -e "install-taostools.sh not found"
fi fi
if [ -f ${top_dir}/src/kit/taos-tools/packaging/tools/uninstall-taostools.sh ]; then
cp ${top_dir}/src/kit/taos-tools/packaging/tools/uninstall-taostools.sh \
${taostools_install_dir}/ >/dev/null &&
chmod a+x ${taostools_install_dir}/uninstall-taostools.sh ||
echo -e "failed to copy uninstall-taostools.sh"
else
echo -e "uninstall-taostools.sh not found"
fi
if [ -f ${build_dir}/lib/libavro.so.23.0.0 ]; then if [ -f ${build_dir}/lib/libavro.so.23.0.0 ]; then
mkdir -p ${taostools_install_dir}/avro/{lib,lib/pkgconfig} || echo -e "failed to create ${taostools_install_dir}/avro" mkdir -p ${taostools_install_dir}/avro/{lib,lib/pkgconfig} || echo -e "failed to create ${taostools_install_dir}/avro"
cp ${build_dir}/lib/libavro.* ${taostools_install_dir}/avro/lib cp ${build_dir}/lib/libavro.* ${taostools_install_dir}/avro/lib
...@@ -246,18 +255,18 @@ fi ...@@ -246,18 +255,18 @@ fi
mkdir -p ${install_dir}/driver && cp ${lib_files} ${install_dir}/driver && echo "${versionComp}" >${install_dir}/driver/vercomp.txt mkdir -p ${install_dir}/driver && cp ${lib_files} ${install_dir}/driver && echo "${versionComp}" >${install_dir}/driver/vercomp.txt
# Copy connector # Copy connector
connector_dir="${code_dir}/connector" #connector_dir="${code_dir}/connector"
mkdir -p ${install_dir}/connector #mkdir -p ${install_dir}/connector
if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then #if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then
cp ${build_dir}/lib/*.jar ${install_dir}/connector || : # cp ${build_dir}/lib/*.jar ${install_dir}/connector || :
if find ${connector_dir}/go -mindepth 1 -maxdepth 1 | read; then # if find ${connector_dir}/go -mindepth 1 -maxdepth 1 | read; then
cp -r ${connector_dir}/go ${install_dir}/connector # cp -r ${connector_dir}/go ${install_dir}/connector
else # else
echo "WARNING: go connector not found, please check if want to use it!" # echo "WARNING: go connector not found, please check if want to use it!"
fi # fi
cp -r ${connector_dir}/python ${install_dir}/connector # cp -r ${connector_dir}/python ${install_dir}/connector
cp -r ${connector_dir}/nodejs ${install_dir}/connector # cp -r ${connector_dir}/nodejs ${install_dir}/connector
fi #fi
# Copy release note # Copy release note
# cp ${script_dir}/release_note ${install_dir} # cp ${script_dir}/release_note ${install_dir}
......
...@@ -207,7 +207,7 @@ TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index); ...@@ -207,7 +207,7 @@ TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo); void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index); int32_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
void tscFieldInfoClear(SFieldInfo* pFieldInfo); void tscFieldInfoClear(SFieldInfo* pFieldInfo);
void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArray* pExprList); void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArray* pExprList);
...@@ -258,8 +258,6 @@ void tscColumnListCopyAll(SArray* dst, const SArray* src); ...@@ -258,8 +258,6 @@ void tscColumnListCopyAll(SArray* dst, const SArray* src);
void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId, bool convertNchar, bool convertJson); void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId, bool convertNchar, bool convertJson);
void tscDequoteAndTrimToken(SStrToken* pToken);
void tscRmEscapeAndTrimToken(SStrToken* pToken);
int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded); int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded);
void tscIncStreamExecutionCount(void* pStream); void tscIncStreamExecutionCount(void* pStream);
......
...@@ -52,3 +52,4 @@ taos_stmt_bind_single_param_batch ...@@ -52,3 +52,4 @@ taos_stmt_bind_single_param_batch
taos_is_null taos_is_null
taos_insert_lines taos_insert_lines
taos_schemaless_insert taos_schemaless_insert
taos_result_block
...@@ -481,32 +481,12 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -481,32 +481,12 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
// Remove quotation marks // Remove quotation marks
if (TK_STRING == sToken.type) { if (TK_STRING == sToken.type) {
// delete escape character: \\, \', \"
char delim = sToken.z[0];
int32_t cnt = 0;
int32_t j = 0;
if (sToken.n >= TSDB_MAX_BYTES_PER_ROW) { if (sToken.n >= TSDB_MAX_BYTES_PER_ROW) {
return tscSQLSyntaxErrMsg(pInsertParam->msg, "too long string", sToken.z); return tscSQLSyntaxErrMsg(pInsertParam->msg, "too long string", sToken.z);
} }
strncpy(tmpTokenBuf, sToken.z, sToken.n);
for (uint32_t k = 1; k < sToken.n - 1; ++k) { sToken.n = stringProcess(tmpTokenBuf, sToken.n);
if (sToken.z[k] == '\\' || (sToken.z[k] == delim && sToken.z[k + 1] == delim)) {
tmpTokenBuf[j] = sToken.z[k + 1];
cnt++;
j++;
k++;
continue;
}
tmpTokenBuf[j] = sToken.z[k];
j++;
}
tmpTokenBuf[j] = 0;
sToken.z = tmpTokenBuf; sToken.z = tmpTokenBuf;
sToken.n -= 2 + cnt;
} }
bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX);
...@@ -1057,10 +1037,12 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -1057,10 +1037,12 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
break; break;
} }
char* tmp = NULL;
// Remove quotation marks // Remove quotation marks
if (TK_STRING == sToken.type) { if (TK_STRING == sToken.type) {
sToken.z++; tmp = strndup(sToken.z, sToken.n);
sToken.n -= 2; sToken.n = stringProcess(tmp, sToken.n);
sToken.z = tmp;
} }
char tagVal[TSDB_MAX_TAGS_LEN] = {0}; char tagVal[TSDB_MAX_TAGS_LEN] = {0};
...@@ -1068,6 +1050,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -1068,6 +1050,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd); tscDestroyBoundColumnInfo(&spd);
tfree(tmp);
return code; return code;
} }
...@@ -1078,18 +1061,18 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -1078,18 +1061,18 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
if(sToken.n > TSDB_MAX_JSON_TAGS_LEN/TSDB_NCHAR_SIZE){ if(sToken.n > TSDB_MAX_JSON_TAGS_LEN/TSDB_NCHAR_SIZE){
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd); tscDestroyBoundColumnInfo(&spd);
tfree(tmp);
return tscSQLSyntaxErrMsg(pInsertParam->msg, "json tag too long", NULL); return tscSQLSyntaxErrMsg(pInsertParam->msg, "json tag too long", NULL);
} }
char* json = strndup(sToken.z, sToken.n); code = parseJsontoTagData(sToken.z, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId);
code = parseJsontoTagData(json, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd); tscDestroyBoundColumnInfo(&spd);
tfree(json); tfree(tmp);
return code; return code;
} }
tfree(json);
} }
tfree(tmp);
} }
tscDestroyBoundColumnInfo(&spd); tscDestroyBoundColumnInfo(&spd);
...@@ -1246,12 +1229,8 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -1246,12 +1229,8 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
strncpy(tmpTokenBuf, sToken.z, sToken.n); strncpy(tmpTokenBuf, sToken.z, sToken.n);
sToken.z = tmpTokenBuf; sToken.z = tmpTokenBuf;
if (TK_STRING == sToken.type) { if (TK_STRING == sToken.type || TK_ID == sToken.type) {
tscDequoteAndTrimToken(&sToken); sToken.n = stringProcess(sToken.z, sToken.n);
}
if (TK_ID == sToken.type) {
tscRmEscapeAndTrimToken(&sToken);
} }
if (sToken.type == TK_RP) { if (sToken.type == TK_RP) {
...@@ -1371,7 +1350,7 @@ _clean: ...@@ -1371,7 +1350,7 @@ _clean:
static int32_t getFileFullPath(SStrToken* pToken, char* output) { static int32_t getFileFullPath(SStrToken* pToken, char* output) {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
strncpy(path, pToken->z, pToken->n); strncpy(path, pToken->z, pToken->n);
strdequote(path); stringProcess(path, (int32_t)strlen(path));
wordexp_t full_path; wordexp_t full_path;
if (wordexp(path, &full_path, 0) != 0) { if (wordexp(path, &full_path, 0) != 0) {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "tscParseLine.h" #include "tscParseLine.h"
typedef struct { typedef struct {
char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; char sTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE];
SHashObj* tagHash; SHashObj* tagHash;
SHashObj* fieldHash; SHashObj* fieldHash;
SArray* tags; //SArray<SSchema> SArray* tags; //SArray<SSchema>
...@@ -68,13 +68,13 @@ typedef enum { ...@@ -68,13 +68,13 @@ typedef enum {
} ESchemaAction; } ESchemaAction;
typedef struct { typedef struct {
char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; char sTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE];
SArray* tags; //SArray<SSchema> SArray* tags; //SArray<SSchema>
SArray* fields; //SArray<SSchema> SArray* fields; //SArray<SSchema>
} SCreateSTableActionInfo; } SCreateSTableActionInfo;
typedef struct { typedef struct {
char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; char sTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE];
SSchema* field; SSchema* field;
} SAlterSTableActionInfo; } SAlterSTableActionInfo;
...@@ -161,14 +161,14 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa ...@@ -161,14 +161,14 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa
} }
SStringBuilder sb; memset(&sb, 0, sizeof(sb)); SStringBuilder sb; memset(&sb, 0, sizeof(sb));
char sTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char sTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
strncpy(sTableName, point->stableName, strlen(point->stableName)); strncpy(sTableName, point->stableName, strlen(point->stableName));
//strtolower(sTableName, point->stableName); //strtolower(sTableName, point->stableName);
taosStringBuilderAppendString(&sb, sTableName); taosStringBuilderAppendString(&sb, sTableName);
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
taosStringBuilderAppendChar(&sb, ','); taosStringBuilderAppendChar(&sb, ',');
TAOS_SML_KV* tagKv = point->tags + j; TAOS_SML_KV* tagKv = point->tags + j;
char tagName[TSDB_COL_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char tagName[TSDB_COL_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
strncpy(tagName, tagKv->key, strlen(tagKv->key)); strncpy(tagName, tagKv->key, strlen(tagKv->key));
//strtolower(tagName, tagKv->key); //strtolower(tagName, tagKv->key);
taosStringBuilderAppendString(&sb, tagName); taosStringBuilderAppendString(&sb, tagName);
...@@ -192,8 +192,8 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa ...@@ -192,8 +192,8 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa
static int32_t buildSmlChildTableName(TAOS_SML_DATA_POINT* point, SSmlLinesInfo* info) { static int32_t buildSmlChildTableName(TAOS_SML_DATA_POINT* point, SSmlLinesInfo* info) {
tscDebug("SML:0x%"PRIx64" taos_sml_insert build child table name", info->id); tscDebug("SML:0x%"PRIx64" taos_sml_insert build child table name", info->id);
char childTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; char childTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE];
int32_t tableNameLen = TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE; int32_t tableNameLen = TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE;
getSmlMd5ChildTableName(point, childTableName, &tableNameLen, info); getSmlMd5ChildTableName(point, childTableName, &tableNameLen, info);
point->childTableName = calloc(1, tableNameLen+1); point->childTableName = calloc(1, tableNameLen+1);
strncpy(point->childTableName, childTableName, tableNameLen); strncpy(point->childTableName, childTableName, tableNameLen);
...@@ -251,15 +251,15 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -251,15 +251,15 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
size_t nameLen = strlen(tsSmlTagNullName); size_t nameLen = strlen(tsSmlTagNullName);
strncpy(tagNullName, tsSmlTagNullName, nameLen); strncpy(tagNullName, tsSmlTagNullName, nameLen);
addEscapeCharToString(tagNullName, (int32_t)nameLen); addEscapeCharToString(tagNullName, (int32_t)nameLen);
size_t* pTagNullIdx = taosHashGet(pStableSchema->tagHash, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE); size_t* pTagNullIdx = taosHashGet(pStableSchema->tagHash, tagNullName, nameLen + TS_BACKQUOTE_CHAR_SIZE);
if (!pTagNullIdx) { if (!pTagNullIdx) {
SSchema tagNull = {0}; SSchema tagNull = {0};
tagNull.type = TSDB_DATA_TYPE_NCHAR; tagNull.type = TSDB_DATA_TYPE_NCHAR;
tagNull.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; tagNull.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
strncpy(tagNull.name, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE); strncpy(tagNull.name, tagNullName, nameLen + TS_BACKQUOTE_CHAR_SIZE);
taosArrayPush(pStableSchema->tags, &tagNull); taosArrayPush(pStableSchema->tags, &tagNull);
size_t tagNullIdx = taosArrayGetSize(pStableSchema->tags) - 1; size_t tagNullIdx = taosArrayGetSize(pStableSchema->tags) - 1;
taosHashPut(pStableSchema->tagHash, tagNull.name, nameLen + TS_ESCAPE_CHAR_SIZE, &tagNullIdx, sizeof(tagNullIdx)); taosHashPut(pStableSchema->tagHash, tagNull.name, nameLen + TS_BACKQUOTE_CHAR_SIZE, &tagNullIdx, sizeof(tagNullIdx));
} }
} }
...@@ -295,7 +295,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -295,7 +295,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, SArray* dbAttrArray, bool isTag, char sTableName[], static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, SArray* dbAttrArray, bool isTag, char sTableName[],
SSchemaAction* action, bool* actionNeeded, SSmlLinesInfo* info) { SSchemaAction* action, bool* actionNeeded, SSmlLinesInfo* info) {
char fieldName[TSDB_COL_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char fieldName[TSDB_COL_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
strcpy(fieldName, pointColField->name); strcpy(fieldName, pointColField->name);
size_t* pDbIndex = taosHashGet(dbAttrHash, fieldName, strlen(fieldName)); size_t* pDbIndex = taosHashGet(dbAttrHash, fieldName, strlen(fieldName));
...@@ -315,7 +315,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash ...@@ -315,7 +315,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
action->action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE; action->action = SCHEMA_ACTION_CHANGE_COLUMN_SIZE;
} }
memset(&action->alterSTable, 0, sizeof(SAlterSTableActionInfo)); memset(&action->alterSTable, 0, sizeof(SAlterSTableActionInfo));
memcpy(action->alterSTable.sTableName, sTableName, TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE); memcpy(action->alterSTable.sTableName, sTableName, TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE);
action->alterSTable.field = pointColField; action->alterSTable.field = pointColField;
*actionNeeded = true; *actionNeeded = true;
} }
...@@ -326,7 +326,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash ...@@ -326,7 +326,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
action->action = SCHEMA_ACTION_ADD_COLUMN; action->action = SCHEMA_ACTION_ADD_COLUMN;
} }
memset(&action->alterSTable, 0, sizeof(SAlterSTableActionInfo)); memset(&action->alterSTable, 0, sizeof(SAlterSTableActionInfo));
memcpy(action->alterSTable.sTableName, sTableName, TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE); memcpy(action->alterSTable.sTableName, sTableName, TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE);
action->alterSTable.field = pointColField; action->alterSTable.field = pointColField;
*actionNeeded = true; *actionNeeded = true;
} }
...@@ -572,7 +572,7 @@ static int32_t getSuperTableMetaFromLocalCache(TAOS* taos, char* tableName, STab ...@@ -572,7 +572,7 @@ static int32_t getSuperTableMetaFromLocalCache(TAOS* taos, char* tableName, STab
pSql->fp = NULL; pSql->fp = NULL;
registerSqlObj(pSql); registerSqlObj(pSql);
char tableNameBuf[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char tableNameBuf[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
memcpy(tableNameBuf, tableName, strlen(tableName)); memcpy(tableNameBuf, tableName, strlen(tableName));
SStrToken tableToken = {.z = tableNameBuf, .n = (uint32_t)strlen(tableName), .type = TK_ID}; SStrToken tableToken = {.z = tableNameBuf, .n = (uint32_t)strlen(tableName), .type = TK_ID};
tGetToken(tableNameBuf, &tableToken.type); tGetToken(tableNameBuf, &tableToken.type);
...@@ -689,7 +689,7 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo* ...@@ -689,7 +689,7 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo*
SSchemaAction schemaAction = {0}; SSchemaAction schemaAction = {0};
schemaAction.action = SCHEMA_ACTION_CREATE_STABLE; schemaAction.action = SCHEMA_ACTION_CREATE_STABLE;
memset(&schemaAction.createSTable, 0, sizeof(SCreateSTableActionInfo)); memset(&schemaAction.createSTable, 0, sizeof(SCreateSTableActionInfo));
memcpy(schemaAction.createSTable.sTableName, pointSchema->sTableName, TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE); memcpy(schemaAction.createSTable.sTableName, pointSchema->sTableName, TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE);
schemaAction.createSTable.tags = pointSchema->tags; schemaAction.createSTable.tags = pointSchema->tags;
schemaAction.createSTable.fields = pointSchema->fields; schemaAction.createSTable.fields = pointSchema->fields;
applySchemaAction(taos, &schemaAction, info); applySchemaAction(taos, &schemaAction, info);
...@@ -726,7 +726,7 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo* ...@@ -726,7 +726,7 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo*
SSchema* pointColTs = taosArrayGet(pointSchema->fields, 0); SSchema* pointColTs = taosArrayGet(pointSchema->fields, 0);
SSchema* dbColTs = taosArrayGet(dbSchema.fields, 0); SSchema* dbColTs = taosArrayGet(dbSchema.fields, 0);
memcpy(pointColTs->name, dbColTs->name, TSDB_COL_NAME_LEN + TS_ESCAPE_CHAR_SIZE); memcpy(pointColTs->name, dbColTs->name, TSDB_COL_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE);
for (int j = 1; j < pointFieldSize; ++j) { for (int j = 1; j < pointFieldSize; ++j) {
SSchema* pointCol = taosArrayGet(pointSchema->fields, j); SSchema* pointCol = taosArrayGet(pointSchema->fields, j);
...@@ -1398,7 +1398,7 @@ char* addEscapeCharToString(char *str, int32_t len) { ...@@ -1398,7 +1398,7 @@ char* addEscapeCharToString(char *str, int32_t len) {
return NULL; return NULL;
} }
memmove(str + 1, str, len); memmove(str + 1, str, len);
str[0] = str[len + 1] = TS_ESCAPE_CHAR; str[0] = str[len + 1] = TS_BACKQUOTE_CHAR;
str[len + 2] = '\0'; str[len + 2] = '\0';
return str; return str;
} }
...@@ -2129,7 +2129,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -2129,7 +2129,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
pKV->key = calloc(len + TS_ESCAPE_CHAR_SIZE + 1, 1); pKV->key = calloc(len + TS_BACKQUOTE_CHAR_SIZE + 1, 1);
memcpy(pKV->key, key, len + 1); memcpy(pKV->key, key, len + 1);
addEscapeCharToString(pKV->key, len); addEscapeCharToString(pKV->key, len);
tscDebug("SML:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len); tscDebug("SML:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len);
...@@ -2227,7 +2227,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index ...@@ -2227,7 +2227,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
const char *cur = *index; const char *cur = *index;
int16_t len = 0; int16_t len = 0;
pSml->stableName = calloc(TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE, 1); pSml->stableName = calloc(TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE, 1);
if (pSml->stableName == NULL){ if (pSml->stableName == NULL){
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -2313,7 +2313,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -2313,7 +2313,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
} }
size_t childTableNameLen = strlen(tsSmlChildTableName); size_t childTableNameLen = strlen(tsSmlChildTableName);
char childTableName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char childTableName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
if (childTableNameLen != 0) { if (childTableNameLen != 0) {
memcpy(childTableName, tsSmlChildTableName, childTableNameLen); memcpy(childTableName, tsSmlChildTableName, childTableNameLen);
addEscapeCharToString(childTableName, (int32_t)(childTableNameLen)); addEscapeCharToString(childTableName, (int32_t)(childTableNameLen));
...@@ -2332,7 +2332,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -2332,7 +2332,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
} }
if (!isField && childTableNameLen != 0 && strcasecmp(pkv->key, childTableName) == 0) { if (!isField && childTableNameLen != 0 && strcasecmp(pkv->key, childTableName) == 0) {
smlData->childTableName = malloc(pkv->length + TS_ESCAPE_CHAR_SIZE + 1); smlData->childTableName = malloc(pkv->length + TS_BACKQUOTE_CHAR_SIZE + 1);
memcpy(smlData->childTableName, pkv->value, pkv->length); memcpy(smlData->childTableName, pkv->value, pkv->length);
addEscapeCharToString(smlData->childTableName, (int32_t)pkv->length); addEscapeCharToString(smlData->childTableName, (int32_t)pkv->length);
free(pkv->key); free(pkv->key);
......
...@@ -37,7 +37,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, ...@@ -37,7 +37,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index,
const char *cur = *index; const char *cur = *index;
uint16_t len = 0; uint16_t len = 0;
pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE, 1); pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE, 1);
if (pSml->stableName == NULL) { if (pSml->stableName == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -125,7 +125,7 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char ...@@ -125,7 +125,7 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char
} }
tfree(value); tfree(value);
(*pTS)->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); (*pTS)->key = tcalloc(sizeof(key) + TS_BACKQUOTE_CHAR_SIZE, 1);
memcpy((*pTS)->key, key, sizeof(key)); memcpy((*pTS)->key, key, sizeof(key));
addEscapeCharToString((*pTS)->key, (int32_t)strlen(key)); addEscapeCharToString((*pTS)->key, (int32_t)strlen(key));
...@@ -196,7 +196,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch ...@@ -196,7 +196,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch
} }
tfree(value); tfree(value);
pVal->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); pVal->key = tcalloc(sizeof(key) + TS_BACKQUOTE_CHAR_SIZE, 1);
memcpy(pVal->key, key, sizeof(key)); memcpy(pVal->key, key, sizeof(key));
addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key)); addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key));
*num_kvs += 1; *num_kvs += 1;
...@@ -240,7 +240,7 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj ...@@ -240,7 +240,7 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj
return TSDB_CODE_TSC_DUP_TAG_NAMES; return TSDB_CODE_TSC_DUP_TAG_NAMES;
} }
pKV->key = tcalloc(len + TS_ESCAPE_CHAR_SIZE + 1, 1); pKV->key = tcalloc(len + TS_BACKQUOTE_CHAR_SIZE + 1, 1);
memcpy(pKV->key, key, len + 1); memcpy(pKV->key, key, len + 1);
addEscapeCharToString(pKV->key, len); addEscapeCharToString(pKV->key, len);
//tscDebug("OTD:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len); //tscDebug("OTD:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len);
...@@ -307,7 +307,7 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -307,7 +307,7 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs,
pkv = *pKVs; pkv = *pKVs;
size_t childTableNameLen = strlen(tsSmlChildTableName); size_t childTableNameLen = strlen(tsSmlChildTableName);
char childTbName[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; char childTbName[TSDB_TABLE_NAME_LEN + TS_BACKQUOTE_CHAR_SIZE] = {0};
if (childTableNameLen != 0) { if (childTableNameLen != 0) {
memcpy(childTbName, tsSmlChildTableName, childTableNameLen); memcpy(childTbName, tsSmlChildTableName, childTableNameLen);
addEscapeCharToString(childTbName, (int32_t)(childTableNameLen)); addEscapeCharToString(childTbName, (int32_t)(childTableNameLen));
...@@ -324,7 +324,7 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -324,7 +324,7 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs,
return ret; return ret;
} }
if (childTableNameLen != 0 && strcasecmp(pkv->key, childTbName) == 0) { if (childTableNameLen != 0 && strcasecmp(pkv->key, childTbName) == 0) {
*childTableName = tcalloc(pkv->length + TS_ESCAPE_CHAR_SIZE + 1, 1); *childTableName = tcalloc(pkv->length + TS_BACKQUOTE_CHAR_SIZE + 1, 1);
memcpy(*childTableName, pkv->value, pkv->length); memcpy(*childTableName, pkv->value, pkv->length);
(*childTableName)[pkv->length] = '\0'; (*childTableName)[pkv->length] = '\0';
addEscapeCharToString(*childTableName, pkv->length); addEscapeCharToString(*childTableName, pkv->length);
...@@ -500,7 +500,7 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL ...@@ -500,7 +500,7 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
} }
pSml->stableName = tcalloc(stableLen + TS_ESCAPE_CHAR_SIZE + 1, sizeof(char)); pSml->stableName = tcalloc(stableLen + TS_BACKQUOTE_CHAR_SIZE + 1, sizeof(char));
if (pSml->stableName == NULL){ if (pSml->stableName == NULL){
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -879,7 +879,7 @@ static int32_t parseMetricValueFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *nu ...@@ -879,7 +879,7 @@ static int32_t parseMetricValueFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *nu
return ret; return ret;
} }
pVal->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); pVal->key = tcalloc(sizeof(key) + TS_BACKQUOTE_CHAR_SIZE, 1);
memcpy(pVal->key, key, sizeof(key)); memcpy(pVal->key, key, sizeof(key));
addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key)); addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key));
...@@ -910,7 +910,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -910,7 +910,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs,
return TSDB_CODE_TSC_INVALID_JSON; return TSDB_CODE_TSC_INVALID_JSON;
} }
size_t idLen = strlen(id->valuestring); size_t idLen = strlen(id->valuestring);
*childTableName = tcalloc(idLen + TS_ESCAPE_CHAR_SIZE + 1, sizeof(char)); *childTableName = tcalloc(idLen + TS_BACKQUOTE_CHAR_SIZE + 1, sizeof(char));
memcpy(*childTableName, id->valuestring, idLen); memcpy(*childTableName, id->valuestring, idLen);
addEscapeCharToString(*childTableName, (int32_t)idLen); addEscapeCharToString(*childTableName, (int32_t)idLen);
...@@ -948,7 +948,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, ...@@ -948,7 +948,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs,
tscError("OTD:0x%"PRIx64" Tag key cannot exceeds %d characters in JSON", info->id, TSDB_COL_NAME_LEN - 1); tscError("OTD:0x%"PRIx64" Tag key cannot exceeds %d characters in JSON", info->id, TSDB_COL_NAME_LEN - 1);
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
} }
pkv->key = tcalloc(keyLen + TS_ESCAPE_CHAR_SIZE + 1, sizeof(char)); pkv->key = tcalloc(keyLen + TS_BACKQUOTE_CHAR_SIZE + 1, sizeof(char));
strncpy(pkv->key, tag->string, keyLen); strncpy(pkv->key, tag->string, keyLen);
addEscapeCharToString(pkv->key, (int32_t)keyLen); addEscapeCharToString(pkv->key, (int32_t)keyLen);
//value //value
......
...@@ -322,7 +322,7 @@ static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) { ...@@ -322,7 +322,7 @@ static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) {
static int convertTimestampStrToInt64(tVariant *pVar, int32_t precision) { static int convertTimestampStrToInt64(tVariant *pVar, int32_t precision) {
int64_t time = 0; int64_t time = 0;
strdequote(pVar->pz); stringProcess(pVar->pz, pVar->nLen);
char* seg = strnchr(pVar->pz, '-', pVar->nLen, false); char* seg = strnchr(pVar->pz, '-', pVar->nLen, false);
if (seg != NULL) { if (seg != NULL) {
...@@ -359,7 +359,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) { ...@@ -359,7 +359,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
strdequote(pPwd->z); stringProcess(pPwd->z, pPwd->n);
pPwd->n = (uint32_t)strtrim(pPwd->z); // trim space before and after passwords pPwd->n = (uint32_t)strtrim(pPwd->z); // trim space before and after passwords
if (pPwd->n <= 0) { if (pPwd->n <= 0) {
...@@ -477,7 +477,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -477,7 +477,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (validateColumnName(createInfo->name.z) != TSDB_CODE_SUCCESS) { if (validateColumnName(createInfo->name.z) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
strdequote(createInfo->name.z); stringProcess(createInfo->name.z, createInfo->name.n);
if (strlen(createInfo->name.z) >= TSDB_FUNC_NAME_LEN) { if (strlen(createInfo->name.z) >= TSDB_FUNC_NAME_LEN) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
...@@ -485,7 +485,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -485,7 +485,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) {
createInfo->path.z[createInfo->path.n] = 0; createInfo->path.z[createInfo->path.n] = 0;
strdequote(createInfo->path.z); stringProcess(createInfo->path.z, createInfo->path.n);
if (strlen(createInfo->path.z) >= PATH_MAX) { if (strlen(createInfo->path.z) >= PATH_MAX) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
...@@ -543,7 +543,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -543,7 +543,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) {
t0->z[t0->n] = 0; t0->z[t0->n] = 0;
strdequote(t0->z); stringProcess(t0->z, t0->n);
if (strlen(t0->z) >= TSDB_FUNC_NAME_LEN) { if (strlen(t0->z) >= TSDB_FUNC_NAME_LEN) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
...@@ -628,7 +628,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -628,7 +628,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
} else if (pInfo->type == TSDB_SQL_DROP_DNODE) { } else if (pInfo->type == TSDB_SQL_DROP_DNODE) {
if (pzName->type == TK_STRING) { if (pzName->type == TK_STRING) {
pzName->n = strdequote(pzName->z); pzName->n = stringProcess(pzName->z, pzName->n);
} }
strncpy(pCmd->payload, pzName->z, pzName->n); strncpy(pCmd->payload, pzName->z, pzName->n);
} else { // drop user/account } else { // drop user/account
...@@ -718,7 +718,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -718,7 +718,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SStrToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0); SStrToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0);
if (id->type == TK_STRING) { if (id->type == TK_STRING) {
id->n = strdequote(id->z); id->n = stringProcess(id->z, id->n);
} }
break; break;
} }
...@@ -834,7 +834,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -834,7 +834,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SStrToken* t0 = taosArrayGet(pMiscInfo->a, 0); SStrToken* t0 = taosArrayGet(pMiscInfo->a, 0);
SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1); SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1);
t0->n = strdequote(t0->z); t0->n = stringProcess(t0->z, t0->n);
strncpy(pCfg->ep, t0->z, t0->n); strncpy(pCfg->ep, t0->z, t0->n);
if (validateEp(pCfg->ep) != TSDB_CODE_SUCCESS) { if (validateEp(pCfg->ep) != TSDB_CODE_SUCCESS) {
...@@ -2674,6 +2674,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2674,6 +2674,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg15 = "parameter is out of range [1, 1000]"; const char* msg15 = "parameter is out of range [1, 1000]";
const char* msg16 = "elapsed duration should be greater than or equal to database precision"; const char* msg16 = "elapsed duration should be greater than or equal to database precision";
const char* msg17 = "elapsed/twa should not be used in nested query if inner query has group by clause"; const char* msg17 = "elapsed/twa should not be used in nested query if inner query has group by clause";
const char* msg18 = "the second parameter is not an integer";
switch (functionId) { switch (functionId) {
case TSDB_FUNC_COUNT: { case TSDB_FUNC_COUNT: {
...@@ -3156,6 +3157,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -3156,6 +3157,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
char* endptr = NULL;
strtoll(pParamElem[1].pNode->exprToken.z, &endptr, 10);
if ((endptr-pParamElem[1].pNode->exprToken.z != pParamElem[1].pNode->exprToken.n) || errno == ERANGE) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg18);
}
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true); tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true);
int64_t numRowsSelected = GET_INT64_VAL(val); int64_t numRowsSelected = GET_INT64_VAL(val);
...@@ -3435,7 +3441,7 @@ static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken ...@@ -3435,7 +3441,7 @@ static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken
pToken->z = tmpTokenBuf; pToken->z = tmpTokenBuf;
if (pToken->type == TK_ID) { if (pToken->type == TK_ID) {
tscRmEscapeAndTrimToken(pToken); pToken->n = stringProcess(pToken->z, pToken->n);
} }
for (int16_t i = 0; i < numOfCols; ++i) { for (int16_t i = 0; i < numOfCols; ++i) {
...@@ -3596,11 +3602,11 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -3596,11 +3602,11 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// show table/stable like 'xxxx', set the like pattern for show tables // show table/stable like 'xxxx', set the like pattern for show tables
SStrToken* pPattern = &pShowInfo->pattern; SStrToken* pPattern = &pShowInfo->pattern;
if (pPattern->type != 0) { if (pPattern->type != 0) {
if (pPattern->type == TK_ID && pPattern->z[0] == TS_ESCAPE_CHAR) { if (pPattern->type == TK_ID && pPattern->z[0] == TS_BACKQUOTE_CHAR) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7);
} }
pPattern->n = strdequote(pPattern->z); pPattern->n = stringProcess(pPattern->z, pPattern->n);
if (pPattern->n <= 0) { if (pPattern->n <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
...@@ -3618,7 +3624,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -3618,7 +3624,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (pShowInfo->prefix.type == TK_STRING) { if (pShowInfo->prefix.type == TK_STRING) {
pShowInfo->prefix.n = strdequote(pShowInfo->prefix.z); pShowInfo->prefix.n = stringProcess(pShowInfo->prefix.z, pShowInfo->prefix.n);
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -4932,7 +4938,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t ...@@ -4932,7 +4938,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
} }
char *v = strndup(pRight->exprToken.z, pRight->exprToken.n); char *v = strndup(pRight->exprToken.z, pRight->exprToken.n);
int32_t len = strRmquote(v, pRight->exprToken.n); int32_t len = stringProcess(v, pRight->exprToken.n);
if (len > 0) { if (len > 0) {
uint32_t type = 0; uint32_t type = 0;
tGetToken(v, &type); tGetToken(v, &type);
...@@ -5046,20 +5052,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ ...@@ -5046,20 +5052,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_
regex_t regex; regex_t regex;
char regErrBuf[256] = {0}; char regErrBuf[256] = {0};
//remove the quote at the begin end of original sql string.
uint32_t lenPattern = pRight->exprToken.n - 2;
char* pattern = malloc(lenPattern + 1);
strncpy(pattern, pRight->exprToken.z+1, lenPattern);
pattern[lenPattern] = '\0';
tfree(pRight->value.pz);
pRight->value.pz = pattern;
pRight->value.nLen = lenPattern;
int cflags = REG_EXTENDED; int cflags = REG_EXTENDED;
if ((errCode = regcomp(&regex, pattern, cflags)) != 0) { if ((errCode = regcomp(&regex, pRight->value.pz, cflags)) != 0) {
regerror(errCode, &regex, regErrBuf, sizeof(regErrBuf)); regerror(errCode, &regex, regErrBuf, sizeof(regErrBuf));
tscError("Failed to compile regex pattern %s. reason %s", pattern, regErrBuf); tscError("Failed to compile regex pattern %s. reason %s", pRight->value.pz, regErrBuf);
return invalidOperationMsg(msgBuf, msg3); return invalidOperationMsg(msgBuf, msg3);
} }
regfree(&regex); regfree(&regex);
...@@ -6059,7 +6055,7 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t ...@@ -6059,7 +6055,7 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t
int64_t val = 0; int64_t val = 0;
bool parsed = false; bool parsed = false;
if (pRight->value.nType == TSDB_DATA_TYPE_BINARY) { if (pRight->value.nType == TSDB_DATA_TYPE_BINARY) {
pRight->value.nLen = strdequote(pRight->value.pz); pRight->value.nLen = stringProcess(pRight->value.pz, pRight->value.nLen);
char* seg = strnchr(pRight->value.pz, '-', pRight->value.nLen, false); char* seg = strnchr(pRight->value.pz, '-', pRight->value.nLen, false);
if (seg != NULL) { if (seg != NULL) {
...@@ -7015,7 +7011,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7015,7 +7011,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
//handle Escape character backstick //handle Escape character backstick
bool inEscape = false; bool inEscape = false;
if (name.z[0] == TS_ESCAPE_CHAR && name.z[name.n - 1] == TS_ESCAPE_CHAR) { if (name.z[0] == TS_BACKQUOTE_CHAR && name.z[name.n - 1] == TS_BACKQUOTE_CHAR) {
inEscape = true; inEscape = true;
name.type = TK_ID; name.type = TK_ID;
} }
...@@ -7034,7 +7030,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7034,7 +7030,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t nameLen = pItem->pVar.nLen; int32_t nameLen = pItem->pVar.nLen;
if (inEscape) { if (inEscape) {
memmove(name1, name1 + 1, nameLen); memmove(name1, name1 + 1, nameLen);
name1[nameLen - TS_ESCAPE_CHAR_SIZE] = '\0'; name1[nameLen - TS_BACKQUOTE_CHAR_SIZE] = '\0';
} }
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypes[TSDB_DATA_TYPE_INT].bytes); TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypes[TSDB_DATA_TYPE_INT].bytes);
...@@ -7055,7 +7051,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7055,7 +7051,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
//handle Escape character backstick //handle Escape character backstick
bool inEscape = false; bool inEscape = false;
if (name.z[0] == TS_ESCAPE_CHAR && name.z[name.n - 1] == TS_ESCAPE_CHAR) { if (name.z[0] == TS_BACKQUOTE_CHAR && name.z[name.n - 1] == TS_BACKQUOTE_CHAR) {
inEscape = true; inEscape = true;
name.type = TK_ID; name.type = TK_ID;
} }
...@@ -7096,8 +7092,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7096,8 +7092,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (inEscape) { if (inEscape) {
memmove(name.z, name.z + 1, name.n); memmove(name.z, name.z + 1, name.n);
name.z[name.n - TS_ESCAPE_CHAR_SIZE] = '\0'; name.z[name.n - TS_BACKQUOTE_CHAR_SIZE] = '\0';
name.n -= TS_ESCAPE_CHAR_SIZE; name.n -= TS_BACKQUOTE_CHAR_SIZE;
} }
TAOS_FIELD f = tscCreateField(pColSchema->type, name.z, pItem->bytes); TAOS_FIELD f = tscCreateField(pColSchema->type, name.z, pItem->bytes);
...@@ -7115,10 +7111,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7115,10 +7111,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
SStrToken name = {.type = TK_STRING, .z = pItem->name, .n = (uint32_t)strlen(pItem->name)}; SStrToken name = {.type = TK_STRING, .z = pItem->name, .n = (uint32_t)strlen(pItem->name)};
//handle Escape character backstick //handle Escape character backstick
if (name.z[0] == TS_ESCAPE_CHAR && name.z[name.n - 1] == TS_ESCAPE_CHAR) { if (name.z[0] == TS_BACKQUOTE_CHAR && name.z[name.n - 1] == TS_BACKQUOTE_CHAR) {
memmove(name.z, name.z + 1, name.n); memmove(name.z, name.z + 1, name.n);
name.z[name.n - TS_ESCAPE_CHAR_SIZE] = '\0'; name.z[name.n - TS_BACKQUOTE_CHAR_SIZE] = '\0';
name.n -= TS_ESCAPE_CHAR_SIZE; name.n -= TS_BACKQUOTE_CHAR_SIZE;
} }
if (getColumnIndexByName(&name, pQueryInfo, &columnIndex, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&name, pQueryInfo, &columnIndex, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(pMsg, msg17); return invalidOperationMsg(pMsg, msg17);
...@@ -7315,7 +7311,7 @@ int32_t validateDNodeConfig(SMiscInfo* pOptions) { ...@@ -7315,7 +7311,7 @@ int32_t validateDNodeConfig(SMiscInfo* pOptions) {
SStrToken* pValToken = taosArrayGet(pOptions->a, 2); SStrToken* pValToken = taosArrayGet(pOptions->a, 2);
int32_t vnodeId = 0; int32_t vnodeId = 0;
int32_t dnodeId = 0; int32_t dnodeId = 0;
strdequote(pValToken->z); pValToken->n = stringProcess(pValToken->z, pValToken->n);
bool parseOk = taosCheckBalanceCfgOptions(pValToken->z, &vnodeId, &dnodeId); bool parseOk = taosCheckBalanceCfgOptions(pValToken->z, &vnodeId, &dnodeId);
if (!parseOk) { if (!parseOk) {
return TSDB_CODE_TSC_INVALID_OPERATION; // options value is invalid return TSDB_CODE_TSC_INVALID_OPERATION; // options value is invalid
...@@ -7417,7 +7413,7 @@ int32_t validateColumnName(char* name) { ...@@ -7417,7 +7413,7 @@ int32_t validateColumnName(char* name) {
} }
if (token.type == TK_STRING) { if (token.type == TK_STRING) {
strdequote(token.z); token.n = stringProcess(token.z, token.n);
strntolower(token.z, token.z, token.n); strntolower(token.z, token.z, token.n);
token.n = (uint32_t)strtrim(token.z); token.n = (uint32_t)strtrim(token.z);
...@@ -7428,7 +7424,7 @@ int32_t validateColumnName(char* name) { ...@@ -7428,7 +7424,7 @@ int32_t validateColumnName(char* name) {
return validateColumnName(token.z); return validateColumnName(token.z);
} else if (token.type == TK_ID) { } else if (token.type == TK_ID) {
strRmquoteEscape(name, token.n); stringProcess(name, token.n);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
if (isNumber(&token)) { if (isNumber(&token)) {
...@@ -7579,7 +7575,7 @@ static int32_t setTimePrecision(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDbInfo ...@@ -7579,7 +7575,7 @@ static int32_t setTimePrecision(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDbInfo
SStrToken* pToken = &pCreateDbInfo->precision; SStrToken* pToken = &pCreateDbInfo->precision;
if (pToken->n > 0) { if (pToken->n > 0) {
pToken->n = strdequote(pToken->z); pToken->n = stringProcess(pToken->z, pToken->n);
if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 && if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) { strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) {
...@@ -8634,12 +8630,8 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -8634,12 +8630,8 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
strncpy(tmpTokenBuf, sToken->z, sToken->n); strncpy(tmpTokenBuf, sToken->z, sToken->n);
sToken->z = tmpTokenBuf; sToken->z = tmpTokenBuf;
if (TK_STRING == sToken->type) { if (TK_STRING == sToken->type || TK_ID == sToken->type) {
tscDequoteAndTrimToken(sToken); sToken->n = stringProcess(sToken->z, sToken->n);
}
if (TK_ID == sToken->type) {
tscRmEscapeAndTrimToken(sToken);
} }
tVariantListItem* pItem = taosArrayGet(pValList, i); tVariantListItem* pItem = taosArrayGet(pValList, i);
...@@ -9578,8 +9570,6 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod ...@@ -9578,8 +9570,6 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
tscDequoteAndTrimToken(oriName);
bool dbIncluded = false; bool dbIncluded = false;
char buf[TSDB_TABLE_FNAME_LEN]; char buf[TSDB_TABLE_FNAME_LEN];
SStrToken sTblToken; SStrToken sTblToken;
...@@ -9601,7 +9591,6 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod ...@@ -9601,7 +9591,6 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
tscDequoteAndTrimToken(aliasName);
if (tscValidateName(aliasName, false, NULL) != TSDB_CODE_SUCCESS || aliasName->n >= TSDB_TABLE_NAME_LEN) { if (tscValidateName(aliasName, false, NULL) != TSDB_CODE_SUCCESS || aliasName->n >= TSDB_TABLE_NAME_LEN) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
......
...@@ -363,6 +363,41 @@ void tscSetFqdnErrorMsg(SSqlObj* pSql, SRpcEpSet* pEpSet) { ...@@ -363,6 +363,41 @@ void tscSetFqdnErrorMsg(SSqlObj* pSql, SRpcEpSet* pEpSet) {
} }
} }
bool shouldRewTableMeta(SSqlObj* pSql, SRpcMsg* rpcMsg) {
SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd);
int32_t cmd = pCmd->command;
if ((cmd != TSDB_SQL_SELECT && cmd != TSDB_SQL_UPDATE_TAGS_VAL)) {
return false;
}
if (rpcMsg->code != TSDB_CODE_TDB_INVALID_TABLE_ID &&
rpcMsg->code != TSDB_CODE_VND_INVALID_VGROUP_ID &&
rpcMsg->code != TSDB_CODE_QRY_INVALID_SCHEMA_VERSION &&
rpcMsg->code != TSDB_CODE_RPC_NETWORK_UNAVAIL &&
rpcMsg->code != TSDB_CODE_APP_NOT_READY ) {
return false;
}
if (rpcMsg->code == TSDB_CODE_QRY_INVALID_SCHEMA_VERSION) {
return true;
}
// 1. super table subquery
// 2. nest queries are all not updated the tablemeta and retry parse the sql after cleanup local tablemeta/vgroup id buffer
if ((TSDB_QUERY_HAS_TYPE(pQueryInfo->type, (TSDB_QUERY_TYPE_STABLE_SUBQUERY | TSDB_QUERY_TYPE_SUBQUERY | TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) &&
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY)) ||
(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_NEST_SUBQUERY)) ||
(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY) && pQueryInfo->distinct)
|| (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY))) {
return false;
}
// single table query error need to renew table meta.
return true;
}
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
TSDB_CACHE_PTR_TYPE handle = (TSDB_CACHE_PTR_TYPE) rpcMsg->ahandle; TSDB_CACHE_PTR_TYPE handle = (TSDB_CACHE_PTR_TYPE) rpcMsg->ahandle;
SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, handle); SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, handle);
...@@ -415,42 +450,29 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { ...@@ -415,42 +450,29 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
pSql->cmd.insertParam.schemaAttached = 1; pSql->cmd.insertParam.schemaAttached = 1;
} }
// single table query error need to be handled here. bool renewTableMeta = shouldRewTableMeta(pSql, rpcMsg);
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAGS_VAL) && if (renewTableMeta) {
(((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) || pSql->retry += 1;
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_APP_NOT_READY)) { tscWarn("0x%" PRIx64 " it shall renew table meta, code:%s, retry:%d", pSql->self, tstrerror(rpcMsg->code), pSql->retry);
// 1. super table subquery pSql->res.code = rpcMsg->code; // keep the previous error code
// 2. nest queries are all not updated the tablemeta and retry parse the sql after cleanup local tablemeta/vgroup id buffer if (pSql->retry > pSql->maxRetry) {
if ((TSDB_QUERY_HAS_TYPE(pQueryInfo->type, (TSDB_QUERY_TYPE_STABLE_SUBQUERY | TSDB_QUERY_TYPE_SUBQUERY | tscError("0x%" PRIx64 " max retry %d reached, give up", pSql->self, pSql->maxRetry);
TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) && } else {
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY)) || // wait for a little bit moment and then retry
(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_NEST_SUBQUERY)) || (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY) && pQueryInfo->distinct) // todo do not sleep in rpc callback thread, add this process into queue to process
|| (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY))) { if (rpcMsg->code == TSDB_CODE_APP_NOT_READY || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) {
// do nothing in case of super table subquery int32_t duration = getWaitingTimeInterval(pSql->retry);
} else { taosMsleep(duration);
pSql->retry += 1; }
tscWarn("0x%" PRIx64 " it shall renew table meta, code:%s, retry:%d", pSql->self, tstrerror(rpcMsg->code), pSql->retry);
pSql->retryReason = rpcMsg->code;
pSql->res.code = rpcMsg->code; // keep the previous error code rpcMsg->code = tscRenewTableMeta(pSql);
if (pSql->retry > pSql->maxRetry) { // if there is an error occurring, proceed to the following error handling procedure.
tscError("0x%" PRIx64 " max retry %d reached, give up", pSql->self, pSql->maxRetry); if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
} else { taosReleaseRef(tscObjRef, handle);
// wait for a little bit moment and then retry rpcFreeCont(rpcMsg->pCont);
// todo do not sleep in rpc callback thread, add this process into queue to process return;
if (rpcMsg->code == TSDB_CODE_APP_NOT_READY || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) {
int32_t duration = getWaitingTimeInterval(pSql->retry);
taosMsleep(duration);
}
pSql->retryReason = rpcMsg->code;
rpcMsg->code = tscRenewTableMeta(pSql);
// if there is an error occurring, proceed to the following error handling procedure.
if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
taosReleaseRef(tscObjRef, handle);
rpcFreeCont(rpcMsg->pCont);
return;
}
} }
} }
} }
...@@ -511,6 +533,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { ...@@ -511,6 +533,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
} }
bool shouldFree = tscShouldBeFreed(pSql); bool shouldFree = tscShouldBeFreed(pSql);
if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
if (rpcMsg->code != TSDB_CODE_SUCCESS) { if (rpcMsg->code != TSDB_CODE_SUCCESS) {
pRes->code = rpcMsg->code; pRes->code = rpcMsg->code;
...@@ -962,7 +985,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -962,7 +985,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols); pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols);
pQueryMsg->queryType = htonl(pQueryInfo->type); pQueryMsg->queryType = htonl(pQueryInfo->type);
pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen); pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen);
// set column list ids // set column list ids
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
char *pMsg = (char *)(pQueryMsg->tableCols) + numOfCols * sizeof(SColumnInfo); char *pMsg = (char *)(pQueryMsg->tableCols) + numOfCols * sizeof(SColumnInfo);
...@@ -1148,21 +1171,21 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1148,21 +1171,21 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg += sqlLen; pMsg += sqlLen;
/*
//MSG EXTEND DEMO
pQueryMsg->extend = 1; pQueryMsg->extend = 1;
STLV *tlv = (STLV *)pMsg; STLV *tlv = (STLV *)pMsg;
tlv->type = htons(TLV_TYPE_DUMMY); tlv->type = htons(TLV_TYPE_META_VERSION);
tlv->len = htonl(sizeof(int16_t)); tlv->len = htonl(sizeof(int16_t) * 2);
*(int16_t *)tlv->value = htons(12345); *(int16_t*)tlv->value = htons(pTableMeta->sversion);
*(int16_t*)(tlv->value+sizeof(int16_t)) = htons(pTableMeta->tversion);
pMsg += sizeof(*tlv) + ntohl(tlv->len); pMsg += sizeof(*tlv) + ntohl(tlv->len);
tlv = (STLV *)pMsg; tlv = (STLV *)pMsg;
tlv->type = htons(TLV_TYPE_END_MARK);
tlv->len = 0; tlv->len = 0;
pMsg += sizeof(*tlv); pMsg += sizeof(*tlv);
*/
int32_t msgLen = (int32_t)(pMsg - pCmd->payload); int32_t msgLen = (int32_t)(pMsg - pCmd->payload);
...@@ -2691,7 +2714,9 @@ int tscProcessQueryRsp(SSqlObj *pSql) { ...@@ -2691,7 +2714,9 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
pRes->data = NULL; pRes->data = NULL;
tscResetForNextRetrieve(pRes); tscResetForNextRetrieve(pRes);
tscDebug("0x%"PRIx64" query rsp received, qId:0x%"PRIx64, pSql->self, pRes->qId); tscDebug("0x%"PRIx64" query rsp received, qId:0x%"PRIx64, pSql->self, pRes->qId);
return 0; return 0;
} }
...@@ -2703,7 +2728,7 @@ static void decompressQueryColData(SSqlObj *pSql, SSqlRes *pRes, SQueryInfo* pQu ...@@ -2703,7 +2728,7 @@ static void decompressQueryColData(SSqlObj *pSql, SSqlRes *pRes, SQueryInfo* pQu
compSizes = (int32_t *)(pData + compLen); compSizes = (int32_t *)(pData + compLen);
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1);
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1); int32_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1);
char *outputBuf = tcalloc(pRes->numOfRows, (pField->bytes + offset)); char *outputBuf = tcalloc(pRes->numOfRows, (pField->bytes + offset));
char *p = outputBuf; char *p = outputBuf;
...@@ -2804,11 +2829,12 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { ...@@ -2804,11 +2829,12 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
pRes->row = 0; pRes->row = 0;
tscDebug("0x%"PRIx64" numOfRows:%d, offset:%" PRId64 ", complete:%d, qId:0x%"PRIx64, pSql->self, pRes->numOfRows, pRes->offset, tscDebug("0x%"PRIx64" numOfRows:%d, offset:%" PRId64 ", complete:%d, qId:0x%"PRIx64, pSql->self, pRes->numOfRows, pRes->offset,
pRes->completed, pRes->qId); pRes->completed, pRes->qId);
return 0; return 0;
} }
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code); void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool autocreate) { static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool autocreate) {
......
...@@ -137,7 +137,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa ...@@ -137,7 +137,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
char tmp[TSDB_DB_NAME_LEN] = {0}; char tmp[TSDB_DB_NAME_LEN] = {0};
tstrncpy(tmp, db, sizeof(tmp)); tstrncpy(tmp, db, sizeof(tmp));
strdequote(tmp); stringProcess(tmp, (int32_t)strlen(tmp));
strtolower(pObj->db, tmp); strtolower(pObj->db, tmp);
} }
...@@ -547,6 +547,28 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -547,6 +547,28 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
return pRes->numOfRows; return pRes->numOfRows;
} }
TAOS_ROW *taos_result_block(TAOS_RES *res) {
SSqlObj *pSql = (SSqlObj *)res;
if (pSql == NULL || pSql->signature != pSql) {
terrno = TSDB_CODE_TSC_DISCONNECTED;
return NULL;
}
SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res;
if (pCmd == NULL ||
pRes == NULL ||
pRes->qId == 0 ||
pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED ||
pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
pCmd->command == TSDB_SQL_INSERT) {
return NULL;
}
return &pRes->urow;
}
int taos_select_db(TAOS *taos, const char *db) { int taos_select_db(TAOS *taos, const char *db) {
char sql[256] = {0}; char sql[256] = {0};
......
...@@ -211,6 +211,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf ...@@ -211,6 +211,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
tfree(pSql->pSubs); tfree(pSql->pSubs);
pSql->subState.numOfSub = 0; pSql->subState.numOfSub = 0;
pSql->parseRetry = 0;
int32_t code = tsParseSql(pSql, true); int32_t code = tsParseSql(pSql, true);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
cbParseSql(pStream, pSql, code); cbParseSql(pStream, pSql, code);
...@@ -220,6 +221,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf ...@@ -220,6 +221,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
tscError("0x%"PRIx64" open stream failed, code:%s", pSql->self, tstrerror(code)); tscError("0x%"PRIx64" open stream failed, code:%s", pSql->self, tstrerror(code));
taosReleaseRef(tscObjRef, pSql->self); taosReleaseRef(tscObjRef, pSql->self);
free(pStream); free(pStream);
return;
} }
// tscSetRetryTimer(pStream, pStream->pSql, retryDelay); // tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
......
...@@ -2369,7 +2369,7 @@ TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) { ...@@ -2369,7 +2369,7 @@ TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) {
return &((SInternalField*)TARRAY_GET_ELEM(pFieldInfo->internalField, index))->field; return &((SInternalField*)TARRAY_GET_ELEM(pFieldInfo->internalField, index))->field;
} }
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) { int32_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) {
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, index); SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, index);
assert(pInfo != NULL && pInfo->pExpr->pExpr == NULL); assert(pInfo != NULL && pInfo->pExpr->pExpr == NULL);
...@@ -2918,7 +2918,7 @@ void tscColumnListDestroy(SArray* pColumnList) { ...@@ -2918,7 +2918,7 @@ void tscColumnListDestroy(SArray* pColumnList) {
* *
*/ */
static int32_t validateQuoteToken(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) { static int32_t validateQuoteToken(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) {
tscDequoteAndTrimToken(pToken); if(pToken->z[0] != TS_BACKQUOTE_CHAR) pToken->n = stringProcess(pToken->z, pToken->n);
int32_t k = tGetToken(pToken->z, &pToken->type); int32_t k = tGetToken(pToken->z, &pToken->type);
...@@ -2932,94 +2932,6 @@ static int32_t validateQuoteToken(SStrToken* pToken, bool escapeEnabled, bool *d ...@@ -2932,94 +2932,6 @@ static int32_t validateQuoteToken(SStrToken* pToken, bool escapeEnabled, bool *d
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void tscDequoteAndTrimToken(SStrToken* pToken) {
uint32_t first = 0, last = pToken->n;
// trim leading spaces
while (first < last) {
char c = pToken->z[first];
if (c != ' ' && c != '\t') {
break;
}
first++;
}
// trim ending spaces
while (first < last) {
char c = pToken->z[last - 1];
if (c != ' ' && c != '\t') {
break;
}
last--;
}
// there are still at least two characters
if (first < last - 1) {
char c = pToken->z[first];
// dequote
if ((c == '\'' || c == '"') && c == pToken->z[last - 1]) {
first++;
last--;
}
}
// left shift the string and pad spaces
for (uint32_t i = 0; i + first < last; i++) {
pToken->z[i] = pToken->z[first + i];
}
for (uint32_t i = last - first; i < pToken->n; i++) {
pToken->z[i] = ' ';
}
// adjust token length
pToken->n = last - first;
}
void tscRmEscapeAndTrimToken(SStrToken* pToken) {
uint32_t first = 0, last = pToken->n;
// trim leading spaces
while (first < last) {
char c = pToken->z[first];
if (c != ' ' && c != '\t') {
break;
}
first++;
}
// trim ending spaces
while (first < last) {
char c = pToken->z[last - 1];
if (c != ' ' && c != '\t') {
break;
}
last--;
}
// there are still at least two characters
if (first < last - 1) {
char c = pToken->z[first];
// dequote
if ((c == '`') && c == pToken->z[last - 1]) {
first++;
last--;
}
}
// left shift the string and pad spaces
for (uint32_t i = 0; i + first < last; i++) {
pToken->z[i] = pToken->z[first + i];
}
for (uint32_t i = last - first; i < pToken->n; i++) {
pToken->z[i] = ' ';
}
// adjust token length
pToken->n = last - first;
}
int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) { int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) {
if (pToken == NULL || pToken->z == NULL if (pToken == NULL || pToken->z == NULL
|| (pToken->type != TK_STRING && pToken->type != TK_ID)) { || (pToken->type != TK_STRING && pToken->type != TK_ID)) {
...@@ -3027,7 +2939,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) ...@@ -3027,7 +2939,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
} }
if ((!escapeEnabled) && pToken->type == TK_ID) { if ((!escapeEnabled) && pToken->type == TK_ID) {
if (pToken->z[0] == TS_ESCAPE_CHAR) { if (pToken->z[0] == TS_BACKQUOTE_CHAR) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
} }
...@@ -3045,7 +2957,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) ...@@ -3045,7 +2957,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
if (pToken->type == TK_STRING) { if (pToken->type == TK_STRING) {
tscDequoteAndTrimToken(pToken); if(pToken->z[0] != TS_BACKQUOTE_CHAR) pToken->n = stringProcess(pToken->z, pToken->n);
// tscStrToLower(pToken->z, pToken->n); // tscStrToLower(pToken->z, pToken->n);
strntolower(pToken->z, pToken->z, pToken->n); strntolower(pToken->z, pToken->z, pToken->n);
//pToken->n = (uint32_t)strtrim(pToken->z); //pToken->n = (uint32_t)strtrim(pToken->z);
...@@ -3065,8 +2977,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) ...@@ -3065,8 +2977,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
return tscValidateName(pToken, escapeEnabled, NULL); return tscValidateName(pToken, escapeEnabled, NULL);
} }
} else if (pToken->type == TK_ID) { } else if (pToken->type == TK_ID) {
tscRmEscapeAndTrimToken(pToken); if(pToken->z[0] == TS_BACKQUOTE_CHAR) pToken->n = stringProcess(pToken->z, pToken->n);
if (pToken->n == 0) { if (pToken->n == 0) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
...@@ -3126,7 +3037,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) ...@@ -3126,7 +3037,7 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
} }
if (escapeEnabled && pToken->type == TK_ID) { if (escapeEnabled && pToken->type == TK_ID) {
tscRmEscapeAndTrimToken(pToken); if(pToken->z[0] == TS_BACKQUOTE_CHAR) pToken->n = stringProcess(pToken->z, pToken->n);
} }
// re-build the whole name string // re-build the whole name string
......
...@@ -289,7 +289,7 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRES ...@@ -289,7 +289,7 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRES
#endif #endif
// long query death-lock // long query death-lock
int8_t tsDeadLockKillQuery = 0; int8_t tsDeadLockKillQuery = 1;
// default JSON string type // default JSON string type
char tsDefaultJSONStrType[7] = "nchar"; char tsDefaultJSONStrType[7] = "nchar";
......
...@@ -50,7 +50,7 @@ SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const ...@@ -50,7 +50,7 @@ SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const
} else { } else {
size_t tlen = MIN(sizeof(s.name), exprStr->n + 1); size_t tlen = MIN(sizeof(s.name), exprStr->n + 1);
tstrncpy(s.name, exprStr->z, tlen); tstrncpy(s.name, exprStr->z, tlen);
strdequote(s.name); stringProcess(s.name, (int32_t)strlen(s.name));
} }
return s; return s;
...@@ -163,7 +163,7 @@ char *tableNameGetPosition(SStrToken* pToken, char target) { ...@@ -163,7 +163,7 @@ char *tableNameGetPosition(SStrToken* pToken, char target) {
return pToken->z + i; return pToken->z + i;
} }
if (*(pToken->z + i) == TS_ESCAPE_CHAR) { if (*(pToken->z + i) == TS_BACKQUOTE_CHAR) {
if (!inQuote) { if (!inQuote) {
inEscape = !inEscape; inEscape = !inEscape;
} }
...@@ -223,7 +223,7 @@ void extractTableNameFromToken(SStrToken* pToken, SStrToken* pTable) { ...@@ -223,7 +223,7 @@ void extractTableNameFromToken(SStrToken* pToken, SStrToken* pTable) {
char* r = tableNameGetPosition(pToken, sep); char* r = tableNameGetPosition(pToken, sep);
if (r != NULL) { // record the table name token if (r != NULL) { // record the table name token
if (pToken->z[0] == TS_ESCAPE_CHAR && *(r - 1) == TS_ESCAPE_CHAR) { if (pToken->z[0] == TS_BACKQUOTE_CHAR && *(r - 1) == TS_BACKQUOTE_CHAR) {
pTable->n = (uint32_t)(r - pToken->z - 2); pTable->n = (uint32_t)(r - pToken->z - 2);
pTable->z = pToken->z + 1; pTable->z = pToken->z + 1;
} else { } else {
......
...@@ -87,7 +87,7 @@ void tVariantCreateExt(tVariant *pVar, SStrToken *token, int32_t optrType, bool ...@@ -87,7 +87,7 @@ void tVariantCreateExt(tVariant *pVar, SStrToken *token, int32_t optrType, bool
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
pVar->pz = strndup(token->z, token->n); pVar->pz = strndup(token->z, token->n);
pVar->nLen = needRmquoteEscape ? strRmquoteEscape(pVar->pz, token->n) : token->n; pVar->nLen = needRmquoteEscape ? stringProcess(pVar->pz, token->n) : token->n;
break; break;
} }
case TSDB_DATA_TYPE_TIMESTAMP: { case TSDB_DATA_TYPE_TIMESTAMP: {
......
...@@ -179,6 +179,7 @@ DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); ...@@ -179,6 +179,7 @@ DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res); DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res); DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res);
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
DLL_EXPORT void taos_reset_current_db(TAOS *taos); DLL_EXPORT void taos_reset_current_db(TAOS *taos);
......
...@@ -95,8 +95,8 @@ extern const int32_t TYPE_BYTES[16]; ...@@ -95,8 +95,8 @@ extern const int32_t TYPE_BYTES[16];
#define TSDB_ERR -1 #define TSDB_ERR -1
#define TS_PATH_DELIMITER "." #define TS_PATH_DELIMITER "."
#define TS_ESCAPE_CHAR '`' #define TS_BACKQUOTE_CHAR '`'
#define TS_ESCAPE_CHAR_SIZE 2 #define TS_BACKQUOTE_CHAR_SIZE 2
#define TSDB_TIME_PRECISION_MILLI 0 #define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1 #define TSDB_TIME_PRECISION_MICRO 1
......
...@@ -115,6 +115,7 @@ int32_t* taosGetErrno(); ...@@ -115,6 +115,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0225) //"Invalid line protocol type") #define TSDB_CODE_TSC_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0225) //"Invalid line protocol type")
#define TSDB_CODE_TSC_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0226) //"Invalid timestamp precision type") #define TSDB_CODE_TSC_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0226) //"Invalid timestamp precision type")
#define TSDB_CODE_TSC_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0227) //"Result set too large to be output") #define TSDB_CODE_TSC_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0227) //"Result set too large to be output")
#define TSDB_CODE_TSC_INVALID_SCHEMA_VERSION TAOS_DEF_ERROR_CODE(0, 0x0228) //"invalid table schema version")
// mnode // mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed" #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed"
...@@ -291,6 +292,7 @@ int32_t* taosGetErrno(); ...@@ -291,6 +292,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica") #define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica")
#define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070D) //"System error") #define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070D) //"System error")
#define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070E) //"invalid time condition") #define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070E) //"invalid time condition")
#define TSDB_CODE_QRY_INVALID_SCHEMA_VERSION TAOS_DEF_ERROR_CODE(0, 0x0710) //"invalid schema version")
// grant // grant
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800) //"License expired" #define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800) //"License expired"
......
...@@ -978,7 +978,9 @@ typedef struct { ...@@ -978,7 +978,9 @@ typedef struct {
} STLV; } STLV;
enum { enum {
TLV_TYPE_DUMMY = 1, TLV_TYPE_END_MARK = -1,
//TLV_TYPE_DUMMY = 1,
TLV_TYPE_META_VERSION = 1,
}; };
#pragma pack(pop) #pragma pack(pop)
......
...@@ -229,6 +229,8 @@ typedef struct { ...@@ -229,6 +229,8 @@ typedef struct {
uint32_t numOfTables; uint32_t numOfTables;
SArray *pGroupList; SArray *pGroupList;
SHashObj *map; // speedup acquire the tableQueryInfo by table uid SHashObj *map; // speedup acquire the tableQueryInfo by table uid
int32_t sVersion;
int32_t tVersion;
} STableGroupInfo; } STableGroupInfo;
#define TSDB_BLOCK_DIST_STEP_ROWS 16 #define TSDB_BLOCK_DIST_STEP_ROWS 16
......
...@@ -51,8 +51,8 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) { ...@@ -51,8 +51,8 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break; if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break;
} }
int rc = mbtowc(&wc, str + pos, MB_CUR_MAX); mbtowc(&wc, str + pos, MB_CUR_MAX);
assert(rc == *size); // assert(rc == *size); // it will be core, if str is encode by utf8 and taos charset is gbk
*width = wcwidth(wc); *width = wcwidth(wc);
} }
......
...@@ -49,9 +49,9 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut ...@@ -49,9 +49,9 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut
TAOS *shellInit(SShellArguments *_args) { TAOS *shellInit(SShellArguments *_args) {
printf("\n"); printf("\n");
if (!_args->is_use_passwd) { if (!_args->is_use_passwd) {
#ifdef TD_WINDOWS #ifdef WINDOWS
strcpy(tsOsName, "Windows"); strcpy(tsOsName, "Windows");
#elif defined(TD_DARWIN) #elif defined(DARWIN)
strcpy(tsOsName, "Darwin"); strcpy(tsOsName, "Darwin");
#endif #endif
printf(CLIENT_VERSION, tsOsName, taos_get_client_info()); printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
...@@ -207,64 +207,27 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -207,64 +207,27 @@ int32_t shellRunCommand(TAOS* con, char* command) {
} }
} }
bool esc = false; char quote = 0, *cmd = command;
char quote = 0, *cmd = command, *p = command;
for (char c = *command++; c != 0; c = *command++) { for (char c = *command++; c != 0; c = *command++) {
if (esc) { if (c == '\\' && (*command == '\'' || *command == '"' || *command == '`')) {
switch (c) { command ++;
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'G':
*p++ = '\\';
break;
case '\'':
case '"':
case '`':
if (quote) {
*p++ = '\\';
}
break;
}
*p++ = c;
esc = false;
continue; continue;
} }
if (c == '\\') {
if (quote != 0 && (*command == '_' || *command == '%' || *command == '\\')) {
//DO nothing
} else {
esc = true;
continue;
}
}
if (quote == c) { if (quote == c) {
quote = 0; quote = 0;
} else if (quote == 0 && (c == '\'' || c == '"' || c == '`')) { } else if (quote == 0 && (c == '\'' || c == '"' || c == '`')) {
quote = c; quote = c;
} } else if (c == ';' && quote == 0) {
c = *command;
*p++ = c; *command = 0;
if (c == ';' && quote == 0) {
c = *p;
*p = 0;
if (shellRunSingleCommand(con, cmd) < 0) { if (shellRunSingleCommand(con, cmd) < 0) {
return -1; return -1;
} }
*p = c; *command = c;
p = cmd; cmd = command;
} }
} }
*p = 0;
return shellRunSingleCommand(con, cmd); return shellRunSingleCommand(con, cmd);
} }
...@@ -379,7 +342,14 @@ int regex_match(const char *s, const char *reg, int cflags) { ...@@ -379,7 +342,14 @@ int regex_match(const char *s, const char *reg, int cflags) {
} else if (reti == REG_NOMATCH) { } else if (reti == REG_NOMATCH) {
regfree(&regex); regfree(&regex);
return 0; return 0;
} else { }
#ifdef DARWIN
else if (reti == REG_ILLSEQ){
regfree(&regex);
return 0;
}
#endif
else {
regerror(reti, &regex, msgbuf, sizeof(msgbuf)); regerror(reti, &regex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf); fprintf(stderr, "Regex match failed: %s\n", msgbuf);
regfree(&regex); regfree(&regex);
...@@ -557,20 +527,25 @@ static void shellPrintNChar(const char *str, int length, int width) { ...@@ -557,20 +527,25 @@ static void shellPrintNChar(const char *str, int length, int width) {
if (bytes <= 0) { if (bytes <= 0) {
break; break;
} }
pos += bytes; int w = 0;
if (pos > length) {
break;
}
#ifdef WINDOWS #ifdef WINDOWS
int w = bytes; w = bytes;
#else #else
int w = wcwidth(wc); if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){
w = bytes;
}else{
w = wcwidth(wc);
}
#endif #endif
if (w <= 0) { if (w <= 0) {
continue; continue;
} }
pos += bytes;
if (pos > length) {
break;
}
if (width <= 0) { if (width <= 0) {
printf("%lc", wc); printf("%lc", wc);
continue; continue;
......
Subproject commit 5c944c1c93c63112890c8c65e1f57cfa6bd89179 Subproject commit 9f1b028ca325f67762826be4caf58d356ad7e389
...@@ -903,6 +903,8 @@ static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) { ...@@ -903,6 +903,8 @@ static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
if (pDb == NULL) return NULL; if (pDb == NULL) return NULL;
if (pVgroup->idPool == NULL) return NULL;
SCreateVnodeMsg *pVnode = rpcMallocCont(sizeof(SCreateVnodeMsg)); SCreateVnodeMsg *pVnode = rpcMallocCont(sizeof(SCreateVnodeMsg));
if (pVnode == NULL) return NULL; if (pVnode == NULL) return NULL;
...@@ -1057,6 +1059,11 @@ void mnodeSendCompactVgroupMsg(SVgObj *pVgroup) { ...@@ -1057,6 +1059,11 @@ void mnodeSendCompactVgroupMsg(SVgObj *pVgroup) {
} }
static void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet, void *ahandle) { static void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet, void *ahandle) {
SCreateVnodeMsg *pCreate = mnodeBuildVnodeMsg(pVgroup); SCreateVnodeMsg *pCreate = mnodeBuildVnodeMsg(pVgroup);
if (pCreate == NULL) {
mError("vgId: %d, can not create vnode msg for send create vnode", pVgroup->vgId);
return;
}
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.ahandle = ahandle, .ahandle = ahandle,
.pCont = pCreate, .pCont = pCreate,
......
...@@ -13,6 +13,22 @@ ELSEIF(TD_BUILD_TAOSA_INTERNAL) ...@@ -13,6 +13,22 @@ ELSEIF(TD_BUILD_TAOSA_INTERNAL)
ELSE () ELSE ()
MESSAGE("") MESSAGE("")
MESSAGE("${Green} use taosadapter as httpd ${ColourReset}") MESSAGE("${Green} use taosadapter as httpd ${ColourReset}")
EXECUTE_PROCESS(
COMMAND git rev-parse --abbrev-ref HEAD
RESULT_VARIABLE result_taos_version
OUTPUT_VARIABLE taos_version
)
STRING(FIND ${taos_version} release is_release_branch)
IF ("${is_release_branch}" STREQUAL "0")
STRING(SUBSTRING "${taos_version}" 12 -1 taos_version)
STRING(STRIP "${taos_version}" taos_version)
ELSE ()
STRING(CONCAT taos_version "branch_" "${taos_version}")
STRING(STRIP "${taos_version}" taos_version)
ENDIF ()
EXECUTE_PROCESS( EXECUTE_PROCESS(
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter
) )
...@@ -22,12 +38,12 @@ ELSE () ...@@ -22,12 +38,12 @@ ELSE ()
OUTPUT_VARIABLE taosadapter_commit_sha1 OUTPUT_VARIABLE taosadapter_commit_sha1
) )
IF ("${taosadapter_commit_sha1}" STREQUAL "") IF ("${taosadapter_commit_sha1}" STREQUAL "")
SET(taosadapter_commit_sha1 "unknown") SET(taosadapter_commit_sha1 "unknown")
ELSE () ELSE ()
STRING(SUBSTRING "${taosadapter_commit_sha1}" 0 7 taosadapter_commit_sha1) STRING(SUBSTRING "${taosadapter_commit_sha1}" 0 7 taosadapter_commit_sha1)
STRING(STRIP "${taosadapter_commit_sha1}" taosadapter_commit_sha1) STRING(STRIP "${taosadapter_commit_sha1}" taosadapter_commit_sha1)
ENDIF () ENDIF ()
MESSAGE("${Green} taosadapter commit: ${taosadapter_commit_sha1} ${ColourReset}") MESSAGE("${Green} taosAdapter will use ${taos_version} and commit ${taosadapter_commit_sha1} as version ${ColourReset}")
EXECUTE_PROCESS( EXECUTE_PROCESS(
COMMAND cd .. COMMAND cd ..
) )
...@@ -43,7 +59,7 @@ ELSE () ...@@ -43,7 +59,7 @@ ELSE ()
CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config"
PATCH_COMMAND PATCH_COMMAND
COMMAND git clean -f -d COMMAND git clean -f -d
BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}" BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
INSTALL_COMMAND INSTALL_COMMAND
COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar -xvJf upx.tar.xz -C ${CMAKE_BINARY_DIR} --strip-components 1 > /dev/null && ${CMAKE_BINARY_DIR}/upx taosadapter || : COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar -xvJf upx.tar.xz -C ${CMAKE_BINARY_DIR} --strip-components 1 > /dev/null && ${CMAKE_BINARY_DIR}/upx taosadapter || :
COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
...@@ -62,7 +78,7 @@ ELSE () ...@@ -62,7 +78,7 @@ ELSE ()
CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config"
PATCH_COMMAND PATCH_COMMAND
COMMAND git clean -f -d COMMAND git clean -f -d
BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}" BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
INSTALL_COMMAND INSTALL_COMMAND
COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
......
Subproject commit 47fb0b3e627ddadf1ca983c1d75b9a4e44cd98fd Subproject commit 8f9501a30b1893c6616d644a924c995aa21ad957
...@@ -428,6 +428,8 @@ typedef struct SQueryParam { ...@@ -428,6 +428,8 @@ typedef struct SQueryParam {
int32_t tableScanOperator; int32_t tableScanOperator;
SArray *pOperator; SArray *pOperator;
SUdfInfo *pUdfInfo; SUdfInfo *pUdfInfo;
int16_t schemaVersion;
int16_t tagVersion;
} SQueryParam; } SQueryParam;
typedef struct SColumnDataParam{ typedef struct SColumnDataParam{
......
...@@ -4618,9 +4618,7 @@ static void mavg_function(SQLFunctionCtx *pCtx) { ...@@ -4618,9 +4618,7 @@ static void mavg_function(SQLFunctionCtx *pCtx) {
} }
} }
if (notNullElems <= 0) { {
assert(pCtx->hasNull);
} else {
for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) { for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) {
SQLFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t]; SQLFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t];
if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) { if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) {
......
...@@ -1808,11 +1808,17 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx ...@@ -1808,11 +1808,17 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
} }
if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_FIRST) { if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_FIRST) {
// if param[2] is set value, input data come from client, order is no relation with pQueryAttr->order , so always return true
if(pCtx->param[2].nType == TSDB_DATA_TYPE_INT)
return true;
return QUERY_IS_ASC_QUERY(pQueryAttr); return QUERY_IS_ASC_QUERY(pQueryAttr);
} }
// denote the order type // denote the order type
if ((functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_LAST)) { if ((functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_LAST)) {
// if param[2] is set value, input data come from client, order is no relation with pQueryAttr->order , so always return true
if(pCtx->param[2].nType == TSDB_DATA_TYPE_INT)
return true;
return pCtx->param[0].i64 == pQueryAttr->order.order; return pCtx->param[0].i64 == pQueryAttr->order.order;
} }
...@@ -8264,10 +8270,6 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { ...@@ -8264,10 +8270,6 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
goto _cleanup; goto _cleanup;
} }
/*
//MSG EXTEND DEMO
if (pQueryMsg->extend) { if (pQueryMsg->extend) {
pMsg += pQueryMsg->sqlstrLen; pMsg += pQueryMsg->sqlstrLen;
...@@ -8276,19 +8278,24 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { ...@@ -8276,19 +8278,24 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
tlv = (STLV *)pMsg; tlv = (STLV *)pMsg;
tlv->type = ntohs(tlv->type); tlv->type = ntohs(tlv->type);
tlv->len = ntohl(tlv->len); tlv->len = ntohl(tlv->len);
if (tlv->len > 0) { if (tlv->type == TLV_TYPE_END_MARK) {
*(int16_t *)tlv->value = ntohs(*(int16_t *)tlv->value); break;
qDebug("Got TLV,type:%d,len:%d,value:%d", tlv->type, tlv->len, *(int16_t*)tlv->value); }
pMsg += sizeof(*tlv) + tlv->len; switch(tlv->type) {
continue; case TLV_TYPE_META_VERSION: {
assert(tlv->len == 2*sizeof(int16_t));
param->schemaVersion = ntohs(*(int16_t*)tlv->value);
param->tagVersion = ntohs(*(int16_t*)(tlv->value + sizeof(int16_t)));
pMsg += sizeof(*tlv) + tlv->len;
break;
}
default: {
pMsg += sizeof(*tlv) + tlv->len;
break;
}
} }
break;
} }
} }
*/
qDebug("qmsg:%p query %d tables, type:%d, qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, order:%d, " qDebug("qmsg:%p query %d tables, type:%d, qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, order:%d, "
"outputCols:%d, numOfCols:%d, interval:%" PRId64 ", fillType:%d, comptsLen:%d, compNumOfBlocks:%d, limit:%" PRId64 ", offset:%" PRId64, "outputCols:%d, numOfCols:%d, interval:%" PRId64 ", fillType:%d, comptsLen:%d, compNumOfBlocks:%d, limit:%" PRId64 ", offset:%" PRId64,
......
...@@ -3585,6 +3585,10 @@ _return: ...@@ -3585,6 +3585,10 @@ _return:
int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) {
if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) {
return TSDB_CODE_SUCCESS;
}
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
......
...@@ -96,7 +96,7 @@ SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct, ...@@ -96,7 +96,7 @@ SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct,
strncpy(item.aliasName, pToken->z, pToken->n); strncpy(item.aliasName, pToken->z, pToken->n);
item.aliasName[pToken->n] = 0; item.aliasName[pToken->n] = 0;
strdequote(item.aliasName); stringProcess(item.aliasName, (int32_t)strlen(item.aliasName));
} }
taosArrayPush(pList, &item); taosArrayPush(pList, &item);
......
...@@ -115,6 +115,8 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -115,6 +115,8 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
bool isSTableQuery = false; bool isSTableQuery = false;
STableGroupInfo tableGroupInfo = {0}; STableGroupInfo tableGroupInfo = {0};
tableGroupInfo.sVersion = -1;
tableGroupInfo.tVersion = -1;
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_TABLE_QUERY)) { if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_TABLE_QUERY)) {
...@@ -160,6 +162,16 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -160,6 +162,16 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
assert(0); assert(0);
} }
int16_t queryTagVersion = param.tagVersion;
int16_t querySchemaVersion = param.schemaVersion;
if (queryTagVersion < tableGroupInfo.tVersion || querySchemaVersion < tableGroupInfo.sVersion) {
qInfo("qmsg:%p invalid schema version. client meta sversion/tversion %d/%d, table sversion/tversion %d/%d", pQueryMsg,
querySchemaVersion, queryTagVersion, tableGroupInfo.sVersion, tableGroupInfo.tVersion);
tsdbDestroyTableGroup(&tableGroupInfo);
code = TSDB_CODE_QRY_INVALID_SCHEMA_VERSION;
goto _over;
}
code = checkForQueryBuf(tableGroupInfo.numOfTables); code = checkForQueryBuf(tableGroupInfo.numOfTables);
if (code != TSDB_CODE_SUCCESS) { // not enough query buffer, abort if (code != TSDB_CODE_SUCCESS) { // not enough query buffer, abort
goto _over; goto _over;
...@@ -425,7 +437,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co ...@@ -425,7 +437,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
*contLen = *contLen - origSize + compSize; *contLen = *contLen - origSize + compSize;
*pRsp = (SRetrieveTableRsp *)rpcReallocCont(*pRsp, *contLen); *pRsp = (SRetrieveTableRsp *)rpcReallocCont(*pRsp, *contLen);
qDebug("QInfo:0x%"PRIx64" compress col data, uncompressed size:%d, compressed size:%d, ratio:%.2f", qDebug("QInfo:0x%"PRIx64" compress col data, uncompressed size:%d, compressed size:%d, ratio:%.2f",
pQInfo->qId, origSize, compSize, (float)origSize / (float)compSize); pQInfo->qId, origSize, compSize, (float)origSize / (float)compSize);
} }
(*pRsp)->compLen = htonl(compLen); (*pRsp)->compLen = htonl(compLen);
......
...@@ -3970,7 +3970,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -3970,7 +3970,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
//NOTE: not add ref count for super table //NOTE: not add ref count for super table
res = taosArrayInit(8, sizeof(STableKeyInfo)); res = taosArrayInit(8, sizeof(STableKeyInfo));
STSchema* pTagSchema = tsdbGetTableTagSchema(pTable); STSchema* pTagSchema = tsdbGetTableTagSchema(pTable);
assert(pTagSchema != NULL);
// no tags and tbname condition, all child tables of this stable are involved // no tags and tbname condition, all child tables of this stable are involved
if (pTagCond == NULL || len == 0) { if (pTagCond == NULL || len == 0) {
int32_t ret = getAllTableList(pTable, res); int32_t ret = getAllTableList(pTable, res);
...@@ -3981,7 +3981,8 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -3981,7 +3981,8 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res); pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res);
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey);
pGroupInfo->sVersion = tsdbGetTableSchema(pTable)->version;
pGroupInfo->tVersion = pTagSchema->version;
tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu", tsdb, tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu", tsdb,
pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList));
...@@ -4068,6 +4069,11 @@ int32_t tsdbGetOneTableGroup(STsdbRepo* tsdb, uint64_t uid, TSKEY startKey, STab ...@@ -4068,6 +4069,11 @@ int32_t tsdbGetOneTableGroup(STsdbRepo* tsdb, uint64_t uid, TSKEY startKey, STab
taosArrayPush(group, &info); taosArrayPush(group, &info);
taosArrayPush(pGroupInfo->pGroupList, &group); taosArrayPush(pGroupInfo->pGroupList, &group);
pGroupInfo->sVersion = tsdbGetTableSchema(pTable)->version;
if (tsdbGetTableTagSchema(pTable) != NULL) {
pGroupInfo->tVersion = tsdbGetTableTagSchema(pTable)->version;
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
_error: _error:
...@@ -4084,6 +4090,8 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl ...@@ -4084,6 +4090,8 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl
pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES); pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES);
SArray* group = taosArrayInit(1, sizeof(STableKeyInfo)); SArray* group = taosArrayInit(1, sizeof(STableKeyInfo));
int32_t sVersion = -1;
int32_t tVersion = -1;
for(int32_t i = 0; i < size; ++i) { for(int32_t i = 0; i < size; ++i) {
STableIdInfo *id = taosArrayGet(pTableIdList, i); STableIdInfo *id = taosArrayGet(pTableIdList, i);
...@@ -4105,6 +4113,19 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl ...@@ -4105,6 +4113,19 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl
STableKeyInfo info = {.pTable = pTable, .lastKey = id->key}; STableKeyInfo info = {.pTable = pTable, .lastKey = id->key};
taosArrayPush(group, &info); taosArrayPush(group, &info);
if (sVersion == -1) {
sVersion = tsdbGetTableSchema(pTable)->version;
} else {
assert (sVersion == tsdbGetTableSchema(pTable)->version);
}
assert(tsdbGetTableTagSchema(pTable) != NULL);
if (tVersion == -1) {
tVersion = tsdbGetTableTagSchema(pTable)->version;
} else {
assert (tVersion == tsdbGetTableTagSchema(pTable)->version);
}
} }
if (tsdbUnlockRepoMeta(tsdb) < 0) { if (tsdbUnlockRepoMeta(tsdb) < 0) {
...@@ -4119,6 +4140,9 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl ...@@ -4119,6 +4140,9 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl
taosArrayDestroy(&group); taosArrayDestroy(&group);
} }
pGroupInfo->sVersion = sVersion;
pGroupInfo->tVersion = tVersion;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -25,9 +25,8 @@ extern "C" { ...@@ -25,9 +25,8 @@ extern "C" {
#include "tcrc32c.h" #include "tcrc32c.h"
#include "taosdef.h" #include "taosdef.h"
int32_t strdequote(char *src); int32_t strDealWithEscape(char *z, int32_t len);
int32_t strRmquote(char *z, int32_t len); int32_t stringProcess(char *z, int32_t len);
int32_t strRmquoteEscape(char *z, int32_t len);
size_t strtrim(char *src); size_t strtrim(char *src);
char * tstrstr(char *src, char *dst, bool ignoreInEsc); char * tstrstr(char *src, char *dst, bool ignoreInEsc);
char * strnchr(char *haystack, char needle, int32_t len, bool skipquote); char * strnchr(char *haystack, char needle, int32_t len, bool skipquote);
......
...@@ -390,6 +390,7 @@ int WCSPatternMatch(const uint32_t *patterStr, const uint32_t *str, size_t size, ...@@ -390,6 +390,7 @@ int WCSPatternMatch(const uint32_t *patterStr, const uint32_t *str, size_t size,
uint32_t c, c1; uint32_t c, c1;
uint32_t matchOne = (uint32_t) L'_'; // "_" uint32_t matchOne = (uint32_t) L'_'; // "_"
uint32_t matchAll = (uint32_t) L'%'; // "%" uint32_t matchAll = (uint32_t) L'%'; // "%"
uint32_t escape = (uint32_t) L'\\'; // "\"
int32_t i = 0; int32_t i = 0;
int32_t j = 0; int32_t j = 0;
...@@ -427,6 +428,8 @@ int WCSPatternMatch(const uint32_t *patterStr, const uint32_t *str, size_t size, ...@@ -427,6 +428,8 @@ int WCSPatternMatch(const uint32_t *patterStr, const uint32_t *str, size_t size,
c1 = str[j++]; c1 = str[j++];
if (j <= size) { if (j <= size) {
if (c == escape && patterStr[i] == matchOne && c1 == matchOne) { i++; continue; }
if (c == escape && patterStr[i] == matchAll && c1 == matchAll) { i++; continue; }
if (c == c1 || towlower(c) == towlower(c1) || (c == matchOne && c1 != 0)) { if (c == c1 || towlower(c) == towlower(c1) || (c == matchOne && c1 != 0)) {
continue; continue;
} }
......
...@@ -448,6 +448,13 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) { ...@@ -448,6 +448,13 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) {
} }
case '`': { case '`': {
for (i = 1; z[i]; i++) { for (i = 1; z[i]; i++) {
// if(isprint(z[i]) == 0){
// break;
// }
// if (z[i] == '`' && z[i+1] == '`') {
// i++;
// continue;
// }
if (z[i] == '`') { if (z[i] == '`') {
i++; i++;
*tokenId = TK_ID; *tokenId = TK_ID;
......
...@@ -26,74 +26,81 @@ bool isInteger(double x){ ...@@ -26,74 +26,81 @@ bool isInteger(double x){
return (x == truncated); return (x == truncated);
} }
int32_t strdequote(char *z) { int32_t strDealWithEscape(char *z, int32_t len){
if (z == NULL) { if (z == NULL) {
return 0; return 0;
} }
int32_t quote = z[0]; int32_t j = 0;
if (quote != '\'' && quote != '"') { for (int32_t i = 0; i < len; i++) {
return (int32_t)strlen(z); if (z[i] == '\\') { // deal with escape character
} if(z[i+1] == 'n'){
z[j++] = '\n';
int32_t i = 1, j = 0; }else if(z[i+1] == 'r'){
z[j++] = '\r';
while (z[i] != 0) { }else if(z[i+1] == 't'){
if (z[i] == quote) { z[j++] = '\t';
if (z[i + 1] == quote) { }else if(z[i+1] == '\\'){
z[j++] = (char)quote; z[j++] = '\\';
i++; }else if(z[i+1] == '\''){
} else { z[j++] = '\'';
z[j++] = 0; }else if(z[i+1] == '"'){
return (j - 1); z[j++] = '"';
}else if(z[i+1] == '%'){
z[j++] = z[i];
z[j++] = z[i+1];
}else if(z[i+1] == '_'){
z[j++] = z[i];
z[j++] = z[i+1];
}else{
z[j++] = z[i+1];
} }
} else {
z[j++] = z[i]; i++;
continue;
} }
i++; z[j++] = z[i];
} }
z[j] = 0;
return j + 1; // only one quote, do nothing return j;
} }
// delete escape character: \\, \', \" /*
int32_t strRmquote(char *z, int32_t len){ * remove the quotation marks at both ends
char delim = 0; * "fsd" => fsd
int32_t cnt = 0; * "f""sd" =>f"sd
int32_t j = 0; * 'fsd' => fsd
for (size_t k = 0; k < len; ++k) { * 'f''sd' =>f'sd
if (!delim && (z[k] == '\'' || z[k] == '"')){ // find the start ' or " * `fsd => fsd
delim = z[k]; * `f``sd` =>f`sd
} */
static int32_t strdequote(char *z, int32_t n){
if ((z[k] == '\\' && z[k + 1] == '_') || (z[k] == '\\' && z[k + 1] == '%')) { if(z == NULL || n < 2) return n;
//match '_' '%' self int32_t quote = z[0];
}else if(z[k] == '\\'){ z[0] = 0;
z[j] = z[k + 1]; z[n - 1] = 0;
cnt++; int32_t i = 1, j = 0;
j++; while (i < n) {
k++; if (i < n - 1 && z[i] == quote && z[i + 1] == quote) { // two consecutive quotation marks keep one
continue; z[j++] = (char)quote;
}else if(z[k] == delim){ i += 2;
continue; } else {
z[j++] = z[i++];
} }
z[j] = z[k];
j++;
} }
z[j] = 0; z[j - 1] = 0;
return j; return j - 1;
} }
int32_t strRmquoteEscape(char *z, int32_t len) { int32_t stringProcess(char *z, int32_t len) {
if (len <= 0) return len; if (z == NULL || len < 2) return len;
if (z[0] == '\'' || z[0] == '\"') { if ((z[0] == '\'' && z[len - 1] == '\'')|| (z[0] == '"' && z[len - 1] == '"')) {
return strRmquote(z, len); int32_t n = strdequote(z, len);
} else if (len > 1 && z[0] == TS_ESCAPE_CHAR && z[len - 1] == TS_ESCAPE_CHAR) { return strDealWithEscape(z, n);
memmove(z, z + 1, len - 2); } else if (z[0] == TS_BACKQUOTE_CHAR && z[len - 1] == TS_BACKQUOTE_CHAR) {
z[len - 2] = '\0'; return strdequote(z, len);
return len - 2;
} }
return len; return len;
...@@ -192,7 +199,7 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) { ...@@ -192,7 +199,7 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) {
char *str = src, *res = NULL; char *str = src, *res = NULL;
for (int32_t i = 0; i < len; ++i) { for (int32_t i = 0; i < len; ++i) {
if (src[i] == TS_ESCAPE_CHAR || src[i] == '\'' || src[i] == '\"') { if (src[i] == TS_BACKQUOTE_CHAR || src[i] == '\'' || src[i] == '\"') {
if (!inEsc) { if (!inEsc) {
escChar = src[i]; escChar = src[i];
src[i] = 0; src[i] = 0;
......
...@@ -6,56 +6,80 @@ ...@@ -6,56 +6,80 @@
#include "taos.h" #include "taos.h"
#include "tutil.h" #include "tutil.h"
TEST(testCase, str_rmquote_test) { TEST(testCase, str_escape_test) {
char t1[] = "\"\".dd"; char t1[] = "\"\\\".dd";
int32_t len = strRmquote(t1, strlen(t1)); int32_t len = strDealWithEscape(t1, strlen(t1));
printf("t1:%s, len:%d\n", t1, len); printf("t1:%s, len:%d\n", t1, len);
EXPECT_EQ(3, len); EXPECT_EQ(5, len);
EXPECT_STRCASEEQ(t1, ".dd"); EXPECT_STRCASEEQ(t1, "\"\".dd");
char t2[] = "\"fsd\\\"fs\".dd"; char t2[] = "'\\\'.dd";
len = strRmquote(t2, strlen(t2)); len = strDealWithEscape(t2, strlen(t2));
printf("t2:%s, len:%d\n", t2, len); printf("t2:%s, len:%d\n", t2, len);
EXPECT_EQ(9, len); EXPECT_EQ(5, len);
EXPECT_STRCASEEQ(t2, "fsd\"fs.dd"); EXPECT_STRCASEEQ(t2, "''.dd");
char t3[] = "fs\\_d\\%.d\\d"; char t3[] = "\\\\.dd";
len = strRmquote(t3, strlen(t3)); len = strDealWithEscape(t3, strlen(t3));
printf("t3:%s, len:%d\n", t3, len); printf("t3:%s, len:%d\n", t3, len);
EXPECT_EQ(10, len); EXPECT_EQ(4, len);
EXPECT_STRCASEEQ(t3, "fs\\_d\\%.dd"); EXPECT_STRCASEEQ(t3, "\\.dd");
char t4[] = "\"fs\\_d\\%\".dd"; char t4[] = "'\\n.dd";
len = strRmquote(t4, strlen(t4)); len = strDealWithEscape(t4, strlen(t4));
printf("t4:%s, len:%d\n", t4, len); printf("t4:%s, len:%d\n", t4, len);
EXPECT_EQ(10, len); EXPECT_EQ(4, len);
EXPECT_STRCASEEQ(t4, "fs\\_d\\%.dd"); EXPECT_STRCASEEQ(t4, "\n.dd");
char t5[] = "\"fs\\_d\\%\""; // char t2[] = "\"fsd\\\"fs\".dd";
len = strRmquote(t5, strlen(t5)); // len = strDealWithEscape(t2, strlen(t2));
printf("t5:%s, len:%d\n", t5, len); // printf("t2:%s, len:%d\n", t2, len);
EXPECT_EQ(7, len); // EXPECT_EQ(11, len);
EXPECT_STRCASEEQ(t5, "fs\\_d\\%"); // EXPECT_STRCASEEQ(t2, "\"fsd\"fs\".dd");
//
char t6[] = "'fs\\_d\\%'"; // char t3[] = "fs\\_d\\%.d\\d";
len = strRmquote(t6, strlen(t6)); // len = strRmquote(t3, strlen(t3));
printf("t6:%s, len:%d\n", t6, len); // printf("t3:%s, len:%d\n", t3, len);
EXPECT_EQ(7, len); // EXPECT_EQ(10, len);
EXPECT_STRCASEEQ(t6, "fs\\_d\\%"); // EXPECT_STRCASEEQ(t3, "fs\\_d\\%.dd");
//
// char t4[] = "\"fs\\_d\\%\".dd";
// len = strRmquote(t4, strlen(t4));
// printf("t4:%s, len:%d\n", t4, len);
// EXPECT_EQ(10, len);
// EXPECT_STRCASEEQ(t4, "fs\\_d\\%.dd");
//
// char t5[] = "\"fs\\_d\\%\"";
// len = strRmquote(t5, strlen(t5));
// printf("t5:%s, len:%d\n", t5, len);
// EXPECT_EQ(7, len);
// EXPECT_STRCASEEQ(t5, "fs\\_d\\%");
//
// char t6[] = "'fs\\_d\\%'";
// len = strRmquote(t6, strlen(t6));
// printf("t6:%s, len:%d\n", t6, len);
// EXPECT_EQ(7, len);
// EXPECT_STRCASEEQ(t6, "fs\\_d\\%");
} }
TEST(testCase, string_dequote_test) { TEST(testCase, string_dequote_test) {
char t1[] = "'abc'"; char t1[] = "'ab''c'";
int32_t len = strdequote(t1); int32_t len = stringProcess(t1, strlen(t1));
EXPECT_EQ(3, len); EXPECT_EQ(4, len);
EXPECT_STRCASEEQ(t1, "abc"); EXPECT_STRCASEEQ(t1, "ab'c");
char t2[] = "\"ab\"\"c\"";
len = stringProcess(t2, strlen(t2));
EXPECT_EQ(4, len);
EXPECT_STRCASEEQ(t1, "ab\"c");
char t2[] = "\"abc\""; char t3[] = "`ab``c`";
len = strdequote(t2); len = stringProcess(t3, strlen(t3));
EXPECT_EQ(3, len); EXPECT_EQ(3, len);
EXPECT_STRCASEEQ(t1, "abc"); EXPECT_STRCASEEQ(t1, "ab`c");
char t21[] = " abc "; char t21[] = " abc ";
int32_t lx = strtrim(t21); int32_t lx = strtrim(t21);
......
###################################################################
# Copyright (c) 2021 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def caseDescription(self):
'''
case1: [TD-12251] json type containing single quotes cannot be inserted
case2: [TD-12334] '\' escape unknown
case3: [TD-11071] escape table creation problem
case5: [TD-12815] like wildcards (% _) are not supported nchar type
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self._conn = conn
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists escape")
tdSql.execute("create database if not exists escape")
tdSql.execute('use escape')
# [TD-12251]
tdSql.execute('create stable st (ts timestamp,t int) tags(metrics json)')
tdSql.execute(r"insert into t1 using st tags('{\"a\":\"a\",\"b\":\"\'a\'=b\"}') values(now,1)")
tdSql.query('select * from st')
tdSql.checkData(0, 2, '''{"a":"a","b":"'a'=b"}''')
# [TD-12334]
tdSql.execute('create table car (ts timestamp, s int) tags(j int)')
tdSql.execute(r'create table `zz\ ` using car tags(11)')
tdSql.execute(r'create table `zz\\ ` using car tags(11)')
tdSql.execute(r'create table `zz\\\ ` using car tags(11)')
tdSql.query(r'select tbname from car where tbname like "zz\\\\ "')
tdSql.checkRows(1)
tdSql.checkData(0, 0, r"zz\\ ")
tdSql.query(r'show tables like "zz\\\\ "')
tdSql.checkRows(1)
tdSql.checkData(0, 0, r"zz\\ ")
tdSql.query(r'show tables like "zz\\ "')
tdSql.checkRows(1)
tdSql.execute(r"insert into `zz\\ ` values(1591060658000, 1)")
tdSql.query(r'select * from `zz\\ `')
tdSql.checkRows(1)
# [TD-11071]
tdSql.execute('create table es (ts timestamp, s int) tags(j int)')
tdSql.execute(r'create table `zz\t` using es tags(11)')
tdSql.execute(r'create table `zz\\n` using es tags(11)')
tdSql.execute(r'create table `zz\r\ ` using es tags(11)')
tdSql.execute(r'create table ` ` using es tags(11)')
tdSql.query(r'select tbname from es')
tdSql.checkData(0, 0, r'zz\t')
tdSql.checkData(1, 0, r'zz\\n')
tdSql.checkData(2, 0, r'zz\r\ ')
tdSql.checkData(3, 0, r' ')
# [TD-6232]
tdSql.execute(r'create table tt(ts timestamp, `i\t` nchar(128))')
tdSql.execute(r"insert into tt values(1591060628000, '\t')")
tdSql.execute(r"insert into tt values(1591060638000, '\n')")
tdSql.execute(r"insert into tt values(1591060648000, '\r')")
tdSql.execute(r"insert into tt values(1591060658000, '\\t')")
tdSql.execute(r"insert into tt values(1591060668000, '\"')")
tdSql.execute(r"insert into tt values(1591060678000, '\'')")
tdSql.execute(r"insert into tt values(1591060688000, '\%')")
tdSql.execute(r"insert into tt values(1591060688100, '\\%')")
tdSql.execute(r"insert into tt values(1591060688200, '\\\%')")
tdSql.execute(r"insert into tt values(1591060698000, '\_')")
tdSql.execute(r"insert into tt values(1591060708000, '\9')")
tdSql.query(r"select * from tt where `i\t`='\t'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t`='\n'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t`='\r'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, '\r')
tdSql.query(r"select * from tt where `i\t`='\\t'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, r'\t')
tdSql.query(r"select * from tt where `i\t`='\"'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t`='\''")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t`='\%'")
tdSql.checkRows(2)
tdSql.checkData(0, 1, r'\%')
tdSql.query(r"select * from tt where `i\t`='\\%'")
tdSql.checkRows(2)
tdSql.checkData(0, 1, r'\%')
tdSql.query(r"select * from tt where `i\t`='\\\%'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, r'\\%')
tdSql.query(r"select * from tt where `i\t`='\_'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, r'\_')
tdSql.query(r"select * from tt where `i\t`='\9'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t`='9'")
tdSql.checkRows(1)
tdSql.execute(r'create table tb(ts timestamp, `i\t` binary(128))')
tdSql.execute(r"insert into tb values(1591060628000, '\t')")
tdSql.query(r"select * from tb where `i\t`='\t'")
tdSql.checkRows(1)
tdSql.execute(r"insert into tb values(1591060629000, '\\%')")
tdSql.query(r"select * from tb where `i\t`='\%'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, r'\%')
# [TD-12815] like wildcard(%, _) are not supported nchar
tdSql.execute(r"insert into tt values(1591070708000, 'h%d')")
tdSql.execute(r"insert into tt values(1591080708000, 'h_j')")
tdSql.execute(r"insert into tt values(1591090708000, 'h\\j')")
tdSql.query(r"select * from tt where `i\t` like 'h\%d'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\_j'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\\j'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` match 'h\\\\j'")
tdSql.checkRows(1)
# normal test
tdSql.error(r"select * from tt where i\t='\t'")
tdSql.error(r"select * from zz\t where s=1")
tdSql.error(r"select i\t from tt where `i\t`='\t'")
tdSql.execute(r'create table `\n`(ts timestamp, `i\"` nchar(128))')
tdSql.execute(r"insert into `\n` values(1591060708000, 'js')")
tdSql.query(r"select `i\"` from `\n` where `i\"`='js'")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 'js')
tdSql.query(r'show tables like "\\n"')
tdSql.checkRows(1)
tdSql.checkData(0, 0, r"\n")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2021 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def caseDescription(self):
'''
case1<shenglian zhou>: [TD-10799]mavg(col, 4-3 ) promots error
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self._conn = conn
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists td10799")
tdSql.execute("create database if not exists td10799")
tdSql.execute('use td10799')
tdSql.execute('create stable st(ts timestamp , value int ) tags (ind int)')
tdSql.execute('insert into tb1 using st tags(1) values(now ,1)')
tdSql.execute('insert into tb1 using st tags(1) values(now+1s ,2)')
tdSql.execute('insert into tb1 using st tags(1) values(now+2s ,3)')
tdSql.query('select * from st')
tdSql.checkRows(3)
tdSql.query('select mavg(value, 100) from st group by tbname')
tdSql.checkRows(0)
tdSql.error('select mavg(value, 4-3) from st group by tbname')
tdSql.execute('drop database td10799')
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
...@@ -3,3 +3,5 @@ python3 ./test.py -f 2-query/union-order.py ...@@ -3,3 +3,5 @@ python3 ./test.py -f 2-query/union-order.py
python3 ./test.py -f 2-query/session_two_stage.py python3 ./test.py -f 2-query/session_two_stage.py
python3 ./test.py -f 2-query/timeline_agg_func_groupby.py python3 ./test.py -f 2-query/timeline_agg_func_groupby.py
python3 ./test.py -f 2-query/ts_2016.py python3 ./test.py -f 2-query/ts_2016.py
python3 ./test.py -f 2-query/escape.py
python3 ./test.py -f 2-query/function_mavg.py
...@@ -154,7 +154,22 @@ class TDTestCase: ...@@ -154,7 +154,22 @@ class TDTestCase:
sql = "select last(*) from ( select sum(i1) from st where ts>='2017-07-14 11:40:00' and ts<'2017-07-14 12:40:00' interval(10m) order by ts desc );" # desc sql = "select last(*) from ( select sum(i1) from st where ts>='2017-07-14 11:40:00' and ts<'2017-07-14 12:40:00' interval(10m) order by ts desc );" # desc
tdSql.waitedQuery(sql, 1, WAITS) tdSql.waitedQuery(sql, 1, WAITS)
tdSql.checkData(0, 1, 192419100) tdSql.checkData(0, 1, 192419100)
# add parent query order by
# first
sql = "select first(*) from (select first(i1) from st interval(10m) order by ts asc) order by ts desc;"
tdSql.waitedQuery(sql, 1, WAITS)
tdSql.checkData(0, 1, 0)
sql = "select first(*) from (select first(i1) from st interval(10m) order by ts desc) order by ts asc;"
tdSql.waitedQuery(sql, 1, WAITS)
tdSql.checkData(0, 1, 0)
# last
sql = "select last(*) from (select first(i1) from st interval(10m) order by ts asc) order by ts desc;"
tdSql.waitedQuery(sql, 1, WAITS)
tdSql.checkData(0, 1, 229400)
sql = "select last(*) from (select first(i1) from st interval(10m) order by ts desc) order by ts asc;"
tdSql.waitedQuery(sql, 1, WAITS)
tdSql.checkData(0, 1, 229400)
# #
# add case with filename # add case with filename
......
...@@ -32,7 +32,7 @@ class TDTestCase: ...@@ -32,7 +32,7 @@ class TDTestCase:
tb_str = "" tb_str = ""
for tbname in tbname_list: for tbname in tbname_list:
globals()[tbname] = tdCom.getLongName(8, "letters_mixed") globals()[tbname] = tdCom.getLongName(8, "letters_mixed").upper()
tdSql.execute(f'CREATE TABLE {table_name} (ts timestamp, {table_name_sub1} tinyint, \ tdSql.execute(f'CREATE TABLE {table_name} (ts timestamp, {table_name_sub1} tinyint, \
{table_name_sub2} smallint, {table_name_sub3} int, {table_name_sub4} bigint, \ {table_name_sub2} smallint, {table_name_sub3} int, {table_name_sub4} bigint, \
{table_name_sub5} float, {table_name_sub6} double, {table_name_sub7} binary(20),\ {table_name_sub5} float, {table_name_sub6} double, {table_name_sub7} binary(20),\
...@@ -44,7 +44,7 @@ class TDTestCase: ...@@ -44,7 +44,7 @@ class TDTestCase:
for i in range(10): for i in range(10):
for tbname in tbname_list: for tbname in tbname_list:
tdSql.execute(f'insert into {globals()[tbname]} values (now, 1, 2, 3, 4, 1.1, 2.2, "{globals()[tbname]}", "{globals()[tbname]}", True)') tdSql.execute(f'insert into {globals()[tbname]} values (now-{i*i}s, 1, 2, 3, 4, 1.1, 2.2, "{globals()[tbname]}", "{globals()[tbname]}", True)')
for i in range(100): for i in range(100):
tdSql.query(f'select {table_name_sub1},{table_name_sub2},{table_name_sub3},{table_name_sub4},{table_name_sub5},{table_name_sub6},{table_name_sub7},{table_name_sub8},{table_name_sub9} from {table_name} where tbname in ("{table_name_sub1}","{table_name_sub2}","{table_name_sub3}","{table_name_sub4}","{table_name_sub5}","{table_name_sub6}","{table_name_sub7}","{table_name_sub8}","{table_name_sub9}") and ts >= "1980-01-01 00:00:00.000"') tdSql.query(f'select {table_name_sub1},{table_name_sub2},{table_name_sub3},{table_name_sub4},{table_name_sub5},{table_name_sub6},{table_name_sub7},{table_name_sub8},{table_name_sub9} from {table_name} where tbname in ("{table_name_sub1}","{table_name_sub2}","{table_name_sub3}","{table_name_sub4}","{table_name_sub5}","{table_name_sub6}","{table_name_sub7}","{table_name_sub8}","{table_name_sub9}") and ts >= "1980-01-01 00:00:00.000"')
......
...@@ -92,10 +92,10 @@ class TDTestCase: ...@@ -92,10 +92,10 @@ class TDTestCase:
tdSql.error('select * from stb_test where c0 nmatch abc') tdSql.error('select * from stb_test where c0 nmatch abc')
tdSql.query("select * from stb_1 where c0 match '\\\\'") tdSql.query(r"select * from stb_1 where c0 match '\\\\'")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.query("select * from stb_1 where c0 nmatch '\\\\'") tdSql.query(r"select * from stb_1 where c0 nmatch '\\\\'")
tdSql.checkRows(3) tdSql.checkRows(3)
#2021-10-20 for https://jira.taosdata.com:18080/browse/TD-10708 #2021-10-20 for https://jira.taosdata.com:18080/browse/TD-10708
......
...@@ -21,14 +21,16 @@ exe: ...@@ -21,14 +21,16 @@ exe:
gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS) gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS)
gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS) gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS)
gcc $(CFLAGS) ./openTSDBTest.c -o $(ROOT)openTSDBTest $(LFLAGS) gcc $(CFLAGS) ./openTSDBTest.c -o $(ROOT)openTSDBTest $(LFLAGS)
gcc $(CFLAGS) ./resultBlock.c -o $(ROOT)resultBlock $(LFLAGS)
clean: clean:
rm $(ROOT)batchprepare rm $(ROOT)batchprepare
rm $(ROOT)stmtBatchTest rm $(ROOT)stmtBatchTest
rm $(ROOT)stmtTest rm $(ROOT)stmtTest
rm $(ROOT)stmt
rm $(ROOT)stmt_function rm $(ROOT)stmt_function
rm $(ROOT)clientcfgtest rm $(ROOT)clientcfgtest
rm $(ROOT)openTSDBTest rm $(ROOT)openTSDBTest
rm $(ROOT)stmt rm $(ROOT)resultBlock
#include "taoserror.h"
#include "cJSON.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h>
#include <unistd.h>
#include <inttypes.h>
static void prepare_data(TAOS* taos) {
TAOS_RES* result;
result = taos_query(taos, "drop database if exists test;");
taos_free_result(result);
usleep(100000);
result = taos_query(taos, "create database test precision 'ms';");
taos_free_result(result);
usleep(100000);
taos_select_db(taos, "test");
result = taos_query(taos, "create table meters(ts timestamp, c0 tinyint, c1 smallint, c2 int, c3 bigint, c4 float, c5 double, c6 bool, c7 binary(10), c8 nchar(10)) tags (t0 int, t1 float, t2 double, t3 bool, t4 binary(10), t5 nchar(10));");
taos_free_result(result);
result = taos_query(taos, "create table tb0 using meters tags(0, 0.0, 0.0, true, \"tag0\", \"标签0\");");
taos_free_result(result);
result = taos_query(taos, "create table tb1 using meters tags(1, 1.0, 1.0, true, \"tag1\", \"标签1\");");
taos_free_result(result);
result = taos_query(taos, "create table tb2 using meters tags(2, 2.0, 2.0, true, \"tag2\", \"标签2\");");
taos_free_result(result);
result = taos_query(taos, "create table tb3 using meters tags(3, 3.0, 3.0, true, \"tag3\", \"标签3\");");
taos_free_result(result);
result = taos_query(taos, "create table tb4 using meters tags(4, 4.0, 4.0, true, \"tag4\", \"标签4\");");
taos_free_result(result);
result = taos_query(taos, "create table tb5 using meters tags(5, 5.0, 5.0, true, \"tag5\", \"标签5\");");
taos_free_result(result);
result = taos_query(taos, "create table tb6 using meters tags(6, 6.0, 6.0, true, \"tag6\", \"标签6\");");
taos_free_result(result);
result = taos_query(taos, "create table tb7 using meters tags(7, 7.0, 7.0, true, \"tag7\", \"标签7\");");
taos_free_result(result);
result = taos_query(taos, "create table tb8 using meters tags(8, 8.0, 8.0, true, \"tag8\", \"标签8\");");
taos_free_result(result);
result = taos_query(taos, "create table tb9 using meters tags(9, 9.0, 9.0, true, \"tag9\", \"标签9\");");
taos_free_result(result);
result = taos_query(taos,
"insert into tb0 values('2020-01-01 00:00:00.000', 11, 11, 11, 11, 11.0, 11.0, false, \"col11\", \"值11\")"
" ('2020-01-01 00:01:00.000', 12, 12, 12, 12, 12.0, 12.0, false, \"col12\", \"值12\")"
" ('2020-01-01 00:02:00.000', 13, 13, 13, 13, 13.0, 13.0, false, \"col13\", \"值13\")"
" tb1 values('2020-01-01 00:00:00.000', 21, 21, 21, 21, 21.0, 21.0, false, \"col21\", \"值21\")"
" tb2 values('2020-01-01 00:00:00.000', 31, 31, 31, 31, 31.0, 31.0, false, \"col31\", \"值31\")"
" tb3 values('2020-01-01 00:01:02.000', 41, 41, 41, 41, 41.0, 41.0, false, \"col41\", \"值41\")"
" tb4 values('2020-01-01 00:01:02.000', 51, 51, 51, 51, 51.0, 51.0, false, \"col51\", \"值51\")"
" tb5 values('2020-01-01 00:01:02.000', 61, 61, 61, 61, 61.0, 61.0, false, \"col61\", \"值61\")"
" tb6 values('2020-01-01 00:01:02.000', 71, 71, 71, 71, 71.0, 71.0, false, \"col71\", \"值71\")"
" tb7 values('2020-01-01 00:01:02.000', 81, 81, 81, 81, 81.0, 81.0, false, \"col81\", \"值81\")"
" tb8 values('2020-01-01 00:01:02.000', 91, 91, 91, 91, 91.0, 91.0, false, \"col91\", \"值91\")"
" tb9 values('2020-01-01 00:01:02.000', 101, 101, 101, 101, 101.0, 101.0, false, \"col101\", \"值101\")");
int affected = taos_affected_rows(result);
if (affected != 12) {
printf("\033[31m%d rows affected by last insert statement, but it should be 12\033[0m\n", affected);
}
taos_free_result(result);
// super tables subscription
usleep(1000000);
}
static int print_result(TAOS_RES* res, int32_t rows) {
TAOS_ROW* block_ptr = NULL;
int num_fields = taos_num_fields(res);
TAOS_FIELD* fields = taos_fetch_fields(res);
block_ptr = taos_result_block(res);
TAOS_ROW col = *block_ptr;
for (int k = 0; k < rows; k++) {
char str[256] = {0};
int32_t len = 0;
for (int i = 0; i < num_fields; ++i) {
if (i > 0) {
str[len++] = ' ';
}
switch (fields[i].type) {
case TSDB_DATA_TYPE_TINYINT:
len += sprintf(str + len, "%d", *(((int8_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_UTINYINT:
len += sprintf(str + len, "%u", *(((uint8_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_SMALLINT:
len += sprintf(str + len, "%d", *(((int16_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_USMALLINT:
len += sprintf(str + len, "%u", *(((uint16_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_INT:
len += sprintf(str + len, "%d", *(((int32_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_UINT:
len += sprintf(str + len, "%u", *(((uint32_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_BIGINT:
len += sprintf(str + len, "%" PRId64, *(((int64_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_UBIGINT:
len += sprintf(str + len, "%" PRIu64, *(((uint64_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_FLOAT: {
len += sprintf(str + len, "%f", *(((float *)col[i]) + k));
} break;
case TSDB_DATA_TYPE_DOUBLE: {
len += sprintf(str + len, "%lf", *(((double *)col[i]) + k));
} break;
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: {
int32_t charLen = *(int16_t *)col[i];
int32_t charBytes = (fields[i].type == TSDB_DATA_TYPE_BINARY) ? sizeof(char) : sizeof(wchar_t);
int32_t offset = k * (sizeof(int16_t) + fields[i].bytes * charBytes);
memcpy(str + len, (char *)col[i] + sizeof(int16_t) + offset, charLen);
len += charLen;
} break;
case TSDB_DATA_TYPE_TIMESTAMP:
len += sprintf(str + len, "%" PRId64, *(((int64_t *)col[i]) + k));
break;
case TSDB_DATA_TYPE_BOOL:
len += sprintf(str + len, "%d", *(((int8_t *)col[i]) + k));
default:
break;
}
}
puts(str);
}
}
void fetch_cb(void *param, TAOS_RES* tres, int32_t numOfRows) {
if (tres == NULL) {
printf("result not available!\n");
return;
}
if (numOfRows > 0) {
printf("%d rows async retrieved\n", numOfRows);
print_result(tres, numOfRows);
taos_fetch_rows_a(tres, fetch_cb, param);
} else {
if (numOfRows < 0) {
printf("\033[31masync retrieve failed, code: %d\033[0m\n", numOfRows);
} else {
printf("async retrieve completed\n");
}
taos_free_result(tres);
}
}
void query_cb(void* param, TAOS_RES* tres, int32_t code) {
if (code == 0 && tres) {
taos_fetch_rows_a(tres, fetch_cb, param);
} else {
printf("\033[31masync query failed, code: %d\033[0m\n", code);
}
}
int main(int argc, char *argv[]) {
const char* host = "127.0.0.1";
const char* user = "root";
const char* passwd = "taosdata";
taos_options(TSDB_OPTION_TIMEZONE, "GMT-8");
TAOS* taos = taos_connect(host, user, passwd, "", 0);
if (taos == NULL) {
printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos));
exit(1);
}
char* info = taos_get_server_info(taos);
printf("server info: %s\n", info);
info = taos_get_client_info(taos);
printf("client info: %s\n", info);
printf("************ Prepare data *************\n");
prepare_data(taos);
printf("************ Async query *************\n");
taos_query_a(taos, "select * from meters", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb0", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb1", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb2", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb3", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb4", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb5", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb6", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb7", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb8", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select * from tb9", query_cb, NULL);
usleep(1000000);
taos_query_a(taos, "select count(*) from meters", query_cb, NULL);
usleep(1000000);
printf("done\n");
taos_close(taos);
taos_cleanup();
}
...@@ -28,7 +28,7 @@ import taos ...@@ -28,7 +28,7 @@ import taos
if __name__ == "__main__": if __name__ == "__main__":
fileName = "all" fileName = "all"
deployPath = "" deployPath = ""
masterIp = "" masterIp = ""
...@@ -55,7 +55,7 @@ if __name__ == "__main__": ...@@ -55,7 +55,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-w taos on windows') tdLog.printNoPrefix('-w taos on windows')
sys.exit(0) sys.exit(0)
if key in ['-r', '--restart']: if key in ['-r', '--restart']:
restart = True restart = True
if key in ['-f', '--file']: if key in ['-f', '--file']:
...@@ -117,7 +117,7 @@ if __name__ == "__main__": ...@@ -117,7 +117,7 @@ if __name__ == "__main__":
time.sleep(2) time.sleep(2)
tdLog.info('stop All dnodes') tdLog.info('stop All dnodes')
if masterIp == "": if masterIp == "":
host = '127.0.0.1' host = '127.0.0.1'
else: else:
...@@ -129,11 +129,11 @@ if __name__ == "__main__": ...@@ -129,11 +129,11 @@ if __name__ == "__main__":
tdLog.info("Procedures for testing self-deployment") tdLog.info("Procedures for testing self-deployment")
td_clinet = TDSimClient("C:\\TDengine") td_clinet = TDSimClient("C:\\TDengine")
td_clinet.deploy() td_clinet.deploy()
remote_conn = Connection("root@%s"%host) remote_conn = Connection("root@%s" % host)
with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'): with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'):
remote_conn.run("python3 ./test.py") remote_conn.run("python3 ./test.py")
conn = taos.connect( conn = taos.connect(
host="%s"%(host), host="%s" % (host),
config=td_clinet.cfgDir) config=td_clinet.cfgDir)
tdCases.runOneWindows(conn, fileName) tdCases.runOneWindows(conn, fileName)
else: else:
...@@ -146,23 +146,21 @@ if __name__ == "__main__": ...@@ -146,23 +146,21 @@ if __name__ == "__main__":
try: try:
if key_word in open(fileName).read(): if key_word in open(fileName).read():
is_test_framework = 1 is_test_framework = 1
except: except BaseException:
pass pass
if is_test_framework: if is_test_framework:
moduleName = fileName.replace(".py", "").replace("/", ".") moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName) uModule = importlib.import_module(moduleName)
try: try:
ucase = uModule.TDTestCase() ucase = uModule.TDTestCase()
tdDnodes.deploy(1,ucase.updatecfgDict) tdDnodes.deploy(1, ucase.updatecfgDict)
except : except BaseException:
tdDnodes.deploy(1,{}) tdDnodes.deploy(1, {})
else: else:
pass pass
tdDnodes.deploy(1,{}) tdDnodes.deploy(1, {})
tdDnodes.start(1) tdDnodes.start(1)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if testCluster: if testCluster:
...@@ -179,18 +177,20 @@ if __name__ == "__main__": ...@@ -179,18 +177,20 @@ if __name__ == "__main__":
if fileName == "all": if fileName == "all":
tdCases.runAllLinux(conn) tdCases.runAllLinux(conn)
else: else:
tdCases.runOneWindows(conn, fileName) tdCases.runOneLinux(conn, fileName)
if restart: if restart:
if fileName == "all": if fileName == "all":
tdLog.info("not need to query ") tdLog.info("not need to query ")
else: else:
sp = fileName.rsplit(".", 1) sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py": if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll() tdDnodes.stopAll()
tdDnodes.start(1) tdDnodes.start(1)
time.sleep(1) time.sleep(1)
conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) conn = taos.connect(host, config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info(
"Procedures for tdengine deployed in %s" %
(host))
tdLog.info("query test after taosd restart") tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py")
else: else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册