def main(args=None) -> None: """ The command line interface entry point. :param args: the command line arguments for sqllineage command """ parser = argparse.ArgumentParser(prog="sqllineage", description="SQL Lineage Parser.") parser.add_argument("-e", metavar="<quoted-query-string>", help="SQL from command line") parser.add_argument("-f", metavar="<filename>", help="SQL from files") parser.add_argument( "-v", "--verbose", help="increase output verbosity, show statement level lineage result", action="store_true", ) parser.add_argument( "-g", "--graph-visualization", help="show graph visualization of the lineage within a webserver", action="store_true", ) parser.add_argument( "-p", help="the port visualization webserver will be listening on", type=int, default=DEFAULT_PORT, metavar="<port_number>{0..65536}", ) args = parser.parse_args(args) if args.e and args.f: logging.warning( "Both -e and -f options are specified. -e option will be ignored") if args.f or args.e: sql = extract_sql_from_args(args) runner = LineageRunner( sql, verbose=args.verbose, draw_options={ "p": args.p, "f": args.f if args.f else None }, ) if args.graph_visualization: runner.draw() else: print(runner) elif args.graph_visualization: return draw_lineage_graph( **{ "p": args.p, "f": os.path.join(os.path.dirname(__file__), "data/tpcds/query01.sql"), }) else: parser.print_help()
sql = """ """ result = LineageRunner(sql) print(result) # 打印result,会产出下面的信息 # Statements(#): 2 # Source Tables: # db1.table12 # db2.table21 # db2.table22 # Target Tables: # db3.table3 # Intermediate Tables: # db1.table11 # 也可以直接获取各个源表 for tbl in result.source_tables: print(tbl) # db1.table12 # db2.table21 # db2.table22 # 目标表当然也是可以的 for tbl in result.target_tables: print(tbl) # db3.table13 # 甚至还可以调用matplotlib绘制血缘图 result.draw()