fix: Editor page with redundant table fields of the same name in othe… (#1765)

Co-authored-by: 王玉东 <wangyudong@qiyi.com>
This commit is contained in:
yudong 2024-08-05 19:26:39 +08:00 committed by GitHub
parent 5bd946fbdd
commit 9fe060a771
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 16 additions and 14 deletions

View File

@ -54,7 +54,7 @@ async def get_editor_tables(
for table in tables:
table_node: DataNode = DataNode(title=table, key=table, type="table")
db_node.children.append(table_node)
fields = db_conn.get_fields(table)
fields = db_conn.get_fields(table, db_name)
for field in fields:
table_node.children.append(
DataNode(

View File

@ -532,16 +532,17 @@ class RDBMSConnector(BaseConnector):
ans = cursor.fetchall()
return ans[0][1]
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
session = self._db_sessions()
cursor = session.execute(
text(
"SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, IS_NULLABLE, "
"COLUMN_COMMENT from information_schema.COLUMNS where "
f"table_name='{table_name}'".format(table_name)
)
query = (
"SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, IS_NULLABLE, "
"COLUMN_COMMENT from information_schema.COLUMNS where "
f"table_name='{table_name}'"
)
if db_name is not None:
query += f" AND table_schema='{db_name}'"
cursor = session.execute(text(query))
fields = cursor.fetchall()
return [(field[0], field[1], field[2], field[3], field[4]) for field in fields]

View File

@ -155,16 +155,17 @@ class ClickhouseConnector(RDBMSConnector):
"""Return string representation of dialect to use."""
return ""
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
session = self.client
_query_sql = f"""
SELECT name, type, default_expression, is_in_primary_key, comment
from system.columns where table='{table_name}'
""".format(
table_name
)
if db_name is not None:
_query_sql += f" AND database='{db_name}'"
with session.query_row_block_stream(_query_sql) as stream:
fields = [block for block in stream] # noqa
return fields

View File

@ -100,7 +100,7 @@ class DorisConnector(RDBMSConnector):
for field in fields
]
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
cursor = self.get_session().execute(
text(

View File

@ -96,7 +96,7 @@ class PostgreSQLConnector(RDBMSConnector):
logger.warning(f"postgresql get users error: {str(e)}")
return []
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
session = self._db_sessions()
cursor = session.execute(

View File

@ -55,7 +55,7 @@ class SQLiteConnector(RDBMSConnector):
ans = cursor.fetchall()
return ans[0][0]
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
cursor = self.session.execute(text(f"PRAGMA table_info('{table_name}')"))
fields = cursor.fetchall()

View File

@ -88,7 +88,7 @@ table name should keep its schema name in "
logger.warning(f"vertica get users error: {str(e)}")
return []
def get_fields(self, table_name) -> List[Tuple]:
def get_fields(self, table_name, db_name=None) -> List[Tuple]:
"""Get column fields about specified table."""
session = self._db_sessions()
cursor = session.execute(