Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz1273327 committed Aug 16, 2022
1 parent 46d266c commit e8260bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
+ 增加了对mutation的支持
+ put操作增加了额外参数
+ 丰富了文档
+ 统一了TTableName的输入,现在会全部转换为bytes
+ 统一了TColumn的输入,现在全部会转换为bytes

# 0.0.1

Expand Down
2 changes: 2 additions & 0 deletions document/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

+ 增加了对mutation的支持
+ put操作增加了额外参数
+ 统一了TTableName的输入,现在会全部转换为bytes
+ 统一了TColumn的输入,现在全部会转换为bytes

# 0.0.1

Expand Down
98 changes: 49 additions & 49 deletions pyhbasecli/HBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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}")

Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e8260bd

Please sign in to comment.