pg-materialize
pg-materialize copied to clipboard
a bug
hi,I think this is a bug, like "f isinstance(data, dict): if 'relname' in data and 'schemaname' in data and re.search(pattern, data['relname']):"
because if the SQL like this:"select (b.script_name),'中' from (select * from temp.halfisolateworkjob20171221) a left join (select * from temp.script2table) b on a.schema_name||'.'||a.table_name=b.table_name where a.create_time <'20171201' and a.owner='app_vgop' and schema_name='SESSION' and process_flag=false and b.script_name is not null order by 1" the program will not work,you must add “create view....”
def extract_nodes(content, pattern):
class NS(object):
pass
ns = NS()
ns.views = set()
ns.dependencies = set()
def inner(data, depth):
if isinstance(data, dict):
if 'relname' in data and 'schemaname' in data and re.search(pattern, data['relname']):
entity = '.'.join([
data['schemaname'],
data['relname']
])
if depth == 1:
ns.views.add(entity)
else:
ns.dependencies.add(entity)
else:
for key, value in data.items():
inner(value, depth)
elif isinstance(data, list) or isinstance(data, tuple):
for item in data:
inner(item, depth + 1)
parsed_content = parse(content)
inner(parsed_content, 0)
return {
'views': ns.views,
'dependencies': ns.dependencies - ns.views
}