MCPcopy Index your code
hub / github.com/dataease/SQLBot / get_tables_sample_data

Function get_tables_sample_data

backend/apps/datasource/crud/datasource.py:490–505  ·  view source on GitHub ↗

Get sample data (3 rows) for all tables to help AI understand the data

(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource,
                           table_list: list[str] = None)

Source from the content-addressed store, hash-verified

488
489
490def get_tables_sample_data(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource,
491 table_list: list[str] = None) -> str:
492 """Get sample data (3 rows) for all tables to help AI understand the data"""
493 table_objs = get_table_obj_by_ds(session=session, current_user=current_user, ds=ds)
494 if len(table_objs) == 0:
495 return ""
496
497 sample_data_parts = []
498 for obj in table_objs:
499 if table_list is not None and obj.table.table_name not in table_list:
500 continue
501 if obj.fields:
502 sample = get_table_sample_data(ds, obj.table.table_name, obj.fields)
503 if sample:
504 sample_data_parts.append(f"# Table: {obj.table.table_name}\n{sample}")
505 return "\n".join(sample_data_parts)
506
507
508def get_table_schema(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource, question: str,

Callers 1

choose_table_schemaMethod · 0.90

Calls 3

get_table_obj_by_dsFunction · 0.85
get_table_sample_dataFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected