enh: cols func
This commit is contained in:
parent
465f19567e
commit
de801080e1
|
@ -5642,6 +5642,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_VARCHAR_TYPE}},
|
||||
.translateFunc = translateOutVarchar,
|
||||
},
|
||||
{
|
||||
.name = "cols",
|
||||
},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -2740,7 +2740,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < cts) {
|
||||
char* data = colDataGetData(pInputCol, chosen);
|
||||
int32_t code = doSaveCurrentVal(pCtx, i, cts, NULL, type, data);
|
||||
int32_t code = doSaveCurrentVal(pCtx, chosen, cts, NULL, type, data);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -13726,6 +13726,10 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t*
|
|||
int32_t index = 0;
|
||||
FOREACH(pNode, pProjections) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if(pExpr->tupleFuncIdx != 0) {
|
||||
*numOfCols -= 1;
|
||||
continue;
|
||||
}
|
||||
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
|
||||
(*pSchema)[index].type = TSDB_DATA_TYPE_VARCHAR;
|
||||
(*pSchema)[index].bytes = VARSTR_HEADER_SIZE;
|
||||
|
|
|
@ -1600,6 +1600,9 @@ static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pS
|
|||
int32_t projIdx = 1;
|
||||
FOREACH(pNode, pExprs) {
|
||||
SColumnNode* pCol = createColumnByExpr(pStmtName, (SExprNode*)pNode);
|
||||
if (pCol->node.tupleFuncIdx != 0) {
|
||||
continue;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != (code = nodesListStrictAppend(pList, (SNode*)pCol))) {
|
||||
nodesDestroyList(pList);
|
||||
return code;
|
||||
|
|
|
@ -3471,6 +3471,10 @@ static bool eliminateProjOptCanChildConditionUseChildTargets(SLogicNode* pChild,
|
|||
nodesWalkExpr(pJoinLogicNode->pFullOnCond, eliminateProjOptCanUseNewChildTargetsImpl, &cxt);
|
||||
if (!cxt.canUse) return false;
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pChild) &&
|
||||
((SAggLogicNode*)pChild)->node.pTargets->length != pNewChildTargets->length) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3599,7 +3603,8 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan*
|
|||
} else {
|
||||
FOREACH(pProjection, pProjectNode->pProjections) {
|
||||
FOREACH(pChildTarget, pChild->pTargets) {
|
||||
if (0 == strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) {
|
||||
if (0 == strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)
|
||||
&& ((SColumnNode*)pProjection)->node.bindTupleFuncIdx == 0) {
|
||||
SNode* pNew = NULL;
|
||||
code = nodesCloneNode(pChildTarget, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -86,7 +86,14 @@ class TDTestCase:
|
|||
|
||||
tdSql.query(f'select cols(last(c0), ts, c1, c2, c3), cols(first(c0), ts, c1, c2, c3) from db.st')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 1, 'bbbbbbbbb')
|
||||
tdSql.checkData(0, 0, 1734574929003)
|
||||
tdSql.checkData(0, 1, '4.0')
|
||||
tdSql.checkData(0, 2, 'bbbbbbbbb2')
|
||||
tdSql.checkData(0, 3, False)
|
||||
tdSql.checkData(0, 4, 1734574929000)
|
||||
tdSql.checkData(0, 5, '1.0')
|
||||
tdSql.checkData(0, 6, 'a1')
|
||||
tdSql.checkData(0, 7, True)
|
||||
|
||||
#tdSql.execute(f'drop table if exists db.st')
|
||||
|
||||
|
|
Loading…
Reference in New Issue