Merge pull request #30023 from taosdata/feat/TS-5607/greatest

feat: greatest func
This commit is contained in:
Simon Guan 2025-03-11 14:12:30 +08:00 committed by GitHub
commit 520585184f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 3927 additions and 156 deletions

View File

@ -44,6 +44,7 @@ The TDengine client driver provides all the APIs needed for application programm
|enableQueryHb | |Supported, effective immediately |Internal parameter, whether to send query heartbeat messages|
|minSlidingTime | |Supported, effective immediately |Internal parameter, minimum allowable value for sliding|
|minIntervalTime | |Supported, effective immediately |Internal parameter, minimum allowable value for interval|
|compareAsStrInGreatest | v3.3.6.0 |Supported, effective immediately |When the greatest and least functions have both numeric and string types as parameters, the comparison type conversion rules are as follows: Integer; 1: uniformly converted to string comparison, 0: uniformly converted to numeric type comparison.|
### Writing Related

View File

@ -124,7 +124,39 @@ FLOOR(expr)
```
**Function Description**: Gets the floor of the specified field.
Other usage notes see CEIL function description.
Other usage notes see [CEIL](#ceil) function description.
#### GREATEST
```sql
GREATEST(expr1, expr2[, expr]...)
```
**Function Description**: Get the maximum value of all input parameters. The minimum number of parameters for this function is 2.
**Version**ver-3.3.6.0
**Return Type**Refer to the comparison rules. The comparison type is the final return type.
**Applicable Data Types**:
- Numeric types: timestamp, bool, integer and floating point types
- Strings types: nchar and varchar types.
**Comparison rules**: The following rules describe the conversion method of the comparison operation:
- If any parameter is NULL, the comparison result is NULL.
- If all parameters in the comparison operation are string types, compare them as string types
- If all parameters are numeric types, compare them as numeric types.
- If there are both string types and numeric types in the parameters, according to the `compareAsStrInGreatest` configuration item, they are uniformly compared as strings or numeric values. By default, they are compared as strings.
- In all cases, when different types are compared, the comparison type will choose the type with a larger range for comparison. For example, when comparing integer types, if there is a BIGINT type, BIGINT will definitely be selected as the comparison type.
**Related configuration items**: Client configuration, compareAsStrInGreatest is 1, which means that both string types and numeric types are converted to string comparisons, and 0 means that they are converted to numeric types. The default is 1.
#### LEAST
```sql
LEAST(expr1, expr2[, expr]...)
```
**Function Description**Get the minimum value of all input parameters. The rest of the description is the same as the [GREATEST](#greatest) function.
#### LOG

View File

@ -221,6 +221,12 @@ TDengine 客户端驱动提供了应用编程所需要的全部 API并且在
- 动态修改:不支持
- 支持版本:从 v3.0.0.0 版本开始引入
#### compareAsStrInGreatest
- 说明:用于决定 greatest、least 函数的参数既有数值类型又有字符串类型时,比较类型的转换规则。
- 类型整数1统一转为字符串比较0统一转为数值类型比较。
- 动态修改:支持通过 SQL 修改,立即生效
- 支持版本:从 v3.3.6.0 版本开始引入
### 写入相关
#### smlChildTableName

View File

@ -186,7 +186,38 @@ FLOOR(expr)
```
**功能说明**:获得指定字段的向下取整数的结果。
其他使用说明参见 CEIL 函数描述。
其他使用说明参见 [CEIL](#ceil) 函数描述。
#### GREATEST
```sql
GREATEST(expr1, expr2[, expr]...)
```
**功能说明**:获得输入的所有参数中的最大值。该函数最小参数个数为 2 个。
**使用说明**ver-3.3.6.0
**返回结果类型**:参考比较规则,比较类型即为最终返回类型。
**适用数据类型**
- 数值类型:包括 bool 型,整型和浮点型
- 字符串类型:包括 nchar 和 varchar 类型。
**比较规则**:以下规则描述了比较操作的转换方式:
- 如果有任何一个参数为 NULL则比较结果为 NULL。
- 如果比较操作中的所有参数都是字符串类型,按照字符串类型比较
- 如果所有参数都是数值类型,则将它们作为数值类型进行比较。
- 如果参数中既有字符串类型,也有数值类型,根据 compareAsStrInGreatest 配置项,统一作为字符串或者数值进行比较。默认按照字符串比较。
- 在所有情况下,不同类型比较,比较类型会选择范围更大的类型进行比较,例如作为整数类型比较时,如果存在 BIGINT 类型,必定会选择 BIGINT 作为比较类型。
**相关配置项**客户端配置compareAsStrInGreatest 为 1 表示同时存在字符串类型和数值类型统一转为字符串比较,为 0 表示统一转为数值类型比较。默认为 1。
#### LEAST
```sql
LEAST(expr1, expr2[, expr]...)
```
**功能说明**:获得输入的所有参数中的最小值。其余部分说明同 [GREATEST](#greatest) 函数。
#### LN

View File

@ -299,6 +299,7 @@ extern bool tsStreamCoverage;
extern int8_t tsS3EpNum;
extern int32_t tsStreamNotifyMessageSize;
extern int32_t tsStreamNotifyFrameSize;
extern bool tsCompareAsStrInGreatest;
extern bool tsExperimental;
// #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)

View File

@ -276,6 +276,9 @@ typedef struct {
#define IS_STR_DATA_TYPE(t) \
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define IS_COMPARE_STR_DATA_TYPE(t) \
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define IS_VALID_TINYINT(_t) ((_t) >= INT8_MIN && (_t) <= INT8_MAX)
#define IS_VALID_SMALLINT(_t) ((_t) >= INT16_MIN && (_t) <= INT16_MAX)
#define IS_VALID_INT(_t) ((_t) >= INT32_MIN && (_t) <= INT32_MAX)

View File

@ -90,6 +90,8 @@ typedef enum EFunctionType {
FUNCTION_TYPE_DEGREES,
FUNCTION_TYPE_RADIANS,
FUNCTION_TYPE_TRUNCATE,
FUNCTION_TYPE_GREATEST,
FUNCTION_TYPE_LEAST,
// string function
FUNCTION_TYPE_LENGTH = 1500,

View File

@ -66,6 +66,8 @@ int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode *
SNode **pOtherCond);
int32_t filterIsMultiTableColsCond(SNode *pCond, bool *res);
EConditionType filterClassifyCondition(SNode *pNode);
int32_t filterGetCompFunc(__compar_fn_t *func, int32_t type, int32_t optr);
bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right);
#ifdef __cplusplus
}

View File

@ -44,6 +44,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type, int8_
int32_t vectorGetConvertType(int32_t type1, int32_t type2);
int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow, int32_t startIndex, int32_t numOfRows);
int32_t vectorConvertSingleCol(SScalarParam *input, SScalarParam *output, int32_t type, int32_t startIndex, int32_t numOfRows);
/* Math functions */
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
@ -71,6 +72,8 @@ int32_t signFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t degreesFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t radiansFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t randFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t greatestFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t leastFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
/* String functions */
int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);

View File

