Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9285e8ea
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9285e8ea
编写于
10月 08, 2022
作者:
A
Alex Duan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(shell): support nest query tab complete select clause
上级
019ae02b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
162 addition
and
52 deletion
+162
-52
src/kit/shell/src/shellAuto.c
src/kit/shell/src/shellAuto.c
+159
-49
src/kit/shell/src/shellDarwin.c
src/kit/shell/src/shellDarwin.c
+1
-1
src/kit/shell/src/shellWindows.c
src/kit/shell/src/shellWindows.c
+2
-2
未找到文件。
src/kit/shell/src/shellAuto.c
浏览文件 @
9285e8ea
...
...
@@ -251,6 +251,9 @@ char * key_tags[] = {
"tags("
};
char
*
key_select
[]
=
{
"select "
};
//
// ------- gobal variant define ---------
...
...
@@ -278,7 +281,8 @@ bool waitAutoFill = false;
#define WT_VAR_DATATYPE 10
#define WT_VAR_KEYTAGS 11
#define WT_VAR_ANYWORD 12
#define WT_VAR_CNT 13
#define WT_VAR_KEYSELECT 13
#define WT_VAR_CNT 14
#define WT_FROM_DB_MAX 4 // max get content from db
#define WT_FROM_DB_CNT (WT_FROM_DB_MAX + 1)
...
...
@@ -305,7 +309,8 @@ char varTypes[WT_VAR_CNT][64] = {
"<db_options>"
,
"<data_types>"
,
"<key_tags>"
,
"<anyword>"
"<anyword>"
,
"<key_select>"
};
char
varSqls
[
WT_FROM_DB_CNT
][
64
]
=
{
...
...
@@ -330,9 +335,10 @@ int cntDel = 0; // delete byte count after next press tab
// show auto tab introduction
void
printfIntroduction
()
{
printf
(
" ********************* How to Use TAB in TAOS Shell ******************************
\n
"
);
printf
(
" * Taos shell supports pressing TAB key to complete word. You can try it. *
\n
"
);
printf
(
" * Press TAB key anywhere, You'll get surprise. *
\n
"
);
printf
(
" **************************** How To Use TAB Key ********************************
\n
"
);
printf
(
" * TDengine Command Line supports pressing TAB key to complete word, *
\n
"
);
printf
(
" * including database name, table name, function name and keywords. *
\n
"
);
printf
(
" * Press TAB key anywhere, you'll get surprise. *
\n
"
);
printf
(
" * KEYBOARD SHORTCUT: *
\n
"
);
printf
(
" * [ TAB ] ...... Complete the word or show help if no input *
\n
"
);
printf
(
" * [ Ctrl + A ] ...... move cursor to [A]head of line *
\n
"
);
...
...
@@ -346,7 +352,7 @@ void printfIntroduction() {
}
void
showHelp
()
{
printf
(
"
\n
The following are supported commands for T
aos shell
:"
);
printf
(
"
\n
The following are supported commands for T
Dengine Command Line
:"
);
printf
(
"
\n
\
----- A -----
\n
\
alter database <db_name> <db_options>
\n
\
...
...
@@ -586,6 +592,7 @@ bool shellAutoInit() {
GenerateVarType
(
WT_VAR_TBACTION
,
tb_actions
,
sizeof
(
tb_actions
)
/
sizeof
(
char
*
));
GenerateVarType
(
WT_VAR_DATATYPE
,
data_types
,
sizeof
(
data_types
)
/
sizeof
(
char
*
));
GenerateVarType
(
WT_VAR_KEYTAGS
,
key_tags
,
sizeof
(
key_tags
)
/
sizeof
(
char
*
));
GenerateVarType
(
WT_VAR_KEYSELECT
,
key_select
,
sizeof
(
key_select
)
/
sizeof
(
char
*
));
printfIntroduction
();
...
...
@@ -1242,7 +1249,7 @@ char * lastWord(char * p) {
char
*
p2
=
strrchr
(
p
,
','
);
if
(
p1
&&
p2
)
{
return
MAX
(
p1
,
p2
)
+
1
;
return
p1
>
p2
?
p1
:
p2
+
1
;
}
else
if
(
p1
)
{
return
p1
+
1
;
}
else
if
(
p2
)
{
...
...
@@ -1325,37 +1332,9 @@ bool needInsertFrom(char * sql, int len) {
return
true
;
}
bool
matchSelectQuery
(
TAOS
*
con
,
Command
*
cmd
)
{
// if continue press Tab , delete bytes by previous autofill
if
(
cntDel
>
0
)
{
deleteCount
(
cmd
,
cntDel
);
cntDel
=
0
;
}
// match select ...
int
len
=
cmd
->
commandSize
;
char
*
p
=
cmd
->
command
;
// remove prefix blank
while
(
p
[
0
]
==
' '
&&
len
>
0
)
{
p
++
;
len
--
;
}
// special range
if
(
len
<
7
||
len
>
512
)
{
return
false
;
}
// select and from
if
(
strncasecmp
(
p
,
"select "
,
7
)
!=
0
)
{
// not select query clause
return
false
;
}
p
+=
7
;
len
-=
7
;
char
*
ps
=
p
=
strndup
(
p
,
len
);
// p is string following select keyword
bool
appendAfterSelect
(
TAOS
*
con
,
Command
*
cmd
,
char
*
sql
,
int32_t
len
)
{
char
*
p
=
strndup
(
sql
,
len
);
// union all
char
*
p1
;
...
...
@@ -1374,8 +1353,8 @@ bool matchSelectQuery(TAOS * con, Command * cmd) {
bool
fieldEnd
=
fieldsInputEnd
(
p
);
// cheeck fields input end then insert from keyword
if
(
fieldEnd
&&
p
[
len
-
1
]
==
' '
)
{
i
nsertChar
(
cmd
,
"from"
,
4
);
free
(
ps
);
shellI
nsertChar
(
cmd
,
"from"
,
4
);
taosMemoryFree
(
p
);
return
true
;
}
...
...
@@ -1387,7 +1366,7 @@ bool matchSelectQuery(TAOS * con, Command * cmd) {
ret
=
fillWithType
(
con
,
cmd
,
last
,
WT_VAR_FUNC
);
}
free
(
ps
);
taosMemoryFree
(
p
);
return
ret
;
}
...
...
@@ -1400,10 +1379,83 @@ bool matchSelectQuery(TAOS * con, Command * cmd) {
ret
=
fillWithType
(
con
,
cmd
,
last
,
WT_VAR_KEYWORD
);
}
free
(
ps
);
taosMemoryFree
(
p
);
return
ret
;
}
int32_t
searchAfterSelect
(
char
*
p
,
int32_t
len
)
{
// select * from st;
if
(
strncasecmp
(
p
,
"select "
,
7
)
==
0
)
{
// check nest query
char
*
p1
=
p
+
7
;
while
(
1
)
{
char
*
p2
=
strstr
(
p1
,
"select "
);
if
(
p2
==
NULL
)
break
;
p1
=
p2
+
7
;
}
return
p1
-
p
;
}
// explain as select * from st;
if
(
strncasecmp
(
p
,
"explain select "
,
15
)
==
0
)
{
return
15
;
}
char
*
as_pos_end
=
strstr
(
p
,
" as select "
);
if
(
as_pos_end
==
NULL
)
return
-
1
;
as_pos_end
+=
11
;
// create stream <stream_name> as select
if
(
strncasecmp
(
p
,
"create stream "
,
14
)
==
0
)
{
return
as_pos_end
-
p
;;
}
// create topic <topic_name> as select
if
(
strncasecmp
(
p
,
"create topic "
,
13
)
==
0
)
{
return
as_pos_end
-
p
;
}
return
-
1
;
}
bool
matchSelectQuery
(
TAOS
*
con
,
Command
*
cmd
)
{
// if continue press Tab , delete bytes by previous autofill
if
(
cntDel
>
0
)
{
deleteCount
(
cmd
,
cntDel
);
cntDel
=
0
;
}
// match select ...
int
len
=
cmd
->
commandSize
;
char
*
p
=
cmd
->
command
;
// remove prefix blank
while
(
p
[
0
]
==
' '
&&
len
>
0
)
{
p
++
;
len
--
;
}
// special range
if
(
len
<
7
||
len
>
512
)
{
return
false
;
}
// search
char
*
sql_cp
=
strndup
(
p
,
len
);
int32_t
n
=
searchAfterSelect
(
sql_cp
,
len
);
taosMemoryFree
(
sql_cp
);
if
(
n
==
-
1
||
n
>
len
)
return
false
;
p
+=
n
;
len
-=
n
;
// append
return
appendAfterSelect
(
con
,
cmd
,
p
,
len
);
}
// if is input create fields or tags area, return true
bool
isCreateFieldsArea
(
char
*
p
)
{
char
*
left
=
strrchr
(
p
,
'('
);
...
...
@@ -1484,18 +1536,76 @@ bool matchCreateTable(TAOS * con, Command * cmd) {
bool
matchOther
(
TAOS
*
con
,
Command
*
cmd
)
{
int
len
=
cmd
->
commandSize
;
char
*
p
=
cmd
->
command
;
// '\\'
if
(
p
[
len
-
1
]
==
'\\'
)
{
// append '\G'
char
a
[]
=
"G;"
;
i
nsertChar
(
cmd
,
a
,
2
);
shellI
nsertChar
(
cmd
,
a
,
2
);
return
true
;
}
// too small
if
(
len
<
8
)
return
false
;
// like 'from ( '
char
*
sql
=
strndup
(
p
,
len
);
char
*
last
=
lastWord
(
sql
);
if
(
strcmp
(
last
,
"from("
)
==
0
)
{
fillWithType
(
con
,
cmd
,
""
,
WT_VAR_KEYSELECT
);
taosMemoryFree
(
sql
);
return
true
;
}
if
(
strncmp
(
last
,
"("
,
1
)
==
0
)
{
last
+=
1
;
}
char
*
from
=
strstr
(
sql
,
" from"
);
// find last ' from'
while
(
from
)
{
char
*
p1
=
strstr
(
from
+
5
,
" from"
);
if
(
p1
==
NULL
)
break
;
from
=
p1
;
}
if
(
from
)
{
// find next is '('
char
*
p2
=
from
+
5
;
bool
found
=
false
;
// found 'from ... ( ...' ... is any count of blank
bool
found1
=
false
;
// found '('
while
(
1
)
{
if
(
p2
==
last
||
*
p2
==
'\0'
)
{
// last word or string end
if
(
found1
)
{
found
=
true
;
}
break
;
}
else
if
(
*
p2
==
'('
)
{
found1
=
true
;
}
else
if
(
*
p2
==
' '
)
{
// do nothing
}
else
{
// have any other char
break
;
}
// move next
p2
++
;
}
if
(
found
)
{
fillWithType
(
con
,
cmd
,
last
,
WT_VAR_KEYSELECT
);
taosMemoryFree
(
sql
);
return
true
;
}
}
taosMemoryFree
(
sql
);
return
false
;
}
// main key press tab
void
pressTabKey
(
TAOS
*
con
,
Command
*
cmd
)
{
// check
...
...
@@ -1602,7 +1712,7 @@ bool dealUseDB(char * sql) {
}
// switch new db
pthread_mutex_l
ock
(
&
tiresMutex
);
taosThreadMutexL
ock
(
&
tiresMutex
);
// STABLE set null
STire
*
tire
=
tires
[
WT_VAR_STABLE
];
tires
[
WT_VAR_STABLE
]
=
NULL
;
...
...
@@ -1617,7 +1727,7 @@ bool dealUseDB(char * sql) {
}
// save
strcpy
(
dbName
,
db
);
pthread_mutex_u
nlock
(
&
tiresMutex
);
taosThreadMutexU
nlock
(
&
tiresMutex
);
return
true
;
}
...
...
@@ -1761,4 +1871,4 @@ void callbackAutoTab(char* sqlstr, TAOS* pSql, bool usedb) {
}
return
;
}
}
\ No newline at end of file
src/kit/shell/src/shellDarwin.c
浏览文件 @
9285e8ea
...
...
@@ -35,7 +35,7 @@ void insertChar(Command *cmd, char *c, int size);
void
printHelp
()
{
char
indent
[
10
]
=
" "
;
printf
(
"
taos shell
is used to test the TDengine database
\n
"
);
printf
(
"
TDengine Command Line
is used to test the TDengine database
\n
"
);
printf
(
"%s%s
\n
"
,
indent
,
"-h"
);
printf
(
"%s%s%s
\n
"
,
indent
,
indent
,
"TDengine server IP address to connect. The default host is localhost."
);
...
...
src/kit/shell/src/shellWindows.c
浏览文件 @
9285e8ea
...
...
@@ -21,7 +21,7 @@
extern
char
configDir
[];
char
WINCLIENT_VERSION
[]
=
"Welcome to the TDengine
shell
from %s, Client Version:%s
\n
"
char
WINCLIENT_VERSION
[]
=
"Welcome to the TDengine
Command Line Interface
from %s, Client Version:%s
\n
"
"Copyright (c) 2022 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
void
printVersion
()
{
...
...
@@ -30,7 +30,7 @@ void printVersion() {
void
printHelp
()
{
char
indent
[
10
]
=
" "
;
printf
(
"
taos shell
is used to test the TDengine database
\n
"
);
printf
(
"
TDengine Command Line
is used to test the TDengine database
\n
"
);
printf
(
"%s%s
\n
"
,
indent
,
"-h"
);
printf
(
"%s%s%s
\n
"
,
indent
,
indent
,
"TDengine server FQDN to connect. The default host is localhost."
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录