提交 0170c3bb 编写于 作者: wmmhello's avatar wmmhello

add json tag support for group by

上级 bf8cb8fd
...@@ -5922,15 +5922,25 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -5922,15 +5922,25 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return invalidOperationMsg(pMsgBuf, msg10); return invalidOperationMsg(pMsgBuf, msg10);
} }
SStrToken columnName = {0};
CommonItem* pItem = taosArrayGet(pSortOrder, 0);
if (pItem->isJsonExp){
assert(pItem->jsonExp->tokenId == TK_ARROW);
columnName = pItem->jsonExp->pLeft->columnName;
}else{
// handle the first part of order by // handle the first part of order by
tVariant* pVar = &((CommonItem*)taosArrayGet(pSortOrder, 0))->pVar; tVariant* pVar = &pItem->pVar;
// e.g., order by 1 asc, return directly with out further check. // e.g., order by 1 asc, return directly with out further check.
if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_BIGINT) { if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_BIGINT) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
SStrToken columnName = {pVar->nLen, pVar->nType, pVar->pz}; columnName.n = pVar->nLen;
columnName.type = pVar->nType;
columnName.z = pVar->pz;
}
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
bool udf = false; bool udf = false;
...@@ -6048,7 +6058,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6048,7 +6058,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
} }
} }
} else { } else {
CommonItem *pItem = taosArrayGet(pSqlNode->pSortOrder, 0); pItem = taosArrayGet(pSqlNode->pSortOrder, 0);
if (orderByTags) { if (orderByTags) {
pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
pQueryInfo->groupbyExpr.orderType = pItem->sortOrder; pQueryInfo->groupbyExpr.orderType = pItem->sortOrder;
...@@ -6066,9 +6076,18 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6066,9 +6076,18 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
} }
} }
SStrToken cname = {0};
pItem = taosArrayGet(pSqlNode->pSortOrder, 1); pItem = taosArrayGet(pSqlNode->pSortOrder, 1);
tVariant* pVar2 = &pItem->pVar; if (pItem->isJsonExp){
SStrToken cname = {pVar2->nLen, pVar2->nType, pVar2->pz}; assert(pItem->jsonExp->tokenId == TK_ARROW);
cname = pItem->jsonExp->pLeft->columnName;
}else{
tVariant* pVar = &pItem->pVar;
cname.n = pVar->nLen;
cname.type = pVar->nType;
cname.z = pVar->pz;
}
if (getColumnIndexByName(&cname, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&cname, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(pMsgBuf, msg1); return invalidOperationMsg(pMsgBuf, msg1);
} }
...@@ -6076,8 +6095,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6076,8 +6095,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
return invalidOperationMsg(pMsgBuf, msg6); return invalidOperationMsg(pMsgBuf, msg6);
} else { } else {
CommonItem* p1 = taosArrayGet(pSortOrder, 1); pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.order = p1->sortOrder;
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
} }
} }
...@@ -6133,7 +6151,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6133,7 +6151,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
} }
} }
CommonItem* pItem = taosArrayGet(pSqlNode->pSortOrder, 0); pItem = taosArrayGet(pSqlNode->pSortOrder, 0);
pQueryInfo->order.order = pItem->sortOrder; pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId; pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
...@@ -6144,7 +6162,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6144,7 +6162,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return invalidOperationMsg(pMsgBuf, msg11); return invalidOperationMsg(pMsgBuf, msg11);
} }
CommonItem* pItem = taosArrayGet(pSqlNode->pSortOrder, 0); pItem = taosArrayGet(pSqlNode->pSortOrder, 0);
pQueryInfo->order.order = pItem->sortOrder; pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId; pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
} else { } else {
...@@ -6160,7 +6178,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq ...@@ -6160,7 +6178,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return invalidOperationMsg(pMsgBuf, msg11); return invalidOperationMsg(pMsgBuf, msg11);
} }
CommonItem* pItem = taosArrayGet(pSqlNode->pSortOrder, 0); pItem = taosArrayGet(pSqlNode->pSortOrder, 0);
pQueryInfo->order.order = pItem->sortOrder; pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId; pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
} }
......
...@@ -391,7 +391,8 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t ...@@ -391,7 +391,8 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
} }
}; };
case TSDB_DATA_TYPE_NCHAR: { // todo handle the var string compare case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON: { // todo handle the var string compare
int32_t len1 = varDataLen(f1); int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2); int32_t len2 = varDataLen(f2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册