Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
4e2ed952
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4e2ed952
编写于
7月 29, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-225] fix bugs in join query.
上级
6e45e832
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
79 addition
and
73 deletion
+79
-73
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+6
-4
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+72
-68
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
4e2ed952
...
...
@@ -106,7 +106,7 @@ typedef struct SColumnIndex {
typedef
struct
SFieldSupInfo
{
bool
visible
;
SExprInfo
*
pArithExprInfo
;
SSqlExpr
*
pSqlExpr
;
SSqlExpr
*
pSqlExpr
;
}
SFieldSupInfo
;
typedef
struct
SFieldInfo
{
...
...
src/client/src/tscSubquery.c
浏览文件 @
4e2ed952
...
...
@@ -1026,9 +1026,11 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
pRes
->
pColumnIndex
=
calloc
(
1
,
sizeof
(
SColumnIndex
)
*
pQueryInfo
->
fieldsInfo
.
numOfOutput
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
int32_t
numOfExprs
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
pRes
->
pColumnIndex
=
calloc
(
1
,
sizeof
(
SColumnIndex
)
*
numOfExprs
);
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
int32_t
tableIndexOfSub
=
-
1
;
...
...
@@ -1045,8 +1047,8 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
SSqlCmd
*
pSubCmd
=
&
pSql
->
pSubs
[
tableIndexOfSub
]
->
cmd
;
SQueryInfo
*
pSubQueryInfo
=
tscGetQueryInfoDetail
(
pSubCmd
,
0
);
size_t
numOf
Exprs
=
taosArrayGetSize
(
pSubQueryInfo
->
exprList
);
for
(
int32_t
k
=
0
;
k
<
numOf
Exprs
;
++
k
)
{
size_t
numOf
SubExpr
=
taosArrayGetSize
(
pSubQueryInfo
->
exprList
);
for
(
int32_t
k
=
0
;
k
<
numOf
SubExpr
;
++
k
)
{
SSqlExpr
*
pSubExpr
=
tscSqlExprGet
(
pSubQueryInfo
,
k
);
if
(
pExpr
->
functionId
==
pSubExpr
->
functionId
&&
pExpr
->
colInfo
.
colId
==
pSubExpr
->
colInfo
.
colId
)
{
pRes
->
pColumnIndex
[
i
]
=
(
SColumnIndex
){.
tableIndex
=
tableIndexOfSub
,
.
columnIndex
=
k
};
...
...
src/client/src/tscUtil.c
浏览文件 @
4e2ed952
...
...
@@ -1673,6 +1673,77 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm
return
pNew
;
}
// current sql function is not direct output result, so create a dummy output field
static
void
doSetNewFieldInfo
(
SQueryInfo
*
pNewQueryInfo
,
SSqlExpr
*
pExpr
)
{
TAOS_FIELD
f
=
{.
type
=
pExpr
->
resType
,
.
bytes
=
pExpr
->
resBytes
};
tstrncpy
(
f
.
name
,
pExpr
->
aliasName
,
sizeof
(
f
.
name
));
SFieldSupInfo
*
pInfo1
=
tscFieldInfoAppend
(
&
pNewQueryInfo
->
fieldsInfo
,
&
f
);
pInfo1
->
pSqlExpr
=
pExpr
;
pInfo1
->
visible
=
false
;
}
static
void
doSetSqlExprAndResultFieldInfo
(
SQueryInfo
*
pQueryInfo
,
SQueryInfo
*
pNewQueryInfo
,
int64_t
uid
)
{
int32_t
numOfOutput
=
tscSqlExprNumOfExprs
(
pNewQueryInfo
);
if
(
numOfOutput
==
0
)
{
return
;
}
size_t
numOfExprs
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
SFieldInfo
*
pFieldInfo
=
&
pQueryInfo
->
fieldsInfo
;
// set the field info in pNewQueryInfo object
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
uid
==
uid
)
{
if
(
i
<
pFieldInfo
->
numOfOutput
)
{
SFieldSupInfo
*
pInfo
=
tscFieldInfoGetSupp
(
pFieldInfo
,
i
);
if
(
pInfo
->
pSqlExpr
!=
NULL
)
{
TAOS_FIELD
*
p
=
tscFieldInfoGetField
(
pFieldInfo
,
i
);
assert
(
strcmp
(
p
->
name
,
pExpr
->
aliasName
)
==
0
);
SFieldSupInfo
*
pInfo1
=
tscFieldInfoAppend
(
&
pNewQueryInfo
->
fieldsInfo
,
p
);
*
pInfo1
=
*
pInfo
;
}
else
{
assert
(
pInfo
->
pArithExprInfo
!=
NULL
);
doSetNewFieldInfo
(
pNewQueryInfo
,
pExpr
);
}
}
else
{
// it is a arithmetic column, does not have actual field for sqlExpr, so build it
doSetNewFieldInfo
(
pNewQueryInfo
,
pExpr
);
}
}
}
// make sure the the sqlExpr for each fields is correct
numOfExprs
=
tscSqlExprNumOfExprs
(
pNewQueryInfo
);
// update the pSqlExpr pointer in SFieldSupInfo according the field name
// make sure the pSqlExpr point to the correct SqlExpr in pNewQueryInfo, not SqlExpr in pQueryInfo
for
(
int32_t
f
=
0
;
f
<
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
f
)
{
TAOS_FIELD
*
field
=
tscFieldInfoGetField
(
&
pNewQueryInfo
->
fieldsInfo
,
f
);
bool
matched
=
false
;
for
(
int32_t
k1
=
0
;
k1
<
numOfExprs
;
++
k1
)
{
SSqlExpr
*
pExpr1
=
tscSqlExprGet
(
pNewQueryInfo
,
k1
);
if
(
strcmp
(
field
->
name
,
pExpr1
->
aliasName
)
==
0
)
{
// establish link according to the result field name
SFieldSupInfo
*
pInfo
=
tscFieldInfoGetSupp
(
&
pNewQueryInfo
->
fieldsInfo
,
f
);
pInfo
->
pSqlExpr
=
pExpr1
;
matched
=
true
;
break
;
}
}
assert
(
matched
);
}
tscFieldInfoUpdateOffset
(
pNewQueryInfo
);
}
SSqlObj
*
createSubqueryObj
(
SSqlObj
*
pSql
,
int16_t
tableIndex
,
void
(
*
fp
)(),
void
*
param
,
int32_t
cmd
,
SSqlObj
*
pPrevSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
...
...
@@ -1766,74 +1837,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
uint64_t
uid
=
pTableMetaInfo
->
pTableMeta
->
id
.
uid
;
tscSqlExprCopy
(
pNewQueryInfo
->
exprList
,
pQueryInfo
->
exprList
,
uid
,
true
);
int32_t
numOfOutput
=
tscSqlExprNumOfExprs
(
pNewQueryInfo
);
if
(
numOfOutput
>
0
)
{
// todo refactor to extract method
size_t
numOfExprs
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
SFieldInfo
*
pFieldInfo
=
&
pQueryInfo
->
fieldsInfo
;
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
->
uid
==
uid
)
{
if
(
i
<
pFieldInfo
->
numOfOutput
)
{
SFieldSupInfo
*
pInfo
=
tscFieldInfoGetSupp
(
pFieldInfo
,
i
);
if
(
pInfo
->
pSqlExpr
!=
NULL
)
{
TAOS_FIELD
*
p
=
tscFieldInfoGetField
(
pFieldInfo
,
i
);
assert
(
strcmp
(
p
->
name
,
pExpr
->
aliasName
)
==
0
);
SFieldSupInfo
*
pInfo1
=
tscFieldInfoAppend
(
&
pNewQueryInfo
->
fieldsInfo
,
p
);
*
pInfo1
=
*
pInfo
;
}
else
{
// current sql function is not direct output result, so create a dummy output field
assert
(
pInfo
->
pArithExprInfo
!=
NULL
);
TAOS_FIELD
f
=
{.
type
=
pExpr
->
resType
,
.
bytes
=
pExpr
->
resBytes
};
tstrncpy
(
f
.
name
,
pExpr
->
aliasName
,
sizeof
(
f
.
name
));
SFieldSupInfo
*
pInfo1
=
tscFieldInfoAppend
(
&
pNewQueryInfo
->
fieldsInfo
,
&
f
);
pInfo1
->
pSqlExpr
=
pExpr
;
pInfo1
->
visible
=
false
;
}
}
else
{
// current sql function is not direct output result, so create a dummy output field
TAOS_FIELD
f
=
{.
type
=
pExpr
->
resType
,
.
bytes
=
pExpr
->
resBytes
};
tstrncpy
(
f
.
name
,
pExpr
->
aliasName
,
sizeof
(
f
.
name
));
SFieldSupInfo
*
pInfo1
=
tscFieldInfoAppend
(
&
pNewQueryInfo
->
fieldsInfo
,
&
f
);
pInfo1
->
pSqlExpr
=
pExpr
;
pInfo1
->
visible
=
false
;
}
}
}
// make sure the the sqlExpr for each fields is correct
// todo handle the agg arithmetic expression
numOfExprs
=
tscSqlExprNumOfExprs
(
pNewQueryInfo
);
for
(
int32_t
f
=
0
;
f
<
pNewQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
f
)
{
TAOS_FIELD
*
field
=
tscFieldInfoGetField
(
&
pNewQueryInfo
->
fieldsInfo
,
f
);
bool
matched
=
false
;
for
(
int32_t
k1
=
0
;
k1
<
numOfExprs
;
++
k1
)
{
SSqlExpr
*
pExpr1
=
tscSqlExprGet
(
pNewQueryInfo
,
k1
);
if
(
strcmp
(
field
->
name
,
pExpr1
->
aliasName
)
==
0
)
{
// establish link according to the result field name
SFieldSupInfo
*
pInfo
=
tscFieldInfoGetSupp
(
&
pNewQueryInfo
->
fieldsInfo
,
f
);
pInfo
->
pSqlExpr
=
pExpr1
;
matched
=
true
;
break
;
}
}
assert
(
matched
);
}
tscFieldInfoUpdateOffset
(
pNewQueryInfo
);
}
doSetSqlExprAndResultFieldInfo
(
pQueryInfo
,
pNewQueryInfo
,
uid
);
pNew
->
fp
=
fp
;
pNew
->
fetchFp
=
fp
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录