Skip to content

Commit

Permalink
[优化]alter_table_base
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Mar 1, 2024
1 parent 159871c commit f5810da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions pydbapi/api/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2024-03-01 12:27:39
# @Last Modified time: 2024-03-01 13:34:58
# @github: https://github.com/longfengpili


Expand All @@ -13,6 +13,7 @@
import pymysql

from pydbapi.db import DBMixin, DBFileExec
from pydbapi.col import ColumnModel
from pydbapi.sql import SqlCompile
from pydbapi.conf import AUTO_RULES

Expand Down Expand Up @@ -171,9 +172,6 @@ def alter_tablecol(self, tablename: str, colname: str, newname: str = None, newt
indexes: list = None, index_part: int = 128, ismultiple_index: bool = True,
partition: str = None, distribution: str = None, conditions: list[str] = None,
verbose: int = 0):

from pydbapi.col import ColumnModel

alter_columns = self.alter_column(tablename, colname, newname, newtype)
if isinstance(alter_columns, ColumnModel):
mysqllogger.info(f"{alter_columns} same, not needed to alter ~")
Expand Down
5 changes: 2 additions & 3 deletions pydbapi/api/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2024-03-01 12:27:47
# @Last Modified time: 2024-03-01 13:34:40
# @github: https://github.com/longfengpili


Expand All @@ -13,6 +13,7 @@
from trino.auth import BasicAuthentication

from pydbapi.db import DBMixin, DBFileExec
from pydbapi.col import ColumnModel
from pydbapi.sql import SqlCompile
# from pydbapi.col import ColumnModel, ColumnsModel
from pydbapi.conf import AUTO_RULES
Expand Down Expand Up @@ -152,8 +153,6 @@ def insert(self, tablename, columns, inserttype='value', values=None, chunksize=

def alter_tablecol(self, tablename: str, colname: str, newname: str = None, newtype: str = None,
partition: str = 'part_date', conditions: list[str] = None, verbose: int = 0):
from pydbapi.col import ColumnModel

alter_columns = self.alter_column(tablename, colname, newname, newtype)
if isinstance(alter_columns, ColumnModel):
mytrinologger.info(f"{alter_columns} same, not needed to alter ~")
Expand Down
9 changes: 5 additions & 4 deletions pydbapi/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2024-03-01 12:31:00
# @Last Modified time: 2024-03-01 13:21:20
# @github: https://github.com/longfengpili


Expand Down Expand Up @@ -269,15 +269,16 @@ def alter_tablename(self, ftablename: str, ttablename: str, retries: int = 3, ve
try:
self.execute(altersql, verbose=verbose)
break
except Exception as e: # noqa: F841
except: # noqa: E722
attempt += 1
time.sleep(5)

try:
self.get_columns(ttablename)
dblogger.info(f"alter table {ftablename} to {ttablename} succeeded ~")
break
except Exception as e1:
dblogger.error(e1)
except: # noqa: E722
pass

def alter_column(self, tablename: str, colname: str, newname: str = None, newtype: str = None):
old_columns = self.get_columns(tablename)
Expand Down

0 comments on commit f5810da

Please sign in to comment.