From e8260bd0a4557a4013178cdad4ab882cb7210042 Mon Sep 17 00:00:00 2001 From: HUANG SIZHE Date: Tue, 16 Aug 2022 19:25:33 +0800 Subject: [PATCH] update --- CHANGELOG.md | 2 + document/CHANGELOG.md | 2 + pyhbasecli/HBase.py | 98 +++++++++++++++++++++---------------------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c177f..7ebddf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ + 增加了对mutation的支持 + put操作增加了额外参数 + 丰富了文档 ++ 统一了TTableName的输入,现在会全部转换为bytes ++ 统一了TColumn的输入,现在全部会转换为bytes # 0.0.1 diff --git a/document/CHANGELOG.md b/document/CHANGELOG.md index cdb9e46..b78f212 100644 --- a/document/CHANGELOG.md +++ b/document/CHANGELOG.md @@ -2,6 +2,8 @@ + 增加了对mutation的支持 + put操作增加了额外参数 ++ 统一了TTableName的输入,现在会全部转换为bytes ++ 统一了TColumn的输入,现在全部会转换为bytes # 0.0.1 diff --git a/pyhbasecli/HBase.py b/pyhbasecli/HBase.py index 5ec8cf8..703fc35 100644 --- a/pyhbasecli/HBase.py +++ b/pyhbasecli/HBase.py @@ -527,7 +527,7 @@ def add_delete(self, *, raise ResubmitException("can not add mutation to a submited session") _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: _timestamp = int(timestamp.timestamp() * 1000) @@ -697,13 +697,13 @@ def create_table(self, table: str, families: List[Dict[str, Any]], *, AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") sk = None @@ -738,13 +738,13 @@ def table_exists(self, table: str, *, ns: Optional[str] = None) -> bool: bool: 是否存在 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") flg = self.client.tableExists(tableName) @@ -764,13 +764,13 @@ def desc_table(self, table: str, *, ns: Optional[str] = None) -> Dict[str, str]: Dict[str, str]: 描述表基础信息 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") @@ -814,13 +814,13 @@ def show_families(self, table: str, *, ns: Optional[str] = None) -> List[Dict[st List[Dict[str, Any]]: 列簇信息 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") @@ -896,13 +896,13 @@ def delete_table(self, table: str, *, ns: Optional[str] = None) -> None: AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") self.client.deleteTable(tableName) @@ -918,13 +918,13 @@ def truncate_table(self, table: str, *, ns: Optional[str] = None, preserveSplits AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") self.client.truncateTable(tableName, preserveSplits) @@ -939,13 +939,13 @@ def enable_table(self, table: str, *, ns: Optional[str] = None) -> None: AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") self.client.enableTable(tableName) @@ -960,13 +960,13 @@ def disable_table(self, table: str, *, ns: Optional[str] = None) -> None: AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") self.client.disableTable(tableName) @@ -984,13 +984,13 @@ def is_table_enabled(self, table: str, *, ns: Optional[str] = None) -> bool: bool: 是否已激活 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") return self.client.isTableEnabled(tableName) @@ -1008,13 +1008,13 @@ def is_table_disabled(self, table: str, *, ns: Optional[str] = None) -> bool: bool: 是否已取消激活 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") return self.client.isTableDisabled(tableName) @@ -1032,13 +1032,13 @@ def is_table_available(self, table: str, *, ns: Optional[str] = None) -> bool: bool: 是否可用 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") return self.client.isTableAvailable(tableName) @@ -1095,13 +1095,13 @@ def create_family(self, family: str, table: str, *, AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") _bloomnFilterType = None @@ -1155,13 +1155,13 @@ def delete_family(self, family: str, table: str, *, ns: Optional[str] = None) -> AttributeError: _description_ """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") self.client.deleteColumnFamily(tableName, family.encode("utf-8")) @@ -1219,13 +1219,13 @@ def modify_family(self, family: str, table: str, *, AttributeError: 表名格式不合法 """ if ns is not None: - tableName = TTableName(qualifier=table, ns=ns) + tableName = TTableName(qualifier=table.encode(), ns=ns.encode()) else: tabelinfo = table.split(":") if len(tabelinfo) == 1: - tableName = TTableName(qualifier=table) + tableName = TTableName(qualifier=table.encode()) elif len(tabelinfo) == 2: - tableName = TTableName(qualifier=tabelinfo[1], ns=tabelinfo[0]) + tableName = TTableName(qualifier=tabelinfo[1].encode(), ns=tabelinfo[0].encode()) else: raise AttributeError(f"parameter table syntax error: {table}") _bloomnFilterType = None @@ -1390,7 +1390,7 @@ def delete(self, table: str, row: str, *, row_bytes = row.encode("utf8") _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: @@ -1523,7 +1523,7 @@ def batch_delete(self, table: str, rows: List[str], *, raise AttributeError(f"parameter table syntax error: {table}") _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: @@ -1794,7 +1794,7 @@ def exists(self, table: str, row: str, *, row_bytes = row.encode("utf8") _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: @@ -1901,7 +1901,7 @@ def get(self, table: str, row: str, *, row_bytes = row.encode("utf8") _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: @@ -2024,7 +2024,7 @@ def batch_get(self, table: str, rows: List[str], *, rows_bytes = [row.encode("utf8") for row in rows] _columns = None if columns: - _columns = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + _columns = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] _timestamp = None if timestamp: @@ -2155,7 +2155,7 @@ def scan(self, table: str, *, raise AttributeError(f"parameter table syntax error: {table}") scan_dict: Dict[str, Any] = {} if columns: - scan_dict["columns"] = [TColumn(family=c.split(":")[0], qualifier=c.split(":")[1]) if len(c.split(":")) == 2 else TColumn(family=c) for c in columns] + scan_dict["columns"] = [TColumn(family=c.split(":")[0].encode(), qualifier=c.split(":")[1].encode()) if len(c.split(":")) == 2 else TColumn(family=c.encode()) for c in columns] if caching: scan_dict["caching"] = caching if maxVersions: