Skip to content

Commit

Permalink
jsonextractpath
Browse files Browse the repository at this point in the history
jsonextractpath
  • Loading branch information
rlsalcido24 committed May 22, 2024
1 parent 804352e commit 96c8024
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions helper/_resources/config/redshift/syntax_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"strtol_to_conv" : {"source_pattern": "strtol\\([^)]*?\\)",
"target_pattern": "conv(#arg0, #arg1, 10)"
},
"jsonextractpath_to_gjo" : {"source_pattern": "(json_extract_path_text\\()([^)]*)(\\))",
"target_pattern": "jsonextractpathplaceholder"
"jsonextractpath_to_gjo" : {"source_pattern": "json_extract_path_text\\([^)]*?\\)",
"target_pattern": "get_json_object(#arg0, #arg1)"
},
"jsonal_to_arraysize" : {"source_pattern": "json_array_length\\([^)]*?\\)",
"target_pattern": "array_size(#arg0)"
Expand Down
15 changes: 13 additions & 2 deletions helper/convert_to_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def findargs (contentstring, sourcepatterninit):
if tmplogs == 'true':
print(f"findfunc prior to error: {findfunction}")
print(f"funlength patter prior to error: {funlength}")
[('JSON_EXTRACT_PATH_TEXT(', '\'{"f2":{"f3":1},"f4":{"f5":99,"f6":"star"}}\',\'f4\', \'f6\'', ')')]
if funlength > 0:
for i in range(funlength):
leftparen = findfunction[i].count("(")
Expand Down Expand Up @@ -308,7 +309,17 @@ def finalcountdown(finaldf, contentstring, targetstring):
lastarget = putarget.replace('#arg2', args[2])
updated_content = updated_content.replace(sourcesting, lastarget)
elif sourcesting.find("xmlget") > -1:
xmlfunc = "true"
xmlfunc = "true"
elif targetstring == "get_json_object(#arg0, #arg1)":
firstarg = args[0]
restarg = args[1:]
newarray = list(restarg)
jsonpatharg = '.'.join(newarray)
jsonpathnq = jsonpatharg.replace("'","")
jsonpathfinal = "$."+ jsonpathnq
firstargenrich = firstarg.replace('#tmpcommaplaceholder', ",")
getjsonddl = "get_json_object({}, '{}')".format(firstargenrich, jsonpathfinal)
updated_content = updated_content.replace(sourcesting, getjsonddl)
else:
targetstringlocal = targetstring
counter = 0
Expand Down Expand Up @@ -553,7 +564,7 @@ def convert_syntax_expressions(content: str, source_pattern: str, target_pattern
updated_match = re.sub(commas,commareplace, i, flags=re.IGNORECASE)
updated_content = updated_content.replace(i, updated_match)

elif target_pattern == "jsonextractpathplaceholder":
elif target_pattern == "jsonextractpathplaceholderzzz":
# todo eliminate some of this custom logic
source_patternuno = "json_extract_path_text\([^)]*\)"
inputsearchinit = re.findall(source_patternuno, content, flags= re.DOTALL | re.IGNORECASE)
Expand Down

0 comments on commit 96c8024

Please sign in to comment.