Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/rule_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ def parse_validate(pattern: str, rewrite: str) -> Tuple[bool, str, int]:
patternASTJson = mosql.parse(pattern)
except Exception as e:
#if mosql error, find index of the offending part
var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
if var:
errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope]
return False, "Error in first query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2
Expand All @@ -3694,14 +3694,14 @@ def parse_validate(pattern: str, rewrite: str) -> Tuple[bool, str, int]:
except Exception as e:
#checks case that there are variables in the rewrite that are not in the original query
partialSQL = RuleGenerator.extractPartialSQL(rewrite, rewriteScope)
regexPattern = VarTypesInfo[VarType.Var]['markerStart'] + '(\w+)' + VarTypesInfo[VarType.Var]['markerEnd']
regexPattern = VarTypesInfo[VarType.Var]['markerStart'] + r'(\w+)' + VarTypesInfo[VarType.Var]['markerEnd']
var = re.search(regexPattern, partialSQL)
if var:
#returns the index of variable that is not in first query
return False, str(var.group()) + "not in first rule", var.start()

# if all variables present, then mosql error, find index of the offending part
var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
if var:
errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope]
return False, "Error in second query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2
Expand Down Expand Up @@ -3763,7 +3763,7 @@ def parse_validate_single(pattern: str) -> Tuple[bool, str, int]:
return True, "success", 0
except Exception as e:
#if mosql error, find index of the offending part
var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping))
if var:
errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope]
return False, "Error in first query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2
Expand Down
10 changes: 5 additions & 5 deletions core/rule_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def replaceVars(pattern: str, rewrite: str) -> Tuple[str, str, dict]:
# common function to replace one VarType
#
def replaceVars(pattern: str, rewrite: str, varType: VarType, mapping: dict) -> Tuple[str, str]:
regexPattern = VarTypesInfo[varType]['markerStart'] + '(\w+)' + VarTypesInfo[varType]['markerEnd']
regexPattern = VarTypesInfo[varType]['markerStart'] + r'(\w+)' + VarTypesInfo[varType]['markerEnd']
vars = re.findall(regexPattern, pattern)
varInternalBase = VarTypesInfo[varType]['internalBase']
varInternalCount = 1
Expand Down Expand Up @@ -235,13 +235,13 @@ def parse_actions(actions: str, mapping: str) -> list:
@staticmethod
def find_malformed_brackets(pattern: str) -> int:
CommonMistakeVarTypesInfo = {
'markerStart': ['\(', '\{', '\['],
'markerEnd': ['\)', '\}', '\]'],
'markerStart': [r'\(', r'\{', r'\['],
'markerEnd': [r'\)', r'\}', r'\]'],
}

for i in range(len(CommonMistakeVarTypesInfo['markerStart'])):
regexPatternVarStart = CommonMistakeVarTypesInfo['markerStart'][i] + '(\w+)' + VarTypesInfo[VarType.Var]['markerEnd']
regexPatternVarEnd = VarTypesInfo[VarType.Var]['markerStart'] + '(\w+)' + CommonMistakeVarTypesInfo['markerEnd'][i]
regexPatternVarStart = CommonMistakeVarTypesInfo['markerStart'][i] + r'(\w+)' + VarTypesInfo[VarType.Var]['markerEnd']
regexPatternVarEnd = VarTypesInfo[VarType.Var]['markerStart'] + r'(\w+)' + CommonMistakeVarTypesInfo['markerEnd'][i]

varStart = re.search(regexPatternVarStart, pattern)
varEnd = re.search(regexPatternVarEnd, pattern)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ def test_complete_query():
# Analyze query structure
clause_types = [child.type for child in query.children]
print(f" Clause types: {[ct.value for ct in clause_types]}")

return query


def test_varsql_pattern_matching():
Expand Down Expand Up @@ -274,9 +272,6 @@ def test_varsql_pattern_matching():
multi_select = SelectNode({var_columns})
print(f"\nVarSet pattern for multiple columns:")
print(f" VarSet {var_columns.name} can match multiple SELECT items")

return pattern_query


def test_node_relationships():
"""Test node relationships and tree structure"""
Expand Down