@@ -51,41 +51,6 @@ def query(self, kql: str) -> pd.DataFrame:
5151 return dataframe_from_result_table (result .primary_results [0 ])
5252
5353 def list_tables (self ) -> List [Dict [str , Any ]]:
54- # first list functions (views)
55- query = ".show functions"
56- function_result_df = self .query (query )
57-
58- functions = []
59- for func in function_result_df .to_dict (orient = "records" ):
60- func_name = func ['Name' ]
61- result = self .query (f".show function ['{ func_name } '] schema as json" ).to_dict (orient = "records" )
62- schema = json .loads (result [0 ]['Schema' ])
63- parameters = schema ['InputParameters' ]
64- columns = [{
65- 'name' : r ["Name" ],
66- 'type' : r ["Type" ]
67- } for r in schema ['OutputColumns' ]]
68-
69- # skip functions with parameters at the moment
70- if len (parameters ) > 0 :
71- continue
72-
73- sample_query = f"['{ func_name } '] | take { 10 } "
74- sample_result = self .query (sample_query ).to_dict (orient = "records" )
75-
76- function_metadata = {
77- "row_count" : 0 ,
78- "columns" : columns ,
79- "parameters" : parameters ,
80- "sample_rows" : sample_result
81- }
82- functions .append ({
83- "type" : "function" ,
84- "name" : func_name ,
85- "metadata" : function_metadata
86- })
87-
88- # then list tables
8954 query = ".show tables"
9055 tables_df = self .query (query )
9156
@@ -101,8 +66,8 @@ def list_tables(self) -> List[Dict[str, Any]]:
10166 row_count_result = self .query (f".show table ['{ table_name } '] details" ).to_dict (orient = "records" )
10267 row_count = row_count_result [0 ]["TotalRowCount" ]
10368
104- sample_query = f"['{ table_name } '] | take { 10 } "
105- sample_result = self .query (sample_query ).to_dict (orient = "records" )
69+ sample_query = f"['{ table_name } '] | take { 5 } "
70+ sample_result = json . loads ( self .query (sample_query ).to_json (orient = "records" ) )
10671
10772 table_metadata = {
10873 "row_count" : row_count ,
@@ -116,7 +81,7 @@ def list_tables(self) -> List[Dict[str, Any]]:
11681 "metadata" : table_metadata
11782 })
11883
119- return functions + tables
84+ return tables
12085
12186 def ingest_data (self , table_name : str , name_as : str = None , size : int = 5000000 ) -> pd .DataFrame :
12287 if name_as is None :
@@ -167,7 +132,7 @@ def ingest_data(self, table_name: str, name_as: str = None, size: int = 5000000)
167132 total_rows_ingested += len (chunk_df )
168133
169134 def view_query_sample (self , query : str ) -> str :
170- return self .query (query ).head (10 ).to_dict (orient = "records" )
135+ return json . loads ( self .query (query ).head (10 ).to_json (orient = "records" ) )
171136
172137 def ingest_data_from_query (self , query : str , name_as : str ) -> pd .DataFrame :
173138 # Sanitize the table name for SQL compatibility
0 commit comments