diff --git a/backend/apps/system/crud/assistant.py b/backend/apps/system/crud/assistant.py index 76c8c3bf..d56acb97 100644 --- a/backend/apps/system/crud/assistant.py +++ b/backend/apps/system/crud/assistant.py @@ -132,14 +132,24 @@ class AssistantOutDs: def get_db_schema(self, ds_id: int) -> str: ds = self.get_ds(ds_id) schema_str = "" - db_name = ds.db_schema + #db_name = ds.db_schema + db_name = ds.db_schema if ds.db_schema is not None and ds.db_schema != "" else ds.dataBase schema_str += f"【DB_ID】 {db_name}\n【Schema】\n" for table in ds.tables: - schema_str += f"# Table: {db_name}.{table.name}" - schema_str += f", {table.comment}\n[\n" + schema_str += f"# Table: {db_name}.{table.name}" if ds.type != "mysql" else f"# Table: {table.name}" + table_comment = table.comment + if table_comment == '': + schema_str += '\n[\n' + else: + schema_str += f", {table_comment}\n[\n" + field_list = [] for field in table.fields: - field_list.append(f"({field.name}:{field.type}, {field.comment})") + field_comment = field.comment + if field_comment == '': + field_list.append(f"({field.name}:{field.type})") + else: + field_list.append(f"({field.name}:{field.type}, {field_comment})") schema_str += ",\n".join(field_list) schema_str += '\n]\n' return schema_str diff --git a/backend/common/utils/utils.py b/backend/common/utils/utils.py index bbc4c2a0..9d35dd4b 100644 --- a/backend/common/utils/utils.py +++ b/backend/common/utils/utils.py @@ -76,7 +76,9 @@ def extract_nested_json(text): def string_to_numeric_hash(text: str, bits: Optional[int] = 64) -> int: hash_bytes = hashlib.sha256(text.encode()).digest() - return int.from_bytes(hash_bytes[:bits//8], byteorder='big') + hash_num = int.from_bytes(hash_bytes, byteorder='big') + max_bigint = 2**63 - 1 + return hash_num % max_bigint def setup_logging():