From a36bad7e0c257a4d335070c9f7d01f233c59468f Mon Sep 17 00:00:00 2001 From: longfengpili <398745129@qq.com> Date: Wed, 25 Aug 2021 15:01:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]mysql=E6=96=B0=E5=A2=9Edori?= =?UTF-8?q?s=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydbapi/api/mysql.py | 15 +++++++++++---- pydbapi/col/colmodel.py | 5 ++++- setup.py | 4 ++-- tests/mysql/mysql_test.py | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pydbapi/api/mysql.py b/pydbapi/api/mysql.py index cb7cf95..4c71af7 100644 --- a/pydbapi/api/mysql.py +++ b/pydbapi/api/mysql.py @@ -1,7 +1,7 @@ # @Author: chunyang.xu # @Email: 398745129@qq.com # @Date: 2020-06-10 14:40:50 -# @Last Modified time: 2021-08-11 11:10:48 +# @Last Modified time: 2021-08-25 14:46:54 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -61,7 +61,7 @@ def create_partition(self, partition): partition = f"partition by hash (to_days({partition.newname}))" return partition - def create(self, columns, indexes, index_part=128, ismultiple_index=True, partition=None): + def create(self, columns, indexes, index_part=128, ismultiple_index=True, partition=None, isdoris=False): 'mysql 暂不考虑索引' sql = self.create_nonindex(columns) @@ -77,6 +77,11 @@ def create(self, columns, indexes, index_part=128, ismultiple_index=True, partit partition = self.create_partition(partition) sql = sql.replace(';', f'\n{partition};') + if isdoris: + distributed_col = columns[0].newname + distributed = f"distributed by hash({distributed_col})" + sql = sql.replace(';', f'\n{distributed};') + return sql def dumpsql(self, columns, dumpfile, fromtable=None, condition=None): @@ -95,13 +100,14 @@ def loadsql(self, columns, loadfile, intotable=None, fieldterminated=','): class MysqlDB(DBCommon, DBFileExec): _instance_lock = threading.Lock() - def __init__(self, host, user, password, database, port=3306, charset="utf8", safe_rule=True): + def __init__(self, host, user, password, database, port=3306, charset="utf8", safe_rule=True, isdoris=False): self.host = host self.port = port self.user = user self.password = password self.database = database self.charset = charset + self.isdoris = isdoris super(MysqlDB, self).__init__() self.auto_rules = AUTO_RULES if safe_rule else None @@ -115,7 +121,8 @@ def get_instance(cls, *args, **kwargs): return MysqlDB._instance def get_conn(self): - conn = pymysql.connect(database=self.database, user=self.user, password=self.password, host=self.host, port=self.port, charset=self.charset) + conn = pymysql.connect(database=self.database, user=self.user, password=self.password, + host=self.host, port=self.port, charset=self.charset) if not conn: self.get_conn() return conn diff --git a/pydbapi/col/colmodel.py b/pydbapi/col/colmodel.py index d34c70b..32fbe04 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: 2021-08-09 13:46:27 +# @Last Modified time: 2021-08-25 14:46:00 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -53,6 +53,9 @@ def __init__(self, *columns): def __repr__(self): return f"{[column for column in self.columns]}" + def __getitem__(self, key): + return self.columns[key] + @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 f54535e..9435f1e 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: 2021-08-11 11:13:22 +# @Last Modified time: 2021-08-25 14:36:33 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -12,7 +12,7 @@ import shutil import setuptools -VERSION = '0.0.64' +VERSION = '0.0.65' PROJECT_NAME = 'pydbapi' with open('README.md', 'r', encoding='utf-8') as f: diff --git a/tests/mysql/mysql_test.py b/tests/mysql/mysql_test.py index e85e4b1..c56ed3b 100644 --- a/tests/mysql/mysql_test.py +++ b/tests/mysql/mysql_test.py @@ -2,7 +2,7 @@ # @Author: chunyang.xu # @Date: 2021-03-08 14:19:01 # @Last Modified by: chunyang.xu -# @Last Modified time: 2021-08-10 17:20:50 +# @Last Modified time: 2021-08-25 14:59:13 import os import pytest @@ -15,8 +15,8 @@ class TestMysql: def setup_method(self, method): - AdLocal = os.environ.get('ADLOCAL') - AdLocal = json.loads(AdLocal) + AdLocal = os.environ.get('ADLOCAL').lower() + AdLocal = json.loads(AdLocal.replace("'", '"')) self.mysqldb = MysqlDB(safe_rule=False, **AdLocal) self.tablename = 'test_xu' self.id = ColumnModel('id', 'varchar(1024)')