Skip to content

Commit

Permalink
[优化]trino partition key位置
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Nov 18, 2022
1 parent 806cc1e commit 2d84f18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
14 changes: 9 additions & 5 deletions pydbapi/api/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions pydbapi/col/colmodel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @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
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @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
Expand All @@ -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:
Expand Down

0 comments on commit 2d84f18

Please sign in to comment.