(ds: CoreDatasource)
| 390 | |
| 391 | |
| 392 | def get_tables(ds: CoreDatasource): |
| 393 | conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 394 | "excel") else get_engine_config() |
| 395 | db = DB.get_db(ds.type) |
| 396 | sql, sql_param = get_table_sql(ds, conf, get_version(ds)) |
| 397 | if db.connect_type == ConnectType.sqlalchemy: |
| 398 | with get_session(ds) as session: |
| 399 | with session.execute(text(sql), {"param": sql_param}) as result: |
| 400 | res = result.fetchall() |
| 401 | res_list = [TableSchema(*item) for item in res] |
| 402 | return res_list |
| 403 | else: |
| 404 | extra_config_dict = get_extra_config(conf) |
| 405 | if equals_ignore_case(ds.type, 'dm'): |
| 406 | with dmPython.connect(user=conf.username, password=conf.password, server=conf.host, |
| 407 | port=conf.port, **extra_config_dict) as conn, conn.cursor() as cursor: |
| 408 | cursor.execute(sql, {"param": sql_param}, timeout=conf.timeout) |
| 409 | res = cursor.fetchall() |
| 410 | res_list = [TableSchema(*item) for item in res] |
| 411 | return res_list |
| 412 | elif equals_ignore_case(ds.type, 'doris', 'starrocks'): |
| 413 | ssl_args = {'ssl': {'ssl_mode': 'REQUIRE'}} if conf.ssl else {} |
| 414 | with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, |
| 415 | port=conf.port, db=conf.database, connect_timeout=conf.timeout, |
| 416 | read_timeout=conf.timeout, **extra_config_dict, |
| 417 | **ssl_args) as conn, conn.cursor() as cursor: |
| 418 | cursor.execute(sql, (sql_param,)) |
| 419 | res = cursor.fetchall() |
| 420 | res_list = [TableSchema(*item) for item in res] |
| 421 | return res_list |
| 422 | elif equals_ignore_case(ds.type, 'redshift'): |
| 423 | with redshift_connector.connect(host=conf.host, port=conf.port, database=conf.database, user=conf.username, |
| 424 | password=conf.password, |
| 425 | timeout=conf.timeout, **extra_config_dict) as conn, conn.cursor() as cursor: |
| 426 | cursor.execute(sql, (sql_param,)) |
| 427 | res = cursor.fetchall() |
| 428 | res_list = [TableSchema(*item) for item in res] |
| 429 | return res_list |
| 430 | elif equals_ignore_case(ds.type, 'kingbase'): |
| 431 | with psycopg2.connect(host=conf.host, port=conf.port, database=conf.database, user=conf.username, |
| 432 | password=conf.password, |
| 433 | options=f"-c statement_timeout={conf.timeout * 1000}", |
| 434 | **extra_config_dict) as conn, conn.cursor() as cursor: |
| 435 | cursor.execute(sql.format(sql_param)) |
| 436 | res = cursor.fetchall() |
| 437 | res_list = [TableSchema(*item) for item in res] |
| 438 | return res_list |
| 439 | elif equals_ignore_case(ds.type, 'es'): |
| 440 | res = get_es_index(conf) |
| 441 | res_list = [TableSchema(*item) for item in res] |
| 442 | return res_list |
| 443 | elif equals_ignore_case(ds.type, 'hive'): |
| 444 | with hive.connect(host=conf.host, port=conf.port, username=conf.username, |
| 445 | database=conf.database, **extra_config_dict) as conn, conn.cursor() as cursor: |
| 446 | cursor.execute(sql) |
| 447 | res = cursor.fetchall() |
| 448 | res_list = [TableSchema(*item) for item in res] |
| 449 | return res_list |
no test coverage detected