56
56
JSONDoc2 sqlparser.Expr
57
57
}
58
58
59
- mysqlQueryConverter struct {}
59
+ mysqlQueryConverter struct {
60
+ namespaceID namespace.ID
61
+ }
60
62
)
61
63
62
64
var convertTypeJSON = & sqlparser.ConvertType {Type : "json" }
@@ -67,6 +69,10 @@ var _ sqlparser.Expr = (*jsonOverlapsExpr)(nil)
67
69
68
70
var _ pluginQueryConverter = (* mysqlQueryConverter )(nil )
69
71
72
+ const (
73
+ mysqlCustomSearchAttributesTableName = "custom_search_attributes"
74
+ )
75
+
70
76
func (node * castExpr ) Format (buf * sqlparser.TrackedBuffer ) {
71
77
buf .Myprintf ("cast(%v as %v)" , node .Value , node .Type )
72
78
}
@@ -85,7 +91,7 @@ func newMySQLQueryConverter(
85
91
saMapper searchattribute.Mapper ,
86
92
) * QueryConverter {
87
93
return newQueryConverterInternal (
88
- & mysqlQueryConverter {},
94
+ & mysqlQueryConverter {namespaceID : request . NamespaceID },
89
95
request ,
90
96
saTypeMap ,
91
97
saMapper ,
@@ -164,10 +170,27 @@ func (c *mysqlQueryConverter) convertTextComparisonExpr(
164
170
if ! isSupportedTextOperator (expr .Operator ) {
165
171
return nil , query .NewConverterError ("invalid query" )
166
172
}
173
+ valueExpr , ok := expr .Right .(* unsafeSQLString )
174
+ if ! ok {
175
+ return nil , query .NewConverterError ("invalid query" )
176
+ }
177
+ valueExpr .Val = fmt .Sprintf ("%s %s" , c .namespaceID , valueExpr .Val )
178
+ // build the following expression:
179
+ // `match (custom_search_attributes.namespace_id, {expr.Left}) against ({expr.Right} in natural language mode)`
167
180
var newExpr sqlparser.Expr = & sqlparser.MatchExpr {
168
- Columns : []sqlparser.SelectExpr {& sqlparser.AliasedExpr {Expr : expr .Left }},
169
- Expr : expr .Right ,
170
- Option : sqlparser .NaturalLanguageModeStr ,
181
+ Columns : []sqlparser.SelectExpr {
182
+ & sqlparser.AliasedExpr {
183
+ Expr : & sqlparser.ColName {
184
+ Name : sqlparser .NewColIdent (searchattribute .GetSqlDbColName (searchattribute .NamespaceID )),
185
+ Qualifier : sqlparser.TableName {
186
+ Name : sqlparser .NewTableIdent (mysqlCustomSearchAttributesTableName ),
187
+ },
188
+ },
189
+ },
190
+ & sqlparser.AliasedExpr {Expr : expr .Left },
191
+ },
192
+ Expr : expr .Right ,
193
+ Option : sqlparser .NaturalLanguageModeStr ,
171
194
}
172
195
if expr .Operator == sqlparser .NotEqualStr {
173
196
newExpr = & sqlparser.NotExpr {Expr : newExpr }
0 commit comments