Skip to content

Commit 4fb66b7

Browse files
author
tkc
committed
Feat pattern like expr
1 parent 0171fa4 commit 4fb66b7

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/domain/model/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type OpType string
5252

5353
const OpTypeEq OpType = "eq"
5454
const OpTypeIn OpType = "in"
55+
const OpTypeLike OpType = "like"
5556

5657
type StmtType string
5758

src/usecase/services/analyzer_service_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ func TestSelectQueries(t *testing.T) {
335335
NotNullColumns: nil,
336336
}},
337337
},
338+
{
339+
query: `SELECT * FROM t_a WHERE c_1 like '%' AND c_2 like '%'`,
340+
expect: []*model.Analyzer{{
341+
Tables: []model.Table{{Name: "t_a"}},
342+
Operations: []model.AnalyzerOperation{
343+
{
344+
Type: model.OpTypeLike,
345+
Column: "c_1",
346+
Value: "%",
347+
},
348+
{
349+
Type: model.OpTypeLike,
350+
Column: "c_2",
351+
Value: "%",
352+
},
353+
},
354+
355+
StmtType: model.StmtTypeSelect,
356+
}},
357+
},
338358
}
339359

340360
analyzerService := NewAnalyzerService()

src/usecase/services/visitors.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ type OperationExprVisitor struct {
217217
}
218218

219219
func (v *OperationExprVisitor) Enter(in ast.Node) (ast.Node, bool) {
220+
// BinaryOperationExpr
220221
if binaryOperationExpr, ok := in.(*ast.BinaryOperationExpr); ok {
221222
if binaryOperationExpr.Op.String() == string(model.OpTypeEq) {
222223
var operation model.AnalyzerOperation
@@ -237,6 +238,20 @@ func (v *OperationExprVisitor) Enter(in ast.Node) (ast.Node, bool) {
237238
v.Operations = append(v.Operations, operation)
238239
}
239240
}
241+
242+
// PatternLikeExpr
243+
if patternLikeExpr, ok := in.(*ast.PatternLikeExpr); ok {
244+
var operation model.AnalyzerOperation
245+
operation.Type = model.OpTypeLike
246+
if columnNameExpr, ok := patternLikeExpr.Expr.(*ast.ColumnNameExpr); ok {
247+
operation.Column = columnNameExpr.Name.Name.String()
248+
}
249+
if valueExpr, ok := patternLikeExpr.Pattern.(*test_driver.ValueExpr); ok {
250+
operation.Value = valueExpr.GetString()
251+
}
252+
v.Operations = append(v.Operations, operation)
253+
}
254+
240255
return in, false
241256
}
242257

0 commit comments

Comments
 (0)