Adjust code structure
This commit is contained in:
parent
20d340f520
commit
c2e91fcb75
|
@ -23,5 +23,14 @@ tests/script/
|
|||
tests/pytest/
|
||||
tests/jenkins/
|
||||
tests/hdfs/
|
||||
|
||||
*.iml
|
||||
*.class
|
||||
nmake/
|
||||
sln/
|
||||
hdfs/
|
||||
c/
|
||||
taoshebei/
|
||||
taosdalipu/
|
||||
Target/
|
||||
*.failed
|
||||
*.sql
|
294
CMakeLists.txt
294
CMakeLists.txt
|
@ -3,171 +3,193 @@ PROJECT(TDengine)
|
|||
|
||||
SET(CMAKE_C_STANDARD 11)
|
||||
SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
SET(TD_ROOT_DIR ${PROJECT_SOURCE_DIR})
|
||||
|
||||
#
|
||||
# If it is a Linux operating system
|
||||
# If need to set debug options
|
||||
# 1.Generate debug version:
|
||||
# mkdir debug; cd debug;
|
||||
# mkdir debug; cd debug;
|
||||
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
# 2.Generate release version:
|
||||
# mkdir release; cd release;
|
||||
# cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
# mkdir release; cd release;
|
||||
# cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
#
|
||||
|
||||
#
|
||||
# If it is a Windows operating system
|
||||
# 1.Use command line tool of VS2013 or higher version
|
||||
# mkdir build; cd build;
|
||||
# cmake -G "NMake Makefiles" ..
|
||||
# nmake install
|
||||
# 2.Use the VS development interface tool
|
||||
# 2.Use the VS development interface tool
|
||||
# mkdir build; cd build;
|
||||
# cmake -A x64 ..
|
||||
# open the file named TDengine.sln
|
||||
#
|
||||
|
||||
# Set macro definitions according to os platform
|
||||
SET(TD_WINDOWS FALSE)
|
||||
SET(TD_LINUX FALSE)
|
||||
SET(TD_ARM FALSE)
|
||||
SET(TD_DARWIN FALSE)
|
||||
IF (NOT DEFINED TD_CLUSTER)
|
||||
MESSAGE(STATUS "Build the Lite Version")
|
||||
SET(TD_CLUSTER FALSE)
|
||||
SET(TD_LITE TRUE)
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
||||
SET(TD_OS_DIR ${PROJECT_SOURCE_DIR}/src/os/linux)
|
||||
SET(TD_LINUX TRUE)
|
||||
ADD_DEFINITIONS(-DLINUX)
|
||||
SET(TD_COMMUNITY_DIR ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Community directory: " ${TD_COMMUNITY_DIR})
|
||||
|
||||
IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ELSE ()
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-O0")
|
||||
|
||||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
MESSAGE(STATUS "The current platform is Linux 64-bit")
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Linux 32-bit, not supported yet")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
|
||||
SET(TD_OS_DIR ${PROJECT_SOURCE_DIR}/src/os/windows)
|
||||
SET(TD_WINDOWS TRUE)
|
||||
ADD_DEFINITIONS(-DWINDOWS)
|
||||
ADD_DEFINITIONS(-D__CLEANUP_C)
|
||||
ADD_DEFINITIONS(-DPTW32_STATIC_LIB)
|
||||
ADD_DEFINITIONS(-DPTW32_BUILD)
|
||||
|
||||
SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
||||
SET(DEBUG_FLAGS "/Zi /W3 /GL")
|
||||
SET(RELEASE_FLAGS "/W0 /GL")
|
||||
|
||||
ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
MESSAGE(STATUS "The current platform is Windows 64-bit")
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Windows 32-bit, not supported yet")
|
||||
|
||||
# Set macro definitions according to os platform
|
||||
SET(TD_LINUX_64 FALSE)
|
||||
SET(TD_LINUX_32 FALSE)
|
||||
SET(TD_ARM_64 FALSE)
|
||||
SET(TD_ARM_32 FALSE)
|
||||
SET(TD_MIPS_64 FALSE)
|
||||
SET(TD_DARWIN_64 FALSE)
|
||||
SET(TD_WINDOWS_64 FALSE)
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_LINUX_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
MESSAGE(STATUS "The current platform is Linux 64-bit")
|
||||
ELSE ()
|
||||
SET(TD_LINUX_32 TRUE)
|
||||
MESSAGE(FATAL_ERROR "The current platform is Linux 32-bit, not supported yet")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_DARWIN_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/darwin)
|
||||
MESSAGE(STATUS "The current platform is Darwin 64-bit")
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Darwin 32-bit, not supported yet")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_WINDOWS_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/windows)
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
MESSAGE(STATUS "The current platform is Windows 64-bit")
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Windows 32-bit, not supported yet")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "The current platform is not Linux/Darwin/Windows, stop compile")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
|
||||
SET(TD_OS_DIR ${PROJECT_SOURCE_DIR}/src/os/darwin)
|
||||
SET(TD_DARWIN TRUE)
|
||||
ADD_DEFINITIONS(-DDARWIN)
|
||||
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-unused-variable -Wno-bitfield-constant-conversion")
|
||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-O0")
|
||||
|
||||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
MESSAGE(STATUS "The current platform is Darwin 64-bit")
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
FIND_PROGRAM(TD_MVN_INSTALLED mvn)
|
||||
IF (TD_MVN_INSTALLED)
|
||||
MESSAGE(STATUS "MVN is installed and JDBC will be compiled")
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Darwin 32-bit, not supported yet")
|
||||
MESSAGE(STATUS "MVN is not installed and JDBC is not compiled")
|
||||
ENDIF ()
|
||||
|
||||
#
|
||||
# debug flag
|
||||
#
|
||||
# ADD_DEFINITIONS(-D_CHECK_HEADER_FILE_)
|
||||
# ADD_DEFINITIONS(-D_TAOS_MEM_TEST_)
|
||||
|
||||
IF (TD_CLUSTER)
|
||||
ADD_DEFINITIONS(-DCLUSTER)
|
||||
ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=3)
|
||||
ELSE ()
|
||||
ADD_DEFINITIONS(-DLITE)
|
||||
ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=1)
|
||||
ENDIF ()
|
||||
IF (TD_LINUX_64)
|
||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-O0")
|
||||
IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ELSE ()
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
ENDIF ()
|
||||
ADD_DEFINITIONS(-DLINUX)
|
||||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
|
||||
SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
||||
SET(DEBUG_FLAGS "/Zi /W3 /GL")
|
||||
SET(RELEASE_FLAGS "/W0 /GL")
|
||||
ADD_DEFINITIONS(-DWINDOWS)
|
||||
ADD_DEFINITIONS(-D__CLEANUP_C)
|
||||
ADD_DEFINITIONS(-DPTW32_STATIC_LIB)
|
||||
ADD_DEFINITIONS(-DPTW32_BUILD)
|
||||
ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-unused-variable -Wno-bitfield-constant-conversion")
|
||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-O0")
|
||||
ADD_DEFINITIONS(-DDARWIN)
|
||||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is not support yet, stop compile")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is not Linux/MAC/Windows, stop compile")
|
||||
EXIT ()
|
||||
|
||||
ENDIF ()
|
||||
# Set compiler options
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}")
|
||||
|
||||
# Set compiler options
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}")
|
||||
# Set c++ compiler options
|
||||
# SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
|
||||
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${DEBUG_FLAGS}")
|
||||
# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
|
||||
|
||||
# Set c++ compiler options
|
||||
# SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
|
||||
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${DEBUG_FLAGS}")
|
||||
# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
|
||||
|
||||
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
|
||||
MESSAGE(STATUS "Build Debug Version")
|
||||
ELSEIF (${CMAKE_BUILD_TYPE} MATCHES "Release")
|
||||
MESSAGE(STATUS "Build Release Version")
|
||||
ELSE ()
|
||||
IF (TD_WINDOWS)
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
MESSAGE(STATUS "Build Release Version")
|
||||
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
|
||||
MESSAGE(STATUS "Build Debug Version")
|
||||
ELSEIF (${CMAKE_BUILD_TYPE} MATCHES "Release")
|
||||
MESSAGE(STATUS "Build Release Version")
|
||||
ELSE ()
|
||||
SET(CMAKE_BUILD_TYPE "Debug")
|
||||
MESSAGE(STATUS "Build Debug Version")
|
||||
ENDIF()
|
||||
IF (TD_WINDOWS_64)
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
MESSAGE(STATUS "Build Release Version in Windows as default")
|
||||
ELSE ()
|
||||
SET(CMAKE_BUILD_TYPE "Debug")
|
||||
MESSAGE(STATUS "Build Debug Version as default")
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
MESSAGE(STATUS "Operating system dependency directory: " ${TD_OS_DIR})
|
||||
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
|
||||
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
|
||||
|
||||
IF (TD_LINUX_64)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
|
||||
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})")
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
SET(CMAKE_INSTALL_PREFIX C:/TDengine)
|
||||
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/go DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/grafana DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/python DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/tests/examples DESTINATION .)
|
||||
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/packaging/cfg DESTINATION .)
|
||||
INSTALL(FILES ${TD_COMMUNITY_DIR}/src/inc/taos.h DESTINATION include)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
|
||||
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .)
|
||||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||
IF (TD_MVN_INSTALLED)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-1.0.2-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
FIND_PROGRAM(TD_MVN_INSTALLED mvn)
|
||||
IF (TD_MVN_INSTALLED)
|
||||
MESSAGE(STATUS "MVN is installed and JDBC will be compiled")
|
||||
ELSE ()
|
||||
MESSAGE(STATUS "MVN is not installed and JDBC is not compiled")
|
||||
ENDIF ()
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
MESSAGE(STATUS "Operating system dependency directory: " ${TD_OS_DIR})
|
||||
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
|
||||
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
|
||||
|
||||
ADD_SUBDIRECTORY(deps)
|
||||
ADD_SUBDIRECTORY(src)
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
||||
IF (TD_LINUX)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_ROOT_DIR}/packaging/tools/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
|
||||
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_ROOT_DIR} ${PROJECT_BINARY_DIR})")
|
||||
ELSEIF (TD_WINDOWS)
|
||||
SET(CMAKE_INSTALL_PREFIX C:/TDengine)
|
||||
INSTALL(DIRECTORY ${TD_ROOT_DIR}/src/connector/go DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_ROOT_DIR}/src/connector/grafana DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_ROOT_DIR}/src/connector/python DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_ROOT_DIR}/tests/examples DESTINATION .)
|
||||
INSTALL(DIRECTORY ${TD_ROOT_DIR}/packaging/cfg DESTINATION .)
|
||||
INSTALL(FILES ${TD_ROOT_DIR}/src/inc/taos.h DESTINATION include)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
|
||||
INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||
INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||
IF (TD_MVN_INSTALLED)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-1.0.2-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
INCLUDE(CPack)
|
||||
INCLUDE(CPack)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(zlib-1.2.11)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
IF (TD_WINDOWS_64)
|
||||
LIST(APPEND SRC iconv.c)
|
||||
LIST(APPEND SRC localcharset.c)
|
||||
INCLUDE_DIRECTORIES(.)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
LIST(APPEND SRC pthread.c)
|
||||
IF (TD_WINDOWS_64)
|
||||
INCLUDE_DIRECTORIES(.)
|
||||
LIST(APPEND SRC pthread.c)
|
||||
ADD_LIBRARY(pthread ${SRC})
|
||||
ENDIF ()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
LIST(APPEND SRC regex.c)
|
||||
IF (TD_WINDOWS_64)
|
||||
INCLUDE_DIRECTORIES(inc .)
|
||||
LIST(APPEND SRC regex.c)
|
||||
ADD_LIBRARY(regex ${SRC})
|
||||
ENDIF ()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
IF (TD_LINUX_64)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(z ${SRC})
|
||||
ENDIF ()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
//#include <stdint.h>
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
|
@ -238,16 +238,16 @@
|
|||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
typedef unsigned long z_size_t;
|
||||
typedef uint64_t z_size_t;
|
||||
#else
|
||||
# define z_longlong long long
|
||||
# define z_longlong int64_t
|
||||
# if defined(NO_SIZE_T)
|
||||
typedef unsigned NO_SIZE_T z_size_t;
|
||||
# elif defined(STDC)
|
||||
# include <stddef.h>
|
||||
typedef size_t z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
typedef uint64_t z_size_t;
|
||||
# endif
|
||||
# undef z_longlong
|
||||
#endif
|
||||
|
@ -391,7 +391,7 @@
|
|||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
typedef uint64_t uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
|
@ -419,7 +419,7 @@ typedef uLong FAR uLongf;
|
|||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# define Z_U4 uint64_t
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
|
@ -428,7 +428,7 @@ typedef uLong FAR uLongf;
|
|||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
typedef uint64_t z_crc_t;
|
||||
#endif
|
||||
|
||||
#if 1 /* was set to #if 1 by ./configure */
|
||||
|
@ -501,7 +501,7 @@ typedef uLong FAR uLongf;
|
|||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
# define z_off_t int64_t
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
|
|
|
@ -999,7 +999,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
|||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
|
||||
ZEXTERN int64_t ZEXPORT inflateMark OF((z_streamp strm));
|
||||
/*
|
||||
This function returns two values, one in the lower 16 bits of the return
|
||||
value, and the other in the remaining upper bits, obtained by shifting the
|
||||
|
@ -1890,7 +1890,7 @@ ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
|
|||
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
|
||||
ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
|
||||
ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp));
|
||||
ZEXTERN uint64_t ZEXPORT inflateCodesUsed OF ((z_streamp));
|
||||
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
|
||||
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
|
||||
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
|
||||
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
||||
|
@ -26,7 +26,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
|||
(thank you to John Reiser for pointing this out) */
|
||||
# define CHOP(a) \
|
||||
do { \
|
||||
unsigned long tmp = a >> 16; \
|
||||
uint64_t tmp = a >> 16; \
|
||||
a &= 0xffffUL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
} while (0)
|
||||
|
@ -65,7 +65,7 @@ uLong ZEXPORT adler32_z(adler, buf, len)
|
|||
const Bytef *buf;
|
||||
z_size_t len;
|
||||
{
|
||||
unsigned long sum2;
|
||||
uint64_t sum2;
|
||||
unsigned n;
|
||||
|
||||
/* split Adler-32 into component sums */
|
||||
|
@ -145,8 +145,8 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
uint64_t sum1;
|
||||
uint64_t sum2;
|
||||
unsigned rem;
|
||||
|
||||
/* for negative len, return invalid adler32 as a clue for debugging */
|
||||
|
@ -163,7 +163,7 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
|
||||
if (sum2 >= ((uint64_t)BASE << 1)) sum2 -= ((uint64_t)BASE << 1);
|
||||
if (sum2 >= BASE) sum2 -= BASE;
|
||||
return sum1 | (sum2 << 16);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdint.h>
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef MAKECRCH
|
||||
# include <stdio.h>
|
||||
# ifndef DYNAMIC_CRC_TABLE
|
||||
|
@ -35,9 +35,9 @@
|
|||
# define BYFOUR
|
||||
#endif
|
||||
#ifdef BYFOUR
|
||||
local unsigned long crc32_little OF((unsigned long,
|
||||
local uint64_t crc32_little OF((uint64_t,
|
||||
const unsigned char FAR *, z_size_t));
|
||||
local unsigned long crc32_big OF((unsigned long,
|
||||
local uint64_t crc32_big OF((uint64_t,
|
||||
const unsigned char FAR *, z_size_t));
|
||||
# define TBLS 8
|
||||
#else
|
||||
|
@ -45,9 +45,9 @@
|
|||
#endif /* BYFOUR */
|
||||
|
||||
/* Local functions for crc concatenation */
|
||||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||
unsigned long vec));
|
||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||
local uint64_t gf2_matrix_times OF((uint64_t *mat,
|
||||
uint64_t vec));
|
||||
local void gf2_matrix_square OF((uint64_t *square, uint64_t *mat));
|
||||
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
|
||||
|
||||
|
||||
|
@ -170,7 +170,7 @@ local void write_table(out, table)
|
|||
|
||||
for (n = 0; n < 256; n++)
|
||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
||||
(unsigned long)(table[n]),
|
||||
(uint64_t)(table[n]),
|
||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||
}
|
||||
#endif /* MAKECRCH */
|
||||
|
@ -199,8 +199,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
|
|||
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
||||
|
||||
/* ========================================================================= */
|
||||
unsigned long ZEXPORT crc32_z(crc, buf, len)
|
||||
unsigned long crc;
|
||||
uint64_t ZEXPORT crc32_z(crc, buf, len)
|
||||
uint64_t crc;
|
||||
const unsigned char FAR *buf;
|
||||
z_size_t len;
|
||||
{
|
||||
|
@ -234,8 +234,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
|
|||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
unsigned long ZEXPORT crc32(crc, buf, len)
|
||||
unsigned long crc;
|
||||
uint64_t ZEXPORT crc32(crc, buf, len)
|
||||
uint64_t crc;
|
||||
const unsigned char FAR *buf;
|
||||
uInt len;
|
||||
{
|
||||
|
@ -263,8 +263,8 @@ unsigned long ZEXPORT crc32(crc, buf, len)
|
|||
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_little(crc, buf, len)
|
||||
unsigned long crc;
|
||||
local uint64_t crc32_little(crc, buf, len)
|
||||
uint64_t crc;
|
||||
const unsigned char FAR *buf;
|
||||
z_size_t len;
|
||||
{
|
||||
|
@ -293,7 +293,7 @@ local unsigned long crc32_little(crc, buf, len)
|
|||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)c;
|
||||
return (uint64_t)c;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
@ -303,8 +303,8 @@ local unsigned long crc32_little(crc, buf, len)
|
|||
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long crc32_big(crc, buf, len)
|
||||
unsigned long crc;
|
||||
local uint64_t crc32_big(crc, buf, len)
|
||||
uint64_t crc;
|
||||
const unsigned char FAR *buf;
|
||||
z_size_t len;
|
||||
{
|
||||
|
@ -333,7 +333,7 @@ local unsigned long crc32_big(crc, buf, len)
|
|||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||
} while (--len);
|
||||
c = ~c;
|
||||
return (unsigned long)(ZSWAP32(c));
|
||||
return (uint64_t)(ZSWAP32(c));
|
||||
}
|
||||
|
||||
#endif /* BYFOUR */
|
||||
|
@ -341,11 +341,11 @@ local unsigned long crc32_big(crc, buf, len)
|
|||
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
|
||||
|
||||
/* ========================================================================= */
|
||||
local unsigned long gf2_matrix_times(mat, vec)
|
||||
unsigned long *mat;
|
||||
unsigned long vec;
|
||||
local uint64_t gf2_matrix_times(mat, vec)
|
||||
uint64_t *mat;
|
||||
uint64_t vec;
|
||||
{
|
||||
unsigned long sum;
|
||||
uint64_t sum;
|
||||
|
||||
sum = 0;
|
||||
while (vec) {
|
||||
|
@ -359,8 +359,8 @@ local unsigned long gf2_matrix_times(mat, vec)
|
|||
|
||||
/* ========================================================================= */
|
||||
local void gf2_matrix_square(square, mat)
|
||||
unsigned long *square;
|
||||
unsigned long *mat;
|
||||
uint64_t *square;
|
||||
uint64_t *mat;
|
||||
{
|
||||
int n;
|
||||
|
||||
|
@ -375,9 +375,9 @@ local uLong crc32_combine_(crc1, crc2, len2)
|
|||
z_off64_t len2;
|
||||
{
|
||||
int n;
|
||||
unsigned long row;
|
||||
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||
uint64_t row;
|
||||
uint64_t even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||
uint64_t odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||
|
||||
/* degenerate case (also disallow negative lengths) */
|
||||
if (len2 <= 0)
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "deflate.h"
|
||||
|
||||
const char deflate_copyright[] =
|
||||
|
@ -430,7 +430,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
|||
fill_window(s);
|
||||
}
|
||||
s->strstart += s->lookahead;
|
||||
s->block_start = (long)s->strstart;
|
||||
s->block_start = (int64_t)s->strstart;
|
||||
s->insert = s->lookahead;
|
||||
s->lookahead = 0;
|
||||
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||
|
@ -1512,7 +1512,7 @@ local void fill_window(s)
|
|||
zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
|
||||
s->match_start -= wsize;
|
||||
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
|
||||
s->block_start -= (long) wsize;
|
||||
s->block_start -= (int64_t) wsize;
|
||||
slide_hash(s);
|
||||
more += wsize;
|
||||
}
|
||||
|
@ -1606,7 +1606,7 @@ local void fill_window(s)
|
|||
_tr_flush_block(s, (s->block_start >= 0L ? \
|
||||
(charf *)&s->window[(unsigned)s->block_start] : \
|
||||
(charf *)Z_NULL), \
|
||||
(ulg)((long)s->strstart - s->block_start), \
|
||||
(ulg)((int64_t)s->strstart - s->block_start), \
|
||||
(last)); \
|
||||
s->block_start = s->strstart; \
|
||||
flush_pending(s->strm); \
|
||||
|
@ -1766,12 +1766,12 @@ local block_state deflate_stored(s, flush)
|
|||
|
||||
/* If flushing and all input has been consumed, then done. */
|
||||
if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
|
||||
s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
|
||||
s->strm->avail_in == 0 && (int64_t)s->strstart == s->block_start)
|
||||
return block_done;
|
||||
|
||||
/* Fill the window with any remaining input. */
|
||||
have = s->window_size - s->strstart - 1;
|
||||
if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
|
||||
if (s->strm->avail_in > have && s->block_start >= (int64_t)s->w_size) {
|
||||
/* Slide the window down. */
|
||||
s->block_start -= s->w_size;
|
||||
s->strstart -= s->w_size;
|
||||
|
|
|
@ -151,7 +151,7 @@ typedef struct internal_state {
|
|||
* hash_shift * MIN_MATCH >= hash_bits
|
||||
*/
|
||||
|
||||
long block_start;
|
||||
int64_t block_start;
|
||||
/* Window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
with inffast.c is retained so that optimized assembler-coded versions of
|
||||
inflate_fast() can be used with either inflate.c or infback.c.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
|
@ -173,7 +173,7 @@ struct inflate_state FAR *state;
|
|||
do { \
|
||||
PULL(); \
|
||||
have--; \
|
||||
hold += (unsigned long)(*next++) << bits; \
|
||||
hold += (uint64_t)(*next++) << bits; \
|
||||
bits += 8; \
|
||||
} while (0)
|
||||
|
||||
|
@ -258,7 +258,7 @@ void FAR *out_desc;
|
|||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
uint64_t hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 1995-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
|
@ -64,7 +64,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||
unsigned long hold; /* local strm->hold */
|
||||
uint64_t hold; /* local strm->hold */
|
||||
unsigned bits; /* local strm->bits */
|
||||
code const FAR *lcode; /* local strm->lencode */
|
||||
code const FAR *dcode; /* local strm->distcode */
|
||||
|
@ -102,9 +102,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||
input data or output space */
|
||||
do {
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
here = lcode[hold & lmask];
|
||||
|
@ -124,7 +124,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
len += (unsigned)hold & ((1U << op) - 1);
|
||||
|
@ -133,9 +133,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", len));
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
here = dcode[hold & dmask];
|
||||
|
@ -148,10 +148,10 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||
dist = (unsigned)(here.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
hold += (uint64_t)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
*
|
||||
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
|
@ -507,7 +507,7 @@ unsigned copy;
|
|||
do { \
|
||||
if (have == 0) goto inf_leave; \
|
||||
have--; \
|
||||
hold += (unsigned long)(*next++) << bits; \
|
||||
hold += (uint64_t)(*next++) << bits; \
|
||||
bits += 8; \
|
||||
} while (0)
|
||||
|
||||
|
@ -627,7 +627,7 @@ int flush;
|
|||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
uint64_t hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned in, out; /* save starting available input and output */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
|
@ -1317,7 +1317,7 @@ const Bytef *dictionary;
|
|||
uInt dictLength;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned long dictid;
|
||||
uint64_t dictid;
|
||||
int ret;
|
||||
|
||||
/* check state */
|
||||
|
@ -1401,7 +1401,7 @@ int ZEXPORT inflateSync(strm)
|
|||
z_streamp strm;
|
||||
{
|
||||
unsigned len; /* number of bytes to look at or looked at */
|
||||
unsigned long in, out; /* temporary to save total_in and total_out */
|
||||
uint64_t in, out; /* temporary to save total_in and total_out */
|
||||
unsigned char buf[4]; /* to restore bit buffer to byte string */
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
|
@ -1538,7 +1538,7 @@ int check;
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
long ZEXPORT inflateMark(strm)
|
||||
int64_t ZEXPORT inflateMark(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
@ -1546,16 +1546,16 @@ z_streamp strm;
|
|||
if (inflateStateCheck(strm))
|
||||
return -(1L << 16);
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
return (long)(((unsigned long)((long)state->back)) << 16) +
|
||||
return (int64_t)(((uint64_t)((int64_t)state->back)) << 16) +
|
||||
(state->mode == COPY ? state->length :
|
||||
(state->mode == MATCH ? state->was - state->length : 0));
|
||||
}
|
||||
|
||||
unsigned long ZEXPORT inflateCodesUsed(strm)
|
||||
uint64_t ZEXPORT inflateCodesUsed(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
if (inflateStateCheck(strm)) return (unsigned long)-1;
|
||||
if (inflateStateCheck(strm)) return (uint64_t)-1;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
return (unsigned long)(state->next - state->codes);
|
||||
return (uint64_t)(state->next - state->codes);
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ struct inflate_state {
|
|||
int havedict; /* true if dictionary provided */
|
||||
int flags; /* gzip header method and flags (0 if zlib) */
|
||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||
unsigned long check; /* protected copy of check value */
|
||||
unsigned long total; /* protected copy of output count */
|
||||
uint64_t check; /* protected copy of check value */
|
||||
uint64_t total; /* protected copy of output count */
|
||||
gz_headerp head; /* where to save gzip header information */
|
||||
/* sliding window */
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
|
@ -98,7 +98,7 @@ struct inflate_state {
|
|||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
uint64_t hold; /* input bit accumulator */
|
||||
unsigned bits; /* number of bits in "in" */
|
||||
/* for string and stored block copying */
|
||||
unsigned length; /* literal or length of data to copy */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 1995-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
/* @(#) $Id$ */
|
||||
|
||||
/* #define GEN_TREES_H */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "deflate.h"
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
|
@ -1038,7 +1038,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
|
|||
if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
|
||||
/* Compute an upper bound for the compressed length */
|
||||
ulg out_length = (ulg)s->last_lit*8L;
|
||||
ulg in_length = (ulg)((long)s->strstart - s->block_start);
|
||||
ulg in_length = (ulg)((int64_t)s->strstart - s->block_start);
|
||||
int dcode;
|
||||
for (dcode = 0; dcode < D_CODES; dcode++) {
|
||||
out_length += (ulg)s->dyn_dtree[dcode].Freq *
|
||||
|
@ -1128,7 +1128,7 @@ local int detect_data_type(s)
|
|||
* set bits 0..6, 14..25, and 28..31
|
||||
* 0xf3ffc07f = binary 11110011111111111100000001111111
|
||||
*/
|
||||
unsigned long black_mask = 0xf3ffc07fUL;
|
||||
uint64_t black_mask = 0xf3ffc07fUL;
|
||||
int n;
|
||||
|
||||
/* Check for non-textual ("black-listed") bytes. */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdint.h>
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
|
||||
|
|
|
@ -238,16 +238,16 @@
|
|||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
typedef unsigned long z_size_t;
|
||||
typedef uint64_t z_size_t;
|
||||
#else
|
||||
# define z_longlong long long
|
||||
# define z_longlong int64_t
|
||||
# if defined(NO_SIZE_T)
|
||||
typedef unsigned NO_SIZE_T z_size_t;
|
||||
# elif defined(STDC)
|
||||
# include <stddef.h>
|
||||
typedef size_t z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
typedef uint64_t z_size_t;
|
||||
# endif
|
||||
# undef z_longlong
|
||||
#endif
|
||||
|
@ -391,7 +391,7 @@
|
|||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
typedef uint64_t uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
|
@ -419,7 +419,7 @@ typedef uLong FAR uLongf;
|
|||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# define Z_U4 uint64_t
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
|
@ -428,7 +428,7 @@ typedef uLong FAR uLongf;
|
|||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
typedef uint64_t z_crc_t;
|
||||
#endif
|
||||
|
||||
#if 1 /* was set to #if 1 by ./configure */
|
||||
|
@ -501,7 +501,7 @@ typedef uLong FAR uLongf;
|
|||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
# define z_off_t int64_t
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
|
|
|
@ -999,7 +999,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
|||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
|
||||
ZEXTERN int64_t ZEXPORT inflateMark OF((z_streamp strm));
|
||||
/*
|
||||
This function returns two values, one in the lower 16 bits of the return
|
||||
value, and the other in the remaining upper bits, obtained by shifting the
|
||||
|
@ -1890,7 +1890,7 @@ ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
|
|||
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
|
||||
ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
|
||||
ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp));
|
||||
ZEXTERN uint64_t ZEXPORT inflateCodesUsed OF ((z_streamp));
|
||||
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
|
||||
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
|
||||
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
#ifndef Z_SOLO
|
||||
# include "gzguts.h"
|
||||
|
@ -280,7 +280,7 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
|||
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
|
||||
{
|
||||
(void)opaque;
|
||||
return _halloc((long)items, size);
|
||||
return _halloc((int64_t)items, size);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
|
||||
typedef int64_t ptrdiff_t; /* guess -- will be caught if guess is wrong */
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
|
@ -44,7 +44,7 @@ typedef unsigned char uch;
|
|||
typedef uch FAR uchf;
|
||||
typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
typedef uint64_t ulg;
|
||||
|
||||
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
@ -89,7 +89,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
void *_Cdecl farmalloc( uint64_t nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
|
|
|
@ -131,10 +131,10 @@
|
|||
# maxVnodeConnections 10000
|
||||
|
||||
# start http service in the cluster
|
||||
# enableHttp 1
|
||||
# http 1
|
||||
|
||||
# start system monitor module in the cluster
|
||||
# enableMonitor 1
|
||||
# monitor 1
|
||||
|
||||
# number of threads used to process http requests
|
||||
# httpMaxThreads 2
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Generate deb package for ubuntu
|
||||
#set -x
|
||||
# set -x
|
||||
|
||||
#curr_dir=$(pwd)
|
||||
compile_dir=$1
|
||||
|
@ -24,7 +24,7 @@ fi
|
|||
mkdir -p ${pkg_dir}
|
||||
cd ${pkg_dir}
|
||||
|
||||
versioninfo=$(${script_dir}/../tools/get_version.sh)
|
||||
versioninfo=$(${script_dir}/../tools/get_version.sh ${script_dir}/../../src/util/lite/src/version.c)
|
||||
libfile="libtaos.so.${versioninfo}"
|
||||
|
||||
# create install dir
|
||||
|
|
|
@ -8,7 +8,7 @@ set -e
|
|||
curr_dir=$(pwd)
|
||||
script_dir="$(dirname $(readlink -f $0))"
|
||||
top_dir="$(readlink -m ${script_dir}/..)"
|
||||
versioninfo="${top_dir}/src/util/src/version.c"
|
||||
versioninfo="${top_dir}/src/util/lite/src/version.c"
|
||||
|
||||
csudo=""
|
||||
if command -v sudo > /dev/null; then
|
||||
|
|
|
@ -39,7 +39,7 @@ echo topdir: %{_topdir}
|
|||
echo version: %{_version}
|
||||
echo buildroot: %{buildroot}
|
||||
|
||||
versioninfo=$(%{_compiledir}/../packaging/tools/get_version.sh)
|
||||
versioninfo=$(%{_compiledir}/../packaging/tools/get_version.sh ../../src/util/lite/src/version.c)
|
||||
libfile="libtaos.so.${versioninfo}"
|
||||
|
||||
# create install path, and cp file
|
||||
|
|
|
@ -7,8 +7,7 @@ set -e
|
|||
# set -x
|
||||
|
||||
# -----------------------Variables definition---------------------
|
||||
script_dir=$(dirname $(readlink -m "$0"))
|
||||
verinfo=$(cat ${script_dir}/../../src/util/src/version.c | grep " version" | cut -d '"' -f2)
|
||||
verinfo=$(cat $1 | grep " version" | cut -d '"' -f2)
|
||||
verinfo=$(echo $verinfo | tr "\n" " ")
|
||||
len=$(echo ${#verinfo})
|
||||
len=$((len-1))
|
||||
|
|
|
@ -101,7 +101,7 @@ function install_lib() {
|
|||
# Remove links
|
||||
${csudo} rm -f ${lib_link_dir}/libtaos.* || :
|
||||
|
||||
versioninfo=$(${script_dir}/get_version.sh)
|
||||
versioninfo=$(${script_dir}/get_version.sh ${source_dir}/src/util/lite/src/version.c)
|
||||
${csudo} cp ${binary_dir}/build/lib/libtaos.so.${versioninfo} ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
|
||||
${csudo} ln -sf ${install_main_dir}/driver/libtaos.so.${versioninfo} ${lib_link_dir}/libtaos.so.1
|
||||
${csudo} ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
|
||||
|
|
|
@ -20,7 +20,7 @@ install_dir="${release_dir}/taos-${version}-${package_name}-$(echo ${build_time}
|
|||
|
||||
# Directories and files.
|
||||
bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdump ${script_dir}/remove.sh"
|
||||
versioninfo=$(${script_dir}/get_version.sh)
|
||||
versioninfo=$(${script_dir}/get_version.sh ${code_dir}/util/lite/src/version.c)
|
||||
lib_files="${build_dir}/lib/libtaos.so.${versioninfo}"
|
||||
header_files="${code_dir}/inc/taos.h"
|
||||
cfg_files="${top_dir}/packaging/cfg/*.cfg"
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
SET(PRJ_HEADER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
ADD_SUBDIRECTORY(os)
|
||||
ADD_SUBDIRECTORY(util)
|
||||
ADD_SUBDIRECTORY(rpc)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
INCLUDE_DIRECTORIES(jni)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
AUX_SOURCE_DIRECTORY(./src SRC)
|
||||
INCLUDE_DIRECTORIES(inc jni ${TD_ROOT_DIR}/src/inc ${TD_OS_DIR}/inc)
|
||||
|
||||
IF (TD_LINUX)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/jni/linux)
|
||||
IF (TD_LINUX_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
|
||||
|
||||
# set the static lib name
|
||||
ADD_LIBRARY(taos_static STATIC ${SRC})
|
||||
|
@ -23,30 +24,38 @@ IF (TD_LINUX)
|
|||
#set version of .so
|
||||
#VERSION so version
|
||||
#SOVERSION api version
|
||||
execute_process(COMMAND chmod 777 ${PROJECT_SOURCE_DIR}/../../packaging/tools/get_version.sh)
|
||||
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/../../packaging/tools/get_version.sh
|
||||
OUTPUT_VARIABLE
|
||||
VERSION_INFO)
|
||||
IF (TD_LITE)
|
||||
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_version.sh)
|
||||
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_version.sh ${TD_COMMUNITY_DIR}/src/util/src/version.c
|
||||
OUTPUT_VARIABLE
|
||||
VERSION_INFO)
|
||||
MESSAGE(STATUS "build lite version ${VERSION_INFO}")
|
||||
ELSE ()
|
||||
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_version.sh)
|
||||
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_version.sh ${TD_ENTERPRISE_DIR}/src/util/src/version.c
|
||||
OUTPUT_VARIABLE
|
||||
VERSION_INFO)
|
||||
MESSAGE(STATUS "build cluster version ${VERSION_INFO}")
|
||||
ENDIF ()
|
||||
|
||||
MESSAGE(STATUS "build version ${VERSION_INFO}")
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES VERSION ${VERSION_INFO} SOVERSION 1)
|
||||
|
||||
ELSEIF (TD_WINDOWS)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/jni/windows)
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/jni/windows/win32)
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/pthread)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
||||
|
||||
ADD_LIBRARY(taos_static STATIC ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos_static trpc tutil)
|
||||
|
||||
# generate dynamic library (*.dll)
|
||||
ADD_LIBRARY(taos SHARED ${SRC})
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_ROOT_DIR}/src/client/src/taos.def)
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def)
|
||||
TARGET_LINK_LIBRARIES(taos trpc)
|
||||
|
||||
ELSEIF (TD_DARWIN)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/jni/linux)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
|
||||
|
||||
ADD_LIBRARY(taos_static STATIC ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos_static trpc tutil pthread m)
|
||||
|
@ -55,6 +64,6 @@ ELSEIF (TD_DARWIN)
|
|||
# generate dynamic library (*.dylib)
|
||||
ADD_LIBRARY(taos SHARED ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos trpc tutil pthread m)
|
||||
|
||||
|
||||
ENDIF ()
|
||||
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TSCJOINPROCESS_H
|
||||
#define TDENGINE_TSCJOINPROCESS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
|
||||
void tscFetchDatablockFromSubquery(SSqlObj* pSql);
|
||||
void tscGetQualifiedTSList(SSqlObj* pSql, SJoinSubquerySupporter* p1, SJoinSubquerySupporter* p2, int32_t* num);
|
||||
|
||||
void tscSetupOutputColumnIndex(SSqlObj* pSql);
|
||||
int32_t tscLaunchSecondSubquery(SSqlObj* pSql);
|
||||
void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code);
|
||||
|
||||
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
|
||||
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter);
|
||||
|
||||
#define MEM_BUF_SIZE (1<<20)
|
||||
#define TS_COMP_BLOCK_PADDING 0xFFFFFFFF
|
||||
#define TS_COMP_FILE_MAGIC 0x87F5EC4C
|
||||
#define TS_COMP_FILE_VNODE_MAX 512
|
||||
|
||||
typedef struct STSList {
|
||||
char* rawBuf;
|
||||
int32_t allocSize;
|
||||
int32_t threshold;
|
||||
int32_t len;
|
||||
} STSList;
|
||||
|
||||
typedef struct STSRawBlock {
|
||||
int32_t vnode;
|
||||
int64_t tag;
|
||||
TSKEY* ts;
|
||||
int32_t len;
|
||||
} STSRawBlock;
|
||||
|
||||
typedef struct STSElem {
|
||||
TSKEY ts;
|
||||
int64_t tag;
|
||||
int32_t vnode;
|
||||
} STSElem;
|
||||
|
||||
typedef struct STSCursor {
|
||||
int32_t vnodeIndex;
|
||||
int32_t blockIndex;
|
||||
int32_t tsIndex;
|
||||
int32_t order;
|
||||
} STSCursor;
|
||||
|
||||
typedef struct STSBlock {
|
||||
int64_t tag; // tag value
|
||||
int32_t numOfElem; // number of elements
|
||||
int32_t compLen; // size after compressed
|
||||
int32_t padding; // 0xFFFFFFFF by default, after the payload
|
||||
char* payload; // actual data that is compressed
|
||||
} STSBlock;
|
||||
|
||||
typedef struct STSVnodeBlockInfo {
|
||||
int32_t vnode;
|
||||
|
||||
/*
|
||||
* The size of buffer file is not expected to be greater than 2G,
|
||||
* and the offset of int32_t type is enough
|
||||
*/
|
||||
int32_t offset;
|
||||
int32_t numOfBlocks;
|
||||
int32_t compLen;
|
||||
} STSVnodeBlockInfo;
|
||||
|
||||
typedef struct STSVnodeBlockInfoEx {
|
||||
STSVnodeBlockInfo info;
|
||||
int32_t len; // length before compress
|
||||
} STSVnodeBlockInfoEx;
|
||||
|
||||
typedef struct STSBuf {
|
||||
FILE* f;
|
||||
char path[PATH_MAX];
|
||||
uint32_t fileSize;
|
||||
|
||||
STSVnodeBlockInfoEx* pData;
|
||||
int32_t numOfAlloc;
|
||||
int32_t numOfVnodes;
|
||||
|
||||
char* assistBuf;
|
||||
int32_t bufSize;
|
||||
STSBlock block;
|
||||
STSList tsData; // uncompressed raw ts data
|
||||
|
||||
uint64_t numOfTotal;
|
||||
bool autoDelete;
|
||||
int32_t tsOrder; // order of timestamp in ts comp buffer
|
||||
|
||||
STSCursor cur;
|
||||
} STSBuf;
|
||||
|
||||
typedef struct STSBufFileHeader {
|
||||
uint32_t magic; // file magic number
|
||||
uint32_t numOfVnode; // number of vnode stored in current file
|
||||
uint32_t tsOrder; // timestamp order in current file
|
||||
} STSBufFileHeader;
|
||||
|
||||
STSBuf* tsBufCreate(bool autoDelete);
|
||||
STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete);
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t tsOrder);
|
||||
|
||||
void tsBufDestory(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag, const char* pData, int32_t len);
|
||||
int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf, int32_t vnodeIdx);
|
||||
|
||||
STSVnodeBlockInfo* tsBufGetVnodeBlockInfo(STSBuf* pTSBuf, int32_t vnodeId);
|
||||
|
||||
void tsBufFlush(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufResetPos(STSBuf* pTSBuf);
|
||||
STSElem tsBufGetElem(STSBuf* pTSBuf);
|
||||
bool tsBufNextPos(STSBuf* pTSBuf);
|
||||
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag);
|
||||
|
||||
STSCursor tsBufGetCursor(STSBuf* pTSBuf);
|
||||
void tsBufSetTraverseOrder(STSBuf* pTSBuf, int32_t order);
|
||||
|
||||
void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur);
|
||||
STSBuf* tsBufClone(STSBuf* pTSBuf);
|
||||
|
||||
/**
|
||||
* display all data in comp block file, for debug purpose only
|
||||
* @param pTSBuf
|
||||
*/
|
||||
void tsBufDisplay(STSBuf* pTSBuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TSCJOINPROCESS_H
|
|
@ -52,74 +52,53 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct SLocalReducer {
|
||||
SLocalDataSource **pLocalDataSrc;
|
||||
int32_t numOfBuffer;
|
||||
int32_t numOfCompleted;
|
||||
|
||||
int32_t numOfVnode;
|
||||
|
||||
SLoserTreeInfo *pLoserTree;
|
||||
char * prevRowOfInput;
|
||||
|
||||
tFilePage *pResultBuf;
|
||||
int32_t nResultBufSize;
|
||||
|
||||
char *pBufForInterpo; // intermediate buffer for interpolation
|
||||
|
||||
tFilePage *pTempBuffer;
|
||||
|
||||
SLocalDataSource ** pLocalDataSrc;
|
||||
int32_t numOfBuffer;
|
||||
int32_t numOfCompleted;
|
||||
int32_t numOfVnode;
|
||||
SLoserTreeInfo * pLoserTree;
|
||||
char * prevRowOfInput;
|
||||
tFilePage * pResultBuf;
|
||||
int32_t nResultBufSize;
|
||||
char * pBufForInterpo; // intermediate buffer for interpolation
|
||||
tFilePage * pTempBuffer;
|
||||
struct SQLFunctionCtx *pCtx;
|
||||
|
||||
int32_t rowSize; // size of each intermediate result.
|
||||
int32_t status; // denote it is in reduce process, in reduce process, it
|
||||
// cannot be released
|
||||
bool hasPrevRow;
|
||||
bool hasUnprocessedRow;
|
||||
|
||||
tOrderDescriptor *pDesc;
|
||||
tColModel * resColModel;
|
||||
|
||||
tExtMemBuffer ** pExtMemBuffer; // disk-based buffer
|
||||
SInterpolationInfo interpolationInfo; // interpolation support structure
|
||||
|
||||
char *pFinalRes; // result data after interpo
|
||||
|
||||
tFilePage *discardData;
|
||||
bool discard;
|
||||
|
||||
int32_t offset;
|
||||
int32_t rowSize; // size of each intermediate result.
|
||||
int32_t status; // denote it is in reduce process, in reduce process, it
|
||||
bool hasPrevRow; // cannot be released
|
||||
bool hasUnprocessedRow;
|
||||
tOrderDescriptor * pDesc;
|
||||
tColModel * resColModel;
|
||||
tExtMemBuffer ** pExtMemBuffer; // disk-based buffer
|
||||
SInterpolationInfo interpolationInfo; // interpolation support structure
|
||||
char * pFinalRes; // result data after interpo
|
||||
tFilePage * discardData;
|
||||
SResultInfo * pResInfo;
|
||||
bool discard;
|
||||
int32_t offset; // limit offset value
|
||||
} SLocalReducer;
|
||||
|
||||
typedef struct SSubqueryState {
|
||||
/*
|
||||
* the number of completed retrieval subquery, once this value equals to numOfVnodes,
|
||||
* all retrieval are completed.Local merge is launched.
|
||||
*/
|
||||
int32_t numOfCompleted;
|
||||
int32_t numOfTotal; // number of total sub-queries
|
||||
int32_t code; // code from subqueries
|
||||
uint64_t numOfRetrievedRows; // total number of points in this query
|
||||
} SSubqueryState;
|
||||
|
||||
typedef struct SRetrieveSupport {
|
||||
tExtMemBuffer ** pExtMemBuffer; // for build loser tree
|
||||
tExtMemBuffer ** pExtMemBuffer; // for build loser tree
|
||||
tOrderDescriptor *pOrderDescriptor;
|
||||
tColModel * pFinalColModel; // colModel for final result
|
||||
|
||||
/*
|
||||
* shared by all subqueries
|
||||
* It is the number of completed retrieval subquery.
|
||||
* once this value equals to numOfVnodes, all retrieval are completed.
|
||||
* Local merge is launched.
|
||||
*/
|
||||
int32_t *numOfFinished;
|
||||
int32_t numOfVnodes; // total number of vnode
|
||||
int32_t vnodeIdx; // index of current vnode in vnode list
|
||||
|
||||
/*
|
||||
* shared by all subqueries
|
||||
* denote the status of query on vnode, if code!=0, all following
|
||||
* retrieval on vnode are aborted.
|
||||
*/
|
||||
int32_t *code;
|
||||
|
||||
SSqlObj * pParentSqlObj;
|
||||
tFilePage *localBuffer; // temp buffer, there is a buffer for each vnode to
|
||||
// save data
|
||||
uint64_t *numOfTotalRetrievedPoints; // total number of points in this query
|
||||
// retrieved from server
|
||||
|
||||
uint32_t numOfRetry; // record the number of retry times
|
||||
pthread_mutex_t queryMutex;
|
||||
tColModel * pFinalColModel; // colModel for final result
|
||||
SSubqueryState * pState;
|
||||
int32_t vnodeIdx; // index of current vnode in vnode list
|
||||
SSqlObj * pParentSqlObj;
|
||||
tFilePage * localBuffer; // temp buffer, there is a buffer for each vnode to
|
||||
uint32_t numOfRetry; // record the number of retry times
|
||||
pthread_mutex_t queryMutex;
|
||||
} SRetrieveSupport;
|
||||
|
||||
int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOrderDescriptor **pDesc,
|
||||
|
|
|
@ -23,18 +23,20 @@ extern "C" {
|
|||
/*
|
||||
* @date 2018/09/30
|
||||
*/
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include "tsdb.h"
|
||||
#include "tsclient.h"
|
||||
#include "textbuffer.h"
|
||||
#include "tsclient.h"
|
||||
#include "tsdb.h"
|
||||
#include "tscSecondaryMerge.h"
|
||||
|
||||
#define UTIL_METER_IS_METRIC(cmd) (((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_METRIC))
|
||||
|
||||
#define UTIL_METER_IS_NOMRAL_METER(cmd) (!(UTIL_METER_IS_METRIC(cmd)))
|
||||
|
||||
#define UTIL_METER_IS_CREATE_FROM_METRIC(cmd) \
|
||||
(((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_MTABLE))
|
||||
|
||||
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
|
||||
|
||||
typedef struct SParsedColElem {
|
||||
int16_t colIndex;
|
||||
int16_t offset;
|
||||
|
@ -47,15 +49,36 @@ typedef struct SParsedDataColInfo {
|
|||
bool hasVal[TSDB_MAX_COLUMNS];
|
||||
} SParsedDataColInfo;
|
||||
|
||||
STableDataBlocks* tscCreateDataBlock(int32_t size);
|
||||
typedef struct SJoinSubquerySupporter {
|
||||
SSubqueryState* pState;
|
||||
SSqlObj* pObj; // parent SqlObj
|
||||
bool hasMore; // has data from vnode to fetch
|
||||
int32_t subqueryIndex; // index of sub query
|
||||
int64_t interval; // interval time
|
||||
SLimitVal limit; // limit info
|
||||
uint64_t uid; // query meter uid
|
||||
SColumnBaseInfo colList; // previous query information
|
||||
SSqlExprInfo exprsInfo;
|
||||
SFieldInfo fieldsInfo;
|
||||
STagCond tagCond;
|
||||
SSqlGroupbyExpr groupbyExpr;
|
||||
|
||||
struct STSBuf* pTSBuf;
|
||||
|
||||
FILE* f;
|
||||
char path[PATH_MAX];
|
||||
} SJoinSubquerySupporter;
|
||||
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||
STableDataBlocks* tscCreateDataBlock(int32_t size);
|
||||
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
|
||||
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes, uint32_t offset);
|
||||
|
||||
SDataBlockList* tscCreateBlockArrayList();
|
||||
void* tscDestroyBlockArrayList(SDataBlockList* pList);
|
||||
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
|
||||
void tscFreeUnusedDataBlocks(SDataBlockList* pList);
|
||||
void tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList);
|
||||
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList);
|
||||
STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
|
||||
int32_t startOffset, int32_t rowSize, char* tableId);
|
||||
STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name);
|
||||
|
@ -63,9 +86,6 @@ STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t sta
|
|||
SVnodeSidList* tscGetVnodeSidList(SMetricMeta* pMetricmeta, int32_t vnodeIdx);
|
||||
SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
|
||||
|
||||
bool tscProjectionQueryOnMetric(SSqlObj* pSql);
|
||||
bool tscIsTwoStageMergeMetricQuery(SSqlObj* pSql);
|
||||
|
||||
/**
|
||||
*
|
||||
* for the projection query on metric or point interpolation query on metric,
|
||||
|
@ -73,52 +93,71 @@ bool tscIsTwoStageMergeMetricQuery(SSqlObj* pSql);
|
|||
*
|
||||
* @param pSql sql object
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
bool tscIsFirstProjQueryOnMetric(SSqlObj* pSql);
|
||||
bool tscIsPointInterpQuery(SSqlCmd* pCmd);
|
||||
void tscClearInterpInfo(SSqlCmd* pCmd);
|
||||
bool tscIsTWAQuery(SSqlCmd* pCmd);
|
||||
bool tscProjectionQueryOnMetric(SSqlCmd* pCmd);
|
||||
bool tscIsTwoStageMergeMetricQuery(SSqlCmd* pCmd);
|
||||
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
||||
bool tscQueryMetricTags(SSqlCmd* pCmd);
|
||||
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
||||
|
||||
int32_t setMeterID(SSqlObj* pSql, SSQLToken* pzTableName);
|
||||
void tscAddSpecialColumnForSelect(SSqlCmd* pCmd, int32_t outputColIndex, int16_t functionId, SColumnIndex* pIndex,
|
||||
SSchema* pColSchema, int16_t isTag);
|
||||
|
||||
void addRequiredTagColumn(SSqlCmd* pCmd, int32_t tagColIndex, int32_t tableIndex);
|
||||
void SStringFree(SString* str);
|
||||
void SStringCopy(SString* pDest, const SString* pSrc);
|
||||
SString SStringCreate(const char* str);
|
||||
|
||||
int32_t SStringAlloc(SString* pStr, int32_t size);
|
||||
int32_t SStringEnsureRemain(SString* pStr, int32_t size);
|
||||
|
||||
int32_t setMeterID(SSqlObj* pSql, SSQLToken* pzTableName, int32_t tableIndex);
|
||||
void tscClearInterpInfo(SSqlCmd* pCmd);
|
||||
|
||||
bool tscIsInsertOrImportData(char* sqlstr);
|
||||
|
||||
/* use for keep current db info temporarily, for handle table with db prefix */
|
||||
void tscGetDBInfoFromMeterId(char* meterId, char* db);
|
||||
|
||||
void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr);
|
||||
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
||||
|
||||
int tscAllocPayloadWithSize(SSqlCmd* pCmd, int size);
|
||||
int tscAllocPayload(SSqlCmd* pCmd, int size);
|
||||
|
||||
void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema);
|
||||
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField);
|
||||
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, char* name, int16_t bytes);
|
||||
void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible);
|
||||
|
||||
void tscFieldInfoCalOffset(SSqlCmd* pCmd);
|
||||
void tscFieldInfoRenewOffsetForInterResult(SSqlCmd* pCmd);
|
||||
void tscFieldInfoClone(SFieldInfo* src, SFieldInfo* dst);
|
||||
void tscFieldInfoUpdateOffset(SSqlCmd* pCmd);
|
||||
void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList, int32_t size);
|
||||
void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst);
|
||||
|
||||
TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index);
|
||||
int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index);
|
||||
int32_t tscGetResRowLength(SSqlCmd* pCmd);
|
||||
void tscClearFieldInfo(SSqlCmd* pCmd);
|
||||
void tscClearFieldInfo(SFieldInfo* pFieldInfo);
|
||||
|
||||
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes);
|
||||
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex);
|
||||
|
||||
SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
int16_t size);
|
||||
SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, /*int16_t colId,*/ int16_t interSize);
|
||||
SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
int16_t size);
|
||||
|
||||
SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index);
|
||||
void tscSqlExprClone(SSqlExprInfo* src, SSqlExprInfo* dst);
|
||||
void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t uid);
|
||||
|
||||
SColumnBase* tscColumnInfoInsert(SSqlCmd* pCmd, int32_t colIndex);
|
||||
SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* colIndex);
|
||||
void tscColumnFilterInfoCopy(SColumnFilterInfo* dst, const SColumnFilterInfo* src);
|
||||
void tscColumnBaseCopy(SColumnBase* dst, const SColumnBase* src);
|
||||
|
||||
void tscColumnInfoClone(SColumnsInfo* src, SColumnsInfo* dst);
|
||||
SColumnBase* tscColumnInfoGet(SSqlCmd* pCmd, int32_t index);
|
||||
void tscColumnInfoReserve(SSqlCmd* pCmd, int32_t size);
|
||||
void tscColumnBaseInfoCopy(SColumnBaseInfo* dst, const SColumnBaseInfo* src, int16_t tableIndex);
|
||||
SColumnBase* tscColumnBaseInfoGet(SColumnBaseInfo* pColumnBaseInfo, int32_t index);
|
||||
void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableIndex);
|
||||
|
||||
void tscColumnBaseInfoReserve(SColumnBaseInfo* pColumnBaseInfo, int32_t size);
|
||||
void tscColumnBaseInfoDestroy(SColumnBaseInfo* pColumnBaseInfo);
|
||||
|
||||
int32_t tscValidateName(SSQLToken* pToken);
|
||||
|
||||
|
@ -127,8 +166,10 @@ void tscIncStreamExecutionCount(void* pStream);
|
|||
bool tscValidateColumnId(SSqlCmd* pCmd, int32_t colId);
|
||||
|
||||
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
|
||||
char* tsGetMetricQueryCondPos(STagCond* pCond);
|
||||
void tscTagCondAssign(STagCond* pDst, STagCond* pSrc);
|
||||
SCond* tsGetMetricQueryCondPos(STagCond* pCond, uint64_t tableIndex);
|
||||
void tsSetMetricQueryCond(STagCond* pTagCond, uint64_t uid, const char* str);
|
||||
|
||||
void tscTagCondCopy(STagCond* dest, const STagCond* src);
|
||||
void tscTagCondRelease(STagCond* pCond);
|
||||
void tscTagCondSetQueryCondType(STagCond* pCond, int16_t type);
|
||||
|
||||
|
@ -138,8 +179,54 @@ void tscSetFreeHeatBeat(STscObj* pObj);
|
|||
bool tscShouldFreeHeatBeat(SSqlObj* pHb);
|
||||
void tscCleanSqlCmd(SSqlCmd* pCmd);
|
||||
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
|
||||
|
||||
void tscRemoveAllMeterMetaInfo(SSqlCmd* pCmd, bool removeFromCache);
|
||||
SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd* pCmd, int32_t index);
|
||||
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* index);
|
||||
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache);
|
||||
|
||||
SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta,
|
||||
int16_t numOfTags, int16_t* tags);
|
||||
SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd);
|
||||
|
||||
void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr, uint64_t uid);
|
||||
int tscGetMetricMeta(SSqlObj* pSql);
|
||||
int tscGetMeterMeta(SSqlObj* pSql, char* meterId, int32_t tableIndex);
|
||||
int tscGetMeterMetaEx(SSqlObj* pSql, char* meterId, bool createIfNotExists);
|
||||
|
||||
void tscResetForNextRetrieve(SSqlRes* pRes);
|
||||
|
||||
void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex);
|
||||
void tscDoQuery(SSqlObj* pSql);
|
||||
|
||||
/**
|
||||
* The create object function must be successful expect for the out of memory issue.
|
||||
*
|
||||
* Therefore, the metermeta/metricmeta object is directly passed to the newly created subquery object from the
|
||||
* previous sql object, instead of retrieving the metermeta/metricmeta from cache.
|
||||
*
|
||||
* Because the metermeta/metricmeta may have been released by other threads, resulting in the retrieving failed as
|
||||
* well as the create function.
|
||||
*
|
||||
* @param pSql
|
||||
* @param vnodeIndex
|
||||
* @param tableIndex
|
||||
* @param fp
|
||||
* @param param
|
||||
* @param pPrevSql
|
||||
* @return
|
||||
*/
|
||||
SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex, void (*fp)(), void* param,
|
||||
SSqlObj* pPrevSql);
|
||||
void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIndex);
|
||||
|
||||
void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex);
|
||||
|
||||
int16_t tscGetJoinTagColIndexByUid(SSqlCmd* pCmd, uint64_t uid);
|
||||
|
||||
TAOS* taos_connect_a(char* ip, char* user, char* pass, char* db, int port, void (*fp)(void*, TAOS_RES*, int),
|
||||
void* param, void** taos);
|
||||
|
||||
void sortRemoveDuplicates(STableDataBlocks* dataBuf);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -63,9 +63,9 @@ enum _sql_cmd {
|
|||
TSDB_SQL_ALTER_DB,
|
||||
TSDB_SQL_CREATE_MNODE,
|
||||
TSDB_SQL_DROP_MNODE,
|
||||
TSDB_SQL_CREATE_PNODE,
|
||||
TSDB_SQL_DROP_PNODE,
|
||||
TSDB_SQL_CFG_PNODE, // 20
|
||||
TSDB_SQL_CREATE_DNODE,
|
||||
TSDB_SQL_DROP_DNODE,
|
||||
TSDB_SQL_CFG_DNODE, // 20
|
||||
TSDB_SQL_CFG_MNODE,
|
||||
TSDB_SQL_SHOW,
|
||||
TSDB_SQL_RETRIEVE,
|
||||
|
@ -78,15 +78,21 @@ enum _sql_cmd {
|
|||
TSDB_SQL_USE_DB,
|
||||
TSDB_SQL_META, // 30
|
||||
TSDB_SQL_METRIC,
|
||||
TSDB_SQL_MULTI_META,
|
||||
TSDB_SQL_HB,
|
||||
|
||||
TSDB_SQL_LOCAL, // SQL below for client local
|
||||
TSDB_SQL_DESCRIBE_TABLE,
|
||||
TSDB_SQL_RETRIEVE_METRIC,
|
||||
TSDB_SQL_METRIC_JOIN_RETRIEVE,
|
||||
TSDB_SQL_RETRIEVE_TAGS,
|
||||
TSDB_SQL_RETRIEVE_EMPTY_RESULT, // build empty result instead of accessing
|
||||
// dnode to fetch result
|
||||
TSDB_SQL_RESET_CACHE, // reset the client cache
|
||||
/*
|
||||
* build empty result instead of accessing dnode to fetch result
|
||||
* reset the client cache
|
||||
*/
|
||||
TSDB_SQL_RETRIEVE_EMPTY_RESULT,
|
||||
|
||||
TSDB_SQL_RESET_CACHE,
|
||||
TSDB_SQL_CFG_LOCAL,
|
||||
|
||||
TSDB_SQL_MAX
|
||||
|
@ -96,24 +102,35 @@ enum _sql_cmd {
|
|||
struct SSqlInfo;
|
||||
|
||||
typedef struct SSqlGroupbyExpr {
|
||||
int16_t numOfGroupbyCols;
|
||||
int16_t tagIndex[TSDB_MAX_TAGS]; /* group by columns information */
|
||||
int16_t orderIdx; /* order by column index */
|
||||
int16_t orderType; /* order by type: asc/desc */
|
||||
int16_t tableIndex;
|
||||
|
||||
int16_t numOfGroupCols;
|
||||
SColIndexEx columnInfo[TSDB_MAX_TAGS]; // group by columns information
|
||||
|
||||
int16_t orderIndex; // order by column index
|
||||
int16_t orderType; // order by type: asc/desc
|
||||
} SSqlGroupbyExpr;
|
||||
|
||||
typedef struct SMeterMetaInfo {
|
||||
SMeterMeta * pMeterMeta; // metermeta
|
||||
SMetricMeta *pMetricMeta; // metricmeta
|
||||
|
||||
char name[TSDB_METER_ID_LEN + 1];
|
||||
int16_t numOfTags; // total required tags in query, including groupby tags
|
||||
int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection
|
||||
} SMeterMetaInfo;
|
||||
|
||||
/* the structure for sql function in select clause */
|
||||
typedef struct SSqlExpr {
|
||||
char aliasName[TSDB_COL_NAME_LEN + 1]; // as aliasName
|
||||
|
||||
SColIndex colInfo;
|
||||
int16_t sqlFuncId; // function id in aAgg array
|
||||
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
char aliasName[TSDB_COL_NAME_LEN + 1]; // as aliasName
|
||||
SColIndexEx colInfo;
|
||||
int64_t uid; // refactor use the pointer
|
||||
int16_t functionId; // function id in aAgg array
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
int16_t interResBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
|
@ -121,6 +138,15 @@ typedef struct SFieldInfo {
|
|||
int16_t numOfAlloc; // allocated size
|
||||
TAOS_FIELD *pFields;
|
||||
short * pOffset;
|
||||
|
||||
/*
|
||||
* define if this column is belong to the queried result, it may be add by parser to faciliate
|
||||
* the query process
|
||||
*
|
||||
* NOTE: these hidden columns always locate at the end of the output columns
|
||||
*/
|
||||
bool * pVisibleCols;
|
||||
int32_t numOfHiddenCols; // the number of column not belongs to the queried result columns
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SSqlExprInfo {
|
||||
|
@ -129,87 +155,122 @@ typedef struct SSqlExprInfo {
|
|||
SSqlExpr *pExprs;
|
||||
} SSqlExprInfo;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
int16_t tableIndex;
|
||||
int16_t columnIndex;
|
||||
} SColumnIndex;
|
||||
|
||||
typedef struct SColumnBase {
|
||||
int16_t colIndex;
|
||||
|
||||
/* todo refactor: the following data is belong to one struct */
|
||||
int16_t filterOn; /* denote if the filter is active */
|
||||
int16_t lowerRelOptr;
|
||||
int16_t upperRelOptr;
|
||||
int16_t filterOnBinary; /* denote if current column is binary */
|
||||
|
||||
union {
|
||||
struct {
|
||||
int64_t lowerBndi;
|
||||
int64_t upperBndi;
|
||||
};
|
||||
struct {
|
||||
double lowerBndd;
|
||||
double upperBndd;
|
||||
};
|
||||
struct {
|
||||
int64_t pz;
|
||||
int64_t len;
|
||||
};
|
||||
};
|
||||
SColumnIndex colIndex;
|
||||
int32_t numOfFilters;
|
||||
SColumnFilterInfo *filterInfo;
|
||||
} SColumnBase;
|
||||
|
||||
typedef struct SColumnsInfo {
|
||||
typedef struct SColumnBaseInfo {
|
||||
int16_t numOfAlloc;
|
||||
int16_t numOfCols;
|
||||
SColumnBase *pColList;
|
||||
} SColumnsInfo;
|
||||
} SColumnBaseInfo;
|
||||
|
||||
struct SLocalReducer;
|
||||
|
||||
// todo move to utility
|
||||
typedef struct SString {
|
||||
int32_t alloc;
|
||||
int32_t n;
|
||||
char * z;
|
||||
} SString;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
SString cond;
|
||||
} SCond;
|
||||
|
||||
typedef struct SJoinNode {
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
uint64_t uid;
|
||||
int16_t tagCol;
|
||||
} SJoinNode;
|
||||
|
||||
typedef struct SJoinInfo {
|
||||
bool hasJoin;
|
||||
SJoinNode left;
|
||||
SJoinNode right;
|
||||
} SJoinInfo;
|
||||
|
||||
typedef struct STagCond {
|
||||
int32_t len;
|
||||
int32_t allocSize;
|
||||
int16_t type;
|
||||
char * pData;
|
||||
// relation between tbname list and query condition, including : TK_AND or TK_OR
|
||||
int16_t relType;
|
||||
|
||||
// tbname query condition, only support tbname query condition on one table
|
||||
SCond tbnameCond;
|
||||
|
||||
// join condition, only support two tables join currently
|
||||
SJoinInfo joinInfo;
|
||||
|
||||
// for different table, the query condition must be seperated
|
||||
SCond cond[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
int16_t numOfTagCond;
|
||||
} STagCond;
|
||||
|
||||
typedef struct SParamInfo {
|
||||
int32_t idx;
|
||||
char type;
|
||||
uint8_t timePrec;
|
||||
short bytes;
|
||||
uint32_t offset;
|
||||
} SParamInfo;
|
||||
|
||||
typedef struct STableDataBlocks {
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
int8_t tsSource;
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
int8_t tsSource;
|
||||
bool ordered;
|
||||
|
||||
int64_t vgid;
|
||||
int64_t size;
|
||||
int64_t vgid;
|
||||
int64_t prevTS;
|
||||
|
||||
int64_t prevTS;
|
||||
bool ordered;
|
||||
int32_t numOfMeters;
|
||||
|
||||
int32_t numOfMeters;
|
||||
int32_t rowSize;
|
||||
uint32_t nAllocSize;
|
||||
int32_t rowSize;
|
||||
uint32_t nAllocSize;
|
||||
uint32_t size;
|
||||
union {
|
||||
char *filename;
|
||||
char *pData;
|
||||
};
|
||||
|
||||
// for parameter ('?') binding
|
||||
uint32_t numOfAllocedParams;
|
||||
uint32_t numOfParams;
|
||||
SParamInfo* params;
|
||||
} STableDataBlocks;
|
||||
|
||||
typedef struct SDataBlockList {
|
||||
int32_t idx;
|
||||
int32_t nSize;
|
||||
int32_t nAlloc;
|
||||
char * userParam; /* user assigned parameters for async query */
|
||||
void * udfp; /* user defined function pointer, used in async model */
|
||||
int32_t idx;
|
||||
int32_t nSize;
|
||||
int32_t nAlloc;
|
||||
char * userParam; /* user assigned parameters for async query */
|
||||
void * udfp; /* user defined function pointer, used in async model */
|
||||
STableDataBlocks **pData;
|
||||
} SDataBlockList;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_METER_ID_LEN];
|
||||
SOrderVal order;
|
||||
int command;
|
||||
int count;
|
||||
int16_t isInsertFromFile; // load data from file or not
|
||||
int16_t metricQuery; // metric query or not
|
||||
bool existsCheck;
|
||||
SOrderVal order;
|
||||
int command;
|
||||
|
||||
// TODO refactor
|
||||
int count;
|
||||
int16_t isInsertFromFile; // load data from file or not
|
||||
|
||||
union {
|
||||
bool existsCheck;
|
||||
int8_t showType;
|
||||
};
|
||||
|
||||
char msgType;
|
||||
char type;
|
||||
uint16_t type;
|
||||
char intervalTimeUnit;
|
||||
int64_t etime;
|
||||
int64_t stime;
|
||||
int64_t etime, stime;
|
||||
int64_t nAggTimeInterval; // aggregation time interval
|
||||
int64_t nSlidingTime; // sliding window in mseconds
|
||||
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
||||
|
@ -224,24 +285,27 @@ typedef struct {
|
|||
char * payload;
|
||||
int payloadLen;
|
||||
short numOfCols;
|
||||
SColumnsInfo colList;
|
||||
SColumnBaseInfo colList;
|
||||
SFieldInfo fieldsInfo;
|
||||
SSqlExprInfo exprsInfo;
|
||||
int16_t numOfReqTags; // total required tags in query, inlcuding groupby clause + tag projection
|
||||
int16_t tagColumnIndex[TSDB_MAX_TAGS + 1];
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
int64_t globalLimit;
|
||||
SLimitVal glimit;
|
||||
STagCond tagCond;
|
||||
int16_t vnodeIdx; // vnode index in pMetricMeta for metric query
|
||||
int16_t interpoType; // interpolate type
|
||||
int16_t numOfTables;
|
||||
|
||||
SDataBlockList *pDataBlocks; // submit data blocks branched according to vnode
|
||||
SMeterMeta * pMeterMeta; // metermeta
|
||||
SMetricMeta * pMetricMeta; // metricmeta
|
||||
|
||||
// submit data blocks branched according to vnode
|
||||
SDataBlockList * pDataBlocks;
|
||||
SMeterMetaInfo **pMeterInfo;
|
||||
struct STSBuf * tsBuf;
|
||||
// todo use dynamic allocated memory for defaultVal
|
||||
int64_t defaultVal[TSDB_MAX_COLUMNS]; // default value for interpolation
|
||||
|
||||
// for parameter ('?') binding and batch processing
|
||||
int32_t batchSize;
|
||||
int32_t numOfParams;
|
||||
} SSqlCmd;
|
||||
|
||||
typedef struct SResRec {
|
||||
|
@ -249,28 +313,29 @@ typedef struct SResRec {
|
|||
int numOfTotal;
|
||||
} SResRec;
|
||||
|
||||
typedef struct {
|
||||
uint8_t code;
|
||||
int numOfRows; // num of results in current retrieved
|
||||
int numOfTotal; // num of total results
|
||||
char * pRsp;
|
||||
int rspType;
|
||||
int rspLen;
|
||||
uint64_t qhandle;
|
||||
int64_t useconds;
|
||||
int64_t offset; // offset value from vnode during projection query of stable
|
||||
int row;
|
||||
int16_t numOfnchar;
|
||||
int16_t precision;
|
||||
int32_t numOfGroups;
|
||||
SResRec *pGroupRec;
|
||||
char * data;
|
||||
short * bytes;
|
||||
void ** tsrow;
|
||||
struct STSBuf;
|
||||
|
||||
// Buffer used to put multibytes encoded using unicode (wchar_t)
|
||||
char ** buffer;
|
||||
typedef struct {
|
||||
uint8_t code;
|
||||
int numOfRows; // num of results in current retrieved
|
||||
int numOfTotal; // num of total results
|
||||
char * pRsp;
|
||||
int rspType;
|
||||
int rspLen;
|
||||
uint64_t qhandle;
|
||||
int64_t useconds;
|
||||
int64_t offset; // offset value from vnode during projection query of stable
|
||||
int row;
|
||||
int16_t numOfnchar;
|
||||
int16_t precision;
|
||||
int32_t numOfGroups;
|
||||
SResRec * pGroupRec;
|
||||
char * data;
|
||||
short * bytes;
|
||||
void ** tsrow;
|
||||
char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t)
|
||||
struct SLocalReducer *pLocalReducer;
|
||||
SColumnIndex * pColumnIndex;
|
||||
} SSqlRes;
|
||||
|
||||
typedef struct _tsc_obj {
|
||||
|
@ -328,7 +393,7 @@ typedef struct _sstream {
|
|||
int64_t num; // number of computing count
|
||||
|
||||
/*
|
||||
* bookmark the current number of result in computing,
|
||||
* keep the number of current result in computing,
|
||||
* the value will be set to 0 before set timer for next computing
|
||||
*/
|
||||
int64_t numOfRes;
|
||||
|
@ -336,8 +401,7 @@ typedef struct _sstream {
|
|||
int64_t useconds; // total elapsed time
|
||||
int64_t ctime; // stream created time
|
||||
int64_t stime; // stream next executed time
|
||||
int64_t etime; // stream end query time, when time is larger then etime, the
|
||||
// stream will be closed
|
||||
int64_t etime; // stream end query time, when time is larger then etime, the stream will be closed
|
||||
int64_t interval;
|
||||
int64_t slidingTime;
|
||||
int16_t precision;
|
||||
|
@ -346,8 +410,7 @@ typedef struct _sstream {
|
|||
void (*fp)();
|
||||
void *param;
|
||||
|
||||
// Call backfunction when stream is stopped from client level
|
||||
void (*callback)(void *);
|
||||
void (*callback)(void *); // Callback function when stream is stopped from client level
|
||||
struct _sstream *prev, *next;
|
||||
} SSqlStream;
|
||||
|
||||
|
@ -363,14 +426,12 @@ int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion);
|
|||
void tscInitMsgs();
|
||||
void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle);
|
||||
int tscProcessSql(SSqlObj *pSql);
|
||||
int tscGetMeterMeta(SSqlObj *pSql, char *meterId);
|
||||
int tscGetMeterMetaEx(SSqlObj *pSql, char *meterId, bool createIfNotExists);
|
||||
|
||||
void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
int tscRenewMeterMeta(SSqlObj *pSql, char *meterId);
|
||||
void tscQueueAsyncRes(SSqlObj *pSql);
|
||||
int tscGetMetricMeta(SSqlObj *pSql, char *meterId);
|
||||
|
||||
void tscQueueAsyncError(void(*fp), void *param);
|
||||
|
||||
int tscProcessLocalCmd(SSqlObj *pSql);
|
||||
|
@ -381,7 +442,7 @@ int taos_retrieve(TAOS_RES *res);
|
|||
* transfer function for metric query in stream computing, the function need to be change
|
||||
* before send query message to vnode
|
||||
*/
|
||||
void tscTansformSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
void tscRestoreSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
|
||||
/**
|
||||
|
@ -395,7 +456,7 @@ void tscClearSqlMetaInfoForce(SSqlCmd *pCmd);
|
|||
int32_t tscCreateResPointerInfo(SSqlCmd *pCmd, SSqlRes *pRes);
|
||||
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
||||
|
||||
void tscfreeSqlCmdData(SSqlCmd *pCmd);
|
||||
void tscFreeSqlCmdData(SSqlCmd *pCmd);
|
||||
|
||||
/**
|
||||
* only free part of resources allocated during query.
|
||||
|
@ -413,17 +474,6 @@ void tscFreeSqlObj(SSqlObj *pObj);
|
|||
|
||||
void tscCloseTscObj(STscObj *pObj);
|
||||
|
||||
//
|
||||
// support functions for async metric query.
|
||||
// we declare them as global visible functions, because we need them to check if a
|
||||
// failed async query in tscMeterMetaCallBack is a metric query or not.
|
||||
|
||||
// expr: (fp == tscRetrieveDataRes or fp == tscRetrieveFromVnodeCallBack)
|
||||
// If a query is async query, we simply abort current query process, instead of continuing
|
||||
//
|
||||
void tscRetrieveDataRes(void *param, TAOS_RES *tres, int numOfRows);
|
||||
void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
void tscProcessMultiVnodesInsert(SSqlObj *pSql);
|
||||
void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql);
|
||||
void tscKillMetricQuery(SSqlObj *pSql);
|
||||
|
@ -435,18 +485,18 @@ int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
|
|||
|
||||
void tscQueueAsyncFreeResult(SSqlObj *pSql);
|
||||
|
||||
extern void * pVnodeConn;
|
||||
extern void * pTscMgmtConn;
|
||||
extern void * tscCacheHandle;
|
||||
extern uint8_t globalCode;
|
||||
extern int slaveIndex;
|
||||
extern void * tscTmr;
|
||||
extern void * tscConnCache;
|
||||
extern void * tscQhandle;
|
||||
extern int tscKeepConn[];
|
||||
extern int tsInsertHeadSize;
|
||||
extern int tscNumOfThreads;
|
||||
extern uint32_t tsServerIp;
|
||||
extern void * pVnodeConn;
|
||||
extern void * pTscMgmtConn;
|
||||
extern void * tscCacheHandle;
|
||||
extern uint8_t globalCode;
|
||||
extern int slaveIndex;
|
||||
extern void * tscTmr;
|
||||
extern void * tscConnCache;
|
||||
extern void * tscQhandle;
|
||||
extern int tscKeepConn[];
|
||||
extern int tsInsertHeadSize;
|
||||
extern int tscNumOfThreads;
|
||||
extern SIpStrList tscMgmtIpList;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
|
||||
#include "taos.h"
|
||||
#include "tlog.h"
|
||||
#include "tscJoinProcess.h"
|
||||
#include "tsclient.h"
|
||||
#include "tscUtil.h"
|
||||
|
||||
|
@ -660,4 +661,4 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab
|
|||
|
||||
JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getTsCharset(JNIEnv *env, jobject jobj) {
|
||||
return (*env)->NewStringUTF(env, (const char *)tsCharset);
|
||||
}
|
||||
}
|
|
@ -43,14 +43,11 @@
|
|||
*/
|
||||
|
||||
static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken);
|
||||
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode);
|
||||
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *));
|
||||
|
||||
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i);
|
||||
static void destroySyntaxTree(tSQLSyntaxNode *);
|
||||
|
||||
static void tSQLListTraversePrepare(tQueryInfo *colInfo, SSchema *pSchema, int32_t numOfCols, SSchema *pOneColSchema,
|
||||
uint8_t optr, tVariant *val);
|
||||
|
||||
static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft,
|
||||
const tSQLSyntaxNode *pRight);
|
||||
|
||||
|
@ -78,9 +75,14 @@ static void reviseBinaryExprIfNecessary(tSQLSyntaxNode **pLeft, tSQLSyntaxNode *
|
|||
}
|
||||
}
|
||||
|
||||
// switch left and left and right hand side in expr
|
||||
/*
|
||||
* for expressions that are suitable for switch principle,
|
||||
* switch left and left and right hand side in expr if possible
|
||||
*/
|
||||
if ((*pLeft)->nodeType == TSQL_NODE_VALUE && (*pRight)->nodeType == TSQL_NODE_COL) {
|
||||
SWAP(*pLeft, *pRight, tSQLSyntaxNode*);
|
||||
if (*optr >= TSDB_RELATION_LARGE && *optr <= TSDB_RELATION_LARGE_EQUAL && *optr != TSDB_RELATION_EQUAL) {
|
||||
SWAP(*pLeft, *pRight, tSQLSyntaxNode *);
|
||||
}
|
||||
|
||||
switch (*optr) {
|
||||
case TSDB_RELATION_LARGE:
|
||||
|
@ -119,15 +121,14 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
|
|||
if (strncmp(pToken->z, pSchema[i].name, pToken->n) == 0 && pToken->n == len) break;
|
||||
} while (++i < numOfCols);
|
||||
|
||||
if (i == numOfCols) {
|
||||
// column name is not valid, parse the expression failed
|
||||
if (i == numOfCols) { // column name is not valid, parse the expression failed
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
nodeSize += sizeof(SSchema);
|
||||
|
||||
pNode = malloc(nodeSize);
|
||||
pNode = calloc(1, nodeSize);
|
||||
pNode->pSchema = (struct SSchema *)((char *)pNode + sizeof(tSQLSyntaxNode));
|
||||
pNode->nodeType = TSQL_NODE_COL;
|
||||
|
||||
|
@ -144,7 +145,7 @@ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols,
|
|||
|
||||
} else {
|
||||
nodeSize += sizeof(tVariant);
|
||||
pNode = malloc(nodeSize);
|
||||
pNode = calloc(1, nodeSize);
|
||||
pNode->pVal = (tVariant *)((char *)pNode + sizeof(tSQLSyntaxNode));
|
||||
|
||||
toTSDBType(pToken->type);
|
||||
|
@ -202,12 +203,12 @@ static tSQLSyntaxNode *parseRemainStr(char *pstr, tSQLBinaryExpr *pExpr, SSchema
|
|||
tSQLSyntaxNode *pRight = createSyntaxTree(pSchema, numOfCols, pstr, i);
|
||||
if (pRight == NULL || (pRight->nodeType == TSQL_NODE_COL && pLeft->nodeType != TSQL_NODE_VALUE) ||
|
||||
(pLeft->nodeType == TSQL_NODE_VALUE && pRight->nodeType != TSQL_NODE_COL)) {
|
||||
tSQLSyntaxNodeDestroy(pLeft);
|
||||
tSQLSyntaxNodeDestroy(pRight);
|
||||
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
||||
tSQLSyntaxNodeDestroy(pRight, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSQLBinaryExpr *pNewExpr = (tSQLBinaryExpr *)malloc(sizeof(tSQLBinaryExpr));
|
||||
tSQLBinaryExpr *pNewExpr = (tSQLBinaryExpr *)calloc(1, sizeof(tSQLBinaryExpr));
|
||||
uint8_t k = optr;
|
||||
reviseBinaryExprIfNecessary(&pLeft, &pRight, &k);
|
||||
pNewExpr->pLeft = pLeft;
|
||||
|
@ -228,8 +229,7 @@ uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode
|
|||
// if left node is the primary column,return true
|
||||
return (strcmp(primaryColumnName, pLeft->pSchema->name) == 0) ? 1 : 0;
|
||||
} else {
|
||||
// if any children have query on primary key, their parents are also keep
|
||||
// this value
|
||||
// if any children have query on primary key, their parents are also keep this value
|
||||
return ((pLeft->nodeType == TSQL_NODE_EXPR && pLeft->pExpr->filterOnPrimaryKey == 1) ||
|
||||
(pRight->nodeType == TSQL_NODE_EXPR && pRight->pExpr->filterOnPrimaryKey == 1)) == true
|
||||
? 1
|
||||
|
@ -238,9 +238,9 @@ uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode
|
|||
}
|
||||
|
||||
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i) {
|
||||
SSQLToken t0 = {0};
|
||||
SSQLToken t0;
|
||||
|
||||
tStrGetToken(str, i, &t0, false);
|
||||
t0 = tStrGetToken(str, i, false, 0, NULL);
|
||||
if (t0.n == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -259,11 +259,11 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tStrGetToken(str, i, &t0, false);
|
||||
t0 = tStrGetToken(str, i, false, 0, NULL);
|
||||
if (t0.n == 0 || t0.type == TK_RP) {
|
||||
if (pLeft->nodeType != TSQL_NODE_EXPR) {
|
||||
// if left is not the expr, it is not a legal expr
|
||||
tSQLSyntaxNodeDestroy(pLeft);
|
||||
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
|||
uint8_t optr = getBinaryExprOptr(&t0);
|
||||
if (optr <= 0) {
|
||||
pError("not support binary operator:%d", t0.type);
|
||||
tSQLSyntaxNodeDestroy(pLeft);
|
||||
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -290,9 +290,9 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
|||
* if we do not get the information, in case of value of field presented first,
|
||||
* we revised the value after the binary expression is completed.
|
||||
*/
|
||||
tStrGetToken(str, i, &t0, true);
|
||||
t0 = tStrGetToken(str, i, true, 0, NULL);
|
||||
if (t0.n == 0) {
|
||||
tSQLSyntaxNodeDestroy(pLeft); // illegal expression
|
||||
tSQLSyntaxNodeDestroy(pLeft, NULL); // illegal expression
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -304,12 +304,12 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
|||
}
|
||||
|
||||
if (pRight == NULL) {
|
||||
tSQLSyntaxNodeDestroy(pLeft);
|
||||
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create binary expr as the child of new parent node */
|
||||
tSQLBinaryExpr *pBinExpr = (tSQLBinaryExpr *)malloc(sizeof(tSQLBinaryExpr));
|
||||
tSQLBinaryExpr *pBinExpr = (tSQLBinaryExpr *)calloc(1, sizeof(tSQLBinaryExpr));
|
||||
reviseBinaryExprIfNecessary(&pLeft, &pRight, &optr);
|
||||
|
||||
pBinExpr->filterOnPrimaryKey = isQueryOnPrimaryKey(pSchema[0].name, pLeft, pRight);
|
||||
|
@ -317,7 +317,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
|||
pBinExpr->pRight = pRight;
|
||||
pBinExpr->nSQLBinaryOptr = optr;
|
||||
|
||||
tStrGetToken(str, i, &t0, true);
|
||||
t0 = tStrGetToken(str, i, true, 0, NULL);
|
||||
|
||||
if (t0.n == 0 || t0.type == TK_RP) {
|
||||
tSQLSyntaxNode *pn = malloc(sizeof(tSQLSyntaxNode));
|
||||
|
@ -366,6 +366,7 @@ int32_t tSQLBinaryExprToStringImpl(tSQLSyntaxNode *pNode, char *dst, uint8_t typ
|
|||
return len;
|
||||
}
|
||||
|
||||
// TODO REFACTOR WITH SQL PARSER
|
||||
static char *tSQLOptrToString(uint8_t optr, char *dst) {
|
||||
switch (optr) {
|
||||
case TSDB_RELATION_LESS: {
|
||||
|
@ -432,13 +433,15 @@ void tSQLBinaryExprToString(tSQLBinaryExpr *pExpr, char *dst, int32_t *len) {
|
|||
*len += tSQLBinaryExprToStringImpl(pExpr->pRight, start, pExpr->pRight->nodeType);
|
||||
}
|
||||
|
||||
static void UNUSED_FUNC destroySyntaxTree(tSQLSyntaxNode *pNode) { tSQLSyntaxNodeDestroy(pNode); }
|
||||
static void UNUSED_FUNC destroySyntaxTree(tSQLSyntaxNode *pNode) { tSQLSyntaxNodeDestroy(pNode, NULL); }
|
||||
|
||||
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode) {
|
||||
if (pNode == NULL) return;
|
||||
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)) {
|
||||
if (pNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pNode->nodeType == TSQL_NODE_EXPR) {
|
||||
tSQLBinaryExprDestroy(&pNode->pExpr);
|
||||
tSQLBinaryExprDestroy(&pNode->pExpr, fp);
|
||||
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
||||
tVariantDestroy(pNode->pVal);
|
||||
}
|
||||
|
@ -446,139 +449,20 @@ static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode) {
|
|||
free(pNode);
|
||||
}
|
||||
|
||||
void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExprs) {
|
||||
if (*pExprs == NULL) return;
|
||||
|
||||
tSQLSyntaxNodeDestroy((*pExprs)->pLeft);
|
||||
tSQLSyntaxNodeDestroy((*pExprs)->pRight);
|
||||
|
||||
free(*pExprs);
|
||||
*pExprs = NULL;
|
||||
}
|
||||
|
||||
static int32_t compareIntVal(const void *pLeft, const void *pRight) {
|
||||
DEFAULT_COMP(GET_INT64_VAL(pLeft), GET_INT64_VAL(pRight));
|
||||
}
|
||||
|
||||
static int32_t compareIntDoubleVal(const void *pLeft, const void *pRight) {
|
||||
DEFAULT_COMP(GET_INT64_VAL(pLeft), GET_DOUBLE_VAL(pRight));
|
||||
}
|
||||
|
||||
static int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
|
||||
DEFAULT_COMP(GET_DOUBLE_VAL(pLeft), GET_DOUBLE_VAL(pRight));
|
||||
}
|
||||
|
||||
static int32_t compareDoubleIntVal(const void *pLeft, const void *pRight) {
|
||||
double ret = (*(double *)pLeft) - (*(int64_t *)pRight);
|
||||
if (fabs(ret) < DBL_EPSILON) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t compareStrVal(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = strcmp(pLeft, pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t compareWStrVal(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = wcscmp(pLeft, pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t compareStrPatternComp(const void *pLeft, const void *pRight) {
|
||||
SPatternCompareInfo pInfo = {'%', '_'};
|
||||
|
||||
const char *pattern = pRight;
|
||||
const char *str = pLeft;
|
||||
|
||||
if (patternMatch(pattern, str, strlen(str), &pInfo) == TSDB_PATTERN_MATCH) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t compareWStrPatternComp(const void *pLeft, const void *pRight) {
|
||||
SPatternCompareInfo pInfo = {'%', '_'};
|
||||
|
||||
const wchar_t *pattern = pRight;
|
||||
const wchar_t *str = pLeft;
|
||||
|
||||
if (WCSPatternMatch(pattern, str, wcslen(str), &pInfo) == TSDB_PATTERN_MATCH) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static __compar_fn_t getFilterComparator(int32_t type, int32_t filterType, int32_t optr) {
|
||||
__compar_fn_t comparator = NULL;
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
if (filterType >= TSDB_DATA_TYPE_BOOL && filterType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
comparator = compareIntVal;
|
||||
} else if (filterType >= TSDB_DATA_TYPE_FLOAT && filterType <= TSDB_DATA_TYPE_DOUBLE) {
|
||||
comparator = compareIntDoubleVal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
if (filterType >= TSDB_DATA_TYPE_BOOL && filterType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
comparator = compareDoubleIntVal;
|
||||
} else if (filterType >= TSDB_DATA_TYPE_FLOAT && filterType <= TSDB_DATA_TYPE_DOUBLE) {
|
||||
comparator = compareDoubleVal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
assert(filterType == TSDB_DATA_TYPE_BINARY);
|
||||
|
||||
if (optr == TSDB_RELATION_LIKE) {
|
||||
/* wildcard query using like operator */
|
||||
comparator = compareStrPatternComp;
|
||||
} else {
|
||||
/* normal relational comparator */
|
||||
comparator = compareStrVal;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
assert(filterType == TSDB_DATA_TYPE_NCHAR);
|
||||
|
||||
if (optr == TSDB_RELATION_LIKE) {
|
||||
comparator = compareWStrPatternComp;
|
||||
} else {
|
||||
comparator = compareWStrVal;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
comparator = compareIntVal;
|
||||
break;
|
||||
void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExpr, void (*fp)(void *)) {
|
||||
if (*pExpr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
return comparator;
|
||||
tSQLSyntaxNodeDestroy((*pExpr)->pLeft, fp);
|
||||
tSQLSyntaxNodeDestroy((*pExpr)->pRight, fp);
|
||||
|
||||
if (fp != NULL) {
|
||||
fp((*pExpr)->info);
|
||||
}
|
||||
|
||||
free(*pExpr);
|
||||
*pExpr = NULL;
|
||||
}
|
||||
|
||||
static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t type) {
|
||||
|
@ -619,106 +503,61 @@ static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t
|
|||
}
|
||||
}
|
||||
|
||||
static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *colInfo,
|
||||
static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *queryColInfo,
|
||||
tQueryResultset *result) {
|
||||
// primary key, search according to skiplist
|
||||
if (colInfo->colIdx == 0 && colInfo->optr != TSDB_RELATION_LIKE) {
|
||||
// primary key filter, search according to skiplist
|
||||
if (queryColInfo->colIdx == 0 && queryColInfo->optr != TSDB_RELATION_LIKE) {
|
||||
tSKipListQueryCond q;
|
||||
setInitialValueForRangeQueryCondition(&q, colInfo->q.nType);
|
||||
setInitialValueForRangeQueryCondition(&q, queryColInfo->q.nType);
|
||||
|
||||
switch (colInfo->optr) {
|
||||
switch (queryColInfo->optr) {
|
||||
case TSDB_RELATION_EQUAL: {
|
||||
result->num =
|
||||
tSkipListPointQuery(pSkipList, &colInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
|
||||
tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
case TSDB_RELATION_NOT_EQUAL: {
|
||||
result->num =
|
||||
tSkipListPointQuery(pSkipList, &colInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
|
||||
tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
case TSDB_RELATION_LESS_EQUAL: {
|
||||
tVariantAssign(&q.upperBnd, &colInfo->q);
|
||||
q.upperBndRelOptr = colInfo->optr;
|
||||
tVariantAssign(&q.upperBnd, &queryColInfo->q);
|
||||
q.upperBndRelOptr = queryColInfo->optr;
|
||||
result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
case TSDB_RELATION_LESS: {
|
||||
tVariantAssign(&q.upperBnd, &colInfo->q);
|
||||
tVariantAssign(&q.upperBnd, &queryColInfo->q);
|
||||
result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
case TSDB_RELATION_LARGE: {
|
||||
tVariantAssign(&q.lowerBnd, &colInfo->q);
|
||||
tVariantAssign(&q.lowerBnd, &queryColInfo->q);
|
||||
result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
case TSDB_RELATION_LARGE_EQUAL: {
|
||||
tVariantAssign(&q.lowerBnd, &colInfo->q);
|
||||
q.lowerBndRelOptr = colInfo->optr;
|
||||
tVariantAssign(&q.lowerBnd, &queryColInfo->q);
|
||||
q.lowerBndRelOptr = queryColInfo->optr;
|
||||
result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, colInfo->optr);
|
||||
pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, queryColInfo->optr);
|
||||
}
|
||||
|
||||
tSkipListDestroyKey(&q.upperBnd);
|
||||
tSkipListDestroyKey(&q.lowerBnd);
|
||||
} else {
|
||||
// brutal force search
|
||||
result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, colInfo);
|
||||
/*
|
||||
* Brutal force scan the whole skiplit to find the appropriate result,
|
||||
* since the filter is not applied to indexed column.
|
||||
*/
|
||||
result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void tSQLListTraversePrepare(tQueryInfo *colInfo, SSchema *pSchema, int32_t numOfCols, SSchema *pOneColSchema,
|
||||
uint8_t optr, tVariant *val) {
|
||||
int32_t i = 0, offset = 0;
|
||||
if (strcasecmp(pOneColSchema->name, TSQL_TBNAME_L) == 0) {
|
||||
i = -1;
|
||||
offset = -1;
|
||||
} else {
|
||||
while (i < numOfCols) {
|
||||
if (pSchema[i].bytes == pOneColSchema->bytes && pSchema[i].type == pOneColSchema->type &&
|
||||
strcmp(pSchema[i].name, pOneColSchema->name) == 0) {
|
||||
break;
|
||||
} else {
|
||||
offset += pSchema[i++].bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
colInfo->pSchema = pSchema;
|
||||
colInfo->colIdx = i;
|
||||
colInfo->optr = optr;
|
||||
colInfo->offset = offset;
|
||||
colInfo->comparator = getFilterComparator(pOneColSchema->type, val->nType, optr);
|
||||
|
||||
if (colInfo->pSchema[i].type != val->nType) {
|
||||
/* convert the query string to be inline with the data type of the queried tags */
|
||||
if (colInfo->pSchema[i].type == TSDB_DATA_TYPE_NCHAR && val->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
colInfo->q.nLen = TSDB_MAX_TAGS_LEN / TSDB_NCHAR_SIZE;
|
||||
|
||||
colInfo->q.wpz = calloc(1, TSDB_MAX_TAGS_LEN);
|
||||
colInfo->q.nType = TSDB_DATA_TYPE_NCHAR;
|
||||
|
||||
taosMbsToUcs4(val->pz, val->nLen, (char *)colInfo->q.wpz, TSDB_MAX_TAGS_LEN);
|
||||
colInfo->q.nLen = wcslen(colInfo->q.wpz) + 1;
|
||||
return;
|
||||
} else if (colInfo->pSchema[i].type == TSDB_DATA_TYPE_BINARY && val->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
colInfo->q.nLen = TSDB_MAX_TAGS_LEN;
|
||||
colInfo->q.pz = calloc(1, TSDB_MAX_TAGS_LEN);
|
||||
colInfo->q.nType = TSDB_DATA_TYPE_BINARY;
|
||||
|
||||
taosUcs4ToMbs(val->wpz, val->nLen, colInfo->q.pz);
|
||||
colInfo->q.nLen = strlen(colInfo->q.pz) + 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
tVariantAssign(&colInfo->q, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* qsort comparator
|
||||
* sort the result to ensure meters with the same gid is grouped together
|
||||
|
@ -731,7 +570,9 @@ static int32_t compareByAddr(const void *pLeft, const void *pRight) {
|
|||
}
|
||||
|
||||
int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) {
|
||||
pFinalRes->pRes = malloc(POINTER_BYTES * (pLeft->num + pRight->num));
|
||||
assert(pFinalRes->pRes == 0);
|
||||
|
||||
pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES);
|
||||
pFinalRes->num = 0;
|
||||
|
||||
// sort according to address
|
||||
|
@ -742,6 +583,7 @@ int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *
|
|||
qsort(pRightNodes, pRight->num, sizeof(pRight->pRes[0]), compareByAddr);
|
||||
|
||||
int32_t i = 0, j = 0;
|
||||
|
||||
// merge two sorted arrays in O(n) time
|
||||
while (i < pLeft->num && j < pRight->num) {
|
||||
int64_t ret = (int64_t)pLeftNodes[i] - (int64_t)pRightNodes[j];
|
||||
|
@ -770,7 +612,9 @@ int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *
|
|||
int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) {
|
||||
int64_t num = MIN(pLeft->num, pRight->num);
|
||||
|
||||
pFinalRes->pRes = malloc(POINTER_BYTES * num);
|
||||
assert(pFinalRes->pRes == 0);
|
||||
|
||||
pFinalRes->pRes = calloc(num, POINTER_BYTES);
|
||||
pFinalRes->num = 0;
|
||||
|
||||
// sort according to address
|
||||
|
@ -802,14 +646,14 @@ int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResults
|
|||
/*
|
||||
*
|
||||
*/
|
||||
void tSQLListTraverseOnResult(struct tSQLBinaryExpr *pExpr, bool (*fp)(tSkipListNode *, void *), tQueryInfo *colInfo,
|
||||
tQueryResultset *pResult) {
|
||||
void tSQLListTraverseOnResult(struct tSQLBinaryExpr *pExpr, bool (*fp)(tSkipListNode *, void *),
|
||||
tQueryResultset * pResult) {
|
||||
assert(pExpr->pLeft->nodeType == TSQL_NODE_COL && pExpr->pRight->nodeType == TSQL_NODE_VALUE);
|
||||
|
||||
// brutal force search
|
||||
int32_t num = pResult->num;
|
||||
int64_t num = pResult->num;
|
||||
for (int32_t i = 0, j = 0; i < pResult->num; ++i) {
|
||||
if (fp == NULL || (fp != NULL && fp(pResult->pRes[i], colInfo) == true)) {
|
||||
if (fp == NULL || (fp != NULL && fp(pResult->pRes[i], pExpr->info) == true)) {
|
||||
pResult->pRes[j++] = pResult->pRes[i];
|
||||
} else {
|
||||
num--;
|
||||
|
@ -819,32 +663,118 @@ void tSQLListTraverseOnResult(struct tSQLBinaryExpr *pExpr, bool (*fp)(tSkipList
|
|||
pResult->num = num;
|
||||
}
|
||||
|
||||
// post-root order traverse syntax tree
|
||||
void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExprs, tSkipList *pSkipList, SSchema *pSchema, int32_t numOfCols,
|
||||
bool (*fp)(tSkipListNode *, void *), tQueryResultset *result) {
|
||||
if (pExprs == NULL) return;
|
||||
static bool filterItem(tSQLBinaryExpr *pExpr, const void *pItem, SBinaryFilterSupp *param) {
|
||||
tSQLSyntaxNode *pLeft = pExpr->pLeft;
|
||||
tSQLSyntaxNode *pRight = pExpr->pRight;
|
||||
|
||||
tSQLSyntaxNode *pLeft = pExprs->pLeft;
|
||||
tSQLSyntaxNode *pRight = pExprs->pRight;
|
||||
/*
|
||||
* non-leaf nodes, recursively traverse the syntax tree in the post-root order
|
||||
*/
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR && pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
if (pExpr->nSQLBinaryOptr == TSDB_RELATION_OR) { // or
|
||||
if (filterItem(pLeft->pExpr, pItem, param)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// left child does not satisfy the query condition, try right child
|
||||
return filterItem(pRight->pExpr, pItem, param);
|
||||
} else { // and
|
||||
if (!filterItem(pLeft->pExpr, pItem, param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return filterItem(pRight->pExpr, pItem, param);
|
||||
}
|
||||
}
|
||||
|
||||
// handle the leaf node
|
||||
assert(pLeft->nodeType == TSQL_NODE_COL && pRight->nodeType == TSQL_NODE_VALUE);
|
||||
param->setupInfoFn(pExpr, param->pExtInfo);
|
||||
|
||||
return param->fp(pItem, pExpr->info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the filter expression on non-indexed tag columns to each element in the result list, which is generated
|
||||
* by filtering on indexed tag column. So the whole result set only needs to be iterated once to generate
|
||||
* result that is satisfied to the filter expression, no matter how the filter expression consisting of.
|
||||
*
|
||||
* @param pExpr filter expression on non-indexed tag columns.
|
||||
* @param pResult results from filter on the indexed tag column, which is usually the first tag column
|
||||
* @param pSchema tag schemas
|
||||
* @param fp filter callback function
|
||||
*/
|
||||
static void tSQLBinaryTraverseOnResult(tSQLBinaryExpr *pExpr, tQueryResultset *pResult, SBinaryFilterSupp *param) {
|
||||
int32_t n = 0;
|
||||
for (int32_t i = 0; i < pResult->num; ++i) {
|
||||
void *pItem = pResult->pRes[i];
|
||||
|
||||
if (filterItem(pExpr, pItem, param)) {
|
||||
pResult->pRes[n++] = pResult->pRes[i];
|
||||
}
|
||||
}
|
||||
|
||||
pResult->num = n;
|
||||
}
|
||||
|
||||
static void tSQLBinaryTraverseOnSkipList(tSQLBinaryExpr *pExpr, tQueryResultset *pResult, tSkipList *pSkipList,
|
||||
SBinaryFilterSupp *param) {
|
||||
int32_t n = 0;
|
||||
SSkipListIterator iter = {0};
|
||||
|
||||
int32_t ret = tSkipListIteratorReset(pSkipList, &iter);
|
||||
assert(ret == 0);
|
||||
|
||||
pResult->pRes = calloc(pSkipList->nSize, POINTER_BYTES);
|
||||
|
||||
while (tSkipListIteratorNext(&iter)) {
|
||||
tSkipListNode *pNode = tSkipListIteratorGet(&iter);
|
||||
if (filterItem(pExpr, pNode, param)) {
|
||||
pResult->pRes[n++] = pNode;
|
||||
}
|
||||
}
|
||||
|
||||
pResult->num = n;
|
||||
}
|
||||
|
||||
// post-root order traverse syntax tree
|
||||
void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExpr, tSkipList *pSkipList, tQueryResultset *result,
|
||||
SBinaryFilterSupp *param) {
|
||||
if (pExpr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tSQLSyntaxNode *pLeft = pExpr->pLeft;
|
||||
tSQLSyntaxNode *pRight = pExpr->pRight;
|
||||
|
||||
// recursive traverse left child branch
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
uint8_t weight = pLeft->pExpr->filterOnPrimaryKey + pRight->pExpr->filterOnPrimaryKey;
|
||||
|
||||
if (weight == 0 && result->num > 0 && pSkipList == NULL) {
|
||||
/* base on the initial filter result to perform the secondary filter */
|
||||
tSQLBinaryExprTraverse(pLeft->pExpr, pSkipList, pSchema, numOfCols, fp, result);
|
||||
tSQLBinaryExprTraverse(pRight->pExpr, pSkipList, pSchema, numOfCols, fp, result);
|
||||
} else if (weight == 0 || weight == 2 || (weight == 1 && pExprs->nSQLBinaryOptr == TSDB_RELATION_OR)) {
|
||||
/**
|
||||
* Perform the filter operation based on the initial filter result, which is obtained from filtering from index.
|
||||
* Since no index presented, the filter operation is done by scan all elements in the result set.
|
||||
*
|
||||
* if the query is a high selectivity filter, only small portion of meters are retrieved.
|
||||
*/
|
||||
tSQLBinaryTraverseOnResult(pExpr, result, param);
|
||||
} else if (weight == 0) {
|
||||
/**
|
||||
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
|
||||
*/
|
||||
assert(result->num == 0);
|
||||
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
|
||||
} else if (weight == 2 || (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_OR)) {
|
||||
tQueryResultset rLeft = {0};
|
||||
tQueryResultset rRight = {0};
|
||||
|
||||
tSQLBinaryExprTraverse(pLeft->pExpr, pSkipList, pSchema, numOfCols, fp, &rLeft);
|
||||
tSQLBinaryExprTraverse(pRight->pExpr, pSkipList, pSchema, numOfCols, fp, &rRight);
|
||||
tSQLBinaryExprTraverse(pLeft->pExpr, pSkipList, &rLeft, param);
|
||||
tSQLBinaryExprTraverse(pRight->pExpr, pSkipList, &rRight, param);
|
||||
|
||||
if (pExprs->nSQLBinaryOptr == TSDB_RELATION_AND) { // CROSS
|
||||
if (pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) { // CROSS
|
||||
intersect(&rLeft, &rRight, result);
|
||||
} else if (pExprs->nSQLBinaryOptr == TSDB_RELATION_OR) { // or
|
||||
} else if (pExpr->nSQLBinaryOptr == TSDB_RELATION_OR) { // or
|
||||
merge(&rLeft, &rRight, result);
|
||||
} else {
|
||||
assert(false);
|
||||
|
@ -854,43 +784,44 @@ void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExprs, tSkipList *pSkipList, SSchem
|
|||
free(rRight.pRes);
|
||||
} else {
|
||||
/*
|
||||
* first, we filter results based on the skiplist index, which is initial filter stage,
|
||||
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
|
||||
*
|
||||
* first, we filter results based on the skiplist index, which is the initial filter stage,
|
||||
* then, we conduct the secondary filter operation based on the result from the initial filter stage.
|
||||
*/
|
||||
if (pExprs->nSQLBinaryOptr == TSDB_RELATION_AND) {
|
||||
tSQLBinaryExpr *pFirst = (pLeft->pExpr->filterOnPrimaryKey == 1) ? pLeft->pExpr : pRight->pExpr;
|
||||
tSQLBinaryExpr *pSec = (pLeft->pExpr->filterOnPrimaryKey == 1) ? pRight->pExpr : pLeft->pExpr;
|
||||
assert(pFirst != pSec && pFirst != NULL && pSec != NULL);
|
||||
assert(pExpr->nSQLBinaryOptr == TSDB_RELATION_AND);
|
||||
|
||||
// we filter the result based on the skiplist index
|
||||
tSQLBinaryExprTraverse(pFirst, pSkipList, pSchema, numOfCols, fp, result);
|
||||
|
||||
/*
|
||||
* recursively perform the filter operation based on the initial results,
|
||||
* So, we do not set the skiplist index as a parameter
|
||||
*/
|
||||
tSQLBinaryExprTraverse(pSec, NULL, pSchema, numOfCols, fp, result);
|
||||
tSQLBinaryExpr *pFirst = NULL;
|
||||
tSQLBinaryExpr *pSecond = NULL;
|
||||
if (pLeft->pExpr->filterOnPrimaryKey == 1) {
|
||||
pFirst = pLeft->pExpr;
|
||||
pSecond = pRight->pExpr;
|
||||
} else {
|
||||
assert(false);
|
||||
pFirst = pRight->pExpr;
|
||||
pSecond = pLeft->pExpr;
|
||||
}
|
||||
}
|
||||
|
||||
assert(pFirst != pSecond && pFirst != NULL && pSecond != NULL);
|
||||
|
||||
// we filter the result based on the skiplist index in the first place
|
||||
tSQLBinaryExprTraverse(pFirst, pSkipList, result, param);
|
||||
|
||||
/*
|
||||
* recursively perform the filter operation based on the initial results,
|
||||
* So, we do not set the skiplist index as a parameter
|
||||
*/
|
||||
tSQLBinaryExprTraverse(pSecond, NULL, result, param);
|
||||
}
|
||||
} else { // column project
|
||||
assert(pLeft->nodeType == TSQL_NODE_COL && pRight->nodeType == TSQL_NODE_VALUE);
|
||||
tVariant *pCond = pRight->pVal;
|
||||
SSchema * pTagSchema = pLeft->pSchema;
|
||||
|
||||
tQueryInfo queryColInfo = {0};
|
||||
tSQLListTraversePrepare(&queryColInfo, pSchema, numOfCols, pTagSchema, pExprs->nSQLBinaryOptr, pCond);
|
||||
|
||||
param->setupInfoFn(pExpr, param->pExtInfo);
|
||||
if (pSkipList == NULL) {
|
||||
tSQLListTraverseOnResult(pExprs, fp, &queryColInfo, result);
|
||||
tSQLListTraverseOnResult(pExpr, param->fp, result);
|
||||
} else {
|
||||
assert(result->num == 0);
|
||||
tSQLDoFilterInitialResult(pSkipList, fp, &queryColInfo, result);
|
||||
tSQLDoFilterInitialResult(pSkipList, param->fp, pExpr->info, result);
|
||||
}
|
||||
|
||||
tVariantDestroy(&queryColInfo.q);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -916,9 +847,11 @@ void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char
|
|||
}
|
||||
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) { // exprLeft + exprRight
|
||||
/* the type of returned value of one expression is always double float
|
||||
* precious */
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
/*
|
||||
* exprLeft + exprRight
|
||||
* the type of returned value of one expression is always double float precious
|
||||
*/
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_DOUBLE, pExprs->nSQLBinaryOptr);
|
||||
fp(pLeftOutput, pRightOutput, numOfRows, numOfRows, pOutput, order);
|
||||
|
||||
|
@ -958,7 +891,7 @@ void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char
|
|||
|
||||
} else if (pRight->nodeType == TSQL_NODE_COL) { // 12 + columnRight
|
||||
// column data specified on right-hand-side
|
||||
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->colId);
|
||||
char * pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->colId);
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pVal->nType, pRight->pSchema->type, pExprs->nSQLBinaryOptr);
|
||||
fp(&pLeft->pVal->i64Key, pRightInputData, 1, numOfRows, pOutput, order);
|
||||
|
||||
|
@ -994,4 +927,13 @@ void tSQLBinaryExprTrv(tSQLBinaryExpr *pExprs, int32_t *val, int16_t *ids) {
|
|||
ids[*val] = pRight->pSchema->colId;
|
||||
(*val) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void tQueryResultClean(tQueryResultset *pRes) {
|
||||
if (pRes == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tfree(pRes->pRes);
|
||||
pRes->num = 0;
|
||||
}
|
|
@ -40,7 +40,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
|
|||
*/
|
||||
static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *, TAOS_RES *, int), void *param) {
|
||||
void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *, int), void *param) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
tscError("bug!!! pObj:%p", pObj);
|
||||
|
@ -72,13 +72,14 @@ void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *, TAOS_RES *, int),
|
|||
pSql->fp = fp;
|
||||
pSql->param = param;
|
||||
|
||||
if (tscAllocPayloadWithSize(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) {
|
||||
tscError("%p failed to alloc payload", pSql);
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
|
||||
tscError("failed to malloc payload");
|
||||
tfree(pSql);
|
||||
tscQueueAsyncError(fp, param);
|
||||
free(pSql);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
pSql->sqlstr = malloc(sqlLen + 1);
|
||||
if (pSql->sqlstr == NULL) {
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
|
@ -116,9 +117,9 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
|
|||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
// sequentially retrieve data from remain vnodes first, query vnode specified by vnodeIdx
|
||||
if (numOfRows == 0 && tscProjectionQueryOnMetric(pSql)) {
|
||||
if (numOfRows == 0 && tscProjectionQueryOnMetric(pCmd)) {
|
||||
// vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx
|
||||
assert(pCmd->vnodeIdx >= 1);
|
||||
assert(pCmd->vnodeIdx >= 0);
|
||||
|
||||
/* reach the maximum number of output rows, abort */
|
||||
if (pCmd->globalLimit > 0 && pRes->numOfTotal >= pCmd->globalLimit) {
|
||||
|
@ -128,14 +129,14 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
|
|||
|
||||
/* update the limit value according to current retrieval results */
|
||||
pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
|
||||
pCmd->limit.offset = pRes->offset;
|
||||
|
||||
if ((++(pSql->cmd.vnodeIdx)) <= pCmd->pMetricMeta->numOfVnodes) {
|
||||
pCmd->command = TSDB_SQL_SELECT; // reset flag to launch query first.
|
||||
if ((++(pCmd->vnodeIdx)) < tscGetMeterMetaInfo(pCmd, 0)->pMetricMeta->numOfVnodes) {
|
||||
tscTrace("%p retrieve data from next vnode:%d", pSql, pCmd->vnodeIdx);
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
pSql->cmd.command = TSDB_SQL_SELECT; // reset flag to launch query first.
|
||||
|
||||
tscResetForNextRetrieve(pRes);
|
||||
pSql->fp = tscProcessAsyncRetrieveNextVnode;
|
||||
tscProcessSql(pSql);
|
||||
return;
|
||||
|
@ -213,14 +214,12 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
|
|||
pSql->fp = tscProcessAsyncFetchRowsProxy;
|
||||
|
||||
pSql->param = param;
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
tscResetForNextRetrieve(pRes);
|
||||
|
||||
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC && pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
}
|
||||
|
||||
|
@ -246,9 +245,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
|
|||
pSql->param = param;
|
||||
|
||||
if (pRes->row >= pRes->numOfRows) {
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
tscResetForNextRetrieve(pRes);
|
||||
pSql->fp = tscProcessAsyncRetrieve;
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
tscProcessSql(pSql);
|
||||
|
@ -269,7 +266,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
|
|||
|
||||
if (numOfRows == 0) {
|
||||
// sequentially retrieve data from remain vnodes.
|
||||
if (tscProjectionQueryOnMetric(pSql)) {
|
||||
if (tscProjectionQueryOnMetric(pCmd)) {
|
||||
/*
|
||||
* vnode is denoted by vnodeIdx, continue to query vnode specified by vnodeIdx till all vnode have been retrieved
|
||||
*/
|
||||
|
@ -284,13 +281,10 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
|
|||
/* update the limit value according to current retrieval results */
|
||||
pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
|
||||
|
||||
if ((++pCmd->vnodeIdx) <= pCmd->pMetricMeta->numOfVnodes) {
|
||||
pCmd->command = TSDB_SQL_SELECT; // reset flag to launch query first.
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
if ((++pCmd->vnodeIdx) <= tscGetMeterMetaInfo(pCmd, 0)->pMetricMeta->numOfVnodes) {
|
||||
pSql->cmd.command = TSDB_SQL_SELECT; // reset flag to launch query first.
|
||||
|
||||
tscResetForNextRetrieve(pRes);
|
||||
pSql->fp = tscProcessAsyncContinueRetrieve;
|
||||
tscProcessSql(pSql);
|
||||
return;
|
||||
|
@ -463,10 +457,10 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
tsem_post(&pSql->rspSem);
|
||||
} else {
|
||||
tscTrace("%p renew meterMeta successfully, command:%d, code:%d, thandle:%p, retry:%d",
|
||||
pSql, pSql->cmd.command, pSql->res.code, pSql->thandle, pSql->retry);
|
||||
pSql, pSql->cmd.command, pSql->res.code, pSql->thandle, pSql->retry);
|
||||
|
||||
assert(pSql->cmd.pMeterMeta == NULL);
|
||||
tscGetMeterMeta(pSql, pSql->cmd.name);
|
||||
assert(tscGetMeterMetaInfo(&pSql->cmd, 0)->pMeterMeta == NULL);
|
||||
tscGetMeterMeta(pSql, tscGetMeterMetaInfo(&pSql->cmd, 0)->name, 0);
|
||||
|
||||
code = tscSendMsgToServer(pSql);
|
||||
if (code != 0) {
|
||||
|
@ -486,21 +480,23 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
if (pSql->pStream == NULL) {
|
||||
// check if it is a sub-query of metric query first, if true, enter another routine
|
||||
// todo refactor
|
||||
if (pSql->fp == tscRetrieveDataRes || pSql->fp == tscRetrieveFromVnodeCallBack) {
|
||||
assert(pCmd->pMeterMeta->numOfTags != 0 && pCmd->vnodeIdx > 0 && pSql->param != NULL);
|
||||
if ((pSql->cmd.type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) == TSDB_QUERY_TYPE_STABLE_SUBQUERY) {
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
assert(pMeterMetaInfo->pMeterMeta->numOfTags != 0 && pCmd->vnodeIdx >= 0 && pSql->param != NULL);
|
||||
|
||||
SRetrieveSupport *trs = (SRetrieveSupport *)pSql->param;
|
||||
SSqlObj * pParObj = trs->pParentSqlObj;
|
||||
assert(pParObj->signature == pParObj && trs->vnodeIdx == pCmd->vnodeIdx && pSql->cmd.pMeterMeta->numOfTags != 0);
|
||||
assert(pParObj->signature == pParObj && trs->vnodeIdx == pCmd->vnodeIdx &&
|
||||
pMeterMetaInfo->pMeterMeta->numOfTags != 0);
|
||||
|
||||
tscTrace("%p get metricMeta during metric query successfully", pSql);
|
||||
|
||||
code = tscGetMeterMeta(pSql, pSql->cmd.name);
|
||||
code = tscGetMeterMeta(pSql, tscGetMeterMetaInfo(&pSql->cmd, 0)->name, 0);
|
||||
pRes->code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
||||
code = tscGetMetricMeta(pSql, pSql->cmd.name);
|
||||
code = tscGetMetricMeta(pSql);
|
||||
pRes->code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
@ -508,14 +504,17 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
code = tsParseSql(pSql, pObj->acctId, pObj->db, false);
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
}
|
||||
|
||||
} else { // stream computing
|
||||
code = tscGetMeterMeta(pSql, pSql->cmd.name);
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
code = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0);
|
||||
pRes->code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS && UTIL_METER_IS_METRIC(pCmd)) {
|
||||
code = tscGetMetricMeta(pSql, pSql->cmd.name);
|
||||
pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
if (code == TSDB_CODE_SUCCESS && UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
code = tscGetMetricMeta(pSql);
|
||||
pRes->code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
|
|
@ -102,7 +102,12 @@ void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, short port, ch
|
|||
|
||||
pObj = (SConnCache *)handle;
|
||||
if (pObj == NULL || pObj->maxSessions == 0) return NULL;
|
||||
|
||||
#ifdef CLUSTER
|
||||
if (data == NULL || ip == 0) {
|
||||
#else
|
||||
if (data == NULL) {
|
||||
#endif
|
||||
tscTrace("data:%p ip:%p:%d not valid, not added in cache", data, ip, port);
|
||||
return NULL;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -16,8 +16,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <taos.h>
|
||||
#include <tsclient.h>
|
||||
#include "taosmsg.h"
|
||||
|
||||
#include "tcache.h"
|
||||
|
@ -40,11 +38,31 @@ static int32_t getToStringLength(char *pData, int32_t length, int32_t type) {
|
|||
return length;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
return length;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
#ifdef _TD_ARM_32_
|
||||
double dv = 0;
|
||||
*(int64_t*)(&dv) = *(int64_t*)pData;
|
||||
len = sprintf(buf, "%f", dv);
|
||||
#else
|
||||
len = sprintf(buf, "%lf", *(double *)pData);
|
||||
#endif
|
||||
if (strncasecmp("nan", buf, 3) == 0) {
|
||||
len = 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
#ifdef _TD_ARM_32_
|
||||
float fv = 0;
|
||||
*(int32_t*)(&fv) = *(int32_t*)pData;
|
||||
len = sprintf(buf, "%f", fv);
|
||||
#else
|
||||
len = sprintf(buf, "%f", *(float *)pData);
|
||||
#endif
|
||||
if (strncasecmp("nan", buf, 3) == 0) {
|
||||
len = 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
|
@ -69,9 +87,10 @@ static int32_t getToStringLength(char *pData, int32_t length, int32_t type) {
|
|||
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
|
||||
*/
|
||||
static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) {
|
||||
SMeterMeta *pMeta = pSql->cmd.pMeterMeta;
|
||||
SMeterMeta *pMeta = tscGetMeterMetaInfo(&pSql->cmd, 0)->pMeterMeta;
|
||||
|
||||
if (pMeta->meterType != TSDB_METER_MTABLE) {
|
||||
if (pMeta->meterType == TSDB_METER_METRIC || pMeta->meterType == TSDB_METER_OTABLE ||
|
||||
pMeta->meterType == TSDB_METER_STABLE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -97,8 +116,9 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
// one column for each row
|
||||
SSqlCmd * pCmd = &pSql->cmd;
|
||||
SMeterMeta *pMeta = pCmd->pMeterMeta;
|
||||
SSqlCmd * pCmd = &pSql->cmd;
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
SMeterMeta * pMeta = pMeterMetaInfo->pMeterMeta;
|
||||
|
||||
/*
|
||||
* tagValueCnt is to denote the number of tags columns for meter, not metric. and is to show the column data.
|
||||
|
@ -109,7 +129,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
int32_t numOfRows = pMeta->numOfColumns;
|
||||
int32_t totalNumOfRows = numOfRows + pMeta->numOfTags;
|
||||
|
||||
if (UTIL_METER_IS_METRIC(pCmd)) {
|
||||
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
numOfRows = pMeta->numOfColumns + pMeta->numOfTags;
|
||||
}
|
||||
|
||||
|
@ -141,7 +161,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
}
|
||||
}
|
||||
|
||||
if (UTIL_METER_IS_METRIC(pCmd)) {
|
||||
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -182,11 +202,25 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
case TSDB_DATA_TYPE_NCHAR:
|
||||
taosUcs4ToMbs(pTagValue, pSchema[i].bytes, target);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
#ifdef _TD_ARM_32_
|
||||
float fv = 0;
|
||||
*(int32_t*)(&fv) = *(int32_t*)pTagValue;
|
||||
sprintf(target, "%f", fv);
|
||||
#else
|
||||
sprintf(target, "%f", *(float *)pTagValue);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
#ifdef _TD_ARM_32_
|
||||
double dv = 0;
|
||||
*(int64_t*)(&dv) = *(int64_t*)pTagValue;
|
||||
sprintf(target, "%lf", dv);
|
||||
#else
|
||||
sprintf(target, "%lf", *(double *)pTagValue);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
sprintf(target, "%d", *(int8_t *)pTagValue);
|
||||
|
@ -240,7 +274,7 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
|||
}
|
||||
|
||||
static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||
assert(pSql->cmd.pMeterMeta != NULL);
|
||||
assert(tscGetMeterMetaInfo(&pSql->cmd, 0)->pMeterMeta != NULL);
|
||||
|
||||
const int32_t NUM_OF_DESCRIBE_TABLE_COLUMNS = 4;
|
||||
const int32_t TYPE_COLUMN_LENGTH = 16;
|
||||
|
@ -261,15 +295,17 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
|||
static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
||||
// the result structure has been completed in sql parse, so we
|
||||
// only need to reorganize the results in the column format
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd * pCmd = &pSql->cmd;
|
||||
SSqlRes * pRes = &pSql->res;
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
SMetricMeta *pMetricMeta = pCmd->pMetricMeta;
|
||||
SSchema * pSchema = tsGetTagSchema(pCmd->pMeterMeta);
|
||||
SMetricMeta *pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
||||
SSchema * pSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta);
|
||||
|
||||
int32_t vOffset[TSDB_MAX_COLUMNS] = {0};
|
||||
for (int32_t f = 1; f < pCmd->numOfReqTags; ++f) {
|
||||
int16_t tagColumnIndex = pCmd->tagColumnIndex[f - 1];
|
||||
|
||||
for (int32_t f = 1; f < pMeterMetaInfo->numOfTags; ++f) {
|
||||
int16_t tagColumnIndex = pMeterMetaInfo->tagColumnIndex[f - 1];
|
||||
if (tagColumnIndex == -1) {
|
||||
vOffset[f] = vOffset[f - 1] + TSDB_METER_NAME_LEN;
|
||||
} else {
|
||||
|
@ -290,10 +326,10 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
SMeterSidExtInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
|
||||
|
||||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SColIndex *pColIndex = &tscSqlExprGet(pCmd, k)->colInfo;
|
||||
int32_t offsetId = pColIndex->colIdx;
|
||||
SColIndexEx *pColIndex = &tscSqlExprGet(pCmd, k)->colInfo;
|
||||
int16_t offsetId = pColIndex->colIdx;
|
||||
|
||||
assert(pColIndex->isTag);
|
||||
assert((pColIndex->flag & TSDB_COL_TAG) != 0);
|
||||
|
||||
char * val = pSidExt->tags + vOffset[offsetId];
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, k);
|
||||
|
@ -312,7 +348,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
|||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
SMetricMeta *pMetricMeta = pCmd->pMetricMeta;
|
||||
SMetricMeta *pMetricMeta = tscGetMeterMetaInfo(pCmd, 0)->pMetricMeta;
|
||||
int32_t totalNumOfResults = 1; // count function only produce one result
|
||||
int32_t rowLen = tscGetResRowLength(pCmd);
|
||||
|
||||
|
@ -323,7 +359,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
|||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
||||
|
||||
if (pExpr->colInfo.colIdx == -1 && pExpr->sqlFuncId == TSDB_FUNC_COUNT) {
|
||||
if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, k);
|
||||
|
||||
memcpy(pRes->data + tscFieldInfoGetOffset(pCmd, i) * totalNumOfResults + pField->bytes * rowIdx,
|
||||
|
@ -342,7 +378,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
|||
static int tscProcessQueryTags(SSqlObj *pSql) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
SMeterMeta *pMeterMeta = pCmd->pMeterMeta;
|
||||
SMeterMeta *pMeterMeta = tscGetMeterMetaInfo(pCmd, 0)->pMeterMeta;
|
||||
if (pMeterMeta == NULL || pMeterMeta->numOfTags == 0 || pMeterMeta->numOfColumns == 0) {
|
||||
strcpy(pCmd->payload, "invalid table");
|
||||
pSql->res.code = TSDB_CODE_INVALID_TABLE;
|
||||
|
@ -350,7 +386,7 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, 0);
|
||||
if (pExpr->sqlFuncId == TSDB_FUNC_COUNT) {
|
||||
if (pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
return tscBuildMetricTagSqlFunctionResult(pSql);
|
||||
} else {
|
||||
return tscBuildMetricTagProjectionResult(pSql);
|
||||
|
@ -367,7 +403,11 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
|
|||
} else if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) {
|
||||
pSql->res.code = (uint8_t)tscProcessQueryTags(pSql);
|
||||
} else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
|
||||
pSql->res.qhandle = 0x1; // pass the qhandle check
|
||||
/*
|
||||
* pass the qhandle check, in order to call partial release function to
|
||||
* free allocated resources and remove the SqlObj from linked list
|
||||
*/
|
||||
pSql->res.qhandle = 0x1; // pass the qhandle check
|
||||
pSql->res.numOfRows = 0;
|
||||
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
||||
taosClearDataCache(tscCacheHandle);
|
||||
|
@ -376,7 +416,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
|
|||
tscError("%p not support command:%d", pSql, pCmd->command);
|
||||
}
|
||||
|
||||
//keep the code in local variable in order to avoid invalid read in case of async query
|
||||
// keep the code in local variable in order to avoid invalid read in case of async query
|
||||
int32_t code = pSql->res.code;
|
||||
|
||||
if (pSql->fp != NULL) { // callback function
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,599 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "taos.h"
|
||||
#include "tsclient.h"
|
||||
#include "tsql.h"
|
||||
#include "tscUtil.h"
|
||||
#include "ttimer.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tstrbuild.h"
|
||||
|
||||
|
||||
int tsParseInsertSql(SSqlObj *pSql, char *sql, char *acct, char *db);
|
||||
int taos_query_imp(STscObj* pObj, SSqlObj* pSql);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// functions for normal statement preparation
|
||||
|
||||
typedef struct SNormalStmtPart {
|
||||
bool isParam;
|
||||
uint32_t len;
|
||||
char* str;
|
||||
} SNormalStmtPart;
|
||||
|
||||
typedef struct SNormalStmt {
|
||||
uint16_t sizeParts;
|
||||
uint16_t numParts;
|
||||
uint16_t numParams;
|
||||
char* sql;
|
||||
SNormalStmtPart* parts;
|
||||
tVariant* params;
|
||||
} SNormalStmt;
|
||||
|
||||
//typedef struct SInsertStmt {
|
||||
//
|
||||
//} SInsertStmt;
|
||||
|
||||
typedef struct STscStmt {
|
||||
bool isInsert;
|
||||
STscObj* taos;
|
||||
SSqlObj* pSql;
|
||||
SNormalStmt normal;
|
||||
} STscStmt;
|
||||
|
||||
|
||||
static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_t len) {
|
||||
uint16_t size = stmt->numParts + 1;
|
||||
if (size > stmt->sizeParts) {
|
||||
size *= 2;
|
||||
void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
stmt->sizeParts = size;
|
||||
stmt->parts = (SNormalStmtPart*)tmp;
|
||||
}
|
||||
|
||||
stmt->parts[stmt->numParts].isParam = isParam;
|
||||
stmt->parts[stmt->numParts].str = str;
|
||||
stmt->parts[stmt->numParts].len = len;
|
||||
|
||||
++stmt->numParts;
|
||||
if (isParam) {
|
||||
++stmt->numParams;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
|
||||
SNormalStmt* normal = &stmt->normal;
|
||||
|
||||
for (uint16_t i = 0; i < normal->numParams; ++i) {
|
||||
TAOS_BIND* tb = bind + i;
|
||||
tVariant* var = normal->params + i;
|
||||
tVariantDestroy(var);
|
||||
|
||||
var->nLen = 0;
|
||||
if (tb->is_null != NULL && *(tb->is_null)) {
|
||||
var->nType = TSDB_DATA_TYPE_NULL;
|
||||
var->i64Key = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
var->nType = tb->buffer_type;
|
||||
switch (tb->buffer_type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
var->i64Key = 0;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
var->i64Key = (*(int8_t*)tb->buffer) ? 1 : 0;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
var->i64Key = *(int8_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
var->i64Key = *(int16_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
var->i64Key = *(int32_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
var->i64Key = *(int64_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
var->dKey = *(float*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
var->dKey = *(double*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
var->pz = (char*)malloc((*tb->length) + 1);
|
||||
if (var->pz == NULL) {
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(var->pz, tb->buffer, (*tb->length));
|
||||
var->pz[*tb->length] = 0;
|
||||
var->nLen = (int32_t)(*tb->length);
|
||||
break;
|
||||
|
||||
default:
|
||||
tscTrace("param %d: type mismatch or invalid", i);
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int normalStmtPrepare(STscStmt* stmt) {
|
||||
SNormalStmt* normal = &stmt->normal;
|
||||
char* sql = stmt->pSql->sqlstr;
|
||||
uint32_t i = 0, start = 0;
|
||||
|
||||
while (sql[i] != 0) {
|
||||
SSQLToken token = {0};
|
||||
token.n = tSQLGetToken(sql + i, &token.type);
|
||||
|
||||
if (token.type == TK_QUESTION) {
|
||||
sql[i] = 0;
|
||||
if (i > start) {
|
||||
int code = normalStmtAddPart(normal, false, sql + start, i - start);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
int code = normalStmtAddPart(normal, true, NULL, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
start = i + token.n;
|
||||
}
|
||||
|
||||
i += token.n;
|
||||
}
|
||||
|
||||
if (i > start) {
|
||||
int code = normalStmtAddPart(normal, false, sql + start, i - start);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (normal->numParams > 0) {
|
||||
normal->params = calloc(normal->numParams, sizeof(tVariant));
|
||||
if (normal->params == NULL) {
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static char* normalStmtBuildSql(STscStmt* stmt) {
|
||||
SNormalStmt* normal = &stmt->normal;
|
||||
SStringBuilder sb = {0};
|
||||
|
||||
if (taosStringBuilderSetJmp(&sb) != 0) {
|
||||
taosStringBuilderDestroy(&sb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosStringBuilderEnsureCapacity(&sb, 4096);
|
||||
uint32_t idxParam = 0;
|
||||
|
||||
for(uint16_t i = 0; i < normal->numParts; i++) {
|
||||
SNormalStmtPart* part = normal->parts + i;
|
||||
if (!part->isParam) {
|
||||
taosStringBuilderAppendStringLen(&sb, part->str, part->len);
|
||||
continue;
|
||||
}
|
||||
|
||||
tVariant* var = normal->params + idxParam++;
|
||||
switch (var->nType)
|
||||
{
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
taosStringBuilderAppendNull(&sb);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
taosStringBuilderAppendInteger(&sb, var->i64Key);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
taosStringBuilderAppendDouble(&sb, var->dKey);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
taosStringBuilderAppendChar(&sb, '\'');
|
||||
for (char* p = var->pz; *p != 0; ++p) {
|
||||
if (*p == '\'' || *p == '"') {
|
||||
taosStringBuilderAppendChar(&sb, '\\');
|
||||
}
|
||||
taosStringBuilderAppendChar(&sb, *p);
|
||||
}
|
||||
taosStringBuilderAppendChar(&sb, '\'');
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
taosStringBuilderAppendChar(&sb, '\'');
|
||||
taosStringBuilderAppend(&sb, var->wpz, var->nLen);
|
||||
taosStringBuilderAppendChar(&sb, '\'');
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return taosStringBuilderGetResult(&sb, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// functions for insertion statement preparation
|
||||
|
||||
static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
|
||||
if (bind->is_null != NULL && *(bind->is_null)) {
|
||||
setNull(data, param->type, param->bytes);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (bind->buffer_type != param->type) {
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
|
||||
short size = 0;
|
||||
switch(param->type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
size = 1;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
size = 2;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
size = 4;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
size = 8;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
if ((*bind->length) > param->bytes) {
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
size = (short)*bind->length;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
if (!taosMbsToUcs4(bind->buffer, *bind->length, data + param->offset, param->bytes)) {
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
|
||||
memcpy(data + param->offset, bind->buffer, size);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
|
||||
SSqlCmd* pCmd = &stmt->pSql->cmd;
|
||||
|
||||
int32_t alloced = 1, binded = 0;
|
||||
if (pCmd->batchSize > 0) {
|
||||
alloced = (pCmd->batchSize + 1) / 2;
|
||||
binded = pCmd->batchSize / 2;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pCmd->pDataBlocks->nSize; ++i) {
|
||||
STableDataBlocks* pBlock = pCmd->pDataBlocks->pData[i];
|
||||
uint32_t totalDataSize = pBlock->size - sizeof(SShellSubmitBlock);
|
||||
uint32_t dataSize = totalDataSize / alloced;
|
||||
assert(dataSize * alloced == totalDataSize);
|
||||
|
||||
if (alloced == binded) {
|
||||
totalDataSize += dataSize + sizeof(SShellSubmitBlock);
|
||||
if (totalDataSize > pBlock->nAllocSize) {
|
||||
const double factor = 1.5;
|
||||
void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor));
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
pBlock->pData = (char*)tmp;
|
||||
pBlock->nAllocSize = (uint32_t)(totalDataSize * factor);
|
||||
}
|
||||
}
|
||||
|
||||
char* data = pBlock->pData + sizeof(SShellSubmitBlock) + dataSize * binded;
|
||||
for (uint32_t j = 0; j < pBlock->numOfParams; ++j) {
|
||||
SParamInfo* param = pBlock->params + j;
|
||||
int code = doBindParam(data, param, bind + param->idx);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscTrace("param %d: type mismatch or invalid", param->idx);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// actual work of all data blocks is done, update block size and numOfRows.
|
||||
// note we don't do this block by block during the binding process, because
|
||||
// we cannot recover if something goes wrong.
|
||||
pCmd->batchSize = binded * 2 + 1;
|
||||
|
||||
if (binded < alloced) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pCmd->pDataBlocks->nSize; ++i) {
|
||||
STableDataBlocks* pBlock = pCmd->pDataBlocks->pData[i];
|
||||
|
||||
uint32_t totalDataSize = pBlock->size - sizeof(SShellSubmitBlock);
|
||||
pBlock->size += totalDataSize / alloced;
|
||||
|
||||
SShellSubmitBlock* pSubmit = (SShellSubmitBlock*)pBlock->pData;
|
||||
pSubmit->numOfRows += pSubmit->numOfRows / alloced;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int insertStmtAddBatch(STscStmt* stmt) {
|
||||
SSqlCmd* pCmd = &stmt->pSql->cmd;
|
||||
if ((pCmd->batchSize % 2) == 1) {
|
||||
++pCmd->batchSize;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int insertStmtPrepare(STscStmt* stmt) {
|
||||
STscObj* taos = stmt->taos;
|
||||
SSqlObj *pSql = stmt->pSql;
|
||||
pSql->cmd.numOfParams = 0;
|
||||
pSql->cmd.batchSize = 0;
|
||||
|
||||
return tsParseInsertSql(pSql, pSql->sqlstr, taos->acctId, taos->db);
|
||||
}
|
||||
|
||||
static int insertStmtReset(STscStmt* pStmt) {
|
||||
SSqlCmd* pCmd = &pStmt->pSql->cmd;
|
||||
if (pCmd->batchSize > 2) {
|
||||
int32_t alloced = (pCmd->batchSize + 1) / 2;
|
||||
for (int32_t i = 0; i < pCmd->pDataBlocks->nSize; ++i) {
|
||||
STableDataBlocks* pBlock = pCmd->pDataBlocks->pData[i];
|
||||
|
||||
uint32_t totalDataSize = pBlock->size - sizeof(SShellSubmitBlock);
|
||||
pBlock->size = sizeof(SShellSubmitBlock) + totalDataSize / alloced;
|
||||
|
||||
SShellSubmitBlock* pSubmit = (SShellSubmitBlock*)pBlock->pData;
|
||||
pSubmit->numOfRows = pSubmit->numOfRows / alloced;
|
||||
}
|
||||
}
|
||||
pCmd->batchSize = 0;
|
||||
pCmd->vnodeIdx = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int insertStmtExecute(STscStmt* stmt) {
|
||||
SSqlCmd* pCmd = &stmt->pSql->cmd;
|
||||
if (pCmd->batchSize == 0) {
|
||||
return TSDB_CODE_INVALID_VALUE;
|
||||
}
|
||||
if ((pCmd->batchSize % 2) == 1) {
|
||||
++pCmd->batchSize;
|
||||
}
|
||||
|
||||
if (pCmd->pDataBlocks->nSize > 0) {
|
||||
// merge according to vgid
|
||||
int code = tscMergeTableDataBlocks(stmt->pSql, pCmd->pDataBlocks);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
STableDataBlocks *pDataBlock = pCmd->pDataBlocks->pData[0];
|
||||
code = tscCopyDataBlockToPayload(stmt->pSql, pDataBlock);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// set the next sent data vnode index in data block arraylist
|
||||
pCmd->vnodeIdx = 1;
|
||||
} else {
|
||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||
}
|
||||
|
||||
SSqlObj *pSql = stmt->pSql;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
pRes->numOfRows = 0;
|
||||
pRes->numOfTotal = 0;
|
||||
pRes->qhandle = 0;
|
||||
pSql->thandle = NULL;
|
||||
|
||||
tscDoQuery(pSql);
|
||||
|
||||
// tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
}
|
||||
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// interface functions
|
||||
|
||||
TAOS_STMT* taos_stmt_init(TAOS* taos) {
|
||||
STscObj* pObj = (STscObj*)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
globalCode = TSDB_CODE_DISCONNECTED;
|
||||
tscError("connection disconnected");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STscStmt* pStmt = calloc(1, sizeof(STscStmt));
|
||||
if (pStmt == NULL) {
|
||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("failed to allocate memory for statement");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
|
||||
if (pSql == NULL) {
|
||||
free(pStmt);
|
||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("failed to allocate memory for statement");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tsem_init(&pSql->rspSem, 0, 0);
|
||||
tsem_init(&pSql->emptyRspSem, 0, 1);
|
||||
pSql->signature = pSql;
|
||||
pSql->pTscObj = pObj;
|
||||
|
||||
pStmt->pSql = pSql;
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (length == 0) {
|
||||
length = strlen(sql);
|
||||
}
|
||||
char* sqlstr = (char*)malloc(length + 1);
|
||||
if (sqlstr == NULL) {
|
||||
tscError("failed to malloc sql string buffer");
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(sqlstr, sql, length);
|
||||
sqlstr[length] = 0;
|
||||
strtolower(sqlstr, sqlstr);
|
||||
|
||||
pStmt->pSql->sqlstr = sqlstr;
|
||||
if (tscIsInsertOrImportData(sqlstr)) {
|
||||
pStmt->isInsert = true;
|
||||
return insertStmtPrepare(pStmt);
|
||||
}
|
||||
|
||||
pStmt->isInsert = false;
|
||||
return normalStmtPrepare(pStmt);
|
||||
}
|
||||
|
||||
int taos_stmt_close(TAOS_STMT* stmt) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (!pStmt->isInsert) {
|
||||
SNormalStmt* normal = &pStmt->normal;
|
||||
if (normal->params != NULL) {
|
||||
for (uint16_t i = 0; i < normal->numParams; i++) {
|
||||
tVariantDestroy(normal->params + i);
|
||||
}
|
||||
free(normal->params);
|
||||
}
|
||||
free(normal->parts);
|
||||
free(normal->sql);
|
||||
}
|
||||
|
||||
tscFreeSqlObj(pStmt->pSql);
|
||||
free(pStmt);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (pStmt->isInsert) {
|
||||
return insertStmtBindParam(pStmt, bind);
|
||||
}
|
||||
return normalStmtBindParam(pStmt, bind);
|
||||
}
|
||||
|
||||
int taos_stmt_add_batch(TAOS_STMT* stmt) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (pStmt->isInsert) {
|
||||
return insertStmtAddBatch(pStmt);
|
||||
}
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int taos_stmt_reset(TAOS_STMT* stmt) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (pStmt->isInsert) {
|
||||
return insertStmtReset(pStmt);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int taos_stmt_execute(TAOS_STMT* stmt) {
|
||||
int ret = 0;
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (pStmt->isInsert) {
|
||||
ret = insertStmtExecute(pStmt);
|
||||
} else {
|
||||
char* sql = normalStmtBuildSql(pStmt);
|
||||
if (sql == NULL) {
|
||||
ret = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tfree(pStmt->pSql->sqlstr);
|
||||
pStmt->pSql->sqlstr = sql;
|
||||
ret = taos_query_imp(pStmt->taos, pStmt->pSql);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("statement is invalid.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
if (pStmt->pSql == NULL) {
|
||||
tscError("result has been used already.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TAOS_RES* result = pStmt->pSql;
|
||||
pStmt->pSql = NULL;
|
||||
return result;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -15,13 +15,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "os.h"
|
||||
|
@ -119,31 +115,29 @@ void tSQLExprListDestroy(tSQLExprList *pList) {
|
|||
free(pList);
|
||||
}
|
||||
|
||||
tSQLExpr *tSQLExprIdValueCreate(SSQLToken *pToken, int32_t optrType) {
|
||||
tSQLExpr *tSQLExprIdValueCreate(SSQLToken *pAliasToken, int32_t optrType) {
|
||||
tSQLExpr *nodePtr = calloc(1, sizeof(tSQLExpr));
|
||||
|
||||
if (optrType == TK_INTEGER || optrType == TK_STRING || optrType == TK_FLOAT || optrType == TK_BOOL) {
|
||||
toTSDBType(pToken->type);
|
||||
toTSDBType(pAliasToken->type);
|
||||
|
||||
tVariantCreate(&nodePtr->val, pToken);
|
||||
tVariantCreate(&nodePtr->val, pAliasToken);
|
||||
nodePtr->nSQLOptr = optrType;
|
||||
} else if (optrType == TK_NOW) {
|
||||
// default use microsecond
|
||||
nodePtr->val.i64Key = taosGetTimestamp(TSDB_TIME_PRECISION_MICRO);
|
||||
nodePtr->val.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
nodePtr->nSQLOptr = TK_TIMESTAMP;
|
||||
// TK_TIMESTAMP used to denote the time value is in microsecond
|
||||
nodePtr->nSQLOptr = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond
|
||||
} else if (optrType == TK_VARIABLE) {
|
||||
int32_t ret = getTimestampInUsFromStr(pToken->z, pToken->n, &nodePtr->val.i64Key);
|
||||
int32_t ret = getTimestampInUsFromStr(pAliasToken->z, pAliasToken->n, &nodePtr->val.i64Key);
|
||||
UNUSED(ret);
|
||||
|
||||
nodePtr->val.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
nodePtr->nSQLOptr = TK_TIMESTAMP;
|
||||
} else { // must be field id if not numbers
|
||||
assert(optrType == TK_ALL || optrType == TK_ID);
|
||||
|
||||
if (pToken != NULL) { // it must be the column name (tk_id)
|
||||
nodePtr->colInfo = *pToken;
|
||||
} else { // it must be the column name (tk_id) if it is not the number
|
||||
assert(optrType == TK_ID || optrType == TK_ALL);
|
||||
if (pAliasToken != NULL) {
|
||||
nodePtr->colInfo = *pAliasToken;
|
||||
}
|
||||
|
||||
nodePtr->nSQLOptr = optrType;
|
||||
|
@ -273,11 +267,10 @@ tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
|
|||
return pExpr;
|
||||
}
|
||||
|
||||
void tSQLExprDestroy(tSQLExpr *pExpr) {
|
||||
if (pExpr == NULL) return;
|
||||
|
||||
tSQLExprDestroy(pExpr->pLeft);
|
||||
tSQLExprDestroy(pExpr->pRight);
|
||||
void tSQLExprNodeDestroy(tSQLExpr *pExpr) {
|
||||
if (pExpr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pExpr->nSQLOptr == TK_STRING) {
|
||||
tVariantDestroy(&pExpr->val);
|
||||
|
@ -288,6 +281,17 @@ void tSQLExprDestroy(tSQLExpr *pExpr) {
|
|||
free(pExpr);
|
||||
}
|
||||
|
||||
void tSQLExprDestroy(tSQLExpr *pExpr) {
|
||||
if (pExpr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tSQLExprDestroy(pExpr->pLeft);
|
||||
tSQLExprDestroy(pExpr->pRight);
|
||||
|
||||
tSQLExprNodeDestroy(pExpr);
|
||||
}
|
||||
|
||||
static void *tVariantListExpand(tVariantList *pList) {
|
||||
if (pList->nAlloc <= pList->nExpr) { //
|
||||
int32_t newSize = (pList->nAlloc << 1) + 4;
|
||||
|
@ -420,6 +424,44 @@ void setDBName(SSQLToken *pCpxName, SSQLToken *pDB) {
|
|||
pCpxName->n = pDB->n;
|
||||
}
|
||||
|
||||
int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t *result) {
|
||||
*result = val;
|
||||
|
||||
switch (unit) {
|
||||
case 's':
|
||||
(*result) *= MILLISECOND_PER_SECOND;
|
||||
break;
|
||||
case 'm':
|
||||
(*result) *= MILLISECOND_PER_MINUTE;
|
||||
break;
|
||||
case 'h':
|
||||
(*result) *= MILLISECOND_PER_HOUR;
|
||||
break;
|
||||
case 'd':
|
||||
(*result) *= MILLISECOND_PER_DAY;
|
||||
break;
|
||||
case 'w':
|
||||
(*result) *= MILLISECOND_PER_WEEK;
|
||||
break;
|
||||
case 'n':
|
||||
(*result) *= MILLISECOND_PER_MONTH;
|
||||
break;
|
||||
case 'y':
|
||||
(*result) *= MILLISECOND_PER_YEAR;
|
||||
break;
|
||||
case 'a':
|
||||
break;
|
||||
default: {
|
||||
;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the value in microsecond */
|
||||
(*result) *= 1000L;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType) {
|
||||
int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
|
||||
/* truncate the column name */
|
||||
|
@ -462,7 +504,7 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) {
|
|||
/*
|
||||
* extract the select info out of sql string
|
||||
*/
|
||||
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, SSQLToken *pFrom, tSQLExpr *pWhere,
|
||||
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
||||
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
|
||||
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
|
||||
assert(pSelection != NULL && pFrom != NULL && pInterval != NULL && pLimit != NULL && pGLimit != NULL);
|
||||
|
@ -472,13 +514,13 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection,
|
|||
pQuery->selectToken.n = strlen(pQuery->selectToken.z); // all later sql string are belonged to the stream sql
|
||||
|
||||
pQuery->pSelection = pSelection;
|
||||
pQuery->from = *pFrom;
|
||||
pQuery->from = pFrom;
|
||||
pQuery->pGroupby = pGroupby;
|
||||
pQuery->pSortOrder = pSortOrder;
|
||||
pQuery->pWhere = pWhere;
|
||||
|
||||
pQuery->limit = *pLimit;
|
||||
pQuery->glimit = *pGLimit;
|
||||
pQuery->slimit = *pGLimit;
|
||||
|
||||
pQuery->interval = *pInterval;
|
||||
pQuery->sliding = *pSliding;
|
||||
|
@ -532,6 +574,9 @@ void destroyQuerySql(SQuerySQL *pSql) {
|
|||
tVariantListDestroy(pSql->pGroupby);
|
||||
pSql->pGroupby = NULL;
|
||||
|
||||
tVariantListDestroy(pSql->from);
|
||||
pSql->from = NULL;
|
||||
|
||||
tVariantListDestroy(pSql->fillType);
|
||||
|
||||
free(pSql);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tschemautil.h"
|
||||
#include "tsqldef.h"
|
||||
#include "ttypes.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
@ -71,7 +72,7 @@ struct SSchema* tsGetSchema(SMeterMeta* pMeta) {
|
|||
if (pMeta == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return tsGetSchemaColIdx(pMeta, 0);
|
||||
return tsGetColumnSchema(pMeta, 0);
|
||||
}
|
||||
|
||||
struct SSchema* tsGetTagSchema(SMeterMeta* pMeta) {
|
||||
|
@ -79,24 +80,32 @@ struct SSchema* tsGetTagSchema(SMeterMeta* pMeta) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return tsGetSchemaColIdx(pMeta, pMeta->numOfColumns);
|
||||
return tsGetColumnSchema(pMeta, pMeta->numOfColumns);
|
||||
}
|
||||
|
||||
struct SSchema* tsGetSchemaColIdx(SMeterMeta* pMeta, int32_t startCol) {
|
||||
if (pMeta->pSchema == 0) {
|
||||
pMeta->pSchema = sizeof(SMeterMeta);
|
||||
}
|
||||
|
||||
return (SSchema*)(((char*)pMeta + pMeta->pSchema) + startCol * sizeof(SSchema));
|
||||
struct SSchema* tsGetColumnSchema(SMeterMeta* pMeta, int32_t startCol) {
|
||||
return (SSchema*)(((char*)pMeta + sizeof(SMeterMeta)) + startCol * sizeof(SSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* the MeterMeta data format in memory is as follows:
|
||||
*
|
||||
* +--------------------+
|
||||
* |SMeterMeta Body data| sizeof(SMeterMeta)
|
||||
* +--------------------+
|
||||
* |Schema data | numOfTotalColumns * sizeof(SSchema)
|
||||
* +--------------------+
|
||||
* |Tags data | tag_col_1.bytes + tag_col_2.bytes + ....
|
||||
* +--------------------+
|
||||
*
|
||||
* @param pMeta
|
||||
* @return
|
||||
*/
|
||||
char* tsGetTagsValue(SMeterMeta* pMeta) {
|
||||
if (pMeta->tags == 0) {
|
||||
int32_t numOfTotalCols = pMeta->numOfColumns + pMeta->numOfTags;
|
||||
pMeta->tags = sizeof(SMeterMeta) + numOfTotalCols * sizeof(SSchema);
|
||||
}
|
||||
int32_t numOfTotalCols = pMeta->numOfColumns + pMeta->numOfTags;
|
||||
uint32_t offset = sizeof(SMeterMeta) + numOfTotalCols * sizeof(SSchema);
|
||||
|
||||
return ((char*)pMeta + pMeta->tags);
|
||||
return ((char*)pMeta + offset);
|
||||
}
|
||||
|
||||
bool tsMeterMetaIdentical(SMeterMeta* p1, SMeterMeta* p2) {
|
||||
|
@ -111,7 +120,7 @@ bool tsMeterMetaIdentical(SMeterMeta* p1, SMeterMeta* p2) {
|
|||
size_t size = sizeof(SMeterMeta) + p1->numOfColumns * sizeof(SSchema);
|
||||
|
||||
for (int32_t i = 0; i < p1->numOfTags; ++i) {
|
||||
SSchema* pColSchema = tsGetSchemaColIdx(p1, i + p1->numOfColumns);
|
||||
SSchema* pColSchema = tsGetColumnSchema(p1, i + p1->numOfColumns);
|
||||
size += pColSchema->bytes;
|
||||
}
|
||||
|
||||
|
@ -142,7 +151,33 @@ void extractMeterName(char* meterId, char* name) {
|
|||
copySegment(name, r, TS_PATH_DELIMITER[0]);
|
||||
}
|
||||
|
||||
void extractDBName(char* meterId, char* name) {
|
||||
SSQLToken extractDBName(char* meterId, char* name) {
|
||||
char* r = skipSegments(meterId, TS_PATH_DELIMITER[0], 1);
|
||||
copySegment(name, r, TS_PATH_DELIMITER[0]);
|
||||
|
||||
SSQLToken token = {.z = name, .n = strlen(name), .type = TK_STRING};
|
||||
return token;
|
||||
}
|
||||
|
||||
/*
|
||||
* tablePrefix.columnName
|
||||
* extract table name and save it in pTable, with only column name in pToken
|
||||
*/
|
||||
void extractTableNameFromToken(SSQLToken* pToken, SSQLToken* pTable) {
|
||||
const char sep = TS_PATH_DELIMITER[0];
|
||||
|
||||
if (pToken == pTable || pToken == NULL || pTable == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
char* r = strnchr(pToken->z, sep, pToken->n, false);
|
||||
|
||||
if (r != NULL) { // record the table name token
|
||||
pTable->n = r - pToken->z;
|
||||
pTable->z = pToken->z;
|
||||
|
||||
r += 1;
|
||||
pToken->n -= (r - pToken->z);
|
||||
pToken->z = r;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <tsclient.h>
|
||||
|
||||
#include "tlosertree.h"
|
||||
#include "tlosertree.h"
|
||||
|
@ -61,16 +62,17 @@ int32_t treeComparator(const void *pLeft, const void *pRight, void *param) {
|
|||
static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pReducer, tOrderDescriptor *pDesc) {
|
||||
/*
|
||||
* the fields and offset attributes in pCmd and pModel may be different due to
|
||||
* merge requirement. So, the final result in STscRes structure is formatted in accordance with the pCmd object.
|
||||
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
|
||||
*/
|
||||
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
|
||||
|
||||
pCtx->aOutputBuf = pReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pReducer->resColModel->maxCapacity;
|
||||
|
||||
pCtx->order = pCmd->order.order;
|
||||
pCtx->aInputElemBuf =
|
||||
pReducer->pTempBuffer->data + pDesc->pSchema->colOffset[i]; // input buffer hold only one point data
|
||||
pCtx->functionId = pCmd->exprsInfo.pExprs[i].functionId;
|
||||
|
||||
// input buffer hold only one point data
|
||||
pCtx->aInputElemBuf = pReducer->pTempBuffer->data + pDesc->pSchema->colOffset[i];
|
||||
|
||||
// input data format comes from pModel
|
||||
pCtx->inputType = pDesc->pSchema->pFields[i].type;
|
||||
|
@ -80,28 +82,54 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
|
|||
// output data format yet comes from pCmd.
|
||||
pCtx->outputBytes = pField->bytes;
|
||||
pCtx->outputType = pField->type;
|
||||
pCtx->numOfOutputElems = 0;
|
||||
|
||||
pCtx->numOfIteratedElems = 0;
|
||||
pCtx->startOffset = 0;
|
||||
pCtx->size = 1;
|
||||
pCtx->hasNullValue = true;
|
||||
pCtx->hasNull = true;
|
||||
pCtx->currentStage = SECONDARY_STAGE_MERGE;
|
||||
|
||||
pRes->bytes[i] = pField->bytes;
|
||||
|
||||
int32_t sqlFunction = tscSqlExprGet(pCmd, i)->sqlFuncId;
|
||||
if (sqlFunction == TSDB_FUNC_TOP_DST || sqlFunction == TSDB_FUNC_BOTTOM_DST) {
|
||||
/* for top_dst/bottom_dst function, the output of timestamp is the first column */
|
||||
pCtx->ptsOutputBuf = pReducer->pCtx[0].aOutputBuf;
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
||||
|
||||
// for top/bottom function, the output of timestamp is the first column
|
||||
int32_t functionId = pExpr->functionId;
|
||||
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
|
||||
pCtx->ptsOutputBuf = pReducer->pCtx[0].aOutputBuf;
|
||||
pCtx->param[2].i64Key = pCmd->order.order;
|
||||
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
pCtx->param[3].i64Key = sqlFunction;
|
||||
pCtx->param[3].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
|
||||
pCtx->param[1].i64Key = pCmd->order.orderColId;
|
||||
}
|
||||
|
||||
SResultInfo *pResInfo = &pReducer->pResInfo[i];
|
||||
pResInfo->bufLen = pExpr->interResBytes;
|
||||
pResInfo->interResultBuf = calloc(1, (size_t)pResInfo->bufLen);
|
||||
|
||||
pCtx->resultInfo = &pReducer->pResInfo[i];
|
||||
pCtx->resultInfo->superTableQ = true;
|
||||
}
|
||||
|
||||
int16_t n = 0;
|
||||
int16_t tagLen = 0;
|
||||
SQLFunctionCtx** pTagCtx = calloc(pCmd->fieldsInfo.numOfOutputCols, POINTER_BYTES);
|
||||
|
||||
SQLFunctionCtx* pCtx = NULL;
|
||||
for(int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
tagLen += pExpr->resBytes;
|
||||
pTagCtx[n++] = &pReducer->pCtx[i];
|
||||
} else if ((aAggs[pExpr->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
|
||||
pCtx = &pReducer->pCtx[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
free(pTagCtx);
|
||||
} else {
|
||||
pCtx->tagInfo.pTagCtxList = pTagCtx;
|
||||
pCtx->tagInfo.numOfTagCols = n;
|
||||
pCtx->tagInfo.tagsLen = tagLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,13 +268,8 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
pReducer->hasUnprocessedRow = false;
|
||||
|
||||
pReducer->prevRowOfInput = (char *)calloc(1, pReducer->rowSize);
|
||||
if (pReducer->prevRowOfInput == 0) {
|
||||
// todo release previously allocated memory
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
||||
/* used to keep the latest input row */
|
||||
// used to keep the latest input row
|
||||
pReducer->pTempBuffer = (tFilePage *)calloc(1, pReducer->rowSize + sizeof(tFilePage));
|
||||
|
||||
pReducer->discardData = (tFilePage *)calloc(1, pReducer->rowSize + sizeof(tFilePage));
|
||||
|
@ -254,44 +277,56 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
pReducer->nResultBufSize = pMemBuffer[0]->nPageSize * 16;
|
||||
pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage));
|
||||
|
||||
|
||||
int32_t finalRowLength = tscGetResRowLength(pCmd);
|
||||
pReducer->resColModel = finalmodel;
|
||||
pReducer->resColModel->maxCapacity = pReducer->nResultBufSize / finalRowLength;
|
||||
assert(finalRowLength <= pReducer->rowSize);
|
||||
|
||||
pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->maxCapacity);
|
||||
pReducer->pBufForInterpo = calloc(1, pReducer->nResultBufSize);
|
||||
|
||||
if (pReducer->pTempBuffer == NULL || pReducer->pResultBuf == NULL || pReducer->pBufForInterpo == NULL) {
|
||||
if (pReducer->pTempBuffer == NULL|| pReducer->discardData == NULL || pReducer->pResultBuf == NULL ||
|
||||
pReducer->pBufForInterpo == NULL || pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
||||
tfree(pReducer->pTempBuffer);
|
||||
tfree(pReducer->discardData);
|
||||
tfree(pReducer->pResultBuf);
|
||||
tfree(pReducer->pFinalRes);
|
||||
tfree(pReducer->pBufForInterpo);
|
||||
tfree(pReducer->prevRowOfInput);
|
||||
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
||||
pReducer->pTempBuffer->numOfElems = 0;
|
||||
pReducer->pResInfo = calloc((size_t)pCmd->fieldsInfo.numOfOutputCols, sizeof(SResultInfo));
|
||||
|
||||
tscCreateResPointerInfo(pCmd, pRes);
|
||||
tscInitSqlContext(pCmd, pRes, pReducer, pDesc);
|
||||
|
||||
/* we change the maxCapacity of schema to denote that there is only one row in temp buffer */
|
||||
// we change the maxCapacity of schema to denote that there is only one row in temp buffer
|
||||
pReducer->pDesc->pSchema->maxCapacity = 1;
|
||||
pReducer->offset = pCmd->limit.offset;
|
||||
|
||||
pRes->pLocalReducer = pReducer;
|
||||
pRes->numOfGroups = 0;
|
||||
|
||||
int16_t prec = pCmd->pMeterMeta->precision;
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime;
|
||||
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, prec);
|
||||
|
||||
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo;
|
||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupbyCols,
|
||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupCols,
|
||||
pReducer->rowSize);
|
||||
|
||||
int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols;
|
||||
|
||||
if (pCmd->groupbyExpr.numOfGroupbyCols > 0) {
|
||||
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
for (int32_t i = 1; i < pCmd->groupbyExpr.numOfGroupbyCols; ++i) {
|
||||
if (pCmd->groupbyExpr.numOfGroupCols > 0) {
|
||||
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->groupbyExpr.numOfGroupCols;
|
||||
for (int32_t i = 1; i < pCmd->groupbyExpr.numOfGroupCols; ++i) {
|
||||
pInterpoInfo->pTags[i] = pReducer->resColModel->pFields[startIndex + i - 1].bytes + pInterpoInfo->pTags[i - 1];
|
||||
}
|
||||
} else {
|
||||
|
@ -399,6 +434,8 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
return;
|
||||
}
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
// there is no more result, so we release all allocated resource
|
||||
SLocalReducer *pLocalReducer =
|
||||
(SLocalReducer *)__sync_val_compare_and_swap_64(&pRes->pLocalReducer, pRes->pLocalReducer, 0);
|
||||
|
@ -413,12 +450,29 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
tfree(pLocalReducer->interpolationInfo.prevValues);
|
||||
tfree(pLocalReducer->interpolationInfo.pTags);
|
||||
|
||||
tfree(pLocalReducer->pCtx);
|
||||
if (pLocalReducer->pCtx != NULL) {
|
||||
for(int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
|
||||
tVariantDestroy(&pCtx->tag);
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->pCtx);
|
||||
}
|
||||
|
||||
|
||||
tfree(pLocalReducer->prevRowOfInput);
|
||||
|
||||
tfree(pLocalReducer->pTempBuffer);
|
||||
tfree(pLocalReducer->pResultBuf);
|
||||
|
||||
if (pLocalReducer->pResInfo != NULL) {
|
||||
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||
}
|
||||
|
||||
tfree(pLocalReducer->pResInfo);
|
||||
}
|
||||
|
||||
if (pLocalReducer->pLoserTree) {
|
||||
tfree(pLocalReducer->pLoserTree->param);
|
||||
tfree(pLocalReducer->pLoserTree);
|
||||
|
@ -447,8 +501,8 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
|
||||
static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCmd, tColModel *pModel) {
|
||||
int32_t numOfGroupByCols = 0;
|
||||
if (pCmd->groupbyExpr.numOfGroupbyCols > 0) {
|
||||
numOfGroupByCols = pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
if (pCmd->groupbyExpr.numOfGroupCols > 0) {
|
||||
numOfGroupByCols = pCmd->groupbyExpr.numOfGroupCols;
|
||||
}
|
||||
|
||||
// primary timestamp column is involved in final result
|
||||
|
@ -462,15 +516,15 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
|||
}
|
||||
|
||||
if (numOfGroupByCols > 0) {
|
||||
int32_t startCols = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
int32_t startCols = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols;
|
||||
|
||||
// tags value locate at the last columns
|
||||
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupbyCols; ++i) {
|
||||
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) {
|
||||
orderIdx[i] = startCols++;
|
||||
}
|
||||
|
||||
if (pCmd->nAggTimeInterval != 0) {
|
||||
//the first column is the timestamp, handles queries like "interval(10m) group by tags"
|
||||
// the first column is the timestamp, handles queries like "interval(10m) group by tags"
|
||||
orderIdx[numOfGroupByCols - 1] = PRIMARYKEY_TIMESTAMP_COL_INDEX;
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +540,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
|||
}
|
||||
|
||||
bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage *tmpBuffer) {
|
||||
int16_t functionId = tscSqlExprGet(pCmd, 0)->sqlFuncId;
|
||||
int16_t functionId = tscSqlExprGet(pCmd, 0)->functionId;
|
||||
|
||||
// disable merge procedure for column projection query
|
||||
if (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_ARITHM) {
|
||||
|
@ -525,7 +579,9 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
tColModel *pModel = NULL;
|
||||
*pFinalModel = NULL;
|
||||
|
||||
(*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pCmd->pMetricMeta->numOfVnodes);
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
(*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pMeterMetaInfo->pMetricMeta->numOfVnodes);
|
||||
if (*pMemBuffer == NULL) {
|
||||
tscError("%p failed to allocate memory", pSql);
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
|
@ -552,10 +608,10 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
int32_t capacity = nBufferSizes / rlen;
|
||||
pModel = tColModelCreate(pSchema, pCmd->fieldsInfo.numOfOutputCols, capacity);
|
||||
|
||||
for (int32_t i = 0; i < pCmd->pMetricMeta->numOfVnodes; ++i) {
|
||||
for (int32_t i = 0; i < pMeterMetaInfo->pMetricMeta->numOfVnodes; ++i) {
|
||||
char tmpPath[512] = {0};
|
||||
getExtTmpfilePath("/tv_bf_db_%lld_%lld_%d.d", taosGetPthreadId(), i, 0, tmpPath);
|
||||
tscTrace("%p create tmp file:%s", pSql, tmpPath);
|
||||
getTmpfilePath("tv_bf_db", tmpPath);
|
||||
tscTrace("%p create [%d](%d) tmp file for subquery:%s", pSql, pMeterMetaInfo->pMetricMeta->numOfVnodes, i, tmpPath);
|
||||
|
||||
tExtMemBufferCreate(&(*pMemBuffer)[i], nBufferSizes, rlen, tmpPath, pModel);
|
||||
(*pMemBuffer)[i]->flushModel = MULTIPLE_APPEND_MODEL;
|
||||
|
@ -667,11 +723,13 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
|
|||
|
||||
void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pCmd, SInterpolationInfo *pInterpoInfo) {
|
||||
// discard following dataset in the same group and reset the interpolation information
|
||||
int16_t prec = pCmd->pMeterMeta->precision;
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime;
|
||||
int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, prec);
|
||||
|
||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupbyCols,
|
||||
taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupCols,
|
||||
pLocalReducer->rowSize);
|
||||
|
||||
pLocalReducer->discard = true;
|
||||
|
@ -735,10 +793,6 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
assert(pRes->pLocalReducer == NULL);
|
||||
}
|
||||
|
||||
if (pLocalReducer->pFinalRes == NULL) {
|
||||
pLocalReducer->pFinalRes = malloc(pLocalReducer->rowSize * pLocalReducer->resColModel->maxCapacity);
|
||||
}
|
||||
|
||||
if (pCmd->nAggTimeInterval == 0 || pCmd->interpoType == TSDB_INTERPO_NONE) {
|
||||
// no interval query, no interpolation
|
||||
pRes->data = pLocalReducer->pFinalRes;
|
||||
|
@ -808,10 +862,11 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
|
||||
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
srcData[i] = pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pCmd, i) * pInterpoInfo->numOfRawDataInRows;
|
||||
functions[i] = tscSqlExprGet(pCmd, i)->sqlFuncId;
|
||||
functions[i] = tscSqlExprGet(pCmd, i)->functionId;
|
||||
}
|
||||
|
||||
int8_t precision = pCmd->pMeterMeta->precision;
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int8_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
while (1) {
|
||||
int32_t remains = taosNumOfRemainPoints(pInterpoInfo);
|
||||
|
@ -911,22 +966,42 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
|
|||
pLocalReducer->hasPrevRow = true;
|
||||
}
|
||||
|
||||
static void handleUnprocessedRow(SLocalReducer *pLocalReducer, SSqlCmd *pCmd, tFilePage *tmpBuffer) {
|
||||
if (pLocalReducer->hasUnprocessedRow) {
|
||||
for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, j);
|
||||
static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, bool needInit) {
|
||||
// the tag columns need to be set before all functions execution
|
||||
for(int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pCmd, j);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j];
|
||||
|
||||
tVariantAssign(&pLocalReducer->pCtx[j].param[0], &pExpr->param[0]);
|
||||
aAggs[pExpr->sqlFuncId].init(&pLocalReducer->pCtx[j]);
|
||||
tVariantAssign(&pCtx->param[0], &pExpr->param[0]);
|
||||
|
||||
pLocalReducer->pCtx[j].currentStage = SECONDARY_STAGE_MERGE;
|
||||
pLocalReducer->pCtx[j].numOfIteratedElems = 0;
|
||||
aAggs[pExpr->sqlFuncId].distSecondaryMergeFunc(&pLocalReducer->pCtx[j]);
|
||||
// tags/tags_dummy function, the tag field of SQLFunctionCtx is from the input buffer
|
||||
if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TAG ||
|
||||
pExpr->functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
tVariantDestroy(&pCtx->tag);
|
||||
tVariantCreateFromBinary(&pCtx->tag, pCtx->aInputElemBuf, pCtx->inputBytes, pCtx->inputType);
|
||||
}
|
||||
|
||||
pLocalReducer->hasUnprocessedRow = false;
|
||||
pCtx->currentStage = SECONDARY_STAGE_MERGE;
|
||||
|
||||
// copy to previous temp buffer
|
||||
if (needInit) {
|
||||
aAggs[pExpr->functionId].init(pCtx);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||
int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
|
||||
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
aAggs[functionId].distSecondaryMergeFunc(&pLocalReducer->pCtx[j]);
|
||||
}
|
||||
}
|
||||
|
||||
static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) {
|
||||
if (pLocalReducer->hasUnprocessedRow) {
|
||||
pLocalReducer->hasUnprocessedRow = false;
|
||||
doExecuteSecondaryMerge(pCmd, pLocalReducer, true);
|
||||
savePreviousRow(pLocalReducer, tmpBuffer);
|
||||
}
|
||||
}
|
||||
|
@ -935,7 +1010,7 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
|
|||
int64_t maxOutput = 0;
|
||||
|
||||
for (int32_t j = 0; j < pCmd->exprsInfo.numOfExprs; ++j) {
|
||||
int32_t functionId = tscSqlExprGet(pCmd, j)->sqlFuncId;
|
||||
int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
|
||||
|
||||
/*
|
||||
* ts, tag, tagprj function can not decide the output number of current query
|
||||
|
@ -945,34 +1020,37 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (maxOutput < pCtx[j].numOfOutputElems) {
|
||||
maxOutput = pCtx[j].numOfOutputElems;
|
||||
if (maxOutput < GET_RES_INFO(&pCtx[j])->numOfRes) {
|
||||
maxOutput = GET_RES_INFO(&pCtx[j])->numOfRes;
|
||||
}
|
||||
}
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
/*
|
||||
* in handling the to/bottom query, which produce more than one rows result,
|
||||
* in handling the top/bottom query, which produce more than one rows result,
|
||||
* the tsdb_func_tags only fill the first row of results, the remain rows need to
|
||||
* filled with the same result, which is the tags, specified in group by clause
|
||||
*
|
||||
*/
|
||||
static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReducer *pLocalReducer) {
|
||||
int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
|
||||
int32_t maxBufSize = 0;
|
||||
for (int32_t k = startIndex; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
int32_t maxBufSize = 0; // find the max tags column length to prepare the buffer
|
||||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
||||
if (maxBufSize < pExpr->resBytes) {
|
||||
if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) {
|
||||
maxBufSize = pExpr->resBytes;
|
||||
}
|
||||
assert(pExpr->sqlFuncId == TSDB_FUNC_TAG);
|
||||
}
|
||||
|
||||
assert(maxBufSize >= 0);
|
||||
|
||||
char *buf = malloc((size_t)maxBufSize);
|
||||
for (int32_t k = startIndex; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
char *buf = malloc((size_t) maxBufSize);
|
||||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t inc = numOfRes - 1; // tsdb_func_tag function only produce one row of result
|
||||
memset(buf, 0, (size_t)maxBufSize);
|
||||
|
||||
|
@ -991,7 +1069,10 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
|
|||
int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
|
||||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
||||
aAggs[pExpr->sqlFuncId].xFinalize(&pLocalReducer->pCtx[k]);
|
||||
aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]);
|
||||
|
||||
// allow to re-initialize for the next round
|
||||
pLocalReducer->pCtx[k].resultInfo->initialized = false;
|
||||
}
|
||||
|
||||
pLocalReducer->hasPrevRow = false;
|
||||
|
@ -1012,7 +1093,7 @@ int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
|
|||
*/
|
||||
bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) {
|
||||
int32_t ret = 0; // merge all result by default
|
||||
int16_t functionId = tscSqlExprGet(pCmd, 0)->sqlFuncId;
|
||||
int16_t functionId = tscSqlExprGet(pCmd, 0)->functionId;
|
||||
|
||||
if (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_ARITHM) { // column projection query
|
||||
ret = 1; // disable merge procedure
|
||||
|
@ -1033,7 +1114,7 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff
|
|||
}
|
||||
|
||||
static bool reachGroupResultLimit(SSqlCmd *pCmd, SSqlRes *pRes) {
|
||||
return (pRes->numOfGroups >= pCmd->glimit.limit && pCmd->glimit.limit >= 0);
|
||||
return (pRes->numOfGroups >= pCmd->slimit.limit && pCmd->slimit.limit >= 0);
|
||||
}
|
||||
|
||||
static bool saveGroupResultInfo(SSqlObj *pSql) {
|
||||
|
@ -1042,7 +1123,7 @@ static bool saveGroupResultInfo(SSqlObj *pSql) {
|
|||
|
||||
pRes->numOfGroups += 1;
|
||||
|
||||
// the output group is limited by the glimit clause
|
||||
// the output group is limited by the slimit clause
|
||||
if (reachGroupResultLimit(pCmd, pRes)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1073,9 +1154,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
* ignore the output of the current group since this group is skipped by user
|
||||
* We set the numOfRows to be 0 and discard the possible remain results.
|
||||
*/
|
||||
if (pCmd->glimit.offset > 0) {
|
||||
if (pCmd->slimit.offset > 0) {
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->glimit.offset -= 1;
|
||||
pCmd->slimit.offset -= 1;
|
||||
pLocalReducer->discard = !noMoreCurrentGroupRes;
|
||||
return false;
|
||||
}
|
||||
|
@ -1089,9 +1170,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
#endif
|
||||
|
||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupbyCols;
|
||||
int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols;
|
||||
|
||||
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupbyCols; ++i) {
|
||||
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) {
|
||||
memcpy(pInterpoInfo->pTags[i],
|
||||
pLocalReducer->pBufForInterpo + pModel->colOffset[startIndex + i] * pResBuf->numOfElems,
|
||||
pModel->pFields[startIndex + i].bytes);
|
||||
|
@ -1113,20 +1194,21 @@ void resetOutputBuf(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { // reset out
|
|||
}
|
||||
|
||||
static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer *pLocalReducer) {
|
||||
//In handling data in other groups, we need to reset the interpolation information for a new group data
|
||||
// In handling data in other groups, we need to reset the interpolation information for a new group data
|
||||
pRes->numOfRows = 0;
|
||||
pRes->numOfTotal = 0;
|
||||
pCmd->limit.offset = pLocalReducer->offset;
|
||||
|
||||
int16_t precision = pCmd->pMeterMeta->precision;
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int16_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
// for group result interpolation, do not return if not data is generated
|
||||
if (pCmd->interpoType != TSDB_INTERPO_NONE) {
|
||||
/* for group result interpolation, do not return if not data is generated */
|
||||
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime;
|
||||
int64_t newTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, precision);
|
||||
|
||||
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pCmd->order.order, newTime,
|
||||
pCmd->groupbyExpr.numOfGroupbyCols, pLocalReducer->rowSize);
|
||||
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pCmd->order.order, newTime, pCmd->groupbyExpr.numOfGroupCols,
|
||||
pLocalReducer->rowSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1140,7 +1222,9 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
|
|||
|
||||
SLocalReducer * pLocalReducer = pRes->pLocalReducer;
|
||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
int8_t p = pCmd->pMeterMeta->precision;
|
||||
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int8_t p = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
|
||||
assert(pCmd->interpoType != TSDB_INTERPO_NONE);
|
||||
|
@ -1170,7 +1254,9 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
|
|||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
|
||||
bool prevGroupCompleted = (!pLocalReducer->discard) && pLocalReducer->hasUnprocessedRow;
|
||||
int8_t precision = pCmd->pMeterMeta->precision;
|
||||
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
int8_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL ||
|
||||
prevGroupCompleted) {
|
||||
|
@ -1214,40 +1300,17 @@ static void doMergeWithPrevRows(SSqlObj *pSql, int32_t numOfRes) {
|
|||
|
||||
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
|
||||
|
||||
pLocalReducer->pCtx[k].aOutputBuf += pLocalReducer->pCtx[k].outputBytes * numOfRes;
|
||||
pCtx->aOutputBuf += pCtx->outputBytes * numOfRes;
|
||||
|
||||
// set the correct output timestamp column position
|
||||
if (pExpr->sqlFuncId == TSDB_FUNC_TOP_DST || pExpr->sqlFuncId == TSDB_FUNC_BOTTOM_DST) {
|
||||
pLocalReducer->pCtx[k].ptsOutputBuf = ((char *)pLocalReducer->pCtx[k].ptsOutputBuf + TSDB_KEYSIZE * numOfRes);
|
||||
if (pExpr->functionId == TSDB_FUNC_TOP || pExpr->functionId == TSDB_FUNC_BOTTOM) {
|
||||
pCtx->ptsOutputBuf = ((char *)pCtx->ptsOutputBuf + TSDB_KEYSIZE * numOfRes);
|
||||
}
|
||||
|
||||
/* set the parameters for the SQLFunctionCtx */
|
||||
tVariantAssign(&pLocalReducer->pCtx[k].param[0], &pExpr->param[0]);
|
||||
|
||||
aAggs[pExpr->sqlFuncId].init(&pLocalReducer->pCtx[k]);
|
||||
pLocalReducer->pCtx[k].currentStage = SECONDARY_STAGE_MERGE;
|
||||
aAggs[pExpr->sqlFuncId].distSecondaryMergeFunc(&pLocalReducer->pCtx[k]);
|
||||
}
|
||||
}
|
||||
|
||||
static void doExecuteSecondaryMerge(SSqlObj *pSql) {
|
||||
SSqlCmd * pCmd = &pSql->cmd;
|
||||
SSqlRes * pRes = &pSql->res;
|
||||
SLocalReducer *pLocalReducer = pRes->pLocalReducer;
|
||||
|
||||
for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, j);
|
||||
|
||||
tVariantAssign(&pLocalReducer->pCtx[j].param[0], &pExpr->param[0]);
|
||||
pLocalReducer->pCtx[j].numOfIteratedElems = 0;
|
||||
pLocalReducer->pCtx[j].currentStage = 0;
|
||||
|
||||
aAggs[pExpr->sqlFuncId].init(&pLocalReducer->pCtx[j]);
|
||||
pLocalReducer->pCtx[j].currentStage = SECONDARY_STAGE_MERGE;
|
||||
|
||||
aAggs[pExpr->sqlFuncId].distSecondaryMergeFunc(&pLocalReducer->pCtx[j]);
|
||||
}
|
||||
doExecuteSecondaryMerge(pCmd, pLocalReducer, true);
|
||||
}
|
||||
|
||||
int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
||||
|
@ -1272,8 +1335,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
int32_t prevStatus =
|
||||
__sync_val_compare_and_swap_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, TSC_LOCALREDUCE_IN_PROGRESS);
|
||||
if (prevStatus != TSC_LOCALREDUCE_READY || pLocalReducer == NULL) {
|
||||
assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED);
|
||||
/* it is in tscDestroyLocalReducer function already */
|
||||
assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED); // it is in tscDestroyLocalReducer function already
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1292,7 +1354,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
SLoserTreeInfo *pTree = pLocalReducer->pLoserTree;
|
||||
|
||||
// clear buffer
|
||||
handleUnprocessedRow(pLocalReducer, pCmd, tmpBuffer);
|
||||
handleUnprocessedRow(pCmd, pLocalReducer, tmpBuffer);
|
||||
tColModel *pModel = pLocalReducer->pDesc->pSchema;
|
||||
|
||||
while (1) {
|
||||
|
@ -1353,12 +1415,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
if (pLocalReducer->hasPrevRow) {
|
||||
if (needToMerge(pCmd, pLocalReducer, tmpBuffer)) {
|
||||
// belong to the group of the previous row, continue process it
|
||||
for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, j);
|
||||
tVariantAssign(&pLocalReducer->pCtx[j].param[0], &pExpr->param[0]);
|
||||
|
||||
aAggs[pExpr->sqlFuncId].distSecondaryMergeFunc(&pLocalReducer->pCtx[j]);
|
||||
}
|
||||
doExecuteSecondaryMerge(pCmd, pLocalReducer, false);
|
||||
|
||||
// copy to buffer
|
||||
savePreviousRow(pLocalReducer, tmpBuffer);
|
||||
|
@ -1369,7 +1426,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
*/
|
||||
int32_t numOfRes = finalizeRes(pCmd, pLocalReducer);
|
||||
|
||||
bool sameGroup = isSameGroup(pCmd, pLocalReducer, pLocalReducer->prevRowOfInput, tmpBuffer);
|
||||
bool sameGroup = isSameGroup(pCmd, pLocalReducer, pLocalReducer->prevRowOfInput, tmpBuffer);
|
||||
tFilePage *pResBuf = pLocalReducer->pResultBuf;
|
||||
|
||||
/*
|
||||
|
@ -1398,7 +1455,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
assert(pLocalReducer->status == TSC_LOCALREDUCE_IN_PROGRESS);
|
||||
|
||||
if (pRes->numOfRows == 0) {
|
||||
handleUnprocessedRow(pLocalReducer, pCmd, tmpBuffer);
|
||||
handleUnprocessedRow(pCmd, pLocalReducer, tmpBuffer);
|
||||
|
||||
if (!sameGroup) {
|
||||
/*
|
||||
|
@ -1418,7 +1475,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
* We start the process in a new round.
|
||||
*/
|
||||
if (sameGroup) {
|
||||
handleUnprocessedRow(pLocalReducer, pCmd, tmpBuffer);
|
||||
handleUnprocessedRow(pCmd, pLocalReducer, tmpBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1435,7 +1492,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
doExecuteSecondaryMerge(pSql);
|
||||
doExecuteSecondaryMerge(pCmd, pLocalReducer, true);
|
||||
savePreviousRow(pLocalReducer, tmpBuffer); // copy the processed row to buffer
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,16 +20,18 @@
|
|||
#include "tcache.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
#include "tscJoinProcess.h"
|
||||
#include "tscProfile.h"
|
||||
#include "tscSecondaryMerge.h"
|
||||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
#include "tscompression.h"
|
||||
#include "tsocket.h"
|
||||
#include "tsql.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
|
||||
TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, void (*fp)(void *, TAOS_RES *, int),
|
||||
TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const char *db, int port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, void **taos) {
|
||||
STscObj *pObj;
|
||||
|
||||
|
@ -62,14 +64,30 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CLUSTER
|
||||
if (ip && ip[0]) {
|
||||
tscMgmtIpList.numOfIps = 2;
|
||||
strcpy(tscMgmtIpList.ipstr[0], ip);
|
||||
tscMgmtIpList.ip[0] = inet_addr(ip);
|
||||
|
||||
strcpy(tscMgmtIpList.ipstr[1], ip);
|
||||
tscMgmtIpList.ip[1] = inet_addr(ip);
|
||||
}
|
||||
#else
|
||||
if (ip && ip[0]) {
|
||||
if (ip != tsServerIpStr) {
|
||||
strcpy(tsServerIpStr, ip);
|
||||
}
|
||||
tsServerIp = inet_addr(ip);
|
||||
}
|
||||
#endif
|
||||
|
||||
pObj = (STscObj *)malloc(sizeof(STscObj));
|
||||
if (NULL == pObj) {
|
||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(pObj, 0, sizeof(STscObj));
|
||||
pObj->signature = pObj;
|
||||
|
||||
|
@ -96,6 +114,12 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
|
|||
pthread_mutex_init(&pObj->mutex, NULL);
|
||||
|
||||
SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj));
|
||||
if (NULL == pSql) {
|
||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
free(pObj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(pSql, 0, sizeof(SSqlObj));
|
||||
pSql->pTscObj = pObj;
|
||||
pSql->signature = pSql;
|
||||
|
@ -109,7 +133,13 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
|
|||
}
|
||||
|
||||
pSql->cmd.command = TSDB_SQL_CONNECT;
|
||||
tscAllocPayloadWithSize(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
int ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
if (TSDB_CODE_SUCCESS != ret) {
|
||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
free(pSql);
|
||||
free(pObj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSql->res.code = tscProcessSql(pSql);
|
||||
if (fp != NULL) {
|
||||
|
@ -126,28 +156,37 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
|
|||
return pObj;
|
||||
}
|
||||
|
||||
TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) {
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, int port) {
|
||||
if (ip != NULL && (strcmp("127.0.0.1", ip) == 0 || strcasecmp("localhost", ip) == 0)) {
|
||||
#ifdef CLUSTER
|
||||
ip = tsPrivateIp;
|
||||
#else
|
||||
ip = tsServerIpStr;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ip == NULL) ip = tsServerIpStr;
|
||||
tscTrace("try to create a connection to %s", ip);
|
||||
|
||||
void *taos = taos_connect_imp(ip, user, pass, db, port, NULL, NULL, NULL);
|
||||
if (taos != NULL) {
|
||||
STscObj* pObj = (STscObj*) taos;
|
||||
|
||||
// version compare only requires the first 3 segments of the version string
|
||||
int32_t comparedSegments = 3;
|
||||
char client_version[64] = {0};
|
||||
char server_version[64] = {0};
|
||||
int clientVersionNumber[4] = {0};
|
||||
if (!taosGetVersionNumber(version, clientVersionNumber)) {
|
||||
tscError("taos:%p, invalid client version:%s", taos, version);
|
||||
int serverVersionNumber[4] = {0};
|
||||
|
||||
strcpy(client_version, version);
|
||||
strcpy(server_version, taos_get_server_info(taos));
|
||||
|
||||
if (!taosGetVersionNumber(client_version, clientVersionNumber)) {
|
||||
tscError("taos:%p, invalid client version:%s", taos, client_version);
|
||||
pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
taos_close(taos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *server_version = taos_get_server_info(taos);
|
||||
int serverVersionNumber[4] = {0};
|
||||
if (!taosGetVersionNumber(server_version, serverVersionNumber)) {
|
||||
tscError("taos:%p, invalid server version:%s", taos, server_version);
|
||||
pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
|
@ -155,9 +194,6 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// version compare only requires the first 3 segments of the version string
|
||||
int32_t comparedSegments = 3;
|
||||
|
||||
for(int32_t i = 0; i < comparedSegments; ++i) {
|
||||
if (clientVersionNumber[i] != serverVersionNumber[i]) {
|
||||
tscError("taos:%p, the %d-th number of server version:%s not matched with client version:%s, close connection",
|
||||
|
@ -174,17 +210,17 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) {
|
|||
|
||||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, int port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, void **taos) {
|
||||
#ifndef CLUSTER
|
||||
if (ip == NULL) {
|
||||
ip = tsServerIpStr;
|
||||
}
|
||||
#endif
|
||||
return taos_connect_imp(ip, user, pass, db, port, fp, param, taos);
|
||||
}
|
||||
|
||||
void taos_close(TAOS *taos) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
|
||||
tscTrace("%p start to close connection, pSql:%p, HB:%p", pObj, pObj->pSql, pObj->pHb);
|
||||
|
||||
if (pObj == NULL) return;
|
||||
if (pObj->signature != pObj) return;
|
||||
|
||||
|
@ -195,37 +231,12 @@ void taos_close(TAOS *taos) {
|
|||
}
|
||||
}
|
||||
|
||||
int taos_query(TAOS *taos, char *sqlstr) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
globalCode = TSDB_CODE_DISCONNECTED;
|
||||
return TSDB_CODE_DISCONNECTED;
|
||||
}
|
||||
|
||||
SSqlObj *pSql = pObj->pSql;
|
||||
int taos_query_imp(STscObj* pObj, SSqlObj* pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
pRes->numOfRows = 1;
|
||||
pRes->numOfTotal = 0;
|
||||
|
||||
tscTrace("%p SQL: %s pObj:%p", pSql, sqlstr, pObj);
|
||||
|
||||
int32_t sqlLen = strlen(sqlstr);
|
||||
if (sqlLen > TSDB_MAX_SQL_LEN) {
|
||||
tscError("%p sql too long", pSql);
|
||||
pRes->code = TSDB_CODE_INVALID_SQL;
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1);
|
||||
if (pSql->sqlstr == NULL) {
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
strtolower(pSql->sqlstr, sqlstr);
|
||||
tscTrace("%p SQL: %s pObj:%p", pSql, pSql->sqlstr, pObj);
|
||||
|
||||
pRes->code = (uint8_t)tsParseSql(pSql, pObj->acctId, pObj->db, false);
|
||||
|
||||
|
@ -241,7 +252,7 @@ int taos_query(TAOS *taos, char *sqlstr) {
|
|||
|
||||
tscDoQuery(pSql);
|
||||
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
}
|
||||
|
@ -249,6 +260,36 @@ int taos_query(TAOS *taos, char *sqlstr) {
|
|||
return pRes->code;
|
||||
}
|
||||
|
||||
int taos_query(TAOS *taos, const char *sqlstr) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
SSqlObj *pSql = pObj->pSql;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
globalCode = TSDB_CODE_DISCONNECTED;
|
||||
return TSDB_CODE_DISCONNECTED;
|
||||
}
|
||||
|
||||
int32_t sqlLen = strlen(sqlstr);
|
||||
if (sqlLen > TSDB_MAX_SQL_LEN) {
|
||||
tscError("%p sql too long", pSql);
|
||||
pRes->code = TSDB_CODE_INVALID_SQL;
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
void *sql = realloc(pSql->sqlstr, sqlLen + 1);
|
||||
if (sql == NULL) {
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
pSql->sqlstr = sql;
|
||||
strtolower(pSql->sqlstr, sqlstr);
|
||||
return taos_query_imp(pObj, pSql);
|
||||
}
|
||||
|
||||
TAOS_RES *taos_use_result(TAOS *taos) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
|
@ -272,14 +313,16 @@ int taos_num_fields(TAOS_RES *res) {
|
|||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
return pSql->cmd.fieldsInfo.numOfOutputCols;
|
||||
SFieldInfo *pFieldsInfo = &pSql->cmd.fieldsInfo;
|
||||
|
||||
return (pFieldsInfo->numOfOutputCols - pFieldsInfo->numOfHiddenCols);
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS *taos) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) return 0;
|
||||
|
||||
return pObj->pSql->cmd.fieldsInfo.numOfOutputCols;
|
||||
return taos_num_fields(pObj->pSql);
|
||||
}
|
||||
|
||||
int taos_affected_rows(TAOS *taos) {
|
||||
|
@ -304,9 +347,8 @@ int taos_retrieve(TAOS_RES *res) {
|
|||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
if (pRes->qhandle == 0) return 0;
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
tscResetForNextRetrieve(pRes);
|
||||
|
||||
if (pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
@ -327,9 +369,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
}
|
||||
|
||||
// Retrieve new block
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
tscResetForNextRetrieve(pRes);
|
||||
if (pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
@ -355,38 +395,15 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
return (pCmd->order.order == TSQL_SO_DESC) ? pRes->numOfRows : -pRes->numOfRows;
|
||||
}
|
||||
|
||||
TAOS_ROW taos_fetch_row_impl(TAOS_RES *res) {
|
||||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
static void **doSetResultRowData(SSqlObj *pSql) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
STscObj *pObj = pSql->pTscObj;
|
||||
int wccount = 0;
|
||||
|
||||
if (pRes->qhandle == 0) return NULL;
|
||||
|
||||
if (pRes->row >= pRes->numOfRows) {
|
||||
if (pObj->pSql != pSql) return NULL;
|
||||
|
||||
pRes->row = 0;
|
||||
pRes->numOfRows = 0;
|
||||
pCmd->type = 0;
|
||||
if (pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
if (pRes->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// secondary merge has handle this situation
|
||||
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC) {
|
||||
pRes->numOfTotal += pRes->numOfRows;
|
||||
}
|
||||
}
|
||||
int32_t num = 0;
|
||||
|
||||
for (int i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pCmd, i, pCmd->order) + pRes->bytes[i] * pRes->row;
|
||||
|
||||
// primary key column cannot be null in interval query, no need to check
|
||||
if (i == 0 && pCmd->nAggTimeInterval > 0) {
|
||||
continue;
|
||||
|
@ -397,34 +414,169 @@ TAOS_ROW taos_fetch_row_impl(TAOS_RES *res) {
|
|||
if (isNull(pRes->tsrow[i], pField->type)) {
|
||||
pRes->tsrow[i] = NULL;
|
||||
} else if (pField->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
/*
|
||||
* convert unicode to native code in a temporary buffer extra one byte for terminated symbol
|
||||
*/
|
||||
if (pRes->buffer[wccount] == NULL) {
|
||||
pRes->buffer[wccount] = (char *)calloc(1, pField->bytes + 1);
|
||||
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
|
||||
if (pRes->buffer[num] == NULL) {
|
||||
pRes->buffer[num] = malloc(pField->bytes + 1);
|
||||
} else {
|
||||
pRes->buffer[wccount] = realloc(pRes->buffer[wccount], pField->bytes + 1);
|
||||
pRes->buffer[num] = realloc(pRes->buffer[num], pField->bytes + 1);
|
||||
}
|
||||
|
||||
/* string terminated */
|
||||
memset(pRes->buffer[wccount], 0, pField->bytes);
|
||||
memset(pRes->buffer[num], 0, pField->bytes + 1);
|
||||
|
||||
if (taosUcs4ToMbs(pRes->tsrow[i], pField->bytes, pRes->buffer[wccount])) {
|
||||
pRes->tsrow[i] = pRes->buffer[wccount];
|
||||
if (taosUcs4ToMbs(pRes->tsrow[i], pField->bytes, pRes->buffer[num])) {
|
||||
pRes->tsrow[i] = pRes->buffer[num];
|
||||
} else {
|
||||
tscError("%p charset:%s to %s. val:%ls convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, pRes->tsrow);
|
||||
pRes->tsrow[i] = NULL;
|
||||
}
|
||||
wccount++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(wccount <= pRes->numOfnchar);
|
||||
assert(num <= pCmd->fieldsInfo.numOfOutputCols);
|
||||
|
||||
return pRes->tsrow;
|
||||
}
|
||||
|
||||
static void **getOneRowFromBuf(SSqlObj *pSql) {
|
||||
doSetResultRowData(pSql);
|
||||
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
pRes->row++;
|
||||
|
||||
return pRes->tsrow;
|
||||
}
|
||||
|
||||
static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
while (1) {
|
||||
bool hasData = true;
|
||||
|
||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
||||
SSqlRes *pRes1 = &pSql->pSubs[i]->res;
|
||||
|
||||
// in case inner join, if any subquery exhausted, query completed
|
||||
if (pRes1->numOfRows == 0) {
|
||||
hasData = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasData) { // free all sub sqlobj
|
||||
tscTrace("%p one subquery exhausted, free other %d subquery", pSql, pSql->numOfSubs - 1);
|
||||
|
||||
SSubqueryState *pState = NULL;
|
||||
|
||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
||||
SSqlObj * pChildObj = pSql->pSubs[i];
|
||||
SJoinSubquerySupporter *pSupporter = (SJoinSubquerySupporter *)pChildObj->param;
|
||||
pState = pSupporter->pState;
|
||||
|
||||
tscDestroyJoinSupporter(pChildObj->param);
|
||||
taos_free_result(pChildObj);
|
||||
}
|
||||
|
||||
free(pState);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pRes->tsrow == NULL) {
|
||||
pRes->tsrow = malloc(sizeof(void *) * pCmd->exprsInfo.numOfExprs);
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
if (pSql->numOfSubs >= 2) {
|
||||
// do merge result
|
||||
SSqlRes *pRes1 = &pSql->pSubs[0]->res;
|
||||
SSqlRes *pRes2 = &pSql->pSubs[1]->res;
|
||||
|
||||
while (pRes1->row < pRes1->numOfRows && pRes2->row < pRes2->numOfRows) {
|
||||
doSetResultRowData(pSql->pSubs[0]);
|
||||
doSetResultRowData(pSql->pSubs[1]);
|
||||
|
||||
TSKEY key1 = *(TSKEY *)pRes1->tsrow[0];
|
||||
TSKEY key2 = *(TSKEY *)pRes2->tsrow[0];
|
||||
|
||||
if (key1 == key2) {
|
||||
success = true;
|
||||
pRes1->row++;
|
||||
pRes2->row++;
|
||||
break;
|
||||
} else if (key1 < key2) {
|
||||
pRes1->row++;
|
||||
} else if (key1 > key2) {
|
||||
pRes2->row++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SSqlRes *pRes1 = &pSql->pSubs[0]->res;
|
||||
doSetResultRowData(pSql->pSubs[0]);
|
||||
|
||||
success = (pRes1->row++ < pRes1->numOfRows);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) {
|
||||
int32_t tableIndex = pRes->pColumnIndex[i].tableIndex;
|
||||
int32_t columnIndex = pRes->pColumnIndex[i].columnIndex;
|
||||
|
||||
SSqlRes *pRes1 = &pSql->pSubs[tableIndex]->res;
|
||||
pRes->tsrow[i] = pRes1->tsrow[columnIndex];
|
||||
}
|
||||
|
||||
break;
|
||||
} else {
|
||||
tscFetchDatablockFromSubquery(pSql);
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pRes->tsrow;
|
||||
}
|
||||
|
||||
TAOS_ROW taos_fetch_row_impl(TAOS_RES *res) {
|
||||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
if (pRes->qhandle == 0 || pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pCmd->command == TSDB_SQL_METRIC_JOIN_RETRIEVE) {
|
||||
tscFetchDatablockFromSubquery(pSql);
|
||||
if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||
return tscJoinResultsetFromBuf(pSql);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} else if (pRes->row >= pRes->numOfRows) {
|
||||
tscResetForNextRetrieve(pRes);
|
||||
|
||||
if (pCmd->command < TSDB_SQL_LOCAL) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
if (pRes->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// local reducer has handle this situation
|
||||
if (pCmd->command != TSDB_SQL_RETRIEVE_METRIC) {
|
||||
pRes->numOfTotal += pRes->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
return getOneRowFromBuf(pSql);
|
||||
}
|
||||
|
||||
TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
||||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
@ -437,8 +589,10 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
|
||||
// projection query on metric, pipeline retrieve data from vnode list, instead of two-stage merge
|
||||
TAOS_ROW rows = taos_fetch_row_impl(res);
|
||||
while (rows == NULL && tscProjectionQueryOnMetric(pSql)) {
|
||||
/* reach the maximum number of output rows, abort */
|
||||
while (rows == NULL && tscProjectionQueryOnMetric(pCmd)) {
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
// reach the maximum number of output rows, abort
|
||||
if (pCmd->globalLimit > 0 && pRes->numOfTotal >= pCmd->globalLimit) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -452,7 +606,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
|
||||
assert((pRes->offset >= 0 && pRes->numOfRows == 0) || (pRes->offset == 0 && pRes->numOfRows >= 0));
|
||||
|
||||
if ((++pCmd->vnodeIdx) <= pCmd->pMetricMeta->numOfVnodes) {
|
||||
if ((++pCmd->vnodeIdx) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
||||
pCmd->command = TSDB_SQL_SELECT;
|
||||
assert(pSql->fp == NULL);
|
||||
tscProcessSql(pSql);
|
||||
|
@ -460,7 +614,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
// check!!!
|
||||
if (rows != NULL || pCmd->vnodeIdx >= pCmd->pMetricMeta->numOfVnodes) {
|
||||
if (rows != NULL || pCmd->vnodeIdx >= pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -481,20 +635,26 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// projection query on metric, pipeline retrieve data from vnode list, instead
|
||||
// of two-stage mergevnodeProcessMsgFromShell free qhandle
|
||||
// projection query on metric, pipeline retrieve data from vnode list,
|
||||
// instead of two-stage mergevnodeProcessMsgFromShell free qhandle
|
||||
nRows = taos_fetch_block_impl(res, rows);
|
||||
while (*rows == NULL && tscProjectionQueryOnMetric(pSql)) {
|
||||
while (*rows == NULL && tscProjectionQueryOnMetric(pCmd)) {
|
||||
/* reach the maximum number of output rows, abort */
|
||||
if (pCmd->globalLimit > 0 && pRes->numOfTotal >= pCmd->globalLimit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
/* update the limit value according to current retrieval results */
|
||||
pCmd->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal;
|
||||
pCmd->limit.offset = pRes->offset;
|
||||
|
||||
if ((++pSql->cmd.vnodeIdx) <= pSql->cmd.pMetricMeta->numOfVnodes) {
|
||||
#ifdef CLUSTER
|
||||
if ((++pSql->cmd.vnodeIdx) <= pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
||||
#else
|
||||
if ((++pSql->cmd.vnodeIdx) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
||||
#endif
|
||||
pSql->cmd.command = TSDB_SQL_SELECT;
|
||||
assert(pSql->fp == NULL);
|
||||
tscProcessSql(pSql);
|
||||
|
@ -502,7 +662,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
}
|
||||
|
||||
// check!!!
|
||||
if (*rows != NULL || pCmd->vnodeIdx >= pCmd->pMetricMeta->numOfVnodes) {
|
||||
if (*rows != NULL || pCmd->vnodeIdx >= pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -510,7 +670,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
return nRows;
|
||||
}
|
||||
|
||||
int taos_select_db(TAOS *taos, char *db) {
|
||||
int taos_select_db(TAOS *taos, const char *db) {
|
||||
char sql[64];
|
||||
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
|
@ -534,6 +694,7 @@ void taos_free_result(TAOS_RES *res) {
|
|||
tscTrace("%p start to free result", pSql);
|
||||
|
||||
if (pSql->signature != pSql) return;
|
||||
|
||||
if (pRes == NULL || pRes->qhandle == 0) {
|
||||
/* Query rsp is not received from vnode, so the qhandle is NULL */
|
||||
tscTrace("%p qhandle is null, abort free, fp:%p", pSql, pSql->fp);
|
||||
|
@ -547,52 +708,61 @@ void taos_free_result(TAOS_RES *res) {
|
|||
return;
|
||||
}
|
||||
|
||||
pCmd->type = 1; // set freeFlag to 1 in retrieve message if there are
|
||||
// un-retrieved results
|
||||
// set freeFlag to 1 in retrieve message if there are un-retrieved results
|
||||
pCmd->type = TSDB_QUERY_TYPE_FREE_RESOURCE;
|
||||
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
/*
|
||||
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet. We need to recycle
|
||||
* the connection by noticing the vnode return 0 results.
|
||||
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet.
|
||||
* We need to recycle the connection by noticing the vnode return 0 results.
|
||||
* case 2. When the query response is received from vnodes and the numOfRows is set to 0, the user calls
|
||||
* taos_free_result before the taos_fetch_row is called in non-stream computing, we need to recycle the
|
||||
* connection.
|
||||
* case 3. If the query process is cancelled by user in stable query, tscProcessSql should not be called for each
|
||||
* subquery. Because the failure of execution tsProcessSql may trigger the callback function
|
||||
* be executed, and the retry efforts may result in double free the
|
||||
* resources, e.g.,SRetrieveSupport
|
||||
* taos_free_result before the taos_fetch_row is called in non-stream computing,
|
||||
* we need to recycle the connection.
|
||||
* case 3. If the query process is cancelled by user in stable query, tscProcessSql should not be called
|
||||
* for each subquery. Because the failure of execution tsProcessSql may trigger the callback function
|
||||
* be executed, and the retry efforts may result in double free the resources, e.g.,SRetrieveSupport
|
||||
*/
|
||||
if (pRes->code != TSDB_CODE_QUERY_CANCELLED &&
|
||||
((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL) ||
|
||||
(pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows == 0 && pCmd->command == TSDB_SQL_SELECT &&
|
||||
pSql->pStream == NULL && pCmd->pMeterMeta != NULL))) {
|
||||
pSql->pStream == NULL && pMeterMetaInfo->pMeterMeta != NULL))) {
|
||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||
|
||||
void *fp = pSql->fp;
|
||||
if (fp != NULL) {
|
||||
pSql->freed = 1;
|
||||
}
|
||||
|
||||
tscProcessSql(pSql);
|
||||
|
||||
if (pSql->fp) {
|
||||
pSql->freed = 1;
|
||||
} else {
|
||||
pSql->thandle = NULL;
|
||||
|
||||
/*
|
||||
* If release connection msg is sent to vnode, the corresponding SqlObj for async query can not be freed instantly,
|
||||
* since its free operation is delegated to callback function, which is tscProcessMsgFromServer.
|
||||
*/
|
||||
if (fp == NULL) {
|
||||
/*
|
||||
* remove allocated resources and release metermeta/metricmeta references in cache
|
||||
* since current query is completed
|
||||
*/
|
||||
* fp may be released here, so we cannot use the pSql->fp
|
||||
*
|
||||
* In case of handle sync model query, the main SqlObj cannot be freed.
|
||||
* So, we only free part attributes, including allocated resources and references on metermeta/metricmeta
|
||||
* data in cache.
|
||||
*
|
||||
* Then this object will be reused and no free operation is required.
|
||||
*/
|
||||
pSql->thandle = NULL;
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
tscTrace("%p sql result is freed by app", pSql);
|
||||
}
|
||||
} else {
|
||||
// if no free resource msg is sent to vnode, we free this object immediately.
|
||||
pSql->thandle = NULL;
|
||||
|
||||
if (pSql->fp) {
|
||||
assert(pRes->numOfRows == 0 || (pCmd->command > TSDB_SQL_LOCAL));
|
||||
pSql->thandle = NULL;
|
||||
tscFreeSqlObj(pSql);
|
||||
tscTrace("%p Async SqlObj is freed by app", pSql);
|
||||
tscTrace("%p Async sql result is freed by app", pSql);
|
||||
} else {
|
||||
pSql->thandle = NULL;
|
||||
|
||||
/*
|
||||
* remove allocated resources and release metermeta/metricmeta references in cache
|
||||
* since current query is completed
|
||||
*/
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
tscTrace("%p sql result is freed", pSql);
|
||||
}
|
||||
|
@ -658,7 +828,7 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
|
||||
pSql->res.code = TSDB_CODE_QUERY_CANCELLED;
|
||||
|
||||
if (tscIsTwoStageMergeMetricQuery(pSql)) {
|
||||
if (tscIsTwoStageMergeMetricQuery(&pSql->cmd)) {
|
||||
tscKillMetricQuery(pSql);
|
||||
return;
|
||||
}
|
||||
|
@ -710,7 +880,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:{
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
/* limit the max length of string to no greater than the maximum length,
|
||||
* in case of not null-terminated string */
|
||||
size_t xlen = strlen(row[i]);
|
||||
|
@ -737,7 +907,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
return len;
|
||||
}
|
||||
|
||||
int taos_validate_sql(TAOS *taos, char *sql) {
|
||||
int taos_validate_sql(TAOS *taos, const char *sql) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
globalCode = TSDB_CODE_DISCONNECTED;
|
||||
|
@ -777,3 +947,141 @@ int taos_validate_sql(TAOS *taos, char *sql) {
|
|||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int tscParseTblNameList(SSqlObj *pSql, const char* tblNameList, int32_t tblListLen) {
|
||||
// must before clean the sqlcmd object
|
||||
tscRemoveAllMeterMetaInfo(&pSql->cmd, false);
|
||||
tscCleanSqlCmd(&pSql->cmd);
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
pCmd->command = TSDB_SQL_MULTI_META;
|
||||
pCmd->count = 0;
|
||||
|
||||
int code = TSDB_CODE_INVALID_METER_ID;
|
||||
char *str = (char*) tblNameList;
|
||||
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pCmd);
|
||||
|
||||
if ((code = tscAllocPayload(pCmd, tblListLen+16)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
char *nextStr;
|
||||
char tblName[TSDB_METER_ID_LEN];
|
||||
int payloadLen = 0;
|
||||
char *pMsg = pCmd->payload;
|
||||
while (1) {
|
||||
nextStr = strchr(str, ',');
|
||||
if (nextStr == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(tblName, str, nextStr - str);
|
||||
int32_t len = nextStr - str;
|
||||
tblName[len] = '\0';
|
||||
|
||||
str = nextStr + 1;
|
||||
|
||||
strtrim(tblName);
|
||||
len = (uint32_t)strlen(tblName);
|
||||
|
||||
SSQLToken sToken = {.n = len, .type = TK_ID, .z = tblName};
|
||||
tSQLGetToken(tblName, &sToken.type);
|
||||
|
||||
// Check if the table name available or not
|
||||
if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_INVALID_METER_ID;
|
||||
sprintf(pCmd->payload, "table name is invalid");
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((code = setMeterID(pSql, &sToken, 0)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) {
|
||||
code = TSDB_CODE_INVALID_METER_ID;
|
||||
sprintf(pCmd->payload, "tables over the max number");
|
||||
return code;
|
||||
}
|
||||
|
||||
if (payloadLen + strlen(pMeterMetaInfo->name) + 128 >= pCmd->allocSize) {
|
||||
char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen);
|
||||
if (pNewMem == NULL) {
|
||||
code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
sprintf(pCmd->payload, "failed to allocate memory");
|
||||
return code;
|
||||
}
|
||||
|
||||
pCmd->payload = pNewMem;
|
||||
pCmd->allocSize = pCmd->allocSize + tblListLen;
|
||||
pMsg = pCmd->payload;
|
||||
}
|
||||
|
||||
payloadLen += sprintf(pMsg + payloadLen, "%s,", pMeterMetaInfo->name);
|
||||
}
|
||||
|
||||
*(pMsg + payloadLen) = '\0';
|
||||
pCmd->payloadLen = payloadLen + 1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||
const int32_t MAX_TABLE_NAME_LENGTH = 12*1024*1024; // 12MB list
|
||||
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
globalCode = TSDB_CODE_DISCONNECTED;
|
||||
return TSDB_CODE_DISCONNECTED;
|
||||
}
|
||||
|
||||
SSqlObj *pSql = pObj->pSql;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
pRes->numOfTotal = 0; // the number of getting table meta from server
|
||||
pRes->code = 0;
|
||||
|
||||
assert(pSql->fp == NULL);
|
||||
tscTrace("%p tableNameList: %s pObj:%p", pSql, tableNameList, pObj);
|
||||
|
||||
int32_t tblListLen = strlen(tableNameList);
|
||||
if (tblListLen > MAX_TABLE_NAME_LENGTH) {
|
||||
tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH);
|
||||
pRes->code = TSDB_CODE_INVALID_SQL;
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
char* str = calloc(1, tblListLen + 1);
|
||||
if (str == NULL) {
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
strtolower(str, tableNameList);
|
||||
pRes->code = (uint8_t) tscParseTblNameList(pSql, str, tblListLen);
|
||||
|
||||
/*
|
||||
* set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query.
|
||||
* If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql()
|
||||
* to free connection, which may cause segment fault, when the parse phrase is not even successfully executed.
|
||||
*/
|
||||
pRes->qhandle = 0;
|
||||
pSql->thandle = NULL;
|
||||
free(str);
|
||||
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
tscDoQuery(pSql);
|
||||
|
||||
tscTrace("%p load multi metermeta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
}
|
||||
|
||||
return pRes->code;
|
||||
}
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
#include "tsql.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#include "taosmsg.h"
|
||||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
|
||||
|
@ -32,7 +34,7 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer);
|
|||
static bool isProjectStream(SSqlCmd *pCmd) {
|
||||
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
||||
if (pExpr->sqlFuncId != TSDB_FUNC_PRJ) {
|
||||
if (pExpr->functionId != TSDB_FUNC_PRJ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -64,14 +66,15 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
|||
|
||||
pSql->fp = tscProcessStreamQueryCallback;
|
||||
pSql->param = pStream;
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
|
||||
|
||||
int code = tscGetMeterMeta(pSql, pSql->cmd.name);
|
||||
int code = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0);
|
||||
pSql->res.code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
||||
if (code == 0 && UTIL_METER_IS_METRIC(&pSql->cmd)) {
|
||||
code = tscGetMetricMeta(pSql, pSql->cmd.name);
|
||||
if (code == 0 && UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
code = tscGetMetricMeta(pSql);
|
||||
pSql->res.code = code;
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
|
@ -88,7 +91,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
|||
return;
|
||||
}
|
||||
|
||||
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pSql->cmd.name);
|
||||
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pMeterMetaInfo->name);
|
||||
tscProcessSql(pStream->pSql);
|
||||
|
||||
tscIncStreamExecutionCount(pStream);
|
||||
|
@ -102,6 +105,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
|||
|
||||
pStream->numOfRes = 0; // reset the numOfRes.
|
||||
SSqlObj *pSql = pStream->pSql;
|
||||
tscTrace("%p add into timer", pSql);
|
||||
|
||||
if (isProjectStream(&pSql->cmd)) {
|
||||
/*
|
||||
|
@ -135,7 +139,9 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
tscError("%p stream:%p, query data failed, code:%d, retry in %lldms", pStream->pSql, pStream, numOfRows,
|
||||
retryDelay);
|
||||
|
||||
tscClearSqlMetaInfoForce(&(pStream->pSql->cmd));
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pStream->pSql->cmd, 0);
|
||||
tscClearMeterMetaInfo(pMeterMetaInfo, true);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
||||
return;
|
||||
}
|
||||
|
@ -143,7 +149,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
taos_fetch_rows_a(tres, tscProcessStreamRetrieveResult, param);
|
||||
}
|
||||
|
||||
static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql, int32_t numOfRows) {
|
||||
static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
int64_t timestamp = *(int64_t *)pRes->data;
|
||||
|
@ -157,31 +163,29 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql, int32_t nu
|
|||
}
|
||||
|
||||
static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows) {
|
||||
SSqlStream *pStream = (SSqlStream *)param;
|
||||
SSqlObj * pSql = (SSqlObj *)res;
|
||||
SSqlStream * pStream = (SSqlStream *)param;
|
||||
SSqlObj * pSql = (SSqlObj *)res;
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
|
||||
|
||||
if (pSql == NULL || numOfRows < 0) {
|
||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %lldms", pSql, pStream, numOfRows, retryDelayTime);
|
||||
tscClearSqlMetaInfoForce(&(pStream->pSql->cmd));
|
||||
tscClearMeterMetaInfo(pMeterMetaInfo, true);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
||||
return;
|
||||
}
|
||||
|
||||
if (numOfRows > 0) { // save
|
||||
// when reaching here the first execution of stream computing is successful.
|
||||
if (numOfRows > 0) { // when reaching here the first execution of stream computing is successful.
|
||||
pStream->numOfRes += numOfRows;
|
||||
TAOS_ROW row = NULL; //;
|
||||
while ((row = taos_fetch_row(res)) != NULL) {
|
||||
// char result[512] = {0};
|
||||
// taos_print_row(result, row, pSql->cmd.fieldsInfo.pFields, pSql->cmd.fieldsInfo.numOfOutputCols);
|
||||
// tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
TAOS_ROW row = taos_fetch_row(res);
|
||||
tscTrace("%p stream:%p fetch result", pSql, pStream);
|
||||
if (isProjectStream(&pSql->cmd)) {
|
||||
pStream->stime = *(TSKEY *)row[0];
|
||||
} else {
|
||||
tscSetTimestampForRes(pStream, pSql, numOfRows);
|
||||
tscSetTimestampForRes(pStream, pSql);
|
||||
}
|
||||
|
||||
// user callback function
|
||||
|
@ -214,7 +218,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
row[i] = pSql->res.data + offset;
|
||||
}
|
||||
|
||||
tscSetTimestampForRes(pStream, pSql, numOfRows);
|
||||
tscSetTimestampForRes(pStream, pSql);
|
||||
row[0] = pRes->data;
|
||||
|
||||
// char result[512] = {0};
|
||||
|
@ -243,11 +247,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
}
|
||||
}
|
||||
|
||||
tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d.", pSql, pStream, pSql->cmd.name,
|
||||
tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pMeterMetaInfo->name,
|
||||
pStream->numOfRes);
|
||||
|
||||
/* release the metric/meter meta information reference, so data in cache can be updated */
|
||||
tscClearSqlMetaInfo(&(pSql->cmd));
|
||||
// release the metric/meter meta information reference, so data in cache can be updated
|
||||
tscClearMeterMetaInfo(pMeterMetaInfo, false);
|
||||
tscSetNextLaunchTimer(pStream, pSql);
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +355,6 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
|
|||
if (pCmd->nAggTimeInterval < minIntervalTime) {
|
||||
tscWarn("%p stream:%p, original sample interval:%ld too small, reset to:%lld", pSql, pStream,
|
||||
pCmd->nAggTimeInterval, minIntervalTime);
|
||||
|
||||
pCmd->nAggTimeInterval = minIntervalTime;
|
||||
}
|
||||
|
||||
|
@ -447,7 +450,7 @@ static void setErrorInfo(STscObj* pObj, int32_t code, char* info) {
|
|||
strncpy(pCmd->payload, info, pCmd->payloadLen);
|
||||
}
|
||||
|
||||
TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||
int64_t stime, void *param, void (*callback)(void *)) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) return NULL;
|
||||
|
@ -462,7 +465,12 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param,
|
|||
pSql->pTscObj = pObj;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
tscAllocPayloadWithSize(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
int ret = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
if (TSDB_CODE_SUCCESS != ret) {
|
||||
setErrorInfo(pObj, ret, NULL);
|
||||
free(pSql);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSql->sqlstr = strdup(sqlstr);
|
||||
if (pSql->sqlstr == NULL) {
|
||||
|
@ -479,10 +487,16 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param,
|
|||
tSQLParse(&SQLInfo, pSql->sqlstr);
|
||||
|
||||
tscCleanSqlCmd(&pSql->cmd);
|
||||
tscAllocPayloadWithSize(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
|
||||
//todo refactor later
|
||||
pSql->cmd.count = 1;
|
||||
ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||
if (TSDB_CODE_SUCCESS != ret) {
|
||||
setErrorInfo(pObj, ret, NULL);
|
||||
tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_CLI_OUT_OF_MEMORY);
|
||||
tscFreeSqlObj(pSql);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO later refactor use enum
|
||||
pSql->cmd.count = 1; // 1 means sql in stream, allowed the sliding clause.
|
||||
pRes->code = tscToSQLCmd(pSql, &SQLInfo);
|
||||
SQLInfoDestroy(&SQLInfo);
|
||||
|
||||
|
@ -503,13 +517,16 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||
|
||||
pStream->fp = fp;
|
||||
pStream->callback = callback;
|
||||
pStream->param = param;
|
||||
pStream->pSql = pSql;
|
||||
pStream->ctime = taosGetTimestamp(pCmd->pMeterMeta->precision);
|
||||
pStream->precision = pMeterMetaInfo->pMeterMeta->precision;
|
||||
|
||||
pStream->ctime = taosGetTimestamp(pStream->precision);
|
||||
pStream->etime = pCmd->etime;
|
||||
pStream->precision = pCmd->pMeterMeta->precision;
|
||||
|
||||
pSql->pStream = pStream;
|
||||
tscAddIntoStreamList(pStream);
|
||||
|
@ -521,7 +538,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param,
|
|||
taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer);
|
||||
|
||||
tscTrace("%p stream:%p is opened, query on:%s, interval:%lld, sliding:%lld, first launched in:%lld, sql:%s", pSql,
|
||||
pStream, pSql->cmd.name, pStream->interval, pStream->slidingTime, starttime, sqlstr);
|
||||
pStream, pMeterMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr);
|
||||
|
||||
return pStream;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct {
|
|||
TAOS_RES * result;
|
||||
} SSub;
|
||||
|
||||
TAOS_SUB *taos_subscribe(char *host, char *user, char *pass, char *db, char *name, int64_t time, int mseconds) {
|
||||
TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, const char *db, const char *name, int64_t time, int mseconds) {
|
||||
SSub *pSub;
|
||||
|
||||
pSub = (SSub *)malloc(sizeof(SSub));
|
||||
|
|
|
@ -23,39 +23,36 @@
|
|||
#include "ttypes.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
|
||||
{ \
|
||||
int32_t i = ((_ord) == TSQL_SO_ASC) ? 0 : MAX(len1, len2) - 1; \
|
||||
int32_t step = ((_ord) == TSQL_SO_ASC) ? 1 : -1; \
|
||||
\
|
||||
if ((len1) == (len2)) { \
|
||||
for (; i < (len2) && i >= 0; i += step) { \
|
||||
if (isNull((char *)&(left)[i], _left_type) || isNull((char *)&(right)[i], _right_type)) { \
|
||||
setNull((char *)&(out)[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)(left)[i] op(right)[i]; \
|
||||
(out) += step; \
|
||||
} \
|
||||
} else if ((len1) == 1) { \
|
||||
for (; i >= 0 && i < (len2); i += step) { \
|
||||
if (isNull((char *)&(left)[i], _left_type) || isNull((char *)&(right)[i], _right_type)) { \
|
||||
setNull((char *)&(out)[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)pLeft[0] op(pRight)[i]; \
|
||||
(out) += step; \
|
||||
} \
|
||||
} else if ((len2) == 1) { \
|
||||
for (; i >= 0 && i < (len1); i += step) { \
|
||||
if (isNull((char *)&(left)[i], _left_type) || isNull((char *)&(right)[i], _right_type)) { \
|
||||
setNull((char *)&(out)[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)(pLeft)[i] op(pRight)[0]; \
|
||||
(out) += step; \
|
||||
} \
|
||||
} \
|
||||
#define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
|
||||
{ \
|
||||
int32_t i = ((_ord) == TSQL_SO_ASC) ? 0 : MAX(len1, len2) - 1; \
|
||||
int32_t step = ((_ord) == TSQL_SO_ASC) ? 1 : -1; \
|
||||
\
|
||||
if ((len1) == (len2)) { \
|
||||
for (; i < (len2) && i >= 0; i += step, (out) += step) { \
|
||||
if (isNull((char *)&((left)[i]), _left_type) || isNull((char *)&((right)[i]), _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)(left)[i] op(right)[i]; \
|
||||
} \
|
||||
} else if ((len1) == 1) { \
|
||||
for (; i >= 0 && i < (len2); i += step, (out) += step) { \
|
||||
if (isNull((char *)(left), _left_type) || isNull((char *)&(right)[i], _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)(left)[0] op(right)[i]; \
|
||||
} \
|
||||
} else if ((len2) == 1) { \
|
||||
for (; i >= 0 && i < (len1); i += step, (out) += step) { \
|
||||
if (isNull((char *)&(left)[i], _left_type) || isNull((char *)(right), _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)(left)[i] op(right)[0]; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ARRAY_LIST_OP_REM(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
|
||||
|
@ -64,31 +61,28 @@
|
|||
int32_t step = (_ord == TSQL_SO_ASC) ? 1 : -1; \
|
||||
\
|
||||
if (len1 == (len2)) { \
|
||||
for (; i >= 0 && i < (len2); i += step) { \
|
||||
if (isNull((char *)&left[i], _left_type) || isNull((char *)&right[i], _right_type)) { \
|
||||
setNull((char *)&out[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
for (; i >= 0 && i < (len2); i += step, (out) += step) { \
|
||||
if (isNull((char *)&(left[i]), _left_type) || isNull((char *)&(right[i]), _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[i])) * pRight[i]; \
|
||||
(out) += step; \
|
||||
*(out) = (double)(left)[i] - ((int64_t)(((double)(left)[i]) / (right)[i])) * (right)[i]; \
|
||||
} \
|
||||
} else if (len1 == 1) { \
|
||||
for (; i >= 0 && i < (len2); i += step) { \
|
||||
if (isNull((char *)&left[i], _left_type) || isNull((char *)&right[i], _right_type)) { \
|
||||
setNull((char *)&out[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
for (; i >= 0 && i < (len2); i += step, (out) += step) { \
|
||||
if (isNull((char *)(left), _left_type) || isNull((char *)&((right)[i]), _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)pLeft[0] - ((int64_t)(((double)pLeft[0]) / pRight[i])) * pRight[i]; \
|
||||
(out) += step; \
|
||||
*(out) = (double)(left)[0] - ((int64_t)(((double)(left)[0]) / (right)[i])) * (right)[i]; \
|
||||
} \
|
||||
} else if ((len2) == 1) { \
|
||||
for (; i >= 0 && i < len1; i += step) { \
|
||||
if (isNull((char *)&left[i], _left_type) || isNull((char *)&right[i], _right_type)) { \
|
||||
setNull((char *)&out[i], _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
for (; i >= 0 && i < len1; i += step, (out) += step) { \
|
||||
if (isNull((char *)&((left)[i]), _left_type) || isNull((char *)(right), _right_type)) { \
|
||||
setNull((char *)(out), _res_type, tDataTypeDesc[_res_type].nSize); \
|
||||
continue; \
|
||||
} \
|
||||
*(out) = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[0])) * pRight[0]; \
|
||||
(out) += step; \
|
||||
*(out) = (double)(left)[i] - ((int64_t)(((double)(left)[i]) / (right)[0])) * (right)[0]; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
@ -121,33 +115,30 @@ void calc_fn_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRi
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] + pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; ++i) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] + pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; ++i) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] + pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,31 +313,28 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&(pOutput[i]), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] - pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[0] - pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] - pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,31 +524,30 @@ void calc_fn_i32_i32_multi(void *left, void *right, int32_t numLeft, int32_t num
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] * pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -735,31 +722,30 @@ void calc_fn_i32_i32_div(void *left, void *right, int32_t numLeft, int32_t numRi
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] / pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] / pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] / pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -950,32 +936,31 @@ void calc_fn_i32_i32_rem(void *left, void *right, int32_t numLeft, int32_t numRi
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[i])) * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] - ((int64_t)(((double)pLeft[0]) / pRight[i])) * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[0])) * pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1009,31 +994,31 @@ void calc_fn_i32_d_rem(void *left, void *right, int32_t numLeft, int32_t numRigh
|
|||
int32_t step = (order == TSQL_SO_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_DOUBLE)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[i])) * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_DOUBLE)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += step) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] - ((int64_t)(((double)pLeft[0]) / pRight[i])) * pRight[i];
|
||||
pOutput += step;
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step) {
|
||||
if (isNull((char *)&pLeft[i], TSDB_DATA_TYPE_INT) || isNull((char *)&pRight[i], TSDB_DATA_TYPE_DOUBLE)) {
|
||||
setNull((char *)&pOutput[i], TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += step) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
setNull((char *)pOutput, TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] - ((int64_t)(((double)pLeft[i]) / pRight[0])) * pRight[0];
|
||||
pOutput += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1192,98 +1177,63 @@ void calc_fn_d_d_rem(void *left, void *right, int32_t numLeft, int32_t numRight,
|
|||
* the following are two-dimensional array list of callback function .
|
||||
*/
|
||||
_bi_consumer_fn_t add_function_arraylist[8][10] = {
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp,
|
||||
binary*/
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp, binary*/
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // EMPTY,
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // TSDB_DATA_TYPE_BOOL,
|
||||
{NULL, NULL, calc_fn_i8_i8_add, calc_fn_i8_i16_add, calc_fn_i8_i32_add, calc_fn_i8_i64_add, calc_fn_i8_f_add,
|
||||
calc_fn_i8_d_add, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_add, calc_fn_i16_i16_add, calc_fn_i16_i32_add, calc_fn_i16_i64_add, calc_fn_i16_f_add,
|
||||
calc_fn_i16_d_add, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_add, calc_fn_i32_i16_add, calc_fn_i32_i32_add, calc_fn_i32_i64_add, calc_fn_i32_f_add,
|
||||
calc_fn_i32_d_add, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_add, calc_fn_i64_i16_add, calc_fn_i64_i32_add, calc_fn_i64_i64_add, calc_fn_i64_f_add,
|
||||
calc_fn_i64_d_add, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_add, calc_fn_f_i16_add, calc_fn_f_i32_add, calc_fn_f_i64_add, calc_fn_f_f_add,
|
||||
calc_fn_f_d_add, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_add, calc_fn_d_i16_add, calc_fn_d_i32_add, calc_fn_d_i64_add, calc_fn_d_f_add,
|
||||
calc_fn_d_d_add, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
{NULL, NULL, calc_fn_i8_i8_add, calc_fn_i8_i16_add, calc_fn_i8_i32_add, calc_fn_i8_i64_add, calc_fn_i8_f_add, calc_fn_i8_d_add, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_add, calc_fn_i16_i16_add, calc_fn_i16_i32_add, calc_fn_i16_i64_add, calc_fn_i16_f_add, calc_fn_i16_d_add, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_add, calc_fn_i32_i16_add, calc_fn_i32_i32_add, calc_fn_i32_i64_add, calc_fn_i32_f_add, calc_fn_i32_d_add, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_add, calc_fn_i64_i16_add, calc_fn_i64_i32_add, calc_fn_i64_i64_add, calc_fn_i64_f_add, calc_fn_i64_d_add, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_add, calc_fn_f_i16_add, calc_fn_f_i32_add, calc_fn_f_i64_add, calc_fn_f_f_add, calc_fn_f_d_add, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_add, calc_fn_d_i16_add, calc_fn_d_i32_add, calc_fn_d_i64_add, calc_fn_d_f_add, calc_fn_d_d_add, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
};
|
||||
|
||||
_bi_consumer_fn_t sub_function_arraylist[8][10] = {
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp,
|
||||
binary*/
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp, binary*/
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // EMPTY,
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // TSDB_DATA_TYPE_BOOL,
|
||||
{NULL, NULL, calc_fn_i8_i8_sub, calc_fn_i8_i16_sub, calc_fn_i8_i32_sub, calc_fn_i8_i64_sub, calc_fn_i8_f_sub,
|
||||
calc_fn_i8_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_sub, calc_fn_i16_i16_sub, calc_fn_i16_i32_sub, calc_fn_i16_i64_sub, calc_fn_i16_f_sub,
|
||||
calc_fn_i16_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_sub, calc_fn_i32_i16_sub, calc_fn_i32_i32_sub, calc_fn_i32_i64_sub, calc_fn_i32_f_sub,
|
||||
calc_fn_i32_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_sub, calc_fn_i64_i16_sub, calc_fn_i64_i32_sub, calc_fn_i64_i64_sub, calc_fn_i64_f_sub,
|
||||
calc_fn_i64_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_sub, calc_fn_f_i16_sub, calc_fn_f_i32_sub, calc_fn_f_i64_sub, calc_fn_f_f_sub,
|
||||
calc_fn_f_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_sub, calc_fn_d_i16_sub, calc_fn_d_i32_sub, calc_fn_d_i64_sub, calc_fn_d_f_sub,
|
||||
calc_fn_d_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
{NULL, NULL, calc_fn_i8_i8_sub, calc_fn_i8_i16_sub, calc_fn_i8_i32_sub, calc_fn_i8_i64_sub, calc_fn_i8_f_sub, calc_fn_i8_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_sub, calc_fn_i16_i16_sub, calc_fn_i16_i32_sub, calc_fn_i16_i64_sub, calc_fn_i16_f_sub, calc_fn_i16_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_sub, calc_fn_i32_i16_sub, calc_fn_i32_i32_sub, calc_fn_i32_i64_sub, calc_fn_i32_f_sub, calc_fn_i32_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_sub, calc_fn_i64_i16_sub, calc_fn_i64_i32_sub, calc_fn_i64_i64_sub, calc_fn_i64_f_sub, calc_fn_i64_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_sub, calc_fn_f_i16_sub, calc_fn_f_i32_sub, calc_fn_f_i64_sub, calc_fn_f_f_sub, calc_fn_f_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_sub, calc_fn_d_i16_sub, calc_fn_d_i32_sub, calc_fn_d_i64_sub, calc_fn_d_f_sub, calc_fn_d_d_sub, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
};
|
||||
|
||||
_bi_consumer_fn_t multi_function_arraylist[][10] = {
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp,
|
||||
binary*/
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp, binary*/
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // EMPTY,
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // TSDB_DATA_TYPE_BOOL,
|
||||
{NULL, NULL, calc_fn_i8_i8_multi, calc_fn_i8_i16_multi, calc_fn_i8_i32_multi, calc_fn_i8_i64_multi,
|
||||
calc_fn_i8_f_multi, calc_fn_i8_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_multi, calc_fn_i16_i16_multi, calc_fn_i16_i32_multi, calc_fn_i16_i64_multi,
|
||||
calc_fn_i16_f_multi, calc_fn_i16_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_multi, calc_fn_i32_i16_multi, calc_fn_i32_i32_multi, calc_fn_i32_i64_multi,
|
||||
calc_fn_i32_f_multi, calc_fn_i32_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_multi, calc_fn_i64_i16_multi, calc_fn_i64_i32_multi, calc_fn_i64_i64_multi,
|
||||
calc_fn_i64_f_multi, calc_fn_i64_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_multi, calc_fn_f_i16_multi, calc_fn_f_i32_multi, calc_fn_f_i64_multi, calc_fn_f_f_multi,
|
||||
calc_fn_f_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_multi, calc_fn_d_i16_multi, calc_fn_d_i32_multi, calc_fn_d_i64_multi, calc_fn_d_f_multi,
|
||||
calc_fn_d_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
{NULL, NULL, calc_fn_i8_i8_multi, calc_fn_i8_i16_multi, calc_fn_i8_i32_multi, calc_fn_i8_i64_multi, calc_fn_i8_f_multi, calc_fn_i8_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_multi, calc_fn_i16_i16_multi, calc_fn_i16_i32_multi, calc_fn_i16_i64_multi, calc_fn_i16_f_multi, calc_fn_i16_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_multi, calc_fn_i32_i16_multi, calc_fn_i32_i32_multi, calc_fn_i32_i64_multi, calc_fn_i32_f_multi, calc_fn_i32_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_multi, calc_fn_i64_i16_multi, calc_fn_i64_i32_multi, calc_fn_i64_i64_multi, calc_fn_i64_f_multi, calc_fn_i64_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_multi, calc_fn_f_i16_multi, calc_fn_f_i32_multi, calc_fn_f_i64_multi, calc_fn_f_f_multi, calc_fn_f_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_multi, calc_fn_d_i16_multi, calc_fn_d_i32_multi, calc_fn_d_i64_multi, calc_fn_d_f_multi, calc_fn_d_d_multi, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
};
|
||||
|
||||
_bi_consumer_fn_t div_function_arraylist[8][10] = {
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp,
|
||||
binary*/
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp, binary*/
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // EMPTY,
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // TSDB_DATA_TYPE_BOOL,
|
||||
{NULL, NULL, calc_fn_i8_i8_div, calc_fn_i8_i16_div, calc_fn_i8_i32_div, calc_fn_i8_i64_div, calc_fn_i8_f_div,
|
||||
calc_fn_i8_d_div, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_div, calc_fn_i16_i16_div, calc_fn_i16_i32_div, calc_fn_i16_i64_div, calc_fn_i16_f_div,
|
||||
calc_fn_i16_d_div, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_div, calc_fn_i32_i16_div, calc_fn_i32_i32_div, calc_fn_i32_i64_div, calc_fn_i32_f_div,
|
||||
calc_fn_i32_d_div, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_div, calc_fn_i64_i16_div, calc_fn_i64_i32_div, calc_fn_i64_i64_div, calc_fn_i64_f_div,
|
||||
calc_fn_i64_d_div, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_div, calc_fn_f_i16_div, calc_fn_f_i32_div, calc_fn_f_i64_div, calc_fn_f_f_div,
|
||||
calc_fn_f_d_div, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_div, calc_fn_d_i16_div, calc_fn_d_i32_div, calc_fn_d_i64_div, calc_fn_d_f_div,
|
||||
calc_fn_d_d_div, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
{NULL, NULL, calc_fn_i8_i8_div, calc_fn_i8_i16_div, calc_fn_i8_i32_div, calc_fn_i8_i64_div, calc_fn_i8_f_div, calc_fn_i8_d_div, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_div, calc_fn_i16_i16_div, calc_fn_i16_i32_div, calc_fn_i16_i64_div, calc_fn_i16_f_div, calc_fn_i16_d_div, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_div, calc_fn_i32_i16_div, calc_fn_i32_i32_div, calc_fn_i32_i64_div, calc_fn_i32_f_div, calc_fn_i32_d_div, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_div, calc_fn_i64_i16_div, calc_fn_i64_i32_div, calc_fn_i64_i64_div, calc_fn_i64_f_div, calc_fn_i64_d_div, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_div, calc_fn_f_i16_div, calc_fn_f_i32_div, calc_fn_f_i64_div, calc_fn_f_f_div, calc_fn_f_d_div, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_div, calc_fn_d_i16_div, calc_fn_d_i32_div, calc_fn_d_i64_div, calc_fn_d_f_div, calc_fn_d_d_div, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
};
|
||||
|
||||
_bi_consumer_fn_t rem_function_arraylist[8][10] = {
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp,
|
||||
binary*/
|
||||
/*NULL, bool, tinyint, smallint, int, bigint, float, double, timestamp, binary*/
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // EMPTY,
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, // TSDB_DATA_TYPE_BOOL,
|
||||
{NULL, NULL, calc_fn_i8_i8_rem, calc_fn_i8_i16_rem, calc_fn_i8_i32_rem, calc_fn_i8_i64_rem, calc_fn_i8_f_rem,
|
||||
calc_fn_i8_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_rem, calc_fn_i16_i16_rem, calc_fn_i16_i32_rem, calc_fn_i16_i64_rem, calc_fn_i16_f_rem,
|
||||
calc_fn_i16_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_rem, calc_fn_i32_i16_rem, calc_fn_i32_i32_rem, calc_fn_i32_i64_rem, calc_fn_i32_f_rem,
|
||||
calc_fn_i32_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_rem, calc_fn_i64_i16_rem, calc_fn_i64_i32_rem, calc_fn_i64_i64_rem, calc_fn_i64_f_rem,
|
||||
calc_fn_i64_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_rem, calc_fn_f_i16_rem, calc_fn_f_i32_rem, calc_fn_f_i64_rem, calc_fn_f_f_rem,
|
||||
calc_fn_f_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_rem, calc_fn_d_i16_rem, calc_fn_d_i32_rem, calc_fn_d_i64_rem, calc_fn_d_f_rem,
|
||||
calc_fn_d_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
{NULL, NULL, calc_fn_i8_i8_rem, calc_fn_i8_i16_rem, calc_fn_i8_i32_rem, calc_fn_i8_i64_rem, calc_fn_i8_f_rem, calc_fn_i8_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_TINYINT
|
||||
{NULL, NULL, calc_fn_i16_i8_rem, calc_fn_i16_i16_rem, calc_fn_i16_i32_rem, calc_fn_i16_i64_rem, calc_fn_i16_f_rem, calc_fn_i16_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_SMALLINT
|
||||
{NULL, NULL, calc_fn_i32_i8_rem, calc_fn_i32_i16_rem, calc_fn_i32_i32_rem, calc_fn_i32_i64_rem, calc_fn_i32_f_rem, calc_fn_i32_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_INT
|
||||
{NULL, NULL, calc_fn_i64_i8_rem, calc_fn_i64_i16_rem, calc_fn_i64_i32_rem, calc_fn_i64_i64_rem, calc_fn_i64_f_rem, calc_fn_i64_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_BIGINT
|
||||
{NULL, NULL, calc_fn_f_i8_rem, calc_fn_f_i16_rem, calc_fn_f_i32_rem, calc_fn_f_i64_rem, calc_fn_f_f_rem, calc_fn_f_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_FLOAT
|
||||
{NULL, NULL, calc_fn_d_i8_rem, calc_fn_d_i16_rem, calc_fn_d_i32_rem, calc_fn_d_i64_rem, calc_fn_d_f_rem, calc_fn_d_d_rem, NULL, NULL}, // TSDB_DATA_TYPE_DOUBLE
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -87,12 +87,26 @@ void taos_init_imp() {
|
|||
|
||||
tsReadGlobalConfig();
|
||||
tsPrintGlobalConfig();
|
||||
|
||||
|
||||
tscTrace("starting to initialize TAOS client ...");
|
||||
tscTrace("Local IP address is:%s", tsLocalIp);
|
||||
}
|
||||
|
||||
#ifdef CLUSTER
|
||||
tscMgmtIpList.numOfIps = 2;
|
||||
strcpy(tscMgmtIpList.ipstr[0], tsMasterIp);
|
||||
tscMgmtIpList.ip[0] = inet_addr(tsMasterIp);
|
||||
|
||||
strcpy(tscMgmtIpList.ipstr[1], tsMasterIp);
|
||||
tscMgmtIpList.ip[1] = inet_addr(tsMasterIp);
|
||||
|
||||
if (tsSecondIp[0]) {
|
||||
tscMgmtIpList.numOfIps = 3;
|
||||
strcpy(tscMgmtIpList.ipstr[2], tsSecondIp);
|
||||
tscMgmtIpList.ip[2] = inet_addr(tsSecondIp);
|
||||
}
|
||||
#endif
|
||||
|
||||
tscInitMsgs();
|
||||
slaveIndex = rand();
|
||||
int queueSize = tsMaxVnodeConnections + tsMaxMeterConnections + tsMaxMgmtConnections + tsMaxMgmtConnections;
|
||||
|
@ -106,6 +120,10 @@ void taos_init_imp() {
|
|||
if (tscNumOfThreads < 2) tscNumOfThreads = 2;
|
||||
|
||||
tscQhandle = taosInitScheduler(queueSize, tscNumOfThreads, "tsc");
|
||||
if (NULL == tscQhandle) {
|
||||
tscError("failed to init scheduler");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localIp = tsLocalIp;
|
||||
|
@ -126,7 +144,14 @@ void taos_init_imp() {
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < tscNumOfThreads; ++i) taosOpenRpcChann(pVnodeConn, i, rpcInit.sessionsPerChann);
|
||||
for (int i = 0; i < tscNumOfThreads; ++i) {
|
||||
int retVal = taosOpenRpcChann(pVnodeConn, i, rpcInit.sessionsPerChann);
|
||||
if (0 != retVal) {
|
||||
tError("TSC-vnode, failed to open rpc chann");
|
||||
taosCloseRpc(pVnodeConn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localIp = tsLocalIp;
|
||||
|
@ -148,10 +173,9 @@ void taos_init_imp() {
|
|||
}
|
||||
|
||||
tscTmr = taosTmrInit(tsMaxMgmtConnections * 2, 200, 60000, "TSC");
|
||||
if (tscEmbedded == 0) {
|
||||
taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr);
|
||||
if(0 == tscEmbedded){
|
||||
taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr);
|
||||
}
|
||||
|
||||
int64_t refreshTime = tsMetricMetaKeepTimer < tsMeterMetaKeepTimer ? tsMetricMetaKeepTimer : tsMeterMetaKeepTimer;
|
||||
refreshTime = refreshTime > 2 ? 2 : refreshTime;
|
||||
refreshTime = refreshTime < 1 ? 1 : refreshTime;
|
||||
|
@ -188,6 +212,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
|||
tsCfgStatusStr[cfg_configDir->cfgStatus], (char *)cfg_configDir->ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_OPTION_SHELL_ACTIVITY_TIMER:
|
||||
if (cfg_activetimer && cfg_activetimer->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
|
||||
tsShellActivityTimer = atoi((char *)arg);
|
||||
|
@ -200,6 +225,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
|||
tsCfgStatusStr[cfg_activetimer->cfgStatus], (int32_t *)cfg_activetimer->ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_OPTION_LOCALE: { // set locale
|
||||
pStr = (char *)arg;
|
||||
|
||||
|
@ -223,8 +249,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
|||
if (locale != NULL) {
|
||||
tscPrint("locale set, prev locale:%s, new locale:%s", tsLocale, locale);
|
||||
cfg_locale->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
|
||||
} else {
|
||||
/* set the user-specified localed failed, use default LC_CTYPE as current locale */
|
||||
} else { // set the user-specified localed failed, use default LC_CTYPE as current locale
|
||||
locale = setlocale(LC_CTYPE, tsLocale);
|
||||
tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -69,7 +69,7 @@ public enum TSDBError {
|
|||
TSDB_CODE_INVALID_OPTION(45, "invalid option"),
|
||||
TSDB_CODE_NODE_OFFLINE(46, "node offline"),
|
||||
TSDB_CODE_SYNC_REQUIRED(47, "sync required"),
|
||||
TSDB_CODE_NO_ENOUGH_PNODES(48, "more dnodes are needed"),
|
||||
TSDB_CODE_NO_ENOUGH_DNODES(48, "more dnodes are needed"),
|
||||
TSDB_CODE_UNSYNCED(49, "node in unsynced state"),
|
||||
TSDB_CODE_TOO_SLOW(50, "too slow"),
|
||||
TSDB_CODE_OTHERS(51, "others"),
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import com.taosdata.jdbc.TSDBPreparedStatement;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestPreparedStatement {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "192.168.1.117");
|
||||
Connection connection = DriverManager.getConnection("jdbc:TAOS://192.168.1.117:0/?user=root&password=taosdata", properties);
|
||||
String rawSql = "SELECT ts, c1 FROM (select c1, ts from db.tb1) SUB_QRY";
|
||||
// String[] params = new String[]{"ts", "c1"};
|
||||
PreparedStatement pstmt = (TSDBPreparedStatement) connection.prepareStatement(rawSql);
|
||||
ResultSet resSet = pstmt.executeQuery();
|
||||
while(resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s\n", i, resSet.getString(i));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import com.taosdata.jdbc.TSDBDriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestTSDBDatabaseMetaData {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "192.168.1.114");
|
||||
Connection connection = DriverManager.getConnection("jdbc:TAOS://192.168.1.114:0/?user=root&password=taosdata", properties);
|
||||
DatabaseMetaData dbMetaData = connection.getMetaData();
|
||||
ResultSet resSet = dbMetaData.getCatalogs();
|
||||
while(resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("dbMetaData.getCatalogs(%d) = %s\n", i, resSet.getString(i));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,6 +75,9 @@ extern "C" {
|
|||
* LZ4LIB_API :
|
||||
* Control library symbols visibility.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllexport)
|
||||
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
||||
|
@ -392,9 +395,9 @@ typedef struct {
|
|||
* it may change in a future version !
|
||||
*/
|
||||
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
|
||||
#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
|
||||
#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(uint64_t))
|
||||
union LZ4_stream_u {
|
||||
unsigned long long table[LZ4_STREAMSIZE_U64];
|
||||
uint64_t table[LZ4_STREAMSIZE_U64];
|
||||
LZ4_stream_t_internal internal_donotuse;
|
||||
} ; /* previously typedef'd to LZ4_stream_t */
|
||||
|
||||
|
@ -408,9 +411,9 @@ union LZ4_stream_u {
|
|||
* and may change in a future version !
|
||||
*/
|
||||
#define LZ4_STREAMDECODESIZE_U64 4
|
||||
#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
|
||||
#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(uint64_t))
|
||||
union LZ4_streamDecode_u {
|
||||
unsigned long long table[LZ4_STREAMDECODESIZE_U64];
|
||||
uint64_t table[LZ4_STREAMDECODESIZE_U64];
|
||||
LZ4_streamDecode_t_internal internal_donotuse;
|
||||
} ; /* previously typedef'd to LZ4_streamDecode_t */
|
||||
|
||||
|
|
|
@ -71,6 +71,40 @@ enum _sdbaction {
|
|||
SDB_MAX_ACTION_TYPES
|
||||
};
|
||||
|
||||
#ifdef CLUSTER
|
||||
|
||||
#define SDB_MAX_PEERS 4
|
||||
typedef struct {
|
||||
uint32_t ip;
|
||||
uint32_t publicIp;
|
||||
char ipstr[20];
|
||||
char zone[12];
|
||||
char role;
|
||||
int64_t createdTime;
|
||||
uint64_t dbVersion;
|
||||
int64_t lostTime;
|
||||
char status;
|
||||
char numOfMnodes;
|
||||
int numOfDnodes;
|
||||
char updateEnd[1];
|
||||
|
||||
// internal
|
||||
int syncFd;
|
||||
void *hbTimer;
|
||||
void *thandle;
|
||||
void *pSync;
|
||||
} SSdbPeer;
|
||||
|
||||
SSdbPeer *sdbAddPeer(uint32_t ip, uint32_t publicIp, char role);
|
||||
|
||||
void sdbUpdateIpList();
|
||||
|
||||
extern SSdbPeer *sdbPeer[];
|
||||
#define sdbInited (sdbPeer[0])
|
||||
#define sdbStatus (sdbPeer[0]->status)
|
||||
|
||||
#endif
|
||||
|
||||
void *sdbOpenTable(int maxRows, int32_t maxRowSize, char *name, char keyType, char *directory,
|
||||
void *(*appTool)(char, void *, char *, int, int *));
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ program ::= cmd. {}
|
|||
cmd ::= SHOW DATABASES. { setDCLSQLElems(pInfo, SHOW_DATABASES, 0);}
|
||||
cmd ::= SHOW MNODES. { setDCLSQLElems(pInfo, SHOW_MNODES, 0);}
|
||||
cmd ::= SHOW DNODES. { setDCLSQLElems(pInfo, SHOW_DNODES, 0);}
|
||||
cmd ::= SHOW ACCOUNTS. { setDCLSQLElems(pInfo, SHOW_ACCOUNTS, 0);}
|
||||
cmd ::= SHOW USERS. { setDCLSQLElems(pInfo, SHOW_USERS, 0);}
|
||||
|
||||
cmd ::= SHOW MODULES. { setDCLSQLElems(pInfo, SHOW_MODULES, 0); }
|
||||
|
@ -112,7 +113,9 @@ cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
|
|||
}
|
||||
|
||||
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDCLSQLElems(pInfo, DROP_DATABASE, 2, &X, &Y); }
|
||||
cmd ::= DROP DNODE IP(X). { setDCLSQLElems(pInfo, DROP_DNODE, 1, &X); }
|
||||
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, DROP_USER, 1, &X); }
|
||||
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, DROP_ACCOUNT, 1, &X); }
|
||||
|
||||
/////////////////////////////////THE USE STATEMENT//////////////////////////////////////////
|
||||
cmd ::= USE ids(X). { setDCLSQLElems(pInfo, USE_DATABASE, 1, &X);}
|
||||
|
@ -129,8 +132,12 @@ cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setDCLSQLElems(pInfo, ALTER_US
|
|||
cmd ::= ALTER DNODE IP(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_DNODE, 2, &X, &Y); }
|
||||
cmd ::= ALTER DNODE IP(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, ALTER_DNODE, 3, &X, &Y, &Z); }
|
||||
cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, ALTER_LOCAL, 1, &X); }
|
||||
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_LOCAL, 2, &X, &Y); }
|
||||
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, ALTER_DATABASE, &X, &Y, &t);}
|
||||
|
||||
cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { SSQLToken t = {0}; setCreateAcctSQL(pInfo, ALTER_ACCT, &X, &t, &Z);}
|
||||
cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSQL(pInfo, ALTER_ACCT, &X, &Y, &Z);}
|
||||
|
||||
// An IDENTIFIER can be a generic identifier, or one of several keywords.
|
||||
// Any non-standard keyword can also be an identifier.
|
||||
// And "ids" is an identifer-or-string.
|
||||
|
@ -147,9 +154,53 @@ ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;}
|
|||
ifnotexists(X) ::= . {X.n = 0;}
|
||||
|
||||
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
||||
//create option for dnode/db/user/account
|
||||
cmd ::= CREATE DNODE IP(X). { setDCLSQLElems(pInfo, CREATE_DNODE, 1, &X);}
|
||||
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
|
||||
{ setCreateAcctSQL(pInfo, CREATE_ACCOUNT, &X, &Y, &Z);}
|
||||
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, CREATE_DATABASE, &X, &Y, &Z);}
|
||||
cmd ::= CREATE USER ids(X) PASS ids(Y). { setDCLSQLElems(pInfo, CREATE_USER, 2, &X, &Y);}
|
||||
|
||||
pps(Y) ::= . {Y.n = 0; }
|
||||
pps(Y) ::= PPS INTEGER(X). {Y = X; }
|
||||
|
||||
tseries(Y) ::= . {Y.n = 0; }
|
||||
tseries(Y) ::= TSERIES INTEGER(X). {Y = X; }
|
||||
|
||||
dbs(Y) ::= . {Y.n = 0; }
|
||||
dbs(Y) ::= DBS INTEGER(X). {Y = X; }
|
||||
|
||||
streams(Y) ::= . {Y.n = 0; }
|
||||
streams(Y) ::= STREAMS INTEGER(X). {Y = X; }
|
||||
|
||||
storage(Y) ::= . {Y.n = 0; }
|
||||
storage(Y) ::= STORAGE INTEGER(X). {Y = X; }
|
||||
|
||||
qtime(Y) ::= . {Y.n = 0; }
|
||||
qtime(Y) ::= QTIME INTEGER(X). {Y = X; }
|
||||
|
||||
users(Y) ::= . {Y.n = 0; }
|
||||
users(Y) ::= USERS INTEGER(X). {Y = X; }
|
||||
|
||||
conns(Y) ::= . {Y.n = 0; }
|
||||
conns(Y) ::= CONNS INTEGER(X). {Y = X; }
|
||||
|
||||
state(Y) ::= . {Y.n = 0; }
|
||||
state(Y) ::= STATE ids(X). {Y = X; }
|
||||
|
||||
%type acct_optr {SCreateAcctSQL}
|
||||
acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). {
|
||||
Y.users = (K.n>0)?atoi(K.z):-1;
|
||||
Y.dbs = (E.n>0)?atoi(E.z):-1;
|
||||
Y.tseries = (D.n>0)?atoi(D.z):-1;
|
||||
Y.streams = (F.n>0)?atoi(F.z):-1;
|
||||
Y.pps = (C.n>0)?atoi(C.z):-1;
|
||||
Y.storage = (P.n>0)?strtoll(P.z, NULL, 10):-1;
|
||||
Y.qtime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1;
|
||||
Y.conns = (L.n>0)?atoi(L.z):-1;
|
||||
Y.stat = M;
|
||||
}
|
||||
|
||||
%type keep {tVariantList*}
|
||||
%destructor keep {tVariantListDestroy($$);}
|
||||
keep(Y) ::= KEEP tagitemlist(X). { Y = X; }
|
||||
|
@ -183,9 +234,10 @@ db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
|
|||
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
||||
|
||||
%type alter_db_optr {SCreateDBInfo}
|
||||
alter_db_optr(Y) ::= REPLICA tagitem(A). {
|
||||
Y.replica = A.i64Key;
|
||||
}
|
||||
alter_db_optr(Y) ::= . { memset(&Y, 0, sizeof(SCreateDBInfo));}
|
||||
|
||||
alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
|
||||
alter_db_optr(Y) ::= alter_db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); }
|
||||
|
||||
%type typename {TAOS_FIELD}
|
||||
typename(A) ::= ids(X). { tSQLSetColumnType (&A, &X); }
|
||||
|
@ -257,7 +309,7 @@ tagitem(A) ::= INTEGER(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
|||
tagitem(A) ::= FLOAT(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||
tagitem(A) ::= STRING(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||
tagitem(A) ::= BOOL(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||
tagitem(A) ::= NULL(X). { X.type = TK_STRING; toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||
tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
|
||||
|
||||
tagitem(A) ::= MINUS(X) INTEGER(Y).{
|
||||
X.n += Y.n;
|
||||
|
@ -273,6 +325,19 @@ tagitem(A) ::= MINUS(X) FLOAT(Y). {
|
|||
tVariantCreate(&A, &X);
|
||||
}
|
||||
|
||||
tagitem(A) ::= PLUS(X) INTEGER(Y). {
|
||||
X.n += Y.n;
|
||||
X.type = Y.type;
|
||||
toTSDBType(X.type);
|
||||
tVariantCreate(&A, &X);
|
||||
}
|
||||
|
||||
tagitem(A) ::= PLUS(X) FLOAT(Y). {
|
||||
X.n += Y.n;
|
||||
X.type = Y.type;
|
||||
toTSDBType(X.type);
|
||||
tVariantCreate(&A, &X);
|
||||
}
|
||||
|
||||
//////////////////////// The SELECT statement /////////////////////////////////
|
||||
cmd ::= select(X). {
|
||||
|
@ -282,7 +347,7 @@ cmd ::= select(X). {
|
|||
%type select {SQuerySQL*}
|
||||
%destructor select {destroyQuerySql($$);}
|
||||
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). {
|
||||
A = tSetQuerySQLElems(&T, W, &X, Y, P, Z, &K, &S, F, &L, &G);
|
||||
A = tSetQuerySQLElems(&T, W, X, Y, P, Z, &K, &S, F, &L, &G);
|
||||
}
|
||||
|
||||
// selcollist is a list of expressions that are to become the return
|
||||
|
@ -313,9 +378,13 @@ as(X) ::= ids(Y). { X = Y; }
|
|||
as(X) ::= . { X.n = 0; }
|
||||
|
||||
// A complete FROM clause.
|
||||
%type from {SSQLToken}
|
||||
%type from {tVariantList*}
|
||||
// current not support query from no-table
|
||||
from(A) ::= FROM ids(X) cpxName(Y). {A = X; A.n += Y.n;}
|
||||
from(A) ::= FROM tablelist(X). {A = X;}
|
||||
|
||||
%type tablelist {tVariantList*}
|
||||
tablelist(A) ::= ids(X) cpxName(Y). { toTSDBType(X.type); X.n += Y.n; A = tVariantListAppendToken(NULL, &X, -1);}
|
||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). { toTSDBType(X.type); X.n += Z.n; A = tVariantListAppendToken(Y, &X, -1); }
|
||||
|
||||
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
|
||||
%type tmvar {SSQLToken}
|
||||
|
@ -581,4 +650,4 @@ cmd ::= KILL QUERY IP(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n +=
|
|||
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
|
||||
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
|
||||
COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF
|
||||
SPREAD WAVG INTERP LAST_ROW NOW IP SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE.
|
||||
SPREAD TWA INTERP LAST_ROW NOW IP SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE.
|
|
@ -22,11 +22,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TAOS void
|
||||
#define TAOS_ROW void **
|
||||
#define TAOS_RES void
|
||||
#define TAOS_SUB void
|
||||
#define TAOS_STREAM void
|
||||
typedef void TAOS;
|
||||
typedef void** TAOS_ROW;
|
||||
typedef void TAOS_RES;
|
||||
typedef void TAOS_SUB;
|
||||
typedef void TAOS_STREAM;
|
||||
typedef void TAOS_STMT;
|
||||
|
||||
#define TSDB_DATA_TYPE_NULL 0
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
|
@ -56,11 +57,30 @@ typedef struct taosField {
|
|||
char type;
|
||||
} TAOS_FIELD;
|
||||
|
||||
void taos_init();
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port);
|
||||
void taos_close(TAOS *taos);
|
||||
int taos_query(TAOS *taos, char *sqlstr);
|
||||
void taos_init();
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, int port);
|
||||
void taos_close(TAOS *taos);
|
||||
|
||||
typedef struct TAOS_BIND {
|
||||
int buffer_type;
|
||||
void * buffer;
|
||||
unsigned long buffer_length; // unused
|
||||
unsigned long *length;
|
||||
int * is_null;
|
||||
int is_unsigned; // unused
|
||||
int * error; // unused
|
||||
} TAOS_BIND;
|
||||
|
||||
TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||
int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind);
|
||||
int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||
int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
int taos_stmt_close(TAOS_STMT *stmt);
|
||||
|
||||
int taos_query(TAOS *taos, const char *sql);
|
||||
TAOS_RES *taos_use_result(TAOS *taos);
|
||||
TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
|
@ -69,35 +89,40 @@ int taos_field_count(TAOS *taos);
|
|||
int taos_num_fields(TAOS_RES *res);
|
||||
int taos_affected_rows(TAOS *taos);
|
||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||
int taos_select_db(TAOS *taos, char *db);
|
||||
int taos_select_db(TAOS *taos, const char *db);
|
||||
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
void taos_stop_query(TAOS_RES *res);
|
||||
|
||||
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
int taos_validate_sql(TAOS *taos, char *sql);
|
||||
int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
|
||||
// TAOS_RES *taos_list_tables(TAOS *mysql, const char *wild);
|
||||
// TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild);
|
||||
|
||||
// TODO: the return value should be `const`
|
||||
char *taos_get_server_info(TAOS *taos);
|
||||
char *taos_get_client_info();
|
||||
char *taos_errstr(TAOS *taos);
|
||||
|
||||
int taos_errno(TAOS *taos);
|
||||
|
||||
void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *param, TAOS_RES *, int code), void *param);
|
||||
void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
|
||||
void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
|
||||
void taos_fetch_row_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), void *param);
|
||||
|
||||
TAOS_SUB *taos_subscribe(char *host, char *user, char *pass, char *db, char *table, int64_t time, int mseconds);
|
||||
TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, const char *db, const char *table, int64_t time, int mseconds);
|
||||
TAOS_ROW taos_consume(TAOS_SUB *tsub);
|
||||
void taos_unsubscribe(TAOS_SUB *tsub);
|
||||
int taos_subfields_count(TAOS_SUB *tsub);
|
||||
TAOS_FIELD *taos_fetch_subfields(TAOS_SUB *tsub);
|
||||
|
||||
TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||
int64_t stime, void *param, void (*callback)(void *));
|
||||
void taos_close_stream(TAOS_STREAM *tstr);
|
||||
|
||||
int taos_load_table_info(TAOS *taos, const char* tableNameList);
|
||||
|
||||
// TODO: `configDir` should not be declared here
|
||||
extern char configDir[]; // the path to global configuration
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -68,7 +68,7 @@ extern "C" {
|
|||
#define TSDB_CODE_INVALID_OPTION 45
|
||||
#define TSDB_CODE_NODE_OFFLINE 46
|
||||
#define TSDB_CODE_SYNC_REQUIRED 47
|
||||
#define TSDB_CODE_NO_ENOUGH_PNODES 48
|
||||
#define TSDB_CODE_NO_ENOUGH_DNODES 48
|
||||
#define TSDB_CODE_UNSYNCED 49
|
||||
#define TSDB_CODE_TOO_SLOW 50
|
||||
#define TSDB_CODE_OTHERS 51
|
||||
|
@ -129,9 +129,11 @@ extern "C" {
|
|||
#define TSDB_CODE_INVALID_QUERY_MSG 106 // failed to validate the sql expression msg by vnode
|
||||
#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered
|
||||
#define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered
|
||||
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // invalid commit log may be caused by insufficient sotrage
|
||||
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // commit log init failed
|
||||
#define TSDB_CODE_SERVER_NO_SPACE 110
|
||||
#define TSDB_CODE_INVALID_SUBMIT_MSG 111
|
||||
#define TSDB_CODE_NOT_SUPER_TABLE 111 //
|
||||
#define TSDB_CODE_DUPLICATE_TAGS 112 // tags value for join not unique
|
||||
#define TSDB_CODE_INVALID_SUBMIT_MSG 113
|
||||
|
||||
// message type
|
||||
#define TSDB_MSG_TYPE_REG 1
|
||||
|
@ -196,6 +198,7 @@ extern "C" {
|
|||
#define TSDB_MSG_TYPE_USE_DB_RSP 56
|
||||
#define TSDB_MSG_TYPE_CREATE_TABLE 57
|
||||
#define TSDB_MSG_TYPE_CREATE_TABLE_RSP 58
|
||||
|
||||
#define TSDB_MSG_TYPE_DROP_TABLE 59
|
||||
#define TSDB_MSG_TYPE_DROP_TABLE_RSP 60
|
||||
#define TSDB_MSG_TYPE_METERINFO 61
|
||||
|
@ -227,6 +230,9 @@ extern "C" {
|
|||
#define TSDB_MSG_TYPE_ALTER_DB 83
|
||||
#define TSDB_MSG_TYPE_ALTER_DB_RSP 84
|
||||
|
||||
#define TSDB_MSG_TYPE_MULTI_METERINFO 85
|
||||
#define TSDB_MSG_TYPE_MULTI_METERINFO_RSP 86
|
||||
|
||||
#define TSDB_MSG_TYPE_HEARTBEAT 91
|
||||
#define TSDB_MSG_TYPE_HEARTBEAT_RSP 92
|
||||
#define TSDB_MSG_TYPE_STATUS 93
|
||||
|
@ -236,7 +242,8 @@ extern "C" {
|
|||
|
||||
#define TSDB_MSG_TYPE_ALTER_ACCT 97
|
||||
#define TSDB_MSG_TYPE_ALTER_ACCT_RSP 98
|
||||
#define TSDB_MSG_TYPE_MAX 99
|
||||
|
||||
#define TSDB_MSG_TYPE_MAX 101
|
||||
|
||||
// IE type
|
||||
#define TSDB_IE_TYPE_SEC 1
|
||||
|
@ -247,17 +254,22 @@ extern "C" {
|
|||
#define TSDB_IE_TYPE_DNODE_EXT 6
|
||||
#define TSDB_IE_TYPE_DNODE_STATE 7
|
||||
|
||||
// mgmt table
|
||||
enum _mgmt_table {
|
||||
TSDB_MGMT_TABLE_ACCT,
|
||||
TSDB_MGMT_TABLE_USER,
|
||||
TSDB_MGMT_TABLE_DB,
|
||||
TSDB_MGMT_TABLE_TABLE,
|
||||
TSDB_MGMT_TABLE_PNODE,
|
||||
TSDB_MGMT_TABLE_MNODE,
|
||||
TSDB_MGMT_TABLE_VGROUP,
|
||||
TSDB_MGMT_TABLE_METRIC,
|
||||
TSDB_MGMT_TABLE_MODULE,
|
||||
TSDB_MGMT_TABLE_QUERIES,
|
||||
TSDB_MGMT_TABLE_STREAMS,
|
||||
TSDB_MGMT_TABLE_CONFIGS,
|
||||
TSDB_MGMT_TABLE_CONNS,
|
||||
TSDB_MGMT_TABLE_SCORES,
|
||||
TSDB_MGMT_TABLE_GRANTS,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
};
|
||||
|
||||
|
@ -286,15 +298,18 @@ enum _mgmt_table {
|
|||
#define TSDB_METER_STABLE 3 // table created from stream computing
|
||||
#define TSDB_MAX_METER_TYPES 4
|
||||
|
||||
#define TSDB_VN_READ_ACCCESS ((char)0x1)
|
||||
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
|
||||
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS|TSDB_VN_WRITE_ACCCESS)
|
||||
#define TSDB_VN_READ_ACCCESS ((char)0x1)
|
||||
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
|
||||
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
|
||||
|
||||
#define TSDB_COL_NORMAL 0x0U
|
||||
#define TSDB_COL_TAG 0x1U
|
||||
#define TSDB_COL_JOIN 0x2U
|
||||
|
||||
extern char *taosMsg[];
|
||||
extern char *tsError[];
|
||||
|
||||
#pragma pack(1)
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct {
|
||||
char numOfIps;
|
||||
|
@ -410,9 +425,13 @@ typedef struct {
|
|||
short ignoreNotExists;
|
||||
} SDropDbMsg, SUseDbMsg;
|
||||
|
||||
typedef struct { char user[TSDB_USER_LEN]; } SDropUserMsg, SDropAcctMsg;
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
} SDropUserMsg, SDropAcctMsg;
|
||||
|
||||
typedef struct { char db[TSDB_DB_NAME_LEN]; } SShowTableMsg;
|
||||
typedef struct {
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
} SShowTableMsg;
|
||||
|
||||
typedef struct {
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
|
@ -441,7 +460,9 @@ typedef struct {
|
|||
SSchema schema[];
|
||||
} SAlterTableMsg;
|
||||
|
||||
typedef struct { char db[TSDB_METER_ID_LEN]; } SConnectMsg;
|
||||
typedef struct {
|
||||
char db[TSDB_METER_ID_LEN];
|
||||
} SConnectMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t maxUsers;
|
||||
|
@ -470,7 +491,9 @@ typedef struct {
|
|||
char flag;
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
|
||||
typedef struct { char db[TSDB_METER_ID_LEN]; } SMgmtHead;
|
||||
typedef struct {
|
||||
char db[TSDB_METER_ID_LEN];
|
||||
} SMgmtHead;
|
||||
|
||||
typedef struct {
|
||||
char acctId[TSDB_ACCT_LEN];
|
||||
|
@ -486,13 +509,9 @@ typedef struct {
|
|||
char meterId[TSDB_METER_ID_LEN];
|
||||
} SRemoveMeterMsg;
|
||||
|
||||
typedef struct { short vnode; } SFreeVnodeMsg;
|
||||
|
||||
typedef struct SColIndex {
|
||||
int16_t colId;
|
||||
int16_t colIdx;
|
||||
bool isTag;
|
||||
} SColIndex;
|
||||
typedef struct {
|
||||
short vnode;
|
||||
} SFreeVnodeMsg;
|
||||
|
||||
typedef struct SColIndexEx {
|
||||
int16_t colId;
|
||||
|
@ -502,12 +521,11 @@ typedef struct SColIndexEx {
|
|||
* whether current meter schema is up-to-date.
|
||||
*
|
||||
* colIdxInBuf is used to denote the index of column in pQuery->colList,
|
||||
* this value is invalid in client side, as well as in cache block of vnode
|
||||
* either.
|
||||
* this value is invalid in client side, as well as in cache block of vnode either.
|
||||
*/
|
||||
int16_t colIdx;
|
||||
int16_t colIdxInBuf;
|
||||
bool isTag;
|
||||
int16_t colIdx;
|
||||
int16_t colIdxInBuf;
|
||||
uint16_t flag; // denote if it is a tag or not
|
||||
} SColIndexEx;
|
||||
|
||||
/* sql function msg, to describe the message to vnode about sql function
|
||||
|
@ -539,23 +557,14 @@ typedef struct SSqlFunctionExpr {
|
|||
SSqlBinaryExprInfo pBinExprInfo;
|
||||
int16_t resBytes;
|
||||
int16_t resType;
|
||||
int16_t interResBytes;
|
||||
} SSqlFunctionExpr;
|
||||
|
||||
typedef struct SColumnFilterMsg {
|
||||
/* for client side struct, we only need the column id, type, bytes are not
|
||||
* necessary
|
||||
* But for data in vnode side, we need all the following information.
|
||||
* */
|
||||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
|
||||
int16_t filterOn; /* denote if the filter is active */
|
||||
typedef struct SColumnFilterInfo {
|
||||
int16_t lowerRelOptr;
|
||||
int16_t upperRelOptr;
|
||||
int16_t filterOnBinary; /* denote if current column is binary */
|
||||
|
||||
/* double/int64_t/float/int share the this memory */
|
||||
union {
|
||||
struct {
|
||||
int64_t lowerBndi;
|
||||
|
@ -570,13 +579,24 @@ typedef struct SColumnFilterMsg {
|
|||
int64_t len;
|
||||
};
|
||||
};
|
||||
} SColumnFilterMsg;
|
||||
} SColumnFilterInfo;
|
||||
|
||||
/*
|
||||
* for client side struct, we only need the column id, type, bytes are not necessary
|
||||
* But for data in vnode side, we need all the following information.
|
||||
*/
|
||||
typedef struct SColumnInfo {
|
||||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
int16_t numOfFilters;
|
||||
SColumnFilterInfo *filters;
|
||||
} SColumnInfo;
|
||||
|
||||
/*
|
||||
* enable vnode to understand how to group several tables with different tag;
|
||||
*/
|
||||
typedef struct SMeterSidExtInfo {
|
||||
// union {int32_t sid; void* pObj;};
|
||||
int32_t sid;
|
||||
void * pObj;
|
||||
char tags[];
|
||||
|
@ -591,10 +611,8 @@ typedef struct {
|
|||
int16_t vnode;
|
||||
int32_t numOfSids;
|
||||
uint64_t pSidExtInfo; // meter id & tag info ptr, in windows pointer may
|
||||
// occupy only 4bytes
|
||||
|
||||
uint64_t uid;
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
TSKEY skey;
|
||||
TSKEY ekey;
|
||||
int32_t num;
|
||||
|
@ -605,13 +623,15 @@ typedef struct {
|
|||
int16_t numOfCols; // the number of columns will be load from vnode
|
||||
char intervalTimeUnit; // time interval type, for revisement of interval(1d)
|
||||
|
||||
int64_t nAggTimeInterval; // time interval for aggregation, in million second
|
||||
uint64_t pTagSchema; // tag schema, used to parse tag information in pSidExtInfo
|
||||
int64_t nAggTimeInterval; // time interval for aggregation, in million second
|
||||
|
||||
// tag schema, used to parse tag information in pSidExtInfo
|
||||
uint64_t pTagSchema;
|
||||
|
||||
int16_t numOfTagsCols; // required number of tags
|
||||
int16_t tagLength; // tag length in current query
|
||||
|
||||
int16_t numOfGroupbyCols; // num of group by columns
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
int16_t orderByIdx;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
uint64_t groupbyTagIds;
|
||||
|
@ -619,7 +639,7 @@ typedef struct {
|
|||
int64_t limit;
|
||||
int64_t offset;
|
||||
|
||||
int16_t metricQuery; // denote another query process
|
||||
int16_t queryType; // denote another query process
|
||||
int16_t numOfOutputCols; // final output columns numbers
|
||||
|
||||
int16_t interpoType; // interpolate type
|
||||
|
@ -628,8 +648,13 @@ typedef struct {
|
|||
int32_t colNameLen;
|
||||
int64_t colNameList;
|
||||
|
||||
int64_t pSqlFuncExprs;
|
||||
SColumnFilterMsg colList[];
|
||||
int64_t pSqlFuncExprs;
|
||||
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
SColumnInfo colList[];
|
||||
} SQueryMeterMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -648,12 +673,13 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint64_t qhandle;
|
||||
char free;
|
||||
int16_t free;
|
||||
} SRetrieveMeterMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfRows;
|
||||
int16_t precision;
|
||||
int16_t compress;
|
||||
int64_t offset; // updated offset value for multi-vnode projection query
|
||||
int64_t useconds;
|
||||
char data[];
|
||||
|
@ -668,7 +694,8 @@ typedef struct {
|
|||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
char reserved[16];
|
||||
uint8_t syncStatus;
|
||||
uint8_t reserved;
|
||||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
|
@ -724,8 +751,9 @@ typedef struct {
|
|||
uint16_t numOfCores;
|
||||
uint8_t alternativeRole;
|
||||
uint8_t reserve;
|
||||
float memoryAvailable; // MB
|
||||
float diskAvailable; // GB
|
||||
uint16_t numOfTotalVnodes; // from config file
|
||||
uint16_t unused;
|
||||
float diskAvailable; // GB
|
||||
uint32_t openVnodes;
|
||||
char reserved[16];
|
||||
SVnodeLoad load[];
|
||||
|
@ -773,22 +801,39 @@ typedef struct {
|
|||
} SMeterInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
int32_t numOfMeters;
|
||||
char meterId[];
|
||||
} SMultiMeterInfoMsg;
|
||||
|
||||
int16_t numOfGroupbyCols; // num of group by columns
|
||||
int16_t orderIndex;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
uint64_t groupbyTagIds;
|
||||
typedef struct {
|
||||
int16_t elemLen;
|
||||
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
int16_t orderIndex;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
|
||||
int16_t rel; // denotes the relation between condition and table list
|
||||
|
||||
int32_t tableCond; // offset value of table name condition
|
||||
int32_t tableCondLen;
|
||||
|
||||
int32_t cond; // offset of column query condition
|
||||
int32_t condLen;
|
||||
|
||||
int16_t tagCols[TSDB_MAX_TAGS + 1]; // required tag columns, plus one is for table name
|
||||
int16_t numOfTags; // required number of tags
|
||||
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
int32_t groupbyTagColumnList;
|
||||
} SMetricMetaElemMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfMeters;
|
||||
int32_t join;
|
||||
int32_t joinCondLen; // for join condition
|
||||
|
||||
int32_t metaElem[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
|
||||
int32_t condLength;
|
||||
int16_t type; // denotes if it has the meter id pools
|
||||
char tags[];
|
||||
} SMetricMetaMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -806,24 +851,28 @@ typedef struct {
|
|||
} SMetricMeta;
|
||||
|
||||
typedef struct SMeterMeta {
|
||||
int16_t numOfTags;
|
||||
int16_t precision;
|
||||
uint8_t numOfTags : 6;
|
||||
uint8_t precision : 2;
|
||||
uint8_t meterType : 4;
|
||||
uint8_t index : 4; // used locally
|
||||
|
||||
int16_t numOfColumns;
|
||||
|
||||
int32_t sversion;
|
||||
uint64_t pSchema;
|
||||
int16_t rowSize; // used locally, calculated in client
|
||||
int16_t sversion;
|
||||
|
||||
SVPeerDesc vpeerDesc[TSDB_VNODES_SUPPORT];
|
||||
|
||||
int32_t sid;
|
||||
int32_t vgid;
|
||||
|
||||
int32_t sid;
|
||||
int32_t vgid;
|
||||
uint64_t uid;
|
||||
int16_t meterType;
|
||||
int16_t index; // used locally
|
||||
int32_t rowSize; // used locally, calculated in client
|
||||
uint64_t tags;
|
||||
} SMeterMeta;
|
||||
|
||||
typedef struct SMultiMeterMeta {
|
||||
char meterId[TSDB_METER_ID_LEN]; // note: This field must be at the front
|
||||
SMeterMeta meta;
|
||||
} SMultiMeterMeta;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_METER_ID_LEN];
|
||||
char data[TSDB_MAX_TAGS_LEN];
|
||||
|
@ -840,7 +889,9 @@ typedef struct {
|
|||
char payload[];
|
||||
} SShowMsg;
|
||||
|
||||
typedef struct { char ip[20]; } SCreateMnodeMsg, SDropMnodeMsg, SCreateDnodeMsg, SDropDnodeMsg;
|
||||
typedef struct {
|
||||
char ip[20];
|
||||
} SCreateMnodeMsg, SDropMnodeMsg, SCreateDnodeMsg, SDropDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
uint64_t qhandle;
|
||||
|
@ -852,7 +903,9 @@ typedef struct {
|
|||
int32_t sid;
|
||||
} SMeterCfgMsg;
|
||||
|
||||
typedef struct { int32_t vnode; } SVpeerCfgMsg;
|
||||
typedef struct {
|
||||
int32_t vnode;
|
||||
} SVpeerCfgMsg;
|
||||
|
||||
typedef struct {
|
||||
char ip[20];
|
||||
|
@ -907,7 +960,7 @@ typedef struct {
|
|||
char status;
|
||||
} SAlterStreamMsg;
|
||||
|
||||
#pragma pack()
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "taosmsg.h"
|
||||
#include "tsql.h"
|
||||
|
||||
struct tSQLBinaryExpr;
|
||||
|
@ -37,6 +38,28 @@ enum {
|
|||
TSQL_NODE_VALUE = 0x4,
|
||||
};
|
||||
|
||||
typedef bool (*__result_filter_fn_t)(const void *, void *);
|
||||
typedef void (*__do_filter_suppl_fn_t)(void *, void *);
|
||||
|
||||
/**
|
||||
* this structure is used to filter data in tags, so the offset of filtered tag column in tagdata string is required
|
||||
*
|
||||
*/
|
||||
typedef struct tQueryInfo {
|
||||
int32_t offset; // offset value in tags
|
||||
int32_t colIdx; // index of column in schema
|
||||
uint8_t optr; // expression operator
|
||||
SSchema sch; // schema of tags
|
||||
tVariant q; // query condition value on the specific schema, filter expression
|
||||
__compar_fn_t compare; // filter function
|
||||
} tQueryInfo;
|
||||
|
||||
typedef struct SBinaryFilterSupp {
|
||||
__result_filter_fn_t fp;
|
||||
__do_filter_suppl_fn_t setupInfoFn;
|
||||
void * pExtInfo;
|
||||
} SBinaryFilterSupp;
|
||||
|
||||
typedef struct tSQLSyntaxNode {
|
||||
uint8_t nodeType;
|
||||
int16_t colId; // for schema, the id of column
|
||||
|
@ -48,48 +71,37 @@ typedef struct tSQLSyntaxNode {
|
|||
} tSQLSyntaxNode;
|
||||
|
||||
typedef struct tSQLBinaryExpr {
|
||||
uint8_t nSQLBinaryOptr;
|
||||
uint8_t filterOnPrimaryKey; // 0: do not contain primary filter, 1: contain
|
||||
// primary key
|
||||
uint8_t nSQLBinaryOptr; // filter operator
|
||||
uint8_t filterOnPrimaryKey; // 0: do not contain primary filter, 1: contain
|
||||
|
||||
tSQLSyntaxNode *pLeft;
|
||||
tSQLSyntaxNode *pRight;
|
||||
/*
|
||||
* provide the information to support filter operation on this expression
|
||||
* only available for leaf node
|
||||
*/
|
||||
void * info;
|
||||
tSQLSyntaxNode *pLeft; // left child pointer
|
||||
tSQLSyntaxNode *pRight; // right child pointer
|
||||
} tSQLBinaryExpr;
|
||||
|
||||
#define TAST_NODE_TYPE_INDEX_ENTRY 0
|
||||
#define TAST_NODE_TYPE_METER_PTR 1
|
||||
|
||||
typedef struct tQueryResultset {
|
||||
void ** pRes;
|
||||
int64_t num;
|
||||
int32_t nodeType;
|
||||
} tQueryResultset;
|
||||
|
||||
typedef struct tQueryInfo {
|
||||
int32_t offset; // offset value in tags
|
||||
int32_t colIdx; // index of column in schema
|
||||
struct SSchema *pSchema; // schema of tags
|
||||
tVariant q; // queries cond
|
||||
uint8_t optr;
|
||||
__compar_fn_t comparator;
|
||||
} tQueryInfo;
|
||||
|
||||
void tSQLBinaryExprFromString(tSQLBinaryExpr **pExpr, struct SSchema *pSchema, int32_t numOfCols, char *src,
|
||||
int32_t len);
|
||||
void tSQLBinaryExprFromString(tSQLBinaryExpr **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len);
|
||||
|
||||
void tSQLBinaryExprToString(tSQLBinaryExpr *pExpr, char *dst, int32_t *len);
|
||||
|
||||
void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExprs);
|
||||
void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExprs, void (*fp)(void*));
|
||||
|
||||
void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExprs, struct tSkipList *pSkipList, struct SSchema *pSchema,
|
||||
int32_t numOfCols, bool (*fp)(struct tSkipListNode *, void *), tQueryResultset *result);
|
||||
void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExprs, struct tSkipList *pSkipList, tQueryResultset *result,
|
||||
SBinaryFilterSupp *param);
|
||||
|
||||
void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, char *, int32_t));
|
||||
|
||||
void tSQLBinaryExprTrv(tSQLBinaryExpr *pExprs, int32_t *val, int16_t *ids);
|
||||
|
||||
bool tSQLElemFilterCallback(struct tSkipListNode *pNode, void *param);
|
||||
void tQueryResultClean(tQueryResultset *pRes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ typedef struct tExtMemBuffer {
|
|||
EXT_BUFFER_FLUSH_MODEL flushModel;
|
||||
} tExtMemBuffer;
|
||||
|
||||
void getExtTmpfilePath(const char *fileNamePattern, int64_t serialNumber, int32_t seg, int32_t slot, char *dstPath);
|
||||
void getTmpfilePath(const char *fileNamePattern, char *dstPath);
|
||||
|
||||
/*
|
||||
* create ext-memory buffer
|
||||
|
@ -253,10 +253,10 @@ int32_t compare_a(tOrderDescriptor *, int32_t numOfRow1, int32_t s1, char *data1
|
|||
int32_t compare_d(tOrderDescriptor *, int32_t numOfRow1, int32_t s1, char *data1, int32_t numOfRow2, int32_t s2,
|
||||
char *data2);
|
||||
|
||||
void tMemBucketCreate(tMemBucket **pBucket, int32_t totalSlots, int32_t nBufferSize, int16_t nElemSize,
|
||||
tMemBucket* tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nElemSize,
|
||||
int16_t dataType, tOrderDescriptor *pDesc);
|
||||
|
||||
void tMemBucketDestroy(tMemBucket **pBucket);
|
||||
void tMemBucketDestroy(tMemBucket *pBucket);
|
||||
|
||||
void tMemBucketPut(tMemBucket *pBucket, void *data, int32_t numOfRows);
|
||||
|
||||
|
|
|
@ -24,11 +24,15 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include "tsdb.h"
|
||||
|
||||
extern int (*startMonitor)();
|
||||
extern void (*stopMonitor)();
|
||||
|
||||
// system info
|
||||
extern int64_t tsPageSize;
|
||||
extern int64_t tsOpenMax;
|
||||
extern int64_t tsStreamMax;
|
||||
extern int32_t tsNumOfCores;
|
||||
extern int32_t tsAlternativeRole;
|
||||
extern float tsTotalLogDirGB;
|
||||
extern float tsTotalTmpDirGB;
|
||||
extern float tsTotalDataDirGB;
|
||||
|
@ -58,7 +62,6 @@ extern short tsMgmtShellPort;
|
|||
extern short tsVnodeShellPort;
|
||||
extern short tsVnodeVnodePort;
|
||||
extern short tsMgmtMgmtPort;
|
||||
extern short tsVnodeSyncPort;
|
||||
extern short tsMgmtSyncPort;
|
||||
|
||||
extern int tsStatusInterval;
|
||||
|
@ -70,12 +73,14 @@ extern int tsMetricMetaKeepTimer;
|
|||
|
||||
extern float tsNumOfThreadsPerCore;
|
||||
extern float tsRatioOfQueryThreads;
|
||||
extern char tsPublicIp[];
|
||||
extern char tsInternalIp[];
|
||||
extern char tsPrivateIp[];
|
||||
extern char tsServerIpStr[];
|
||||
extern short tsNumOfVnodesPerCore;
|
||||
extern short tsNumOfTotalVnodes;
|
||||
extern int tsShellsPerVnode;
|
||||
extern short tsCheckHeaderFile;
|
||||
extern uint32_t tsServerIp;
|
||||
|
||||
extern int tsSessionsPerVnode;
|
||||
extern int tsAverageCacheBlocks;
|
||||
|
@ -121,6 +126,9 @@ extern int tsMgmtEqualVnodeNum;
|
|||
extern int tsEnableHttpModule;
|
||||
extern int tsEnableMonitorModule;
|
||||
extern int tsRestRowLimit;
|
||||
extern int tsCompressMsgSize;
|
||||
|
||||
extern char tsSocketType[4];
|
||||
|
||||
extern int tsTimePrecision;
|
||||
extern int tsMinSlidingTime;
|
||||
|
@ -132,14 +140,13 @@ extern int tsStreamCompRetryDelay;
|
|||
extern int tsProjectExecInterval;
|
||||
extern int64_t tsMaxRetentWindow;
|
||||
|
||||
extern char tsSocketType[4];
|
||||
|
||||
extern char tsHttpIp[];
|
||||
extern short tsHttpPort;
|
||||
extern int tsHttpCacheSessions;
|
||||
extern int tsHttpSessionExpire;
|
||||
extern int tsHttpMaxThreads;
|
||||
extern int tsHttpEnableCompress;
|
||||
extern int tsHttpEnableRecordSql;
|
||||
extern int tsTelegrafUseFieldNum;
|
||||
extern int tsAdminRowLimit;
|
||||
|
||||
|
@ -177,25 +184,30 @@ extern char tsCharset[64]; // default encode string
|
|||
//
|
||||
void tsReadGlobalLogConfig();
|
||||
bool tsReadGlobalConfig();
|
||||
bool tsReadGlobalConfigSpec();
|
||||
int tsCfgDynamicOptions(char *msg);
|
||||
void tsPrintGlobalConfig();
|
||||
void tsPrintGlobalConfigSpec();
|
||||
void tsSetAllDebugFlag();
|
||||
void tsSetTimeZone();
|
||||
void tsSetLocale();
|
||||
void tsInitGlobalConfig();
|
||||
void tsExpandFilePath(char* option_name, char* input_value);
|
||||
|
||||
#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file
|
||||
#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands
|
||||
#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration
|
||||
#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log
|
||||
#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function
|
||||
#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U
|
||||
#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file
|
||||
#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands
|
||||
#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration
|
||||
#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log
|
||||
#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function
|
||||
#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U // such as password
|
||||
#define TSDB_CFG_CTYPE_B_LITE 64U // is a lite type configuration
|
||||
#define TSDB_CFG_CTYPE_B_CLUSTER 128U // is a cluster type configuration
|
||||
|
||||
#define TSDB_CFG_CSTATUS_NONE 0 // not configured
|
||||
#define TSDB_CFG_CSTATUS_DEFAULT 1 // use system default value
|
||||
#define TSDB_CFG_CSTATUS_FILE 2 // configured from file
|
||||
#define TSDB_CFG_CSTATUS_OPTION 3 // configured by taos_options function
|
||||
#define TSDB_CFG_CSTATUS_ARG 4 // configured by program argument
|
||||
#define TSDB_CFG_CSTATUS_NONE 0 // not configured
|
||||
#define TSDB_CFG_CSTATUS_DEFAULT 1 // use system default value
|
||||
#define TSDB_CFG_CSTATUS_FILE 2 // configured from file
|
||||
#define TSDB_CFG_CSTATUS_OPTION 3 // configured by taos_options function
|
||||
#define TSDB_CFG_CSTATUS_ARG 4 // configured by program argument
|
||||
|
||||
enum {
|
||||
TSDB_CFG_VTYPE_SHORT,
|
||||
|
|
|
@ -22,6 +22,10 @@ extern "C" {
|
|||
|
||||
void *taosInitIdPool(int maxId);
|
||||
|
||||
int taosUpdateIdPool(void *handle, int maxId);
|
||||
|
||||
int taosIdPoolMaxSize(void *handle);
|
||||
|
||||
int taosAllocateId(void *handle);
|
||||
|
||||
void taosFreeId(void *handle, int id);
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
|
||||
#include "taosmsg.h"
|
||||
#include "tsched.h"
|
||||
#include "tglobalcfg.h"
|
||||
|
||||
#define TAOS_CONN_UDPS 0
|
||||
#define TAOS_CONN_UDPC 1
|
||||
|
@ -41,7 +42,7 @@ extern "C" {
|
|||
#define TAOS_CONN_SOCKET_TYPE_C() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDP:TAOS_CONN_TCPC)
|
||||
|
||||
#define taosSendMsgToPeer(x, y, z) taosSendMsgToPeerH(x, y, z, NULL)
|
||||
#define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x, y, z, NULL)
|
||||
#define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x,y,z,NULL)
|
||||
#define taosBuildReqMsg(x, y) taosBuildReqMsgWithSize(x, y, 512)
|
||||
#define taosBuildRspMsg(x, y) taosBuildRspMsgWithSize(x, y, 512)
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
#include "taosmsg.h"
|
||||
#include "tstoken.h"
|
||||
|
||||
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
||||
|
||||
|
@ -45,7 +46,7 @@ struct SSchema *tsGetSchema(SMeterMeta *pMeta);
|
|||
|
||||
struct SSchema *tsGetTagSchema(SMeterMeta *pMeta);
|
||||
|
||||
struct SSchema *tsGetSchemaColIdx(SMeterMeta *pMeta, int32_t startCol);
|
||||
struct SSchema *tsGetColumnSchema(SMeterMeta *pMeta, int32_t startCol);
|
||||
|
||||
char *tsGetTagsValue(SMeterMeta *pMeta);
|
||||
|
||||
|
@ -53,7 +54,9 @@ bool tsMeterMetaIdentical(SMeterMeta *p1, SMeterMeta *p2);
|
|||
|
||||
void extractMeterName(char *meterId, char *name);
|
||||
|
||||
void extractDBName(char *meterId, char *name);
|
||||
SSQLToken extractDBName(char *meterId, char *name);
|
||||
|
||||
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
154
src/inc/tsdb.h
154
src/inc/tsdb.h
|
@ -31,10 +31,10 @@ extern "C" {
|
|||
#define TSKEY int64_t
|
||||
#endif
|
||||
|
||||
#define TSDB_TRUE 1
|
||||
#define TSDB_FALSE 0
|
||||
#define TSDB_OK 0
|
||||
#define TSDB_ERR -1
|
||||
#define TSDB_TRUE 1
|
||||
#define TSDB_FALSE 0
|
||||
#define TSDB_OK 0
|
||||
#define TSDB_ERR -1
|
||||
|
||||
#define TS_PATH_DELIMITER "."
|
||||
|
||||
|
@ -60,23 +60,25 @@ enum _syncstatus {
|
|||
TSDB_SSTATUS_SYNC_FILE,
|
||||
};
|
||||
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // wide string
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
|
||||
#define TSDB_KEYSIZE sizeof(TSKEY)
|
||||
|
||||
#if LINUX
|
||||
#define TSDB_NCHAR_SIZE sizeof(wchar_t)
|
||||
#else
|
||||
#define TSDB_NCHAR_SIZE 4
|
||||
#endif
|
||||
//#define TSDB_CHAR_TERMINATED_SPACE 1
|
||||
|
||||
#define TSDB_RELATION_INVALID 0
|
||||
#define TSDB_RELATION_LESS 1
|
||||
|
@ -96,31 +98,28 @@ enum _syncstatus {
|
|||
#define TSDB_BINARY_OP_MULTIPLY 13
|
||||
#define TSDB_BINARY_OP_DIVIDE 14
|
||||
#define TSDB_BINARY_OP_REMAINDER 15
|
||||
|
||||
#define TSDB_USERID_LEN 9
|
||||
#define TS_PATH_DELIMITER_LEN 1
|
||||
|
||||
#define TSDB_METER_ID_LEN_MARGIN 10
|
||||
#define TSDB_METER_ID_LEN \
|
||||
(TSDB_DB_NAME_LEN + TSDB_METER_NAME_LEN + 2 * TS_PATH_DELIMITER_LEN + TSDB_USERID_LEN + \
|
||||
TSDB_METER_ID_LEN_MARGIN) // TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID)
|
||||
#define TSDB_METER_ID_LEN_MARGIN 10
|
||||
#define TSDB_METER_ID_LEN (TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID)
|
||||
#define TSDB_UNI_LEN 24
|
||||
#define TSDB_USER_LEN TSDB_UNI_LEN
|
||||
#define TSDB_ACCT_LEN TSDB_UNI_LEN
|
||||
#define TSDB_PASSWORD_LEN TSDB_UNI_LEN
|
||||
|
||||
#define TSDB_MAX_COLUMNS 256
|
||||
#define TSDB_MIN_COLUMNS 2 // PRIMARY COLUMN(timestamp) + other columns
|
||||
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
||||
|
||||
#define TSDB_METER_NAME_LEN 64
|
||||
#define TSDB_DB_NAME_LEN 32
|
||||
#define TSDB_COL_NAME_LEN 64
|
||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 16
|
||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 16
|
||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||
|
||||
#define TSDB_MAX_BYTES_PER_ROW TSDB_MAX_COLUMNS * 16
|
||||
#define TSDB_MAX_BYTES_PER_ROW TSDB_MAX_COLUMNS * 16
|
||||
#define TSDB_MAX_TAGS_LEN 512
|
||||
#define TSDB_MAX_TAGS 6
|
||||
#define TSDB_MAX_TAGS 32
|
||||
|
||||
#define TSDB_AUTH_LEN 16
|
||||
#define TSDB_KEY_LEN 16
|
||||
|
@ -134,7 +133,7 @@ enum _syncstatus {
|
|||
#define TSDB_LOCALE_LEN 64
|
||||
#define TSDB_TIMEZONE_LEN 64
|
||||
|
||||
#define TSDB_IPv4ADDR_LEN 16
|
||||
#define TSDB_IPv4ADDR_LEN 16
|
||||
#define TSDB_FILENAME_LEN 128
|
||||
#define TSDB_METER_VNODE_BITS 20
|
||||
#define TSDB_METER_SID_MASK 0xFFFFF
|
||||
|
@ -146,11 +145,11 @@ enum _syncstatus {
|
|||
#define TSDB_METER_STATE_OFFLINE 0
|
||||
#define TSDB_METER_STATE_ONLLINE 1
|
||||
|
||||
#define TSDB_DEFAULT_PKT_SIZE 65480 // same as RPC_MAX_UDP_SIZE
|
||||
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
|
||||
|
||||
#define TSDB_PAYLOAD_SIZE (TSDB_DEFAULT_PKT_SIZE - 100)
|
||||
#define TSDB_DEFAULT_PAYLOAD_SIZE 1024 // default payload size
|
||||
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
||||
#define TSDB_PAYLOAD_SIZE (TSDB_DEFAULT_PKT_SIZE - 100)
|
||||
#define TSDB_DEFAULT_PAYLOAD_SIZE 1024 // default payload size
|
||||
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
||||
#define TSDB_SQLCMD_SIZE 1024
|
||||
#define TSDB_MAX_VNODES 256
|
||||
#define TSDB_MIN_VNODES 50
|
||||
|
@ -161,60 +160,81 @@ enum _syncstatus {
|
|||
#define TSDB_DNODE_ROLE_VNODE 2
|
||||
|
||||
#define TSDB_MAX_MPEERS 5
|
||||
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS + 1)
|
||||
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1)
|
||||
|
||||
#define TSDB_REPLICA_MAX_NUM 3
|
||||
#define TSDB_REPLICA_MIN_NUM 1
|
||||
//#define TSDB_REPLICA_MAX_NUM 3
|
||||
#define TSDB_REPLICA_MIN_NUM 1
|
||||
|
||||
// default value == 10
|
||||
#define TSDB_FILE_MIN_PARTITION_RANGE 1 // minimum partition range of vnode file in days
|
||||
#define TSDB_FILE_MAX_PARTITION_RANGE 3650 // max partition range of vnode file in days
|
||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
|
||||
|
||||
#define TSDB_DATA_MIN_RESERVE_DAY 1 // data in db to be reserved.
|
||||
#define TSDB_DATA_DEFAULT_RESERVE_DAY 3650 // ten years
|
||||
//default value == 10
|
||||
#define TSDB_FILE_MIN_PARTITION_RANGE 1 //minimum partition range of vnode file in days
|
||||
#define TSDB_FILE_MAX_PARTITION_RANGE 3650 //max partition range of vnode file in days
|
||||
|
||||
#define TSDB_MIN_COMPRESSION_LEVEL 0
|
||||
#define TSDB_MAX_COMPRESSION_LEVEL 2
|
||||
#define TSDB_DATA_MIN_RESERVE_DAY 1 // data in db to be reserved.
|
||||
#define TSDB_DATA_DEFAULT_RESERVE_DAY 3650 // ten years
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCKS_PER_METER 32
|
||||
#define TSDB_MAX_CACHE_BLOCKS_PER_METER 40960
|
||||
#define TSDB_MIN_COMPRESSION_LEVEL 0
|
||||
#define TSDB_MAX_COMPRESSION_LEVEL 2
|
||||
|
||||
#define TSDB_MIN_COMMIT_TIME_INTERVAL 30
|
||||
#define TSDB_MAX_COMMIT_TIME_INTERVAL 40960
|
||||
#define TSDB_MIN_CACHE_BLOCKS_PER_METER 32
|
||||
#define TSDB_MAX_CACHE_BLOCKS_PER_METER 40960
|
||||
|
||||
#define TSDB_MIN_ROWS_IN_FILEBLOCK 200
|
||||
#define TSDB_MAX_ROWS_IN_FILEBLOCK 500000
|
||||
#define TSDB_MIN_COMMIT_TIME_INTERVAL 30
|
||||
#define TSDB_MAX_COMMIT_TIME_INTERVAL 40960
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 100
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 104857600
|
||||
#define TSDB_MIN_ROWS_IN_FILEBLOCK 200
|
||||
#define TSDB_MAX_ROWS_IN_FILEBLOCK 500000
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCKS 100
|
||||
#define TSDB_MAX_CACHE_BLOCKS 409600
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 100
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 104857600
|
||||
|
||||
#define TSDB_MAX_AVG_BLOCKS 2048
|
||||
#define TSDB_MIN_CACHE_BLOCKS 100
|
||||
#define TSDB_MAX_CACHE_BLOCKS 409600
|
||||
|
||||
#define TSDB_MIN_TABLES_PER_VNODE 1
|
||||
#define TSDB_MAX_TABLES_PER_VNODE 220000
|
||||
#define TSDB_MAX_AVG_BLOCKS 2048
|
||||
|
||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW - TSDB_KEYSIZE)
|
||||
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW - TSDB_KEYSIZE)
|
||||
#define PRIMARYKEY_TIMESTAMP_COL_INDEX 0
|
||||
#define TSDB_MIN_TABLES_PER_VNODE 1
|
||||
#define TSDB_MAX_TABLES_PER_VNODE 220000
|
||||
|
||||
#define TSDB_DATA_BOOL_NULL 0x02
|
||||
#define TSDB_DATA_TINYINT_NULL 0x80
|
||||
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
||||
#define TSDB_DATA_INT_NULL 0x80000000
|
||||
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
||||
#define TSDB_MAX_JOIN_TABLE_NUM 5
|
||||
|
||||
#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||
#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||
#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||
#define TSDB_DATA_BINARY_NULL 0xFF
|
||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
|
||||
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
|
||||
#define PRIMARYKEY_TIMESTAMP_COL_INDEX 0
|
||||
|
||||
#define TSDB_DATA_NULL_STR "NULL"
|
||||
#define TSDB_DATA_NULL_STR_L "null"
|
||||
#define TSDB_DATA_BOOL_NULL 0x02
|
||||
#define TSDB_DATA_TINYINT_NULL 0x80
|
||||
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
||||
#define TSDB_DATA_INT_NULL 0x80000000
|
||||
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
||||
|
||||
#define TSDB_MAX_RPC_THREADS 5
|
||||
#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||
#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||
#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||
#define TSDB_DATA_BINARY_NULL 0xFF
|
||||
|
||||
#define TSDB_DATA_NULL_STR "NULL"
|
||||
#define TSDB_DATA_NULL_STR_L "null"
|
||||
|
||||
#define TSDB_MAX_RPC_THREADS 5
|
||||
|
||||
#define TSDB_QUERY_TYPE_QUERY 0 // normal query
|
||||
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x1 // free qhandle at vnode
|
||||
|
||||
/*
|
||||
* 1. ordinary sub query for select * from super_table
|
||||
* 2. all sqlobj generated by createSubqueryObj with this flag
|
||||
*/
|
||||
#define TSDB_QUERY_TYPE_SUBQUERY 0x2
|
||||
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x4 // two-stage subquery for super table
|
||||
|
||||
#define TSDB_QUERY_TYPE_TABLE_QUERY 0x8 // query ordinary table; below only apply to client side
|
||||
#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10 // query on super table
|
||||
#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20 // join query
|
||||
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40 // select *,columns... query
|
||||
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80 // join sub query at the second stage
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ typedef enum tSkipListPointQueryType {
|
|||
} tSkipListPointQueryType;
|
||||
|
||||
typedef struct tSkipListNode {
|
||||
uint16_t nLevel;
|
||||
char * pData;
|
||||
uint16_t nLevel;
|
||||
char * pData;
|
||||
|
||||
struct tSkipListNode **pForward;
|
||||
struct tSkipListNode **pBackward;
|
||||
|
@ -55,32 +55,22 @@ typedef struct tSkipListNode {
|
|||
/*
|
||||
* @version 0.2
|
||||
* @date 2017/11/12
|
||||
* @author liaohj
|
||||
* the simple version of SkipList.
|
||||
* for multi-thread safe purpose, we employ pthread_rwlock_t to guarantee to
|
||||
* generate
|
||||
* for multi-thread safe purpose, we employ pthread_rwlock_t to guarantee to generate
|
||||
* deterministic result. Later, we will remove the lock in SkipList to further
|
||||
* enhance the performance. In this case, one should use the concurrent skip
|
||||
* list (by
|
||||
* using michael-scott algorithm) instead of this simple version in a
|
||||
* multi-thread
|
||||
* enhance the performance. In this case, one should use the concurrent skip list (by
|
||||
* using michael-scott algorithm) instead of this simple version in a multi-thread
|
||||
* environment, to achieve higher performance of read/write operations.
|
||||
*
|
||||
* Note: Duplicated primary key situation.
|
||||
* In case of duplicated primary key, two ways can be employed to handle this
|
||||
* situation:
|
||||
* In case of duplicated primary key, two ways can be employed to handle this situation:
|
||||
* 1. add as normal insertion with out special process.
|
||||
* 2. add an overflow pointer at each list node, all nodes with the same key
|
||||
* will be added
|
||||
* in the overflow pointer. In this case, the total steps of each search will
|
||||
* be reduced significantly.
|
||||
* Currently, we implement the skip list in a line with the first means,
|
||||
* maybe refactor it soon.
|
||||
* Memory consumption: the memory alignment causes many memory wasted. So,
|
||||
* employ a memory
|
||||
* pool will significantly reduce the total memory consumption, as well as the
|
||||
* calloc/malloc
|
||||
* operation costs.
|
||||
* 2. add an overflow pointer at each list node, all nodes with the same key will be added
|
||||
* in the overflow pointer. In this case, the total steps of each search will be reduced significantly.
|
||||
* Currently, we implement the skip list in a line with the first means, maybe refactor it soon.
|
||||
*
|
||||
* Memory consumption: the memory alignment causes many memory wasted. So, employ a memory
|
||||
* pool will significantly reduce the total memory consumption, as well as the calloc/malloc operation costs.
|
||||
*
|
||||
* 3. use the iterator pattern to refactor all routines to make it more clean
|
||||
*/
|
||||
|
@ -94,7 +84,6 @@ typedef struct tSkipListState {
|
|||
// in bytes, sizeof(tSkipList)+sizeof(tSkipListNode)*tSkipList->nSize
|
||||
uint64_t nTotalMemSize;
|
||||
uint64_t nLevelNodeCnt[MAX_SKIP_LIST_LEVEL];
|
||||
|
||||
uint64_t queryCount; // total query count
|
||||
|
||||
/*
|
||||
|
@ -115,38 +104,43 @@ typedef struct tSkipListState {
|
|||
typedef struct tSkipList {
|
||||
tSkipListNode pHead;
|
||||
uint64_t nSize;
|
||||
|
||||
uint16_t nMaxLevel;
|
||||
uint16_t nLevel;
|
||||
|
||||
uint16_t keyType;
|
||||
uint16_t nMaxKeyLen;
|
||||
uint16_t nMaxLevel;
|
||||
uint16_t nLevel;
|
||||
uint16_t keyType;
|
||||
uint16_t nMaxKeyLen;
|
||||
|
||||
__compar_fn_t comparator;
|
||||
pthread_rwlock_t lock; // will be removed soon
|
||||
|
||||
// skiplist state
|
||||
tSkipListState state;
|
||||
pthread_rwlock_t lock; // will be removed soon
|
||||
tSkipListState state; // skiplist state
|
||||
} tSkipList;
|
||||
|
||||
/*
|
||||
* iterate the skiplist
|
||||
* this will cause the multi-thread problem, when the skiplist is destroyed, the iterate may
|
||||
* continue iterating the skiplist, so add the reference count for skiplist
|
||||
* TODO add the ref for skiplist when one iterator is created
|
||||
*/
|
||||
typedef struct SSkipListIterator {
|
||||
tSkipList * pSkipList;
|
||||
tSkipListNode *cur;
|
||||
int64_t num;
|
||||
} SSkipListIterator;
|
||||
|
||||
/*
|
||||
* query condition structure to denote the range query
|
||||
* //todo merge the point query cond with range query condition
|
||||
* todo merge the point query cond with range query condition
|
||||
*/
|
||||
typedef struct tSKipListQueryCond {
|
||||
// when the upper bounding == lower bounding, it is a point query
|
||||
tSkipListKey lowerBnd;
|
||||
tSkipListKey upperBnd;
|
||||
|
||||
int32_t lowerBndRelOptr; // relation operator to denote if lower bound is
|
||||
|
||||
// included or not
|
||||
int32_t upperBndRelOptr;
|
||||
int32_t lowerBndRelOptr; // relation operator to denote if lower bound is
|
||||
int32_t upperBndRelOptr; // included or not
|
||||
} tSKipListQueryCond;
|
||||
|
||||
tSkipList* tSkipListCreate(int16_t nMaxLevel, int16_t keyType, int16_t nMaxKeyLen);
|
||||
tSkipList *tSkipListCreate(int16_t nMaxLevel, int16_t keyType, int16_t nMaxKeyLen);
|
||||
|
||||
void* tSkipListDestroy(tSkipList *pSkipList);
|
||||
void *tSkipListDestroy(tSkipList *pSkipList);
|
||||
|
||||
// create skip list key
|
||||
tSkipListKey tSkipListCreateKey(int32_t type, char *val, size_t keyLength);
|
||||
|
@ -200,7 +194,10 @@ int32_t tSkipListQuery(tSkipList *pSkipList, tSKipListQueryCond *pQueryCond, tSk
|
|||
int32_t tSkipListPointQuery(tSkipList *pSkipList, tSkipListKey *pKey, int32_t numOfKey, tSkipListPointQueryType type,
|
||||
tSkipListNode ***pResult);
|
||||
|
||||
void removeNodeEachLevel(tSkipList *pSkipList, int32_t nLevel);
|
||||
int32_t tSkipListIteratorReset(tSkipList *pSkipList, SSkipListIterator *iter);
|
||||
bool tSkipListIteratorNext(SSkipListIterator *iter);
|
||||
tSkipListNode *tSkipListIteratorGet(SSkipListIterator *iter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,28 +24,27 @@ extern "C" {
|
|||
#include "tsqldef.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
#define TK_SPACE 200
|
||||
#define TK_COMMENT 201
|
||||
#define TK_ILLEGAL 202
|
||||
#define TK_HEX 203
|
||||
#define TK_OCT 204
|
||||
#define TK_SPACE 200
|
||||
#define TK_COMMENT 201
|
||||
#define TK_ILLEGAL 202
|
||||
#define TK_HEX 203 // hex number 0x123
|
||||
#define TK_OCT 204 // oct number
|
||||
#define TK_BIN 205 // bin format data 0b111
|
||||
#define TK_FILE 206
|
||||
|
||||
#define TSQL_SO_ASC 1
|
||||
#define TSQL_SO_DESC 0
|
||||
#define TSQL_SO_ASC 1
|
||||
#define TSQL_SO_DESC 0
|
||||
|
||||
#define MAX_TOKEN_LEN 30
|
||||
|
||||
#define TSQL_TBNAME "TBNAME"
|
||||
#define TSQL_TBNAME "TBNAME"
|
||||
#define TSQL_TBNAME_L "tbname"
|
||||
|
||||
#define TSQL_STABLE_QTYPE_COND 1
|
||||
#define TSQL_STABLE_QTYPE_SET 2
|
||||
|
||||
// token type
|
||||
enum {
|
||||
TSQL_NODE_TYPE_EXPR = 0x1,
|
||||
TSQL_NODE_TYPE_ID = 0x2,
|
||||
TSQL_NODE_TYPE_VALUE = 0x4,
|
||||
TSQL_NODE_TYPE_EXPR = 0x1,
|
||||
TSQL_NODE_TYPE_ID = 0x2,
|
||||
TSQL_NODE_TYPE_VALUE = 0x4,
|
||||
};
|
||||
|
||||
extern char tTokenTypeSwitcher[13];
|
||||
|
@ -155,14 +154,14 @@ enum TSQL_TYPE {
|
|||
|
||||
typedef struct SQuerySQL {
|
||||
struct tSQLExprList *pSelection; // select clause
|
||||
struct SSQLToken from; // from clause
|
||||
tVariantList * from; // from clause
|
||||
struct tSQLExpr * pWhere; // where clause [optional]
|
||||
tVariantList * pGroupby; // groupby clause, only for tags[optional]
|
||||
tVariantList * pSortOrder; // orderby [optional]
|
||||
SSQLToken interval; // interval [optional]
|
||||
SSQLToken sliding; // sliding window [optional]
|
||||
SLimitVal limit; // limit offset [optional]
|
||||
SLimitVal glimit; // group limit offset [optional]
|
||||
SLimitVal slimit; // group limit offset [optional]
|
||||
tVariantList * fillType; // fill type[optional]
|
||||
SSQLToken selectToken; // sql string
|
||||
} SQuerySQL;
|
||||
|
@ -327,12 +326,12 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
|||
*/
|
||||
void ParseFree(void *p, void (*freeProc)(void *));
|
||||
|
||||
tVariantList *tVariantListAppendToken(tVariantList *pList, SSQLToken *pAliasToken, uint8_t sortOrder);
|
||||
tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder);
|
||||
|
||||
tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||
|
||||
void tVariantListDestroy(tVariantList *pList);
|
||||
tVariantList *tVariantListAppendToken(tVariantList *pList, SSQLToken *pAliasToken, uint8_t sortOrder);
|
||||
void tVariantListDestroy(tVariantList *pList);
|
||||
|
||||
tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField);
|
||||
|
||||
|
@ -348,12 +347,15 @@ void tSQLExprListDestroy(tSQLExprList *pList);
|
|||
|
||||
int32_t tSQLSyntaxNodeToString(tSQLExpr *pNode, char *dst);
|
||||
|
||||
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, SSQLToken *pFrom, tSQLExpr *pWhere,
|
||||
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
||||
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
|
||||
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
||||
|
||||
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName,
|
||||
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type);
|
||||
void tSQLExprDestroy(tSQLExpr *);
|
||||
void tSQLExprNodeDestroy(tSQLExpr *pExpr);
|
||||
tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr);
|
||||
|
||||
SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type);
|
||||
|
||||
|
|
|
@ -63,143 +63,155 @@
|
|||
#define TK_DATABASES 45
|
||||
#define TK_MNODES 46
|
||||
#define TK_DNODES 47
|
||||
#define TK_USERS 48
|
||||
#define TK_MODULES 49
|
||||
#define TK_QUERIES 50
|
||||
#define TK_CONNECTIONS 51
|
||||
#define TK_STREAMS 52
|
||||
#define TK_CONFIGS 53
|
||||
#define TK_SCORES 54
|
||||
#define TK_GRANTS 55
|
||||
#define TK_DOT 56
|
||||
#define TK_TABLES 57
|
||||
#define TK_STABLES 58
|
||||
#define TK_VGROUPS 59
|
||||
#define TK_DROP 60
|
||||
#define TK_TABLE 61
|
||||
#define TK_DATABASE 62
|
||||
#define TK_USER 63
|
||||
#define TK_USE 64
|
||||
#define TK_DESCRIBE 65
|
||||
#define TK_ALTER 66
|
||||
#define TK_PASS 67
|
||||
#define TK_PRIVILEGE 68
|
||||
#define TK_DNODE 69
|
||||
#define TK_IP 70
|
||||
#define TK_LOCAL 71
|
||||
#define TK_IF 72
|
||||
#define TK_EXISTS 73
|
||||
#define TK_CREATE 74
|
||||
#define TK_KEEP 75
|
||||
#define TK_CACHE 76
|
||||
#define TK_REPLICA 77
|
||||
#define TK_DAYS 78
|
||||
#define TK_ROWS 79
|
||||
#define TK_ABLOCKS 80
|
||||
#define TK_TBLOCKS 81
|
||||
#define TK_CTIME 82
|
||||
#define TK_CLOG 83
|
||||
#define TK_COMP 84
|
||||
#define TK_PRECISION 85
|
||||
#define TK_LP 86
|
||||
#define TK_RP 87
|
||||
#define TK_TAGS 88
|
||||
#define TK_USING 89
|
||||
#define TK_AS 90
|
||||
#define TK_COMMA 91
|
||||
#define TK_NULL 92
|
||||
#define TK_SELECT 93
|
||||
#define TK_FROM 94
|
||||
#define TK_VARIABLE 95
|
||||
#define TK_INTERVAL 96
|
||||
#define TK_FILL 97
|
||||
#define TK_SLIDING 98
|
||||
#define TK_ORDER 99
|
||||
#define TK_BY 100
|
||||
#define TK_ASC 101
|
||||
#define TK_DESC 102
|
||||
#define TK_GROUP 103
|
||||
#define TK_HAVING 104
|
||||
#define TK_LIMIT 105
|
||||
#define TK_OFFSET 106
|
||||
#define TK_SLIMIT 107
|
||||
#define TK_SOFFSET 108
|
||||
#define TK_WHERE 109
|
||||
#define TK_NOW 110
|
||||
#define TK_INSERT 111
|
||||
#define TK_INTO 112
|
||||
#define TK_VALUES 113
|
||||
#define TK_RESET 114
|
||||
#define TK_QUERY 115
|
||||
#define TK_ADD 116
|
||||
#define TK_COLUMN 117
|
||||
#define TK_TAG 118
|
||||
#define TK_CHANGE 119
|
||||
#define TK_SET 120
|
||||
#define TK_KILL 121
|
||||
#define TK_CONNECTION 122
|
||||
#define TK_COLON 123
|
||||
#define TK_STREAM 124
|
||||
#define TK_ABORT 125
|
||||
#define TK_AFTER 126
|
||||
#define TK_ATTACH 127
|
||||
#define TK_BEFORE 128
|
||||
#define TK_BEGIN 129
|
||||
#define TK_CASCADE 130
|
||||
#define TK_CLUSTER 131
|
||||
#define TK_CONFLICT 132
|
||||
#define TK_COPY 133
|
||||
#define TK_DEFERRED 134
|
||||
#define TK_DELIMITERS 135
|
||||
#define TK_DETACH 136
|
||||
#define TK_EACH 137
|
||||
#define TK_END 138
|
||||
#define TK_EXPLAIN 139
|
||||
#define TK_FAIL 140
|
||||
#define TK_FOR 141
|
||||
#define TK_IGNORE 142
|
||||
#define TK_IMMEDIATE 143
|
||||
#define TK_INITIALLY 144
|
||||
#define TK_INSTEAD 145
|
||||
#define TK_MATCH 146
|
||||
#define TK_KEY 147
|
||||
#define TK_OF 148
|
||||
#define TK_RAISE 149
|
||||
#define TK_REPLACE 150
|
||||
#define TK_RESTRICT 151
|
||||
#define TK_ROW 152
|
||||
#define TK_STATEMENT 153
|
||||
#define TK_TRIGGER 154
|
||||
#define TK_VIEW 155
|
||||
#define TK_ALL 156
|
||||
#define TK_COUNT 157
|
||||
#define TK_SUM 158
|
||||
#define TK_AVG 159
|
||||
#define TK_MIN 160
|
||||
#define TK_MAX 161
|
||||
#define TK_FIRST 162
|
||||
#define TK_LAST 163
|
||||
#define TK_TOP 164
|
||||
#define TK_BOTTOM 165
|
||||
#define TK_STDDEV 166
|
||||
#define TK_PERCENTILE 167
|
||||
#define TK_APERCENTILE 168
|
||||
#define TK_LEASTSQUARES 169
|
||||
#define TK_HISTOGRAM 170
|
||||
#define TK_DIFF 171
|
||||
#define TK_SPREAD 172
|
||||
#define TK_WAVG 173
|
||||
#define TK_INTERP 174
|
||||
#define TK_LAST_ROW 175
|
||||
#define TK_SEMI 176
|
||||
#define TK_NONE 177
|
||||
#define TK_PREV 178
|
||||
#define TK_LINEAR 179
|
||||
#define TK_IMPORT 180
|
||||
#define TK_METRIC 181
|
||||
#define TK_TBNAME 182
|
||||
#define TK_JOIN 183
|
||||
#define TK_METRICS 184
|
||||
#define TK_STABLE 185
|
||||
#define TK_ACCOUNTS 48
|
||||
#define TK_USERS 49
|
||||
#define TK_MODULES 50
|
||||
#define TK_QUERIES 51
|
||||
#define TK_CONNECTIONS 52
|
||||
#define TK_STREAMS 53
|
||||
#define TK_CONFIGS 54
|
||||
#define TK_SCORES 55
|
||||
#define TK_GRANTS 56
|
||||
#define TK_DOT 57
|
||||
#define TK_TABLES 58
|
||||
#define TK_STABLES 59
|
||||
#define TK_VGROUPS 60
|
||||
#define TK_DROP 61
|
||||
#define TK_TABLE 62
|
||||
#define TK_DATABASE 63
|
||||
#define TK_DNODE 64
|
||||
#define TK_IP 65
|
||||
#define TK_USER 66
|
||||
#define TK_ACCOUNT 67
|
||||
#define TK_USE 68
|
||||
#define TK_DESCRIBE 69
|
||||
#define TK_ALTER 70
|
||||
#define TK_PASS 71
|
||||
#define TK_PRIVILEGE 72
|
||||
#define TK_LOCAL 73
|
||||
#define TK_IF 74
|
||||
#define TK_EXISTS 75
|
||||
#define TK_CREATE 76
|
||||
#define TK_PPS 77
|
||||
#define TK_TSERIES 78
|
||||
#define TK_DBS 79
|
||||
#define TK_STORAGE 80
|
||||
#define TK_QTIME 81
|
||||
#define TK_CONNS 82
|
||||
#define TK_STATE 83
|
||||
#define TK_KEEP 84
|
||||
#define TK_CACHE 85
|
||||
#define TK_REPLICA 86
|
||||
#define TK_DAYS 87
|
||||
#define TK_ROWS 88
|
||||
#define TK_ABLOCKS 89
|
||||
#define TK_TBLOCKS 90
|
||||
#define TK_CTIME 91
|
||||
#define TK_CLOG 92
|
||||
#define TK_COMP 93
|
||||
#define TK_PRECISION 94
|
||||
#define TK_LP 95
|
||||
#define TK_RP 96
|
||||
#define TK_TAGS 97
|
||||
#define TK_USING 98
|
||||
#define TK_AS 99
|
||||
#define TK_COMMA 100
|
||||
#define TK_NULL 101
|
||||
#define TK_SELECT 102
|
||||
#define TK_FROM 103
|
||||
#define TK_VARIABLE 104
|
||||
#define TK_INTERVAL 105
|
||||
#define TK_FILL 106
|
||||
#define TK_SLIDING 107
|
||||
#define TK_ORDER 108
|
||||
#define TK_BY 109
|
||||
#define TK_ASC 110
|
||||
#define TK_DESC 111
|
||||
#define TK_GROUP 112
|
||||
#define TK_HAVING 113
|
||||
#define TK_LIMIT 114
|
||||
#define TK_OFFSET 115
|
||||
#define TK_SLIMIT 116
|
||||
#define TK_SOFFSET 117
|
||||
#define TK_WHERE 118
|
||||
#define TK_NOW 119
|
||||
#define TK_INSERT 120
|
||||
#define TK_INTO 121
|
||||
#define TK_VALUES 122
|
||||
#define TK_RESET 123
|
||||
#define TK_QUERY 124
|
||||
#define TK_ADD 125
|
||||
#define TK_COLUMN 126
|
||||
#define TK_TAG 127
|
||||
#define TK_CHANGE 128
|
||||
#define TK_SET 129
|
||||
#define TK_KILL 130
|
||||
#define TK_CONNECTION 131
|
||||
#define TK_COLON 132
|
||||
#define TK_STREAM 133
|
||||
#define TK_ABORT 134
|
||||
#define TK_AFTER 135
|
||||
#define TK_ATTACH 136
|
||||
#define TK_BEFORE 137
|
||||
#define TK_BEGIN 138
|
||||
#define TK_CASCADE 139
|
||||
#define TK_CLUSTER 140
|
||||
#define TK_CONFLICT 141
|
||||
#define TK_COPY 142
|
||||
#define TK_DEFERRED 143
|
||||
#define TK_DELIMITERS 144
|
||||
#define TK_DETACH 145
|
||||
#define TK_EACH 146
|
||||
#define TK_END 147
|
||||
#define TK_EXPLAIN 148
|
||||
#define TK_FAIL 149
|
||||
#define TK_FOR 150
|
||||
#define TK_IGNORE 151
|
||||
#define TK_IMMEDIATE 152
|
||||
#define TK_INITIALLY 153
|
||||
#define TK_INSTEAD 154
|
||||
#define TK_MATCH 155
|
||||
#define TK_KEY 156
|
||||
#define TK_OF 157
|
||||
#define TK_RAISE 158
|
||||
#define TK_REPLACE 159
|
||||
#define TK_RESTRICT 160
|
||||
#define TK_ROW 161
|
||||
#define TK_STATEMENT 162
|
||||
#define TK_TRIGGER 163
|
||||
#define TK_VIEW 164
|
||||
#define TK_ALL 165
|
||||
#define TK_COUNT 166
|
||||
#define TK_SUM 167
|
||||
#define TK_AVG 168
|
||||
#define TK_MIN 169
|
||||
#define TK_MAX 170
|
||||
#define TK_FIRST 171
|
||||
#define TK_LAST 172
|
||||
#define TK_TOP 173
|
||||
#define TK_BOTTOM 174
|
||||
#define TK_STDDEV 175
|
||||
#define TK_PERCENTILE 176
|
||||
#define TK_APERCENTILE 177
|
||||
#define TK_LEASTSQUARES 178
|
||||
#define TK_HISTOGRAM 179
|
||||
#define TK_DIFF 180
|
||||
#define TK_SPREAD 181
|
||||
#define TK_TWA 182
|
||||
#define TK_INTERP 183
|
||||
#define TK_LAST_ROW 184
|
||||
#define TK_SEMI 185
|
||||
#define TK_NONE 186
|
||||
#define TK_PREV 187
|
||||
#define TK_LINEAR 188
|
||||
#define TK_IMPORT 189
|
||||
#define TK_METRIC 190
|
||||
#define TK_TBNAME 191
|
||||
#define TK_JOIN 192
|
||||
#define TK_METRICS 193
|
||||
#define TK_STABLE 194
|
||||
#define TK_QUESTION 195
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -39,72 +39,80 @@ extern "C" {
|
|||
#define TSDB_FUNC_FIRST 8
|
||||
#define TSDB_FUNC_LAST 9
|
||||
#define TSDB_FUNC_LAST_ROW 10
|
||||
#define TSDB_FUNC_LEASTSQR 11
|
||||
#define TSDB_FUNC_TOP 12
|
||||
#define TSDB_FUNC_BOTTOM 13
|
||||
#define TSDB_FUNC_SPREAD 14
|
||||
#define TSDB_FUNC_WAVG 15
|
||||
#define TSDB_FUNC_TOP 11
|
||||
#define TSDB_FUNC_BOTTOM 12
|
||||
#define TSDB_FUNC_SPREAD 13
|
||||
#define TSDB_FUNC_TWA 14
|
||||
#define TSDB_FUNC_LEASTSQR 15
|
||||
|
||||
#define TSDB_FUNC_TS 16
|
||||
#define TSDB_FUNC_TS_DUMMY 17
|
||||
#define TSDB_FUNC_TAG_DUMMY 18
|
||||
#define TSDB_FUNC_TS_COMP 19
|
||||
|
||||
#define TSDB_FUNC_TAG 18
|
||||
#define TSDB_FUNC_PRJ 19
|
||||
#define TSDB_FUNC_TAG 20
|
||||
#define TSDB_FUNC_PRJ 21
|
||||
|
||||
#define TSDB_FUNC_TAGPRJ 20
|
||||
#define TSDB_FUNC_ARITHM 21
|
||||
#define TSDB_FUNC_DIFF 22
|
||||
#define TSDB_FUNC_TAGPRJ 22
|
||||
#define TSDB_FUNC_ARITHM 23
|
||||
#define TSDB_FUNC_DIFF 24
|
||||
|
||||
#define TSDB_FUNC_SUM_DST 23
|
||||
#define TSDB_FUNC_AVG_DST 24
|
||||
#define TSDB_FUNC_MIN_DST 25
|
||||
#define TSDB_FUNC_MAX_DST 26
|
||||
#define TSDB_FUNC_FIRST_DST 25
|
||||
#define TSDB_FUNC_LAST_DST 26
|
||||
#define TSDB_FUNC_INTERP 27
|
||||
|
||||
#define TSDB_FUNC_FIRST_DST 27
|
||||
#define TSDB_FUNC_LAST_DST 28
|
||||
#define TSDB_FUNC_LAST_ROW_DST 29
|
||||
#define TSDB_FUNC_SPREAD_DST 30
|
||||
|
||||
#define TSDB_FUNC_WAVG_DST 31
|
||||
#define TSDB_FUNC_TOP_DST 32
|
||||
#define TSDB_FUNC_BOTTOM_DST 33
|
||||
#define TSDB_FUNC_APERCT_DST 34
|
||||
#define TSDB_FUNC_INTERP 35
|
||||
|
||||
#define TSDB_FUNCSTATE_SO 0x1 // single output
|
||||
#define TSDB_FUNCSTATE_MO 0x2 // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
|
||||
#define TSDB_FUNCSTATE_STREAM 0x4 // function avail for stream
|
||||
#define TSDB_FUNCSTATE_METRIC 0x8 // function avail for metric
|
||||
#define TSDB_FUNCSTATE_OF 0x10 // outer forward
|
||||
#define TSDB_FUNCSTATE_NEED_TS 0x20
|
||||
#define TSDB_FUNCSTATE_SO 0x1U // single output
|
||||
#define TSDB_FUNCSTATE_MO 0x2U // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
|
||||
#define TSDB_FUNCSTATE_STREAM 0x4U // function avail for stream
|
||||
#define TSDB_FUNCSTATE_METRIC 0x8U // function avail for metric
|
||||
#define TSDB_FUNCSTATE_OF 0x10U // outer forward
|
||||
#define TSDB_FUNCSTATE_NEED_TS 0x20U // timestamp is required during query processing
|
||||
#define TSDB_FUNCSTATE_SELECTIVITY 0x40U // selectivity functions, can exists along with tag columns
|
||||
|
||||
#define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF
|
||||
#define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_METRIC | TSDB_FUNCSTATE_OF
|
||||
|
||||
#define TSDB_PATTERN_MATCH 0
|
||||
#define TSDB_PATTERN_NOMATCH 1
|
||||
#define TSDB_PATTERN_NOWILDCARDMATCH 2
|
||||
#define TSDB_PATTERN_STRING_MAX_LEN 20
|
||||
#define TSDB_PATTERN_MATCH 0
|
||||
#define TSDB_PATTERN_NOMATCH 1
|
||||
#define TSDB_PATTERN_NOWILDCARDMATCH 2
|
||||
#define TSDB_PATTERN_STRING_MAX_LEN 20
|
||||
|
||||
#define TSDB_FUNCTIONS_NAME_MAX_LENGTH 16
|
||||
#define TSDB_FUNCTIONS_NAME_MAX_LENGTH 16
|
||||
#define TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE 50
|
||||
|
||||
#define PATTERN_COMPARE_INFO_INITIALIZER \
|
||||
{ '%', '_' }
|
||||
|
||||
#define DATA_SET_FLAG ',' // to denote the output area has data, not null value
|
||||
#define DATA_SET_FLAG_SIZE sizeof(char)
|
||||
#define DATA_SET_FLAG_SIZE sizeof(DATA_SET_FLAG)
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_COND_REL_PREFIX_IN "IN|"
|
||||
#define QUERY_COND_REL_PREFIX_LIKE "LIKE|"
|
||||
|
||||
#define QUERY_COND_REL_PREFIX_IN_LEN 3
|
||||
#define QUERY_COND_REL_PREFIX_LIKE_LEN 5
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_DESC_FORWARD_STEP -1
|
||||
|
||||
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSQL_SO_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
|
||||
|
||||
#define MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY 10000000
|
||||
#define TOP_BOTTOM_QUERY_LIMIT 100
|
||||
|
||||
enum {
|
||||
MASTER_SCAN = 0x0,
|
||||
SUPPLEMENTARY_SCAN = 0x1,
|
||||
SECONDARY_STAGE_MERGE = 0x10,
|
||||
MASTER_SCAN = 0x0,
|
||||
SUPPLEMENTARY_SCAN = 0x1,
|
||||
FIRST_STAGE_MERGE = 0x10,
|
||||
SECONDARY_STAGE_MERGE = 0x20,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
#define QUERY_IS_STABLE_QUERY(type) (((type)&TSDB_QUERY_TYPE_STABLE_QUERY) != 0)
|
||||
#define QUERY_IS_JOIN_QUERY(type) (((type)&TSDB_QUERY_TYPE_JOIN_QUERY) != 0)
|
||||
#define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0)
|
||||
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
|
||||
|
||||
typedef struct SArithmeticSupport {
|
||||
SSqlFunctionExpr *pExpr;
|
||||
int32_t elemSize[TSDB_MAX_COLUMNS];
|
||||
int32_t numOfCols;
|
||||
|
@ -114,81 +122,92 @@ typedef struct {
|
|||
|
||||
typedef struct SQLPreAggVal {
|
||||
bool isSet;
|
||||
int32_t numOfNullPoints;
|
||||
int64_t wsum;
|
||||
int32_t numOfNull;
|
||||
int64_t sum;
|
||||
int64_t min;
|
||||
int64_t max;
|
||||
int64_t min;
|
||||
int16_t maxIndex;
|
||||
int16_t minIndex;
|
||||
} SQLPreAggVal;
|
||||
|
||||
/* sql function runtime context */
|
||||
typedef struct SInterpInfoDetail {
|
||||
TSKEY ts; // interp specified timestamp
|
||||
int8_t hasResult;
|
||||
int8_t type;
|
||||
int8_t primaryCol;
|
||||
} SInterpInfoDetail;
|
||||
|
||||
typedef struct SInterpInfo { SInterpInfoDetail *pInterpDetail; } SInterpInfo;
|
||||
|
||||
typedef struct SResultInfo {
|
||||
int8_t hasResult; // result generated, not NULL value
|
||||
bool initialized; // output buffer has been initialized
|
||||
bool complete; // query has completed
|
||||
bool superTableQ; // is super table query
|
||||
int32_t numOfRes; // num of output result in current buffer
|
||||
int32_t bufLen; // buffer size
|
||||
void * interResultBuf; // output result buffer
|
||||
} SResultInfo;
|
||||
|
||||
struct SQLFunctionCtx;
|
||||
|
||||
/**
|
||||
* for selectivity query, the corresponding tag value is assigned if the data is qualified
|
||||
*/
|
||||
typedef struct SExtTagsInfo {
|
||||
int16_t tagsLen; // keep the tags data for top/bottom query result
|
||||
int16_t numOfTagCols;
|
||||
struct SQLFunctionCtx **pTagCtxList;
|
||||
} SExtTagsInfo;
|
||||
|
||||
// sql function runtime context
|
||||
typedef struct SQLFunctionCtx {
|
||||
int32_t startOffset;
|
||||
int32_t size;
|
||||
int32_t order;
|
||||
int32_t scanFlag;
|
||||
int32_t scanFlag; // TODO merge with currentStage
|
||||
|
||||
int16_t inputType;
|
||||
int16_t inputBytes;
|
||||
|
||||
int16_t outputType;
|
||||
int16_t outputBytes; /* size of results, determined by function and input
|
||||
column data type */
|
||||
|
||||
bool hasNullValue; /* null value exist in current block */
|
||||
int32_t blockStatus; /* Indicate if data is loaded, it is first/last/internal
|
||||
block. Only for file blocks */
|
||||
|
||||
void * aInputElemBuf;
|
||||
char * aOutputBuf; /* final result output buffer, point to sdata->data */
|
||||
int64_t numOfIteratedElems; /* total scanned points in processing, used for
|
||||
complex query process */
|
||||
int32_t numOfOutputElems;
|
||||
|
||||
int32_t currentStage; /* record current running step, default: 0 */
|
||||
|
||||
int64_t nStartQueryTimestamp; /* timestamp range of current query when
|
||||
function is executed on a specific data block
|
||||
*/
|
||||
tVariant intermediateBuf[4]; /* to hold intermediate result */
|
||||
|
||||
int16_t outputType;
|
||||
int16_t outputBytes; // size of results, determined by function and input column data type
|
||||
bool hasNull; // null value exist in current block
|
||||
int16_t functionId; // function id
|
||||
int32_t blockStatus; // Indicate if data is loaded, it is first/last/internal block. Only for file blocks
|
||||
void * aInputElemBuf;
|
||||
char * aOutputBuf; // final result output buffer, point to sdata->data
|
||||
uint8_t currentStage; // record current running step, default: 0
|
||||
int64_t nStartQueryTimestamp; // timestamp range of current query when function is executed on a specific data block
|
||||
int32_t numOfParams;
|
||||
tVariant param[4]; /* input parameter, current support only one element */
|
||||
int64_t *ptsList; /* additional array list */
|
||||
void * ptsOutputBuf; /* output buffer for the corresponding timestamp of each
|
||||
result, e.g., top/bottom*/
|
||||
|
||||
tVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param */
|
||||
int64_t *ptsList; // corresponding timestamp array list
|
||||
void * ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
|
||||
SQLPreAggVal preAggVals;
|
||||
tVariant tag;
|
||||
SResultInfo *resultInfo;
|
||||
|
||||
SExtTagsInfo tagInfo;
|
||||
} SQLFunctionCtx;
|
||||
|
||||
typedef struct SQLAggFuncElem {
|
||||
char aName[TSDB_FUNCTIONS_NAME_MAX_LENGTH];
|
||||
|
||||
uint8_t nAggIdx; /* index of function in aAggs */
|
||||
int8_t stableFuncId; /* transfer function for metric query */
|
||||
uint8_t nAggIdx; // index of function in aAggs
|
||||
int8_t stableFuncId; // transfer function for super table query
|
||||
uint16_t nStatus;
|
||||
|
||||
/* setup the execute environment */
|
||||
void (*init)(SQLFunctionCtx *pCtx);
|
||||
bool (*init)(SQLFunctionCtx *pCtx); // setup the execute environment
|
||||
|
||||
/* main execution function */
|
||||
bool (*xFunction)(SQLFunctionCtx *pCtx);
|
||||
void (*xFunction)(SQLFunctionCtx *pCtx); // blocks version function
|
||||
void (*xFunctionF)(SQLFunctionCtx *pCtx, int32_t position); // single-row function version
|
||||
|
||||
/* filter version */
|
||||
bool (*xFunctionF)(SQLFunctionCtx *pCtx, int32_t position);
|
||||
|
||||
/*
|
||||
* some sql function require scan data twice or more in case of no index
|
||||
* existing.
|
||||
* e.g., stddev, percentile[disk based process for extremely large dataset]
|
||||
* @param pCtx
|
||||
*/
|
||||
bool (*xNextStep)(SQLFunctionCtx *pCtx);
|
||||
// some sql function require scan data twice or more, e.g.,stddev
|
||||
void (*xNextStep)(SQLFunctionCtx *pCtx);
|
||||
|
||||
/*
|
||||
* finalizer must be called after all xFunction has been executed to
|
||||
* generated final result. Otherwise, the value in aOutputBuf is a intern
|
||||
* result.
|
||||
* generated final result. Otherwise, the value in aOutputBuf is a intern result.
|
||||
*/
|
||||
void (*xFinalize)(SQLFunctionCtx *pCtx);
|
||||
|
||||
|
@ -204,24 +223,25 @@ typedef struct SPatternCompareInfo {
|
|||
char matchOne; // symbol for match one wildcard, default: '_'
|
||||
} SPatternCompareInfo;
|
||||
|
||||
void function_finalize(SQLFunctionCtx *pCtx);
|
||||
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
|
||||
|
||||
void getResultInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *len);
|
||||
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
|
||||
int16_t *len, int16_t *interResBytes, int16_t extLength, bool isSuperTable);
|
||||
|
||||
SResultInfo *getResultSupportInfo(SQLFunctionCtx *pCtx);
|
||||
|
||||
int patternMatch(const char *zPattern, const char *zString, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size,
|
||||
const struct SPatternCompareInfo *pInfo);
|
||||
int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
#define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0)
|
||||
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
|
||||
#define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0)
|
||||
#define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0)
|
||||
#define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0)
|
||||
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
|
||||
#define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0)
|
||||
#define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0)
|
||||
|
||||
/*
|
||||
* the status of one block, used in metric query. all blocks are mixed together,
|
||||
* we need the status to decide
|
||||
* if one block is a first/end/inter block of one meter
|
||||
* we need the status to decide if one block is a first/end/inter block of one meter
|
||||
*/
|
||||
enum {
|
||||
BLK_FILE_BLOCK = 0x1,
|
||||
|
@ -251,12 +271,12 @@ enum {
|
|||
#define SET_DATA_BLOCK_LOADED(x) ((x) |= BLK_BLOCK_LOADED);
|
||||
#define IS_DATA_BLOCK_LOADED(x) (((x)&BLK_BLOCK_LOADED) != 0)
|
||||
|
||||
typedef struct SWavgRuntime {
|
||||
int8_t valFlag; // flag to denote has value
|
||||
int16_t type; // source data type
|
||||
int64_t lastKey;
|
||||
int64_t sKey;
|
||||
int64_t eKey;
|
||||
typedef struct STwaInfo {
|
||||
TSKEY lastKey;
|
||||
int8_t hasResult; // flag to denote has value
|
||||
int16_t type; // source data type
|
||||
TSKEY SKey;
|
||||
TSKEY EKey;
|
||||
|
||||
union {
|
||||
double dOutput;
|
||||
|
@ -267,33 +287,23 @@ typedef struct SWavgRuntime {
|
|||
double dLastValue;
|
||||
int64_t iLastValue;
|
||||
};
|
||||
} SWavgRuntime;
|
||||
|
||||
typedef struct SSumRuntime {
|
||||
union {
|
||||
double dOutput;
|
||||
int64_t iOutput;
|
||||
};
|
||||
int8_t valFlag;
|
||||
} SSumRuntime;
|
||||
|
||||
typedef struct SAvgRuntime {
|
||||
double sum;
|
||||
int64_t num;
|
||||
int8_t valFlag;
|
||||
} SAvgRuntime;
|
||||
} STwaInfo;
|
||||
|
||||
/* global sql function array */
|
||||
extern struct SQLAggFuncElem aAggs[36];
|
||||
extern struct SQLAggFuncElem aAggs[28];
|
||||
|
||||
/* compatible check array list */
|
||||
extern int32_t funcCompatList[36];
|
||||
extern int32_t funcCompatDefList[28];
|
||||
|
||||
void getStatistics(char *priData, char *data, int32_t size, int32_t numOfRow, int32_t type, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int64_t *wsum, int32_t *numOfNull);
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int32_t *numOfNull);
|
||||
|
||||
bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *minval, char *maxval);
|
||||
|
||||
void resetResultInfo(SResultInfo *pResInfo);
|
||||
void initResultInfo(SResultInfo *pResInfo);
|
||||
void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,8 @@ extern "C" {
|
|||
|
||||
extern char *sdbDnodeStatusStr[];
|
||||
extern char *sdbDnodeBalanceStateStr[];
|
||||
extern char *sdbVnodeDropStateStr[];
|
||||
extern char *sdbVnodeSyncStatusStr[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,8 +29,9 @@ typedef struct SSQLToken {
|
|||
char * z;
|
||||
} SSQLToken;
|
||||
|
||||
#if 0
|
||||
char *tscGetToken(char *string, char **token, int *tokenLen);
|
||||
char *tscGetTokenDelimiter(char *string, char **token, int *tokenLen, const char *delimiters);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* tokenizer for sql string
|
||||
|
@ -40,14 +41,39 @@ char *tscGetTokenDelimiter(char *string, char **token, int *tokenLen, const char
|
|||
*/
|
||||
uint32_t tSQLGetToken(char *z, uint32_t *tokenType);
|
||||
|
||||
void tStrGetToken(char *str, int32_t *i, SSQLToken *t0, bool isPrevOptr);
|
||||
/**
|
||||
* enhanced tokenizer for sql string.
|
||||
*
|
||||
* @param str
|
||||
* @param i
|
||||
* @param isPrevOptr
|
||||
* @param numOfIgnoreToken
|
||||
* @param ignoreTokenTypes
|
||||
* @return
|
||||
*/
|
||||
SSQLToken tStrGetToken(char *str, int32_t *i, bool isPrevOptr, uint32_t numOfIgnoreToken, uint32_t *ignoreTokenTypes);
|
||||
|
||||
/**
|
||||
* check if it is a keyword or not
|
||||
* @param z
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
bool isKeyWord(const char *z, int32_t len);
|
||||
|
||||
/**
|
||||
* check if it is a number or not
|
||||
* @param pToken
|
||||
* @return
|
||||
*/
|
||||
bool isNumber(const SSQLToken *pToken);
|
||||
|
||||
void shiftStr(char *dst, char *src);
|
||||
|
||||
uint64_t changeToTimestampWithDynPrec(SSQLToken *pToken);
|
||||
/**
|
||||
* check if it is a token or not
|
||||
* @param pToken
|
||||
* @return token type, if it is not a number, TK_ILLEGAL will return
|
||||
*/
|
||||
int32_t isValidNumber(const SSQLToken* pToken);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_STRING_BUILDER_H
|
||||
#define TDENGINE_STRING_BUILDER_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SStringBuilder {
|
||||
jmp_buf jb;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
char* buf;
|
||||
} SStringBuilder;
|
||||
|
||||
#define taosStringBuilderSetJmp(sb) setjmp((sb)->jb)
|
||||
|
||||
void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size);
|
||||
char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len);
|
||||
void taosStringBuilderDestroy(SStringBuilder* sb);
|
||||
|
||||
void taosStringBuilderAppend(SStringBuilder* sb, const void* data, size_t len);
|
||||
void taosStringBuilderAppendChar(SStringBuilder* sb, char c);
|
||||
void taosStringBuilderAppendStringLen(SStringBuilder* sb, const char* str, size_t len);
|
||||
void taosStringBuilderAppendString(SStringBuilder* sb, const char* str);
|
||||
void taosStringBuilderAppendNull(SStringBuilder* sb);
|
||||
void taosStringBuilderAppendInteger(SStringBuilder* sb, int64_t v);
|
||||
void taosStringBuilderAppendDouble(SStringBuilder* sb, double v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -23,6 +23,8 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern char dataDir[TSDB_FILENAME_LEN];
|
||||
|
||||
bool taosGetSysMemory(float *memoryUsedMB);
|
||||
|
||||
bool taosGetProcMemory(float *memoryUsedMB);
|
||||
|
|
|
@ -45,6 +45,8 @@ void *taosTmrInit(int maxTmr, int resoultion, int longest, char *label);
|
|||
|
||||
tmr_h taosTmrStart(void (*fp)(void *, void *), int mseconds, void *param1, void *handle);
|
||||
|
||||
void taosTmrStop(tmr_h tmrId);
|
||||
|
||||
void taosTmrStopA(tmr_h *timerId);
|
||||
|
||||
void taosTmrReset(void (*fp)(void *, void *), int mseconds, void *param1, void *handle, tmr_h *pTmrId);
|
||||
|
|
|
@ -67,9 +67,9 @@ typedef struct tVariant {
|
|||
|
||||
void tVariantCreate(tVariant *pVar, SSQLToken *token);
|
||||
|
||||
void tVariantCreateN(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
|
||||
void tVariantCreateB(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
|
||||
void tVariantDestroy(tVariant *pV);
|
||||
|
||||
|
|
|
@ -16,26 +16,20 @@
|
|||
#ifndef TDENGINE_TUTIL_H
|
||||
#define TDENGINE_TUTIL_H
|
||||
|
||||
#include "os.h"
|
||||
#include "tmd5.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "tmd5.h"
|
||||
#include "tcrc32c.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#define VALIDFD(x) ((x) > 2)
|
||||
#ifndef STDERR_FILENO
|
||||
#define VALIDFD(x) ((x) > 2)
|
||||
#else
|
||||
#define VALIDFD(x) ((x) > STDERR_FILENO)
|
||||
#endif
|
||||
|
||||
#define WCHAR wchar_t
|
||||
#define tfree(x) \
|
||||
|
@ -101,8 +95,24 @@ extern "C" {
|
|||
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
||||
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
||||
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
||||
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
||||
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
||||
|
||||
#ifdef _TD_ARM_32_
|
||||
#define GET_FLOAT_VAL(x) taos_align_get_float(x)
|
||||
#define GET_DOUBLE_VAL(x) taos_align_get_double(x)
|
||||
|
||||
float taos_align_get_float(char* pBuf);
|
||||
double taos_align_get_double(char* pBuf);
|
||||
|
||||
//#define __float_align_declear() float __underlyFloat = 0.0;
|
||||
//#define __float_align_declear()
|
||||
//#define GET_FLOAT_VAL_ALIGN(x) (*(int32_t*)&(__underlyFloat) = *(int32_t*)(x); __underlyFloat);
|
||||
// notes: src must be float or double type variable !!!
|
||||
#define SET_FLOAT_VAL_ALIGN(dst, src) (*(int32_t*) dst = *(int32_t*)src);
|
||||
#define SET_DOUBLE_VAL_ALIGN(dst, src) (*(int64_t*) dst = *(int64_t*)src);
|
||||
#else
|
||||
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
||||
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
||||
#endif
|
||||
|
||||
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||
|
||||
|
@ -132,6 +142,10 @@ int64_t strnatoi(char *num, int32_t len);
|
|||
|
||||
char* strreplace(const char* str, const char* pattern, const char* rep);
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
|
||||
int32_t strdequote(char *src);
|
||||
|
||||
char *paGetToken(char *src, char **token, int32_t *tokenLen);
|
||||
|
||||
void taosMsleep(int32_t mseconds);
|
||||
|
@ -173,6 +187,21 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
|
|||
memcpy(target, context.digest, TSDB_KEY_LEN);
|
||||
}
|
||||
|
||||
char *taosIpStr(uint32_t ipInt);
|
||||
|
||||
#ifdef _TAOS_MEM_TEST_
|
||||
// Use during test to simulate the success and failure scenarios of memory allocation
|
||||
extern void* taos_malloc(unsigned int size, char* _func);
|
||||
extern void* taos_calloc(unsigned int num, unsigned int size, char* _func);
|
||||
extern void* taos_realloc(void* ptr, unsigned int size, char* _func);
|
||||
extern void taos_free(void* ptr);
|
||||
#define malloc(size) taos_malloc(size, __FUNCTION__)
|
||||
#define calloc(num, size) taos_calloc(num, size, __FUNCTION__)
|
||||
#define realloc(ptr, size) taos_realloc(ptr, size, __FUNCTION__)
|
||||
#define free(ptr) taos_free(ptr)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(shell)
|
||||
|
|
|
@ -1,43 +1,32 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc ${TD_ROOT_DIR}/src/inc ${TD_ROOT_DIR}/src/client/inc ${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
IF (TD_LINUX_64)
|
||||
AUX_SOURCE_DIRECTORY(./src SRC)
|
||||
LIST(REMOVE_ITEM SRC ./src/shellWindows.c)
|
||||
|
||||
ADD_EXECUTABLE(shell ${SRC})
|
||||
TARGET_LINK_LIBRARIES(shell taos_static)
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME "taos")
|
||||
|
||||
ELSEIF (TD_WINDOWS)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/pthread)
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/deps/regex)
|
||||
INCLUDE_DIRECTORIES(inc ${TD_ROOT_DIR}/src/inc ${TD_ROOT_DIR}/src/client/inc ${TD_OS_DIR}/inc)
|
||||
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex)
|
||||
LIST(APPEND SRC ./src/shellEngine.c)
|
||||
LIST(APPEND SRC ./src/shellMain.c)
|
||||
LIST(APPEND SRC ./src/shellWindows.c)
|
||||
|
||||
ADD_EXECUTABLE(shell ${SRC})
|
||||
TARGET_LINK_LIBRARIES(shell taos_static)
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME "taos")
|
||||
|
||||
ELSEIF (TD_DARWIN)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc ${TD_ROOT_DIR}/src/inc ${TD_ROOT_DIR}/src/client/inc ${TD_OS_DIR}/inc)
|
||||
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
LIST(APPEND SRC ./src/shellEngine.c)
|
||||
LIST(APPEND SRC ./src/shellMain.c)
|
||||
LIST(APPEND SRC ./src/shellWindows.c)
|
||||
|
||||
ADD_EXECUTABLE(shell ${SRC})
|
||||
TARGET_LINK_LIBRARIES(shell taos_static)
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME "taos")
|
||||
|
||||
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
|
||||
ENDIF ()
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "taos.h"
|
||||
#include "tlog.h"
|
||||
#include "tsdb.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#define MAX_USERNAME_SIZE 64
|
||||
#define MAX_DBNAME_SIZE 64
|
||||
|
@ -78,6 +79,7 @@ void cleanup_handler(void* arg);
|
|||
void exitShell();
|
||||
int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode);
|
||||
void shellPrintNChar(char* str, int width, bool printMode);
|
||||
void shellGetGrantInfo(void *con);
|
||||
#define max(a, b) ((int)(a) < (int)(b) ? (int)(b) : (int)(a))
|
||||
|
||||
/**************** Global variable declarations ****************/
|
||||
|
|
|
@ -443,17 +443,27 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
printf("%*d|", l[i], *((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
#ifdef LINUX
|
||||
printf("%*ld|", l[i], *((int64_t *)row[i]));
|
||||
#else
|
||||
printf("%*lld|", l[i], *((int64_t *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
#ifdef _TD_ARM_32_
|
||||
float fv = 0;
|
||||
//memcpy(&fv, row[i], sizeof(float));
|
||||
*(int32_t*)(&fv) = *(int32_t*)row[i];
|
||||
printf("%*.5f|", l[i], fv);
|
||||
#else
|
||||
printf("%*.5f|", l[i], *((float *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
#ifdef _TD_ARM_32_
|
||||
double dv = 0;
|
||||
//memcpy(&dv, row[i], sizeof(double));
|
||||
*(int64_t*)(&dv) = *(int64_t*)row[i];
|
||||
printf("%*.9f|", l[i], dv);
|
||||
#else
|
||||
printf("%*.9f|", l[i], *((double *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
|
@ -466,16 +476,12 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (args.is_raw_time) {
|
||||
#ifdef LINUX
|
||||
printf(" %ld|", *(int64_t *)row[i]);
|
||||
#else
|
||||
printf(" %lld|", *(int64_t *)row[i]);
|
||||
#endif
|
||||
} else {
|
||||
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
|
||||
tt = *(int64_t *)row[i] / 1000000;
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000000);
|
||||
} else {
|
||||
tt = *(int64_t *)row[i] / 1000;
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000);
|
||||
}
|
||||
|
||||
ptm = localtime(&tt);
|
||||
|
@ -520,18 +526,28 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
printf("%d\n", *((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
#ifdef LINUX
|
||||
printf("%ld\n", *((int64_t *)row[i]));
|
||||
#else
|
||||
printf("%lld\n", *((int64_t *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
#ifdef _TD_ARM_32_
|
||||
float fv = 0;
|
||||
//memcpy(&fv, row[i], sizeof(float));
|
||||
*(int32_t*)(&fv) = *(int32_t*)row[i];
|
||||
printf("%.5f\n", fv);
|
||||
#else
|
||||
printf("%.5f\n", *((float *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
#ifdef _TD_ARM_32_
|
||||
double dv = 0;
|
||||
//memcpy(&dv, row[i], sizeof(double));
|
||||
*(int64_t*)(&dv) = *(int64_t*)row[i];
|
||||
printf("%.9f\n", dv);
|
||||
#else
|
||||
printf("%.9f\n", *((double *)row[i]));
|
||||
break;
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
memset(t_str, 0, TSDB_MAX_BYTES_PER_ROW);
|
||||
|
@ -541,16 +557,12 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (args.is_raw_time) {
|
||||
#ifdef LINUX
|
||||
printf("%ld\n", *(int64_t *)row[i]);
|
||||
#else
|
||||
printf("%lld\n", *(int64_t *)row[i]);
|
||||
#endif
|
||||
} else {
|
||||
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
|
||||
tt = *(int64_t *)row[i] / 1000000;
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000000);
|
||||
} else {
|
||||
tt = *(int64_t *)row[i] / 1000;
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000);
|
||||
}
|
||||
|
||||
ptm = localtime(&tt);
|
||||
|
@ -573,6 +585,16 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
} while ((row = taos_fetch_row(result)));
|
||||
|
||||
} else { // dump to file
|
||||
// first write column
|
||||
for (int col = 0; col < num_fields; col++) {
|
||||
fprintf(fp, "%s", fields[col].name);
|
||||
if (col < num_fields - 1) {
|
||||
fprintf(fp, ",");
|
||||
} else {
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
for (int i = 0; i < num_fields; i++) {
|
||||
if (row[i]) {
|
||||
|
@ -590,17 +612,27 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
fprintf(fp, "%d", *((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
#ifdef LINUX
|
||||
fprintf(fp, "%ld", *((int64_t *)row[i]));
|
||||
#else
|
||||
fprintf(fp, "%lld", *((int64_t *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
#ifdef _TD_ARM_32_
|
||||
float fv = 0;
|
||||
//memcpy(&fv, row[i], sizeof(float));
|
||||
*(int32_t*)(&fv) = *(int32_t*)row[i];
|
||||
fprintf(fp, "%.5f", fv);
|
||||
#else
|
||||
fprintf(fp, "%.5f", *((float *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
#ifdef _TD_ARM_32_
|
||||
double dv = 0;
|
||||
//memcpy(&dv, row[i], sizeof(double));
|
||||
*(int64_t*)(&dv) = *(int64_t*)row[i];
|
||||
fprintf(fp, "%.9f", dv);
|
||||
#else
|
||||
fprintf(fp, "%.9f", *((double *)row[i]));
|
||||
#endif
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
|
@ -609,11 +641,24 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
|
|||
fprintf(fp, "\'%s\'", t_str);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
#ifdef LINUX
|
||||
fprintf(fp, "%ld", *(int64_t *)row[i]);
|
||||
#else
|
||||
fprintf(fp, "%lld", *(int64_t *)row[i]);
|
||||
#endif
|
||||
if (args.is_raw_time) {
|
||||
fprintf(fp, "%lld", *(int64_t *)row[i]);
|
||||
} else {
|
||||
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000000);
|
||||
} else {
|
||||
tt = (time_t)((*(int64_t *)row[i]) / 1000);
|
||||
}
|
||||
|
||||
ptm = localtime(&tt);
|
||||
strftime(buf, 64, "%Y-%m-%d %H:%M:%S", ptm);
|
||||
|
||||
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
|
||||
fprintf(fp, "\'%s.%06d\'", buf, (int)(*(int64_t *)row[i] % 1000000));
|
||||
} else {
|
||||
fprintf(fp, "\'%s.%03d\'", buf, (int)(*(int64_t *)row[i] % 1000));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -703,7 +748,7 @@ void write_history() {
|
|||
}
|
||||
|
||||
void taos_error(TAOS *con) {
|
||||
fprintf(stderr, "\nTSDB error: %s\n\n", taos_errstr(con));
|
||||
fprintf(stderr, "\nDB error: %s\n", taos_errstr(con));
|
||||
|
||||
/* free local resouce: allocated memory/metric-meta refcnt */
|
||||
TAOS_RES *pRes = taos_use_result(con);
|
||||
|
@ -771,3 +816,52 @@ void source_file(TAOS *con, char *fptr) {
|
|||
wordfree(&full_path);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void shellGetGrantInfo(void *con) {
|
||||
#ifdef CLUSTER
|
||||
char sql[] = "show grants";
|
||||
|
||||
if (taos_query(con, sql)) {
|
||||
fprintf(stdout, "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int num_fields = taos_field_count(con);
|
||||
if (num_fields == 0) {
|
||||
fprintf(stderr, "\nInvalid grant information.\n");
|
||||
exit(0);
|
||||
} else {
|
||||
result = taos_use_result(con);
|
||||
if (result == NULL) {
|
||||
fprintf(stderr, "\nGrant information is null.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||
TAOS_ROW row = taos_fetch_row(result);
|
||||
if (row == NULL) {
|
||||
fprintf(stderr, "\nGrant information is empty.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
char version[32] = {0};
|
||||
char expiretime[32] = {0};
|
||||
char expired[32] = {0};
|
||||
|
||||
memcpy(version, row[0], fields[0].bytes);
|
||||
memcpy(expiretime, row[1], fields[1].bytes);
|
||||
memcpy(expired, row[2], fields[2].bytes);
|
||||
|
||||
if (strcmp(expiretime, "unlimited") == 0) {
|
||||
fprintf(stdout, "This is the %s version and will never expire.\n", version);
|
||||
} else {
|
||||
fprintf(stdout, "This is the %s version and will expire at %s.\n", version, expiretime);
|
||||
}
|
||||
|
||||
taos_free_result(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ static struct argp_option options[] = {
|
|||
{"user", 'u', "USER", 0, "The TDEngine user name to use when connecting to the server."},
|
||||
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
||||
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
||||
{"raw-time", 'r', 0, 0, "Output time as unsigned long."},
|
||||
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
||||
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
||||
{"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."},
|
||||
{"timezone", 't', "TIMEZONE", 0, "Time zone of the shell, default is local."},
|
||||
|
@ -313,7 +313,7 @@ void shellPrintNChar(char *str, int width, bool printMode) {
|
|||
if (*str == '\0') break;
|
||||
char *tstr = str;
|
||||
int byte_width = mbtowc(&wc, tstr, MB_CUR_MAX);
|
||||
if (byte_width <= 0 ) break;
|
||||
if (byte_width <= 0) break;
|
||||
int col_width = wcwidth(wc);
|
||||
if (col_width <= 0) {
|
||||
str += byte_width;
|
||||
|
|
|
@ -96,6 +96,9 @@ int main(int argc, char* argv[]) {
|
|||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
|
||||
/* Get grant information */
|
||||
shellGetGrantInfo(con);
|
||||
|
||||
/* Loop to query the input. */
|
||||
while (1) {
|
||||
pthread_create(&pid, NULL, shellLoopQuery, con);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
void printHelp() {
|
||||
char indent[10] = " ";
|
||||
printf("taos shell is used to test the TAOS database\n");
|
||||
printf("taos shell is used to test the TDEngine database\n");
|
||||
|
||||
printf("%s%s\n", indent, "-h");
|
||||
printf("%s%s%s\n", indent, indent, "TDEngine server IP address to connect. The default host is localhost.");
|
||||
|
@ -200,7 +200,8 @@ void shellReadCommand(TAOS *con, char command[]) {
|
|||
|
||||
void *shellLoopQuery(void *arg) {
|
||||
TAOS *con = (TAOS *)arg;
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
char *command = malloc(MAX_COMMAND_SIZE);
|
||||
if (command == NULL) return NULL;
|
||||
|
||||
while (1) {
|
||||
memset(command, 0, MAX_COMMAND_SIZE);
|
||||
|
@ -244,4 +245,4 @@ void shellPrintNChar(char *str, int width, bool printMode) {
|
|||
|
||||
void get_history_path(char *history) { sprintf(history, "%s/%s", ".", HISTORY_FILE); }
|
||||
|
||||
void exitShell() { exit(EXIT_SUCCESS); }
|
||||
void exitShell() { exit(EXIT_SUCCESS); }
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
IF (TD_LINUX_64)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
INCLUDE_DIRECTORIES(${TD_ROOT_DIR}/src/inc ${TD_ROOT_DIR}/src/client/inc ${TD_OS_DIR}/inc)
|
||||
ADD_EXECUTABLE(taosdemo ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taosdemo taos_static)
|
||||
ENDIF ()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue