@@ -310,36 +310,42 @@ func getPgAnyOpRegex() *regexp.Regexp {
310310// Replace the operator 'ANY' with a function call.
311311func ConvertAnyOp (sql string ) string {
312312 re := getPgAnyOpRegex ()
313- return re .ReplaceAllString (sql , catalog .SchemaNameMyListContains + "." + catalog .MacroNameMyListContains + "($2, $1)" )
313+ return re .ReplaceAllString (sql , catalog .SchemaNameSYS + "." + catalog .MacroNameMyListContains + "($2, $1)" )
314314}
315315
316316var (
317- typeCastRegex * regexp.Regexp
318- initTypeCastRegex sync.Once
317+ simpleStrMatchingRegex * regexp.Regexp
318+ initSimpleStrMatchingRegex sync.Once
319319)
320320
321+ // TODO(sean): This is a temporary solution. We need to find a better way to handle type cast conversion and column conversion. e.g. Iterating the AST with a visitor pattern.
321322// The Key must be in lowercase. Because the key used for value retrieval is in lowercase.
322- var typeCastConversion = map [string ]string {
323+ var simpleStringsConversion = map [string ]string {
324+ // type cast conversion
323325 "::regclass" : "::varchar" ,
324- "::regtype" : "::integer" ,
326+ "::regtype" : "::varchar" ,
327+
328+ // column conversion
329+ "proallargtypes" : catalog .SchemaNameSYS + "." + catalog .MacroNameMySplitListStr + "(proallargtypes)" ,
330+ "proargtypes" : catalog .SchemaNameSYS + "." + catalog .MacroNameMySplitListStr + "(proargtypes)" ,
325331}
326332
327333// This function will return a regex that matches all type casts in the query.
328- func getTypeCastRegex () * regexp.Regexp {
329- initTypeCastRegex .Do (func () {
330- var typeCasts []string
331- for typeCast := range typeCastConversion {
332- typeCasts = append (typeCasts , regexp .QuoteMeta (typeCast ))
334+ func getSimpleStringMatchingRegex () * regexp.Regexp {
335+ initSimpleStrMatchingRegex .Do (func () {
336+ var simpleStrings []string
337+ for simpleString := range simpleStringsConversion {
338+ simpleStrings = append (simpleStrings , regexp .QuoteMeta (simpleString ))
333339 }
334- typeCastRegex = regexp .MustCompile (`(?i)(` + strings .Join (typeCasts , "|" ) + `)` )
340+ simpleStrMatchingRegex = regexp .MustCompile (`(?i)(` + strings .Join (simpleStrings , "|" ) + `)` )
335341 })
336- return typeCastRegex
342+ return simpleStrMatchingRegex
337343}
338344
339- // This function will replace all type casts in the query with the corresponding type cast in the typeCastConversion map.
340- func ConvertTypeCast (sql string ) string {
341- return getTypeCastRegex ().ReplaceAllStringFunc (sql , func (m string ) string {
342- return typeCastConversion [strings .ToLower (m )]
345+ // This function will replace all type casts in the query with the corresponding type cast in the simpleStringsConversion map.
346+ func SimpleStrReplacement (sql string ) string {
347+ return getSimpleStringMatchingRegex ().ReplaceAllStringFunc (sql , func (m string ) string {
348+ return simpleStringsConversion [strings .ToLower (m )]
343349 })
344350}
345351
0 commit comments