async def api_metadata_analyse_table(request, *, dsId, db, table): ds = await DataSource.find(dsId) from com.phoenix.connections.connectionFactory import get_Connection conn = get_Connection(ds) conn.computeStats(db, table) dsMetadata = ds.get_MetadataSource() from com.phoenix.connections.connectionFactory import get_Connection conn = get_Connection(dsMetadata) arr = conn.analyse(db, table) result = {} for item in arr: result[item["db_name"] + '.' + item["table_name"]] = dict( num_files=item["num_files"], num_rows=item["num_rows"], total_size=item["total_size"]) return result
async def api_datasource_fields(*, id, db, table): ds = await DataSource.find(id) if ds['db_type'] != 'Oracle': ds['database'] = db else: table = db + '.' + table from com.phoenix.connections.connectionFactory import get_Connection conn = get_Connection(ds) fields = conn.showFields(table) return dict(fields=fields)
async def api_datasource_tables(*, id, db): ds = await DataSource.find(id) if ds['db_type'] != 'Oracle': ds['database'] = db from com.phoenix.connections.connectionFactory import get_Connection conn = get_Connection(ds) if ds['db_type'] == 'Oracle': tables = conn.showTables(db) else: tables = conn.showTables() return dict(tables=tables)
def test_Impala(): ds = DataSource(db_type="Impala", host="10.10.8.102", database="fdm_db", port=21050) conn = get_Connection(ds) sql = 'select zsxm_dm,zsxmmc,zsxmjc,xybz,yxbz,sjzsxm_dm,yxqz,yxqq from odm_db.o_hx_qg_dm_gy_zsxm' rows = conn.query(sql) for row in rows: print( "zsxm_dm:%s, zsxmmc:%s, zsxmjc:%s, xybz:%s, yxbz:%s, sjzsxm_dm:%s, yxqz:%s, yxqq:%s" % (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]))
def test_MySQL(): ds = DataSource(db_type="MySQL", host="10.10.8.104", database="fdm_db", port=4000, user="******", password="******") conn = get_Connection(ds) sql = 'select spbm,spmc from fdm_db.f_dm_gy_spbm' rows = conn.query(sql) for row in rows: print("spbm:%s, spmc:%s" % (row[0], row[1]))
async def api_datasource_databases(*, id): ds = await DataSource.find(id) from com.phoenix.connections.connectionFactory import get_Connection conn = get_Connection(ds) databases = conn.showDatabases() return dict(databases=databases)