@ -130,6 +130,8 @@ uint32_t tsEncryptionKeyChksum = 0;
int8_t tsEncryptionKeyStat = ENCRYPT_KEY_STAT_UNSET;
int8_t tsGrant = 1;
bool tsCompareAsStrInGreatest = true;
// monitor
bool tsEnableMonitor = true;
int32_t tsMonitorInterval = 30;
@ -746,6 +748,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(
cfgAddBool(pCfg, "streamCoverage", tsStreamCoverage, CFG_DYN_CLIENT, CFG_DYN_CLIENT, CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "compareAsStrInGreatest", tsCompareAsStrInGreatest, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT,CFG_CATEGORY_LOCAL));
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -1480,6 +1484,9 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "streamCoverage");
tsStreamCoverage = pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compareAsStrInGreatest");
tsCompareAsStrInGreatest = pItem->bval;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -2783,7 +2790,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
{"numOfRpcSessions", &tsNumOfRpcSessions},
{"bypassFlag", &tsBypassFlag},
{"safetyCheckLevel", &tsSafetyCheckLevel},
{"streamCoverage", &tsStreamCoverage}};
{"streamCoverage", &tsStreamCoverage},
{"compareAsStrInGreatest", &tsCompareAsStrInGreatest}};
if ((code = taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true)) != TSDB_CODE_SUCCESS) {
code = taosCfgSetOption(options, tListLen(options), pItem, false);

View File

@ -22,6 +22,9 @@
#include "tanalytics.h"
#include "taoserror.h"
#include "ttime.h"
#include "functionMgt.h"
#include "ttypes.h"
#include "tglobal.h"
static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) {
va_list vArgList;
@ -1745,6 +1748,62 @@ static int32_t translateHistogramPartial(SFunctionNode* pFunc, char* pErrBuf, in
return TSDB_CODE_SUCCESS;
}
#define NUMERIC_TO_STRINGS_LEN 25
static int32_t translateGreatestleast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
bool mixTypeToStrings = tsCompareAsStrInGreatest;
SDataType res = {.type = 0};
bool resInit = false;
for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); i++) {
SDataType* para = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, i));
if (IS_NULL_TYPE(para->type)) {
res.type = TSDB_DATA_TYPE_NULL;
res.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
break;
}
if (!resInit) {
res.type = para->type;
res.bytes = para->bytes;
resInit = true;
continue;
}
if (IS_MATHABLE_TYPE(para->type)) {
if (res.type == para->type) {
continue;
} else if (IS_MATHABLE_TYPE(res.type) || !mixTypeToStrings) {
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = tDataTypes[res.type].bytes;
} else {
// last res is strings, para is numeric and mixTypeToStrings is true
res.bytes = TMAX(res.bytes, NUMERIC_TO_STRINGS_LEN);
}
} else {
if (IS_COMPARE_STR_DATA_TYPE(res.type)) {
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = TMAX(res.bytes, para->bytes);
} else if (mixTypeToStrings) {
// last res is numeric, para is string, and mixTypeToStrings is true
res.type = para->type;
res.bytes = TMAX(para->bytes, NUMERIC_TO_STRINGS_LEN);
} else {
// last res is numeric, para is string, and mixTypeToStrings is false
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = tDataTypes[resType].bytes;
}
}
}
pFunc->node.resType = res;
return TSDB_CODE_SUCCESS;
}
// clang-format off
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
@ -5656,6 +5715,48 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.name = "cols",
.translateFunc = invalidColsFunction,
},
{
.name = "greatest",
.type = FUNCTION_TYPE_GREATEST,
.classification = FUNC_MGT_SCALAR_FUNC,
.parameters = {.minParamNum = 2,
.maxParamNum = -1,
.paramInfoPattern = 1,
.inputParaInfo[0][0] = {.isLastParam = true,
.startParam = 1,
.endParam = -1,
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE | FUNC_PARAM_SUPPORT_BOOL_TYPE | FUNC_PARAM_SUPPORT_TIMESTAMP_TYPE | FUNC_PARAM_SUPPORT_VARCHAR_TYPE | FUNC_PARAM_SUPPORT_NCHAR_TYPE,
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateGreatestleast,
.getEnvFunc = NULL,
.initFunc = NULL,
.sprocessFunc = greatestFunction,
.finalizeFunc = NULL
},
{
.name = "least",
.type = FUNCTION_TYPE_LEAST,
.classification = FUNC_MGT_SCALAR_FUNC,
.parameters = {.minParamNum = 2,
.maxParamNum = -1,
.paramInfoPattern = 1,
.inputParaInfo[0][0] = {.isLastParam = true,
.startParam = 1,
.endParam = -1,
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE | FUNC_PARAM_SUPPORT_BOOL_TYPE | FUNC_PARAM_SUPPORT_TIMESTAMP_TYPE | FUNC_PARAM_SUPPORT_VARCHAR_TYPE | FUNC_PARAM_SUPPORT_NCHAR_TYPE,
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateGreatestleast,
.getEnvFunc = NULL,
.initFunc = NULL,
.sprocessFunc = leastFunction,
.finalizeFunc = NULL
},
};
// clang-format on

View File

@ -1,11 +1,14 @@
#include <stdint.h>
#include "cJSON.h"
#include "function.h"
#include "scalar.h"
#include "sclInt.h"
#include "sclvector.h"
#include "tdatablock.h"
#include "tdef.h"
#include "tjson.h"
#include "ttime.h"
#include "filter.h"
typedef float (*_float_fn)(float);
typedef float (*_float_fn_2)(float, float);
@ -4403,3 +4406,136 @@ int32_t modeScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
return selectScalarFunction(pInput, inputNum, pOutput);
}
typedef struct SCovertScarlarParam {
SScalarParam covertParam;
SScalarParam *param;
bool converted;
} SCovertScarlarParam;
void freeSCovertScarlarParams(SCovertScarlarParam *pCovertParams, int32_t num) {
if (pCovertParams == NULL) {
return;
}
for (int32_t i = 0; i < num; i++) {
if (pCovertParams[i].converted) {
sclFreeParam(pCovertParams[i].param);
}
}
taosMemoryFree(pCovertParams);
}
static int32_t vectorCompareAndSelect(SCovertScarlarParam *pParams, int32_t numOfRows, int numOfCols,
int32_t *resultColIndex, EOperatorType optr) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t type = GET_PARAM_TYPE(pParams[0].param);
__compar_fn_t fp = NULL;
code = filterGetCompFunc(&fp, type, optr);
if(code != TSDB_CODE_SUCCESS) {
qError("failed to get compare function, func:%s type:%d, optr:%d", __FUNCTION__, type, optr);
return code;
}
for (int32_t i = 0; i < numOfRows; i++) {
int selectIndex = 0;
if (colDataIsNull_s(pParams[selectIndex].param->columnData, i)) {
resultColIndex[i] = -1;
continue;
}
for (int32_t j = 1; j < numOfCols; j++) {
if (colDataIsNull_s(pParams[j].param->columnData, i)) {
resultColIndex[i] = -1;
break;
} else {
int32_t leftRowNo = pParams[selectIndex].param->numOfRows == 1 ? 0 : i;
int32_t rightRowNo = pParams[j].param->numOfRows == 1 ? 0 : i;
char *pLeftData = colDataGetData(pParams[selectIndex].param->columnData, leftRowNo);
char *pRightData = colDataGetData(pParams[j].param->columnData, rightRowNo);
bool pRes = filterDoCompare(fp, optr, pLeftData, pRightData);
if (!pRes) {
selectIndex = j;
}
}
resultColIndex[i] = selectIndex;
}
}
return code;
}
static int32_t greatestLeastImpl(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, EOperatorType order) {
int32_t code = TSDB_CODE_SUCCESS;
SColumnInfoData *pOutputData = pOutput[0].columnData;
int16_t outputType = GET_PARAM_TYPE(&pOutput[0]);
int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]);
SCovertScarlarParam *pCovertParams = NULL;
int32_t *resultColIndex = NULL;
int32_t numOfRows = 0;
bool IsNullType = outputType == TSDB_DATA_TYPE_NULL ? true : false;
// If any column is NULL type, the output is NULL type
for (int32_t i = 0; i < inputNum; i++) {
if (IsNullType) {
break;
}
if (numOfRows != 0 && numOfRows != pInput[i].numOfRows && pInput[i].numOfRows != 1 && numOfRows != 1) {
qError("input rows not match, func:%s, rows:%d, %d", __FUNCTION__, numOfRows, pInput[i].numOfRows);
code = TSDB_CODE_TSC_INTERNAL_ERROR;
goto _return;
}
numOfRows = TMAX(numOfRows, pInput[i].numOfRows);
IsNullType |= IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]));
}
if (IsNullType) {
colDataSetNNULL(pOutputData, 0, numOfRows);
pOutput->numOfRows = numOfRows;
return TSDB_CODE_SUCCESS;
}
pCovertParams = taosMemoryMalloc(inputNum * sizeof(SCovertScarlarParam));
for (int32_t j = 0; j < inputNum; j++) {
SScalarParam *pParam = &pInput[j];
int16_t oldType = GET_PARAM_TYPE(&pInput[j]);
if (oldType != outputType) {
pCovertParams[j].covertParam = (SScalarParam){0};
setTzCharset(&pCovertParams[j].covertParam, pParam->tz, pParam->charsetCxt);
SCL_ERR_JRET(vectorConvertSingleCol(pParam, &pCovertParams[j].covertParam, outputType, 0, pParam->numOfRows));
pCovertParams[j].param = &pCovertParams[j].covertParam;
pCovertParams[j].converted = true;
} else {
pCovertParams[j].param = pParam;
pCovertParams[j].converted = false;
}
}
resultColIndex = taosMemoryCalloc(numOfRows, sizeof(int32_t));
SCL_ERR_JRET(vectorCompareAndSelect(pCovertParams, numOfRows, inputNum, resultColIndex, order));
for (int32_t i = 0; i < numOfRows; i++) {
int32_t index = resultColIndex[i];
if (index == -1) {
colDataSetNULL(pOutputData, i);
continue;
}
int32_t rowNo = pCovertParams[index].param->numOfRows == 1 ? 0 : i;
char *data = colDataGetData(pCovertParams[index].param->columnData, rowNo);
SCL_ERR_JRET(colDataSetVal(pOutputData, i, data, false));
}
pOutput->numOfRows = numOfRows;
_return:
freeSCovertScarlarParams(pCovertParams, inputNum);
taosMemoryFree(resultColIndex);
return code;
}
int32_t greatestFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return greatestLeastImpl(pInput, inputNum, pOutput, OP_TYPE_GREATER_THAN);
}
int32_t leastFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return greatestLeastImpl(pInput, inputNum, pOutput, OP_TYPE_LOWER_THAN);
}

