diff --git a/pydbapi/api/trino.py b/pydbapi/api/trino.py index 1142603..63d40db 100644 --- a/pydbapi/api/trino.py +++ b/pydbapi/api/trino.py @@ -2,7 +2,7 @@ # @Author: longfengpili # @Date: 2022-11-14 14:17:02 # @Last Modified by: longfengpili -# @Last Modified time: 2022-11-18 15:06:03 +# @Last Modified time: 2022-11-18 15:44:22 import re @@ -40,12 +40,16 @@ def create_partition(self, partition): return partition def create(self, columns, partition=None): - sql = self.create_nonindex(columns) - if partition: partition_key = columns.get_column_by_name(partition) - partition = self.create_partition(partition_key) - sql = sql.replace(';', f'\n{partition};') + columns = columns.remove(partition) + columns = columns.append(partition_key) + partition_sql = self.create_partition(partition_key) + + sql = self.create_nonindex(columns) + + if partition_sql: + sql = sql.replace(';', f'\n{partition_sql};') return sql diff --git a/pydbapi/col/colmodel.py b/pydbapi/col/colmodel.py index 9fb2275..0230954 100644 --- a/pydbapi/col/colmodel.py +++ b/pydbapi/col/colmodel.py @@ -1,7 +1,7 @@ # @Author: chunyang.xu # @Email: 398745129@qq.com # @Date: 2020-11-30 16:28:21 -# @Last Modified time: 2022-11-14 19:08:24 +# @Last Modified time: 2022-11-18 15:40:35 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -64,11 +64,19 @@ def __contains__(self, name): isin = True if col else False return isin - def append(self, column): + def append(self, column: ColumnModel): columns = list(self.columns) columns.append(column) return ColumnsModel(*columns) + def remove(self, remove_column: str): + new_columns = [] + columns = list(self.columns) + for column in columns: + if column.newname != remove_column: + new_columns.append(column) + return ColumnsModel(*new_columns) + @property def func_cols(self): func_cols = [col for col in self.columns if col.func] diff --git a/setup.py b/setup.py index 1d16dde..a66c79d 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # @Author: chunyang.xu # @Email: 398745129@qq.com # @Date: 2020-06-09 16:46:54 -# @Last Modified time: 2022-11-18 15:06:28 +# @Last Modified time: 2022-11-18 15:44:48 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -12,7 +12,7 @@ import shutil import setuptools -VERSION = '0.0.97' +VERSION = '0.0.98' PROJECT_NAME = 'pydbapi' with open('README.md', 'r', encoding='utf-8') as f: