Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
古剑诛仙
soar
提交
12fe63af
S
soar
项目概览
古剑诛仙
/
soar
与 Fork 源项目一致
Fork自
Xiaomi / soar
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
12fe63af
编写于
1月 13, 2021
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check time format for ARG.003
上级
5f720cbb
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
48 addition
and
1 deletion
+48
-1
advisor/heuristic.go
advisor/heuristic.go
+23
-1
advisor/heuristic_test.go
advisor/heuristic_test.go
+25
-0
未找到文件。
advisor/heuristic.go
浏览文件 @
12fe63af
...
...
@@ -279,7 +279,7 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
continue
}
// 检查
排序
排序不一致导致的隐式数据转换
// 检查
collation
排序不一致导致的隐式数据转换
common
.
Log
.
Debug
(
"Collation: `%s`.`%s` (%s) VS `%s`.`%s` (%s)"
,
colList
[
0
]
.
Table
,
colList
[
0
]
.
Name
,
colList
[
0
]
.
Collation
,
colList
[
1
]
.
Table
,
colList
[
1
]
.
Name
,
colList
[
1
]
.
Collation
)
...
...
@@ -322,6 +322,7 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
isCovered
:=
true
if
tps
,
ok
:=
typMap
[
val
.
Type
];
ok
{
for
_
,
tp
:=
range
tps
{
// colList[0].DataType, eg. year(4)
if
strings
.
HasPrefix
(
colList
[
0
]
.
DataType
,
tp
)
{
isCovered
=
false
}
...
...
@@ -339,6 +340,18 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
common
.
Log
.
Debug
(
"Implicit data type conversion: %s"
,
c
)
content
=
append
(
content
,
c
)
}
else
{
// 检查时间格式,如:"", "2020-0a-01"
switch
strings
.
Split
(
colList
[
0
]
.
DataType
,
"("
)[
0
]
{
case
"date"
,
"time"
,
"datetime"
,
"timestamp"
,
"year"
:
if
!
timeFormatCheck
(
string
(
val
.
Val
))
{
c
:=
fmt
.
Sprintf
(
"%s 表中列 %s 的时间格式错误,%s。"
,
colList
[
0
]
.
Table
,
colList
[
0
]
.
Name
,
string
(
val
.
Val
))
common
.
Log
.
Debug
(
"Implicit data type conversion: %s"
,
c
)
content
=
append
(
content
,
c
)
}
// TODO: 各种数据类型格式检查
default
:
}
}
}
...
...
@@ -355,6 +368,15 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
return
rule
}
// timeFormatCheck 时间格式检查,格式正确返回 true,格式错误返回 false
func
timeFormatCheck
(
t
string
)
bool
{
// 不允许为空,但允许时间前后有空格
t
=
strings
.
TrimSpace
(
t
)
// 仅允许 数字、减号、冒号、空格
allowChars
:=
regexp
.
MustCompile
(
`^[\-0-9: ]+$`
)
return
allowChars
.
MatchString
(
t
)
}
// RuleNoWhere CLA.001 & CLA.014 & CLA.015
func
(
q
*
Query4Audit
)
RuleNoWhere
()
Rule
{
var
rule
=
q
.
RuleOK
()
...
...
advisor/heuristic_test.go
浏览文件 @
12fe63af
...
...
@@ -150,6 +150,31 @@ func TestRuleEqualLike(t *testing.T) {
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
// ARG.003
// TODO:
func
TestTimeFormatError
(
t
*
testing
.
T
)
{
rightTimes
:=
[]
string
{
`2020-01-01`
,
}
for
_
,
rt
:=
range
rightTimes
{
if
!
timeFormatCheck
(
rt
)
{
t
.
Error
(
"wrong time format"
)
}
}
wrongTimes
:=
[]
string
{
``
,
// 空时间
`2020-01-01 abc`
,
// 含英文字符
`2020–02-15 23:59:59`
,
// 2020 后面的不是减号,是个 连接符
}
for
_
,
wt
:=
range
wrongTimes
{
if
timeFormatCheck
(
wt
)
{
t
.
Error
(
"wrong time format"
)
}
}
}
// CLA.001
func
TestRuleNoWhere
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录