View File

@ -996,7 +996,7 @@ int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut,
}
int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 5, 9, 5, 11, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 5, 9, 5, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
@ -1021,7 +1021,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
};
int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/* NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 20,
/*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1,
/*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1,

View File

@ -51,7 +51,7 @@ taos> select ASCII('hello') + 1 from ts_4893.meters limit 1
taos> select ASCII('hello') + ASCII('hello') from ts_4893.meters limit 1
ascii('hello') + ascii('hello') |
==================================
2.080000000000000e+02 |
208 |
taos> select ASCII(nch1) from ts_4893.meters order by ts limit 5
ascii(nch1) |

Can't render this file because it has a wrong number of fields in line 17.

View File

@ -51,7 +51,7 @@ taos> select CHAR_LENGTH('hello') + 1 from ts_4893.meters limit 1
taos> select CHAR_LENGTH('hello') + CHAR_LENGTH('hello') from ts_4893.meters limit 1
char_length('hello') + char_length('hello') |
==============================================
1.000000000000000e+01 |
10 |
taos> select CHAR_LENGTH(nch1) from ts_4893.meters order by ts limit 5
char_length(nch1) |

Can't render this file because it has a wrong number of fields in line 17.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -576,7 +576,7 @@ taos> select max(total_voltage) from (select sum(voltage) as total_voltage from
taos> select round(max(current), 2) from ts_4893.meters
round(max(current), 2) |
=========================
1.2000000e+01 |
12 |
taos> select pow(max(current), 2) from ts_4893.meters
pow(max(current), 2) |
@ -651,7 +651,7 @@ taos> select max(cast(10000000000 as bigint unsigned))
taos> select max(cast(1.1 as float))
max(cast(1.1 as float)) |
==========================
1.1000000e+00 |
1.1 |
taos> select max(cast(1.1 as double))
max(cast(1.1 as double)) |

Can't render this file because it has a wrong number of fields in line 576.

View File

@ -576,7 +576,7 @@ taos> select min(total_voltage) from (select sum(voltage) as total_voltage from
taos> select round(min(current), 2) from ts_4893.meters
round(min(current), 2) |
=========================
8.0000000e+00 |
8 |
taos> select pow(min(current), 2) from ts_4893.meters
pow(min(current), 2) |
@ -651,7 +651,7 @@ taos> select min(cast(10000000000 as bigint unsigned))
taos> select min(cast(1.1 as float))
min(cast(1.1 as float)) |
==========================
1.1000000e+00 |
1.1 |
taos> select min(cast(1.1 as double))
min(cast(1.1 as double)) |

Can't render this file because it has a wrong number of fields in line 576.

View File

@ -42,26 +42,26 @@ taos> select MOD(10.55, 1) + 1
taos> select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123.123456789, 9), 8), 7), 6), 5), 4), 3)
mod(mod(mod(mod(mod(mod(mod(123.123456789, 9), 8), 7), 6), 5), 4 |
===================================================================
1.234567890000022e-01 |
0.123456789000002 |
taos> select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123456789.123456789, -1), -2), -3), -4), -5), -6), -7)
mod(mod(mod(mod(mod(mod(mod(123456789.123456789, -1), -2), -3), |
===================================================================
1.234567910432816e-01 |
0.123456791043282 |
taos> select MOD(87654321.123456789, id + 1) from ts_4893.meters order by ts limit 10
mod(87654321.123456789, id + 1) |
==================================
1.234567910432816e-01 |
1.123456791043282e+00 |
1.234567910432816e-01 |
1.123456791043282e+00 |
1.123456791043282e+00 |
3.123456791043282e+00 |
6.123456791043282e+00 |
1.123456791043282e+00 |
1.234567910432816e-01 |
1.123456791043282e+00 |
0.123456791043282 |
1.12345679104328 |
0.123456791043282 |
1.12345679104328 |
1.12345679104328 |
3.12345679104328 |
6.12345679104328 |
1.12345679104328 |
0.123456791043282 |
1.12345679104328 |
taos> select MOD(current, id + 1) from ts_4893.meters order by ts limit 10
mod(current, id + 1) |
@ -94,16 +94,16 @@ taos> select MOD(current, 1) from ts_4893.meters order by ts limit 10
taos> select MOD(sqrt(current), abs(id + 1)) from ts_4893.meters order by ts limit 10
mod(sqrt(current), abs(id + 1)) |
==================================
2.634337159700784e-01 |
9.281394021770111e-01 |
1.296964830944782e-01 |
3.351566768190027e+00 |
3.272002495118848e+00 |
2.916847677517688e+00 |
3.097741066924800e+00 |
3.310891102586806e+00 |
3.350522322288470e+00 |
3.215120509901375e+00 |
0.263433715970078 |
0.928139402177011 |
0.129696483094478 |
3.35156676819003 |
3.27200249511885 |
2.91684767751769 |
3.0977410669248 |
3.31089110258681 |
3.35052232228847 |
3.21512050990137 |
taos> select mod(10, -3)
mod(10, -3) |

1 taos> select MOD(10.55, 3)
42 mod(87654321.123456789, id + 1) |
43 ==================================
44 1.234567910432816e-01 | 0.123456791043282 |
45 1.123456791043282e+00 | 1.12345679104328 |
46 1.234567910432816e-01 | 0.123456791043282 |
47 1.123456791043282e+00 | 1.12345679104328 |
48 1.123456791043282e+00 | 1.12345679104328 |
49 3.123456791043282e+00 | 3.12345679104328 |
50 6.123456791043282e+00 | 6.12345679104328 |
51 1.123456791043282e+00 | 1.12345679104328 |
52 1.234567910432816e-01 | 0.123456791043282 |
53 1.123456791043282e+00 | 1.12345679104328 |
54 taos> select MOD(current, id + 1) from ts_4893.meters order by ts limit 10
55 mod(current, id + 1) |
56 ============================
57 0.649999618530273 |
58 0.574000358581543 |
59 0.795000076293945 |
60 3.23299980163574 |
61 0.706000328063965 |
62 2.50800037384033 |
63 2.5959997177124 |
64 2.96199989318848 |
65 2.22599983215332 |
66 0.336999893188477 |
67 taos> select MOD(current, 1) from ts_4893.meters order by ts limit 10
94 mod(10, -3) |
95 ============================
96 1 |
97 taos> select mod(10, 3)
98 mod(10, 3) |
99 ============================
100 1 |
101 taos> select mod(id, 3) from ts_4893.d0 order by ts limit 10
102 mod(id, 3) |
103 ============================
104 0 |
105 1 |
106 2 |
107 0 |
108 1 |
109 2 |

View File

@ -190,5 +190,5 @@ taos> select voltage / pi() from ts_4893.meters limit 1
taos> select id, case when voltage > 100 then pi() else pi() / 2 end from ts_4893.meters limit 1
id | case when voltage > 100 then pi() else pi() / 2 end |
====================================================================
0 | 3.141592653589793e+00 |
0 | 3.14159265358979 |

Can't render this file because it has a wrong number of fields in line 90.

View File

@ -201,7 +201,7 @@ taos> select ABS(POSITION('aaa' IN 'aaaaaaaaa'))
taos> select POW(POSITION('aaa' IN 'aaaaaaaaa'), 2)
pow(position('aaa' in 'aaaaaaaaa'), 2) |
=========================================
1.000000000000000e+00 |
1 |
taos> select position('t' in 'taos')
position('t' in 'taos') |

Can't render this file because it has a wrong number of fields in line 22.

View File

@ -50,12 +50,12 @@ taos> select rand(-1)
taos> select rand(12345678901234567890)
rand(12345678901234567890) |
=============================
2.008294813338805e-01 |
0.20082948133388 |
taos> select rand(-12345678901234567890)
rand(-12345678901234567890) |
==============================
8.401877171547095e-01 |
0.84018771715471 |
taos> select rand(12345), rand(12345)
rand(12345) | rand(12345) |

Can't render this file because it has a wrong number of fields in line 60.

View File

@ -67,12 +67,12 @@ taos> select ROUND(10.55, 1) + 1
taos> select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123.123456789, 9), 8), 7), 6), 5), 4))
round(round(round(round(round(round(round(123.123456789, 9), 8), |
===================================================================
1.230000000000000e+02 |
123 |
taos> select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123456789.123456789, -1), -2), -3), -4), -5), -6))
round(round(round(round(round(round(round(123456789.123456789, - |
===================================================================
1.230000000000000e+08 |
123000000 |
taos> select ROUND(current) from ts_4893.meters order by ts limit 20
round(current) |
@ -101,16 +101,16 @@ taos> select ROUND(current) from ts_4893.meters order by ts limit 20
taos> select ROUND(87654321.123456789, id) from ts_4893.meters order by ts limit 10
round(87654321.123456789, id) |
================================
8.765432100000000e+07 |
8.765432109999999e+07 |
8.765432112000000e+07 |
8.765432112300000e+07 |
8.765432112350000e+07 |
8.765432112345999e+07 |
8.765432112345700e+07 |
8.765432112345681e+07 |
8.765432112345679e+07 |
8.765432112345679e+07 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1235 |
87654321.12346 |
87654321.123457 |
87654321.1234568 |
87654321.1234568 |
87654321.1234568 |
taos> select ROUND(current, id) from ts_4893.meters order by ts limit 10
round(current, id) |
@ -286,7 +286,7 @@ taos> select round(voltage, -1) from ts_4893.meters limit 1
taos> select round(current * voltage, 2) from ts_4893.meters limit 1
round(current * voltage, 2) |
==============================
2.353650000000000e+03 |
2353.65 |
taos> select round(abs(voltage), 2) from ts_4893.meters limit 1
round(abs(voltage), 2) |

1 taos> select ROUND(10.55, 3)
67 11 |
68 11 |
69 9 |
70 10 |
71 11 |
72 11 |
73 10 |
74 11 |
75 9 |
76 11 |
77 8 |
78 12 |
101 8.6 |
102 9.8 |
103 11.233 |
104 10.706 |
105 8.508 |
106 9.596 |
107 10.962 |
108 11.226 |
109 10.337 |
110 taos> select ROUND(current, 1) from ts_4893.meters order by ts limit 10
111 round(current, 1) |
112 =======================
113 10.7 |
114 8.6 |
115 9.8 |
116 11.2 |
286 round(cast(5 as tinyint unsigned), 1) |
287 ========================================
288 5 |
289 taos> select round(cast(50 as smallint unsigned), 1);
290 round(cast(50 as smallint unsigned), 1) |
291 ==========================================
292 50 |

View File

@ -164,7 +164,7 @@ taos> select sign(cast(1 as bigint unsigned))
taos> select sign(cast(1 as float))
sign(cast(1 as float)) |
=========================
1.0000000e+00 |
1 |
taos> select sign(cast(1 as double))
sign(cast(1 as double)) |
@ -316,30 +316,30 @@ taos> select sign(current) from ts_4893.meters order by ts limit 10
taos> select sign(cast(current as float)) from ts_4893.d0 order by ts limit 10
sign(cast(current as float)) |
===============================
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
taos> select sign(cast(current as float)) from ts_4893.meters order by ts limit 10
sign(cast(current as float)) |
===============================
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
taos> select sign(null)
sign(null) |

Can't render this file because it has a wrong number of fields in line 239.

View File

@ -109,17 +109,17 @@ taos> select stddev_pop(total_voltage) from (select sum(voltage) as total_voltag
taos> select round(stddev_pop(current), 2) from ts_4893.meters
round(stddev_pop(current), 2) |
================================
1.150000000000000e+00 |
1.15 |
taos> select pow(stddev_pop(current), 2) from ts_4893.meters
pow(stddev_pop(current), 2) |
==============================
1.332500071133751e+00 |
1.33250007113375 |
taos> select log(stddev_pop(voltage) + 1) from ts_4893.meters
log(stddev_pop(voltage) + 1) |
===============================
1.354922290183882e+00 |
1.35492229018388 |
taos> select groupid, stddev_pop(voltage) from ts_4893.meters group by groupid order by groupid
groupid | stddev_pop(voltage) |

Can't render this file because it has a wrong number of fields in line 109.

View File

@ -47,40 +47,40 @@ taos> select TRUNCATE(10.55, 1) + 1
taos> select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123.123456789, 9), 8), 7), 6), 5), 4), 3)
truncate(truncate(truncate(truncate(truncate(truncate(truncate(1 |
===================================================================
1.231230000000000e+02 |
123.123 |
taos> select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123456789.123456789, -1), -2), -3), -4), -5), -6), -7)
truncate(truncate(truncate(truncate(truncate(truncate(truncate(1 |
===================================================================
1.200000000000000e+08 |
120000000 |
taos> select TRUNCATE(87654321.123456789, id) from ts_4893.meters order by ts limit 10
truncate(87654321.123456789, id) |
===================================
8.765432100000000e+07 |
8.765432109999999e+07 |
8.765432112000000e+07 |
8.765432112300000e+07 |
8.765432112340000e+07 |
8.765432112345000e+07 |
8.765432112345600e+07 |
8.765432112345670e+07 |
8.765432112345679e+07 |
8.765432112345679e+07 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1234 |
87654321.12345 |
87654321.123456 |
87654321.1234567 |
87654321.1234568 |
87654321.1234568 |
taos> select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10
truncate(current, id) |
========================
1.0000000e+01 |
8.5000000e+00 |
9.7900000e+00 |
1.1233000e+01 |
1.0706000e+01 |
8.5080004e+00 |
9.5959997e+00 |
1.0962000e+01 |
1.1226000e+01 |
1.0337000e+01 |
10 |
8.5 |
9.79 |
11.233 |
10.706 |
8.508 |
9.596 |
10.962 |
11.226 |
10.337 |
taos> select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10
truncate(current, 1) |
@ -144,26 +144,26 @@ taos> select TRUNC(10.55, 1) + 1
taos> select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123.123456789, 9), 8), 7), 6), 5), 4), 3)
trunc(trunc(trunc(trunc(trunc(trunc(trunc(123.123456789, 9), 8), |
===================================================================
1.231230000000000e+02 |
123.123 |
taos> select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123456789.123456789, -1), -2), -3), -4), -5), -6), -7)
trunc(trunc(trunc(trunc(trunc(trunc(trunc(123456789.123456789, - |
===================================================================
1.200000000000000e+08 |
120000000 |
taos> select TRUNC(87654321.123456789, id) from ts_4893.meters order by ts limit 10
trunc(87654321.123456789, id) |
================================
8.765432100000000e+07 |
8.765432109999999e+07 |
8.765432112000000e+07 |
8.765432112300000e+07 |
8.765432112340000e+07 |
8.765432112345000e+07 |
8.765432112345600e+07 |
8.765432112345670e+07 |
8.765432112345679e+07 |
8.765432112345679e+07 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1234 |
87654321.12345 |
87654321.123456 |
87654321.1234567 |
87654321.1234568 |
87654321.1234568 |
taos> select TRUNC(current, id) from ts_4893.meters order by ts limit 10
trunc(current, id) |
@ -289,7 +289,7 @@ taos> select truncate(100.9876, 2)
taos> select truncate(99999999999999.9999, 2)
truncate(99999999999999.9999, 2) |
===================================
1.000000000000000e+14 |
100000000000000 |
taos> select truncate(-5.678, 2)
truncate(-5.678, 2) |
@ -314,7 +314,7 @@ taos> select truncate(phase, 3) from ts_4893.meters limit 1
taos> select truncate(voltage + current, 2) from ts_4893.meters limit 1
truncate(voltage + current, 2) |
=================================
2.316400000000000e+02 |
231.64 |
taos> select truncate(voltage, -1) from ts_4893.meters limit 1
truncate(voltage, -1) |
@ -329,7 +329,7 @@ taos> select round(truncate(voltage, 1), 2) from ts_4893.meters limit 1
taos> select truncate(abs(current), 1) from ts_4893.meters limit 1
truncate(abs(current), 1) |
============================
1.0600000e+01 |
10.6 |
taos> select truncate(exp(phase), 2) from ts_4893.meters limit 1
truncate(exp(phase), 2) |

1 taos> select TRUNCATE(10.55, 3)
47 ===================================
48 8.765432100000000e+07 | 87654321 |
49 8.765432109999999e+07 | 87654321.1 |
50 8.765432112000000e+07 | 87654321.12 |
51 8.765432112300000e+07 | 87654321.123 |
52 8.765432112340000e+07 | 87654321.1234 |
53 8.765432112345000e+07 | 87654321.12345 |
54 8.765432112345600e+07 | 87654321.123456 |
55 8.765432112345670e+07 | 87654321.1234567 |
56 8.765432112345679e+07 | 87654321.1234568 |
57 8.765432112345679e+07 | 87654321.1234568 |
58 taos> select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10
59 truncate(current, id) |
60 ========================
61 1.0000000e+01 | 10 |
62 8.5000000e+00 | 8.5 |
63 9.7900000e+00 | 9.79 |
64 1.1233000e+01 | 11.233 |
65 1.0706000e+01 | 10.706 |
66 8.5080004e+00 | 8.508 |
67 9.5959997e+00 | 9.596 |
68 1.0962000e+01 | 10.962 |
69 1.1226000e+01 | 11.226 |
70 1.0337000e+01 | 10.337 |
71 taos> select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10
72 truncate(current, 1) |
73 =======================
74 10.6 |
75 8.5 |
76 9.7 |
77 11.2 |
78 10.7 |
79 8.5 |
80 9.5 |
81 10.9 |
82 11.2 |
83 10.3 |
84 taos> select TRUNC(10.55, 3)
85 trunc(10.55, 3) |
86 ============================
144 10 |
145 8.5 |
146 9.79 |
147 11.233 |
148 10.706 |
149 8.508 |
150 9.596 |
151 10.962 |
152 11.226 |
153 10.337 |
154 taos> select TRUNC(current, 1) from ts_4893.meters order by ts limit 10
155 trunc(current, 1) |
156 =======================
157 10.6 |
158 8.5 |
159 9.7 |
160 11.2 |
161 10.7 |
162 8.5 |
163 9.5 |
164 10.9 |
165 11.2 |
166 10.3 |
167 taos> select truncate(99.99, 3)
168 truncate(99.99, 3) |
169 ============================
289
290
291
292
293
294
295
314
315
316
317
318
319
320
329
330
331
332
333
334
335

View File

@ -99,7 +99,7 @@ taos> select var_pop(total_voltage) from (select sum(voltage) as total_voltage f
taos> select round(var_pop(current), 2) from ts_4893.meters
round(var_pop(current), 2) |
=============================
1.330000000000000e+00 |
1.33 |
taos> select pow(var_pop(current), 2) from ts_4893.meters
pow(var_pop(current), 2) |

Can't render this file because it has a wrong number of fields in line 99.

View File

@ -0,0 +1,232 @@
alter local 'compareAsStrInGreatest' '1';
select GREATEST(1,2,3,4,5,6,7,8,9,10);
select GREATEST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select GREATEST(1,'2',3.3,4.4,5);
select GREATEST(121,'18');
select GREATEST(18888,'18');
select GREATEST(1,2,3,4,5,'5.1');
select GREATEST('1','2','3','4',5);
select GREATEST('1','2','3','4','5');
select GREATEST(1,2,3,4,5,6,7,'a','b','一','二','三');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select GREATEST(cast(100 as tinyint), cast(101 as tinyint));
select GREATEST(cast(100 as tinyint), cast(101 as smallint));
select GREATEST(cast(100 as tinyint), cast(101 as int));
select GREATEST(cast(100 as tinyint), cast(101 as bigint));
select GREATEST(cast(100 as tinyint), cast(101 as float));
select GREATEST(cast(100 as tinyint), cast(101 as double));
select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as nchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as tinyint));
select GREATEST(cast(101 as tinyint), cast(100 as smallint));
select GREATEST(cast(101 as tinyint), cast(100 as int));
select GREATEST(cast(101 as tinyint), cast(100 as bigint));
select GREATEST(cast(101 as tinyint), cast(100 as float));
select GREATEST(cast(101 as tinyint), cast(100 as double));
select GREATEST(cast(101 as tinyint), cast(100 as varchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as nchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as smallint));
select GREATEST(cast(1000 as smallint), cast(1001 as int));
select GREATEST(cast(1000 as smallint), cast(1001 as bigint));
select GREATEST(cast(1000 as smallint), cast(1001 as float));
select GREATEST(cast(1000 as smallint), cast(1001 as double));
select GREATEST(cast(1000 as smallint), cast(1001 as varchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as nchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as smallint));
select GREATEST(cast(1001 as smallint), cast(1000 as int));
select GREATEST(cast(1001 as smallint), cast(1000 as bigint));
select GREATEST(cast(1001 as smallint), cast(1000 as float));
select GREATEST(cast(1001 as smallint), cast(1000 as double));
select GREATEST(cast(1001 as smallint), cast(1000 as varchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as nchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as int));
select GREATEST(cast(1000000 as int), cast(1000001 as bigint));
select GREATEST(cast(1000000 as int), cast(1000001 as float));
select GREATEST(cast(1000000 as int), cast(1000001 as double));
select GREATEST(cast(1000000 as int), cast(1000001 as varchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as nchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as int));
select GREATEST(cast(1000001 as int), cast(1000000 as bigint));
select GREATEST(cast(1000001 as int), cast(1000000 as float));
select GREATEST(cast(1000001 as int), cast(1000000 as double));
select GREATEST(cast(1000001 as int), cast(1000000 as varchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as nchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as float));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as double));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as float));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as double));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select GREATEST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));
select GREATEST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select GREATEST('a','b','c','d','e','f','g','h','1231','15155');
select GREATEST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select GREATEST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(221, voltage) from ts_4893.meters order by ts limit 10;
select GREATEST(5, id) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('23', 3443434343434343);
select GREATEST(co, 3443434343434343) from ts_4893.n1;
select GREATEST('23', 3443434343434343) from ts_4893.n1;
select GREATEST('23', 1443434343434343) from ts_4893.n1;
select GREATEST(current, voltage) from ts_4893.n1;
select GREATEST(current, voltage, '15') from ts_4893.n1;
alter local 'compareAsStrInGreatest' '0';
select GREATEST(1,'2',3.3,4.4,5);
select GREATEST(1,2,3,4,5,'5.1');
select GREATEST(121,'18');
select GREATEST('1','2','3','4','5');
select GREATEST(1,2,3,4,5,6,7,'a','b','一','二','三');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select GREATEST(cast(100 as tinyint), cast(101 as tinyint));
select GREATEST(cast(100 as tinyint), cast(101 as smallint));
select GREATEST(cast(100 as tinyint), cast(101 as int));
select GREATEST(cast(100 as tinyint), cast(101 as bigint));
select GREATEST(cast(100 as tinyint), cast(101 as float));
select GREATEST(cast(100 as tinyint), cast(101 as double));
select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as nchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as tinyint));
select GREATEST(cast(101 as tinyint), cast(100 as smallint));
select GREATEST(cast(101 as tinyint), cast(100 as int));
select GREATEST(cast(101 as tinyint), cast(100 as bigint));
select GREATEST(cast(101 as tinyint), cast(100 as float));
select GREATEST(cast(101 as tinyint), cast(100 as double));
select GREATEST(cast(101 as tinyint), cast(100 as varchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as nchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as smallint));
select GREATEST(cast(1000 as smallint), cast(1001 as int));
select GREATEST(cast(1000 as smallint), cast(1001 as bigint));
select GREATEST(cast(1000 as smallint), cast(1001 as float));
select GREATEST(cast(1000 as smallint), cast(1001 as double));
select GREATEST(cast(1000 as smallint), cast(1001 as varchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as nchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as smallint));
select GREATEST(cast(1001 as smallint), cast(1000 as int));
select GREATEST(cast(1001 as smallint), cast(1000 as bigint));
select GREATEST(cast(1001 as smallint), cast(1000 as float));
select GREATEST(cast(1001 as smallint), cast(1000 as double));
select GREATEST(cast(1001 as smallint), cast(1000 as varchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as nchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as int));
select GREATEST(cast(1000000 as int), cast(1000001 as bigint));
select GREATEST(cast(1000000 as int), cast(1000001 as float));
select GREATEST(cast(1000000 as int), cast(1000001 as double));
select GREATEST(cast(1000000 as int), cast(1000001 as varchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as nchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as int));
select GREATEST(cast(1000001 as int), cast(1000000 as bigint));
select GREATEST(cast(1000001 as int), cast(1000000 as float));
select GREATEST(cast(1000001 as int), cast(1000000 as double));
select GREATEST(cast(1000001 as int), cast(1000000 as varchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as nchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as float));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as double));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as float));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as double));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select GREATEST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));
select GREATEST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select GREATEST('a','b','c','d','e','f','g','h','1231','15155');
select GREATEST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select GREATEST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(221, voltage) from ts_4893.meters order by ts limit 10;
select GREATEST(5, id) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('23', 3443434343434343);
select GREATEST(co, 3443434343434343) from ts_4893.n1;
select GREATEST('23', 1443434343434343) from ts_4893.n1;
select GREATEST('23', 3443434343434343) from ts_4893.n1
select GREATEST(current, voltage) from ts_4893.n1;
select GREATEST(current, voltage, '15') from ts_4893.n1;

View File

@ -0,0 +1,228 @@
alter local 'compareAsStrInGreatest' '1';
select LEAST(1,2,3,4,5,6,7,8,9,10);
select LEAST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select LEAST(1,'2',3.3,4.4,5);
select LEAST(1,2,3,4,5,'5.1');
select LEAST('1','2','3','4',5);
select LEAST('1','2','3','4','5');
select LEAST(1,2,3,4,5,6,7,'a','b','一','二','三');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select LEAST(cast(100 as tinyint), cast(101 as tinyint));
select LEAST(cast(100 as tinyint), cast(101 as smallint));
select LEAST(cast(100 as tinyint), cast(101 as int));
select LEAST(cast(100 as tinyint), cast(101 as bigint));
select LEAST(cast(100 as tinyint), cast(101 as float));
select LEAST(cast(100 as tinyint), cast(101 as double));
select LEAST(cast(100 as tinyint), cast(101 as varchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as nchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as tinyint));
select LEAST(cast(101 as tinyint), cast(100 as smallint));
select LEAST(cast(101 as tinyint), cast(100 as int));
select LEAST(cast(101 as tinyint), cast(100 as bigint));
select LEAST(cast(101 as tinyint), cast(100 as float));
select LEAST(cast(101 as tinyint), cast(100 as double));
select LEAST(cast(101 as tinyint), cast(100 as varchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as nchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as smallint));
select LEAST(cast(1000 as smallint), cast(1001 as int));
select LEAST(cast(1000 as smallint), cast(1001 as bigint));
select LEAST(cast(1000 as smallint), cast(1001 as float));
select LEAST(cast(1000 as smallint), cast(1001 as double));
select LEAST(cast(1000 as smallint), cast(1001 as varchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as nchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as smallint));
select LEAST(cast(1001 as smallint), cast(1000 as int));
select LEAST(cast(1001 as smallint), cast(1000 as bigint));
select LEAST(cast(1001 as smallint), cast(1000 as float));
select LEAST(cast(1001 as smallint), cast(1000 as double));
select LEAST(cast(1001 as smallint), cast(1000 as varchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as nchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as int));
select LEAST(cast(1000000 as int), cast(1000001 as bigint));
select LEAST(cast(1000000 as int), cast(1000001 as float));
select LEAST(cast(1000000 as int), cast(1000001 as double));
select LEAST(cast(1000000 as int), cast(1000001 as varchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as nchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as int));
select LEAST(cast(1000001 as int), cast(1000000 as bigint));
select LEAST(cast(1000001 as int), cast(1000000 as float));
select LEAST(cast(1000001 as int), cast(1000000 as double));
select LEAST(cast(1000001 as int), cast(1000000 as varchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as nchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as float));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as double));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as float));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as double));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select LEAST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select LEAST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select LEAST('a','b','c','d','e','f','g','h','1231','15155');
select LEAST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select LEAST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(221, voltage) from ts_4893.meters order by ts limit 10;
select LEAST(5, id) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('23', 3443434343434343);
select LEAST(co, 3443434343434343) from ts_4893.n1;
select LEAST('23', 3443434343434343) from ts_4893.n1;
select LEAST('23', 1443434343434343) from ts_4893.n1;
select LEAST(current, voltage) from ts_4893.n1;
select LEAST(current, voltage, '15') from ts_4893.n1;
alter local 'compareAsStrInGreatest' '0';
select LEAST(1,2,3,4,5,6,7,8,9,10);
select LEAST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select LEAST(1,'2',3.3,4.4,5);
select LEAST(1,2,3,4,5,'5.1');
select LEAST('1','2','3','4',5);
select LEAST('1','2','3','4','5');
select LEAST(1,2,3,4,5,6,7,'a','b','一','二','三');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select LEAST(cast(100 as tinyint), cast(101 as tinyint));
select LEAST(cast(100 as tinyint), cast(101 as smallint));
select LEAST(cast(100 as tinyint), cast(101 as int));
select LEAST(cast(100 as tinyint), cast(101 as bigint));
select LEAST(cast(100 as tinyint), cast(101 as float));
select LEAST(cast(100 as tinyint), cast(101 as double));
select LEAST(cast(100 as tinyint), cast(101 as varchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as nchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as tinyint));
select LEAST(cast(101 as tinyint), cast(100 as smallint));
select LEAST(cast(101 as tinyint), cast(100 as int));
select LEAST(cast(101 as tinyint), cast(100 as bigint));
select LEAST(cast(101 as tinyint), cast(100 as float));
select LEAST(cast(101 as tinyint), cast(100 as double));
select LEAST(cast(101 as tinyint), cast(100 as varchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as nchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as smallint));
select LEAST(cast(1000 as smallint), cast(1001 as int));
select LEAST(cast(1000 as smallint), cast(1001 as bigint));
select LEAST(cast(1000 as smallint), cast(1001 as float));
select LEAST(cast(1000 as smallint), cast(1001 as double));
select LEAST(cast(1000 as smallint), cast(1001 as varchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as nchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as smallint));
select LEAST(cast(1001 as smallint), cast(1000 as int));
select LEAST(cast(1001 as smallint), cast(1000 as bigint));
select LEAST(cast(1001 as smallint), cast(1000 as float));
select LEAST(cast(1001 as smallint), cast(1000 as double));
select LEAST(cast(1001 as smallint), cast(1000 as varchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as nchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as int));
select LEAST(cast(1000000 as int), cast(1000001 as bigint));
select LEAST(cast(1000000 as int), cast(1000001 as float));
select LEAST(cast(1000000 as int), cast(1000001 as double));
select LEAST(cast(1000000 as int), cast(1000001 as varchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as nchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as int));
select LEAST(cast(1000001 as int), cast(1000000 as bigint));
select LEAST(cast(1000001 as int), cast(1000000 as float));
select LEAST(cast(1000001 as int), cast(1000000 as double));
select LEAST(cast(1000001 as int), cast(1000000 as varchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as nchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as float));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as double));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as float));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as double));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select LEAST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select LEAST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select LEAST('a','b','c','d','e','f','g','h','1231','15155');
select LEAST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select LEAST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(221, voltage) from ts_4893.meters order by ts limit 10;
select LEAST(5, id) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('23', 3443434343434343);
select LEAST(co, 3443434343434343) from ts_4893.n1;
select LEAST('23', 3443434343434343) from ts_4893.n1;
select LEAST('23', 1443434343434343) from ts_4893.n1;
select LEAST(current, voltage) from ts_4893.n1;
select LEAST(current, voltage, '15') from ts_4893.n1;

View File

@ -40,37 +40,10 @@ class TDTestCase(TBase):
"`var2` VARCHAR(50)) TAGS (`groupid` TINYINT, `location` VARCHAR(16));")
tdSql.execute("CREATE table d0 using meters tags(1, 'beijing')")
tdSql.execute("insert into d0 file '%s'" % datafile)
def test_normal_query(self, testCase):
# read sql from .sql file and execute
tdLog.info(f"test normal query.")
sqlFile = etool.curFile(__file__, f"in/{testCase}.in")
ansFile = etool.curFile(__file__, f"ans/{testCase}.csv")
with open(sqlFile, 'r') as sql_file:
sql_statement = ''
tdSql.csvLine = 0
for line in sql_file:
if not line.strip() or line.strip().startswith('--'):
continue
sql_statement += line.strip()
if sql_statement.endswith(';'):
sql_statement = sql_statement.rstrip(';')
tdSql.checkDataCsvByLine(sql_statement, ansFile)
sql_statement = ''
err_file_path = etool.curFile(__file__, f"in/{testCase}.err")
if not os.path.isfile(err_file_path):
return None
with open(err_file_path, 'r') as err_file:
err_statement = ''
for line in err_file:
if not line.strip() or line.strip().startswith('--'):
continue
err_statement += line.strip()
if err_statement.endswith(';'):
tdSql.error(err_statement)
err_statement = ''
tdSql.execute("CREATE TABLE `n1` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, co NCHAR(10))")
tdSql.execute("insert into n1 values(now, 1, null, '23')")
tdSql.execute("insert into n1 values(now, null, 3, '23')")
tdSql.execute("insert into n1 values(now, 5, 3, '23')")
def test_normal_query_new(self, testCase):
# read sql from .sql file and execute
@ -310,6 +283,223 @@ class TDTestCase(TBase):
tdSql.error("select * from (select to_iso8601(ts, timezone()), timezone() from ts_4893.meters \
order by ts desc) limit 1000;", expectErrInfo="Invalid parameter data type : to_iso8601") # TS-5340
def test_greatest(self):
self.test_normal_query_new("greatest")
tdSql.execute("alter local 'compareAsStrInGreatest' '1';")
tdSql.query("select GREATEST(NULL, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(1, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(id, NULL, 1) from ts_4893.meters order by ts limit 10;")
tdSql.checkRows(10)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(cast(100 as tinyint), cast(101 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.101")
tdSql.query("select GREATEST(cast(101 as tinyint), cast(100 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.101")
tdSql.query("select GREATEST(cast(1000 as smallint), cast(1001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.001")
tdSql.query("select GREATEST(cast(1001 as smallint), cast(1000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.001")
tdSql.query("select GREATEST(cast(1000000 as int), cast(1000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.001")
tdSql.query("select GREATEST(cast(1000001 as int), cast(1000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.001")
tdSql.query("select GREATEST(cast(1000000000 as bigint), cast(1000000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.001")
tdSql.query("select GREATEST(cast(1000000001 as bigint), cast(1000000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.001")
tdSql.query("select GREATEST(cast(1725506504000 as timestamp), cast(1725506510000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:50")
tdSql.query("select GREATEST(cast(1725506510000 as timestamp), cast(1725506504000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:50")
tdSql.query("select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "102.000000")
tdSql.query("select GREATEST(cast(100 as varchar(20)), cast(101 as tinyint), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "102.000000")
tdSql.query("select GREATEST(now, 1);")
tdSql.query("select GREATEST(now, 1.0);")
tdSql.query("select GREATEST(now, '1');")
tdSql.error("select GREATEST(1)")
tdSql.error("select GREATEST(cast('a' as varbinary), cast('b' as varbinary), 'c', 'd');")
tdSql.error("select GREATEST(6, cast('f' as varbinary), cast('b' as varbinary), 'c', 'd');")
def test_least(self):
self.test_normal_query_new("least")
tdSql.execute("alter local 'compareAsStrInGreatest' '1';")
tdSql.query("select LEAST(NULL, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(1, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(id, NULL, 1) from ts_4893.meters order by ts limit 10;")
tdSql.checkRows(10)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(cast(100 as tinyint), cast(101 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.100")
tdSql.query("select LEAST(cast(101 as tinyint), cast(100 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.100")
tdSql.query("select LEAST(cast(1000 as smallint), cast(1001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.000")
tdSql.query("select LEAST(cast(1001 as smallint), cast(1000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.000")
tdSql.query("select LEAST(cast(1000000 as int), cast(1000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.000")
tdSql.query("select LEAST(cast(1000001 as int), cast(1000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.000")
tdSql.query("select LEAST(cast(1000000000 as bigint), cast(1000000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.000")
tdSql.query("select LEAST(cast(1000000001 as bigint), cast(1000000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.000")
tdSql.query("select LEAST(cast(1725506504000 as timestamp), cast(1725506510000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:44")
tdSql.query("select LEAST(cast(1725506510000 as timestamp), cast(1725506504000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:44")
tdSql.query("select LEAST(cast(100 as tinyint), cast(101 as varchar(20)), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100")
tdSql.query("select LEAST(cast(100 as varchar(20)), cast(101 as tinyint), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100")
tdSql.query("select LEAST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100.000000")
tdSql.query("select LEAST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100.000000")
tdSql.query("select LEAST(now, 1);")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.001")
tdSql.query("select LEAST(now, 1.0);")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, 1)
tdSql.query("select LEAST(now, '1');")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, "1")
tdSql.error("select LEAST(cast('a' as varbinary), cast('b' as varbinary), 'c', 'd');")
tdSql.error("select LEAST(cast('f' as varbinary), cast('b' as varbinary), 'c', 'd');")
def test_greatest_large_table(self):
tdLog.info("test greatest large table.")
ts = 1741341251000
create_table_sql = "CREATE TABLE `large_table` (`ts` TIMESTAMP"
for i in range(1, 1001):
if i % 5 == 1:
create_table_sql += f", `col{i}` INT"
elif i % 5 == 2:
create_table_sql += f", `col{i}` FLOAT"
elif i % 5 == 3:
create_table_sql += f", `col{i}` DOUBLE"
elif i % 5 == 4:
create_table_sql += f", `col{i}` VARCHAR(64)"
else:
create_table_sql += f", `col{i}` NCHAR(50)"
create_table_sql += ");"
tdSql.execute(create_table_sql)
for j in range(1000):
insert_sql = f"INSERT INTO `large_table` VALUES ({ts +j}"
for i in range(1, 1001):
if i % 5 == 1:
insert_sql += f", {j + i}"
elif i % 5 == 2:
insert_sql += f", {j + i}.1"
elif i % 5 == 3:
insert_sql += f", {j + i}.2"
elif i % 5 == 4:
insert_sql += f", '{j + i}'"
else:
insert_sql += f", '{j + i}'"
insert_sql += ");"
tdSql.execute(insert_sql)
greatest_query = "SELECT GREATEST("
for i in range(1, 1001):
greatest_query += f"`col{i}`"
if i < 1000:
greatest_query += ", "
greatest_query += ") FROM `large_table` LIMIT 1;"
tdLog.info(f"greatest_query: {greatest_query}")
tdSql.execute(greatest_query)
greatest_query = "SELECT "
for i in range(1, 1001):
greatest_query += f"`col{i}` > `col5`"
if i < 1000:
greatest_query += ", "
greatest_query += " FROM `large_table` LIMIT 1;"
tdLog.info(f"greatest_query: {greatest_query}")
tdSql.execute(greatest_query)
def run(self):
tdLog.debug(f"start to excute {__file__}")
@ -326,7 +516,10 @@ class TDTestCase(TBase):
self.test_degrees()
self.test_radians()
self.test_rand()
self.test_greatest()
self.test_least()
self.test_greatest_large_table()
# char function
self.test_char_length()
self.test_char()

View File

@ -668,28 +668,22 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
printf("%*" PRIu64, width, *((uint64_t *)val));
break;
case TSDB_DATA_TYPE_FLOAT:
width = width >= LENGTH ? LENGTH - 1 : width;
if (tsEnableScience) {
printf("%*.7e", width, GET_FLOAT_VAL(val));
} else {
n = snprintf(buf, LENGTH, "%*.*g", width, FLT_DIG, GET_FLOAT_VAL(val));
if (n > SHELL_FLOAT_WIDTH) {
printf("%*.7e", width, GET_FLOAT_VAL(val));
} else {
printf("%s", buf);
}
snprintf(buf, LENGTH, "%*.*g", width, FLT_DIG, GET_FLOAT_VAL(val));
printf("%s", buf);
}
break;
case TSDB_DATA_TYPE_DOUBLE:
width = width >= LENGTH ? LENGTH - 1 : width;
if (tsEnableScience) {
snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val));
printf("%s", buf);
} else {
n = snprintf(buf, LENGTH, "%*.*g", width, DBL_DIG, GET_DOUBLE_VAL(val));
if (n > SHELL_DOUBLE_WIDTH) {
printf("%*.15e", width, GET_DOUBLE_VAL(val));
} else {
printf("%*s", width, buf);
}
snprintf(buf, LENGTH, "%*.*g", width, DBL_DIG, GET_DOUBLE_VAL(val));
printf("%*s", width, buf);
}
break;
case TSDB_DATA_TYPE_VARBINARY: {