コード例 #1
0
 def set_scope(self, scope):
     type_check(scope, int)
     if scope < 0:
         raise RuntimeError(
             "Illegal replication scope value {}".format(scope))
     self.scope = scope
     return self
コード例 #2
0
ファイル: table.py プロジェクト: YutSean/thbase
    def get_batch(self, gets):
        # type: (List[Get]) -> List[Cell]
        """
        Send multiple Get requests to the server at one time.
        The requests will be sent batch by batch.
        The logger will log the failed position if one batch of requests failed.
        Args:
            gets: A list of Get objects.

        Returns: If success: a list of cells.
                 If success but not matched data: an empty list.
                 If get failed: False.
                 If partly success, a part result will be returned.

        """
        type_check(gets, (list, tuple))
        for get in gets:
            type_check(get, Get)
        result_list = []
        for i in range(0, len(gets), self.conf.batch_size):
            result = self._client._get_rows(table_name=self.name, gets=gets[i: i + self.conf.batch_size])
            # if result == False, it shows that the operation failed.
            # The task should stop and return the successful part.
            if result is False:
                return self._results_format(result_list)
            elif len(result) > 0:
                result_list += result
        return self._results_format(result_list)
コード例 #3
0
 def add_column(self, col):
     type_check(col, TColumnFamilyDescriptor)
     for i in range(len(self.columns)):
         if col.name == self.columns[i].name:
             self.columns[i] = col
             return self
     self.columns.append(col)
     return self
コード例 #4
0
    def revoke(self, info):
        """

        Args:
            info:

        Returns:

        """
        type_check(info, TAccessControlEntity)
        return self.executor.call(lambda: self.client.revoke(info))
コード例 #5
0
ファイル: table.py プロジェクト: YutSean/thbase
    def delete(self, delete):
        # type: (Delete) -> bool
        """
        Send a Delete request to the thrift server.
        Args:
            delete: a single Delete object

        Returns: True if successes, False otherwise.

        """
        type_check(delete, Delete)
        return self._client._delete_row(table_name=self.name, delete=delete)
コード例 #6
0
    def table_exists(self, table_name):
        """
        Check if a table exists.
        Args:
            table_name: type: TTableName

        Returns: True if the table exists, else False.

        """
        type_check(table_name, str)
        tn = str_to_tablename(table_name)
        return self.executor.call(lambda: self.client.tableExists(tn))
コード例 #7
0
ファイル: table.py プロジェクト: YutSean/thbase
    def put(self, put):
        # type: (Put) -> bool
        """
        Send a single Put operation to the thrift server.
        Args:
            put: A customized Get object.

        Returns: True if successes, False otherwise.

        """
        type_check(put, Put)
        return self.executor.call(lambda: self._client._put_row(table_name=self.name, put=put))
コード例 #8
0
    def modify_table(self, table_descriptor):
        """

        Args:
            table_descriptor:

        Returns:

        """
        type_check(table_descriptor, TTableDescriptor)
        return self.executor.call(
            lambda: self.client.modifyTable(table_descriptor))
コード例 #9
0
    def modify_columnFamily(self, table_name, desc):
        """

        Args:
            table_name:
            desc:

        Returns:

        """
        type_check(desc, TColumnFamilyDescriptor)
        tn = str_to_tablename(table_name)
        return self.executor.call(
            lambda: self.client.modifyColumnFamily(tn, desc))
コード例 #10
0
    def create_table(self, desc, split_keys):
        """

        Args:
            desc: TTableDescriptor, which contains the meta information of the table to create.
            split_keys: split keys for table pre-split.

        Returns: True if success, else False.

        """
        type_check(desc, TTableDescriptor)
        type_check(split_keys, list)
        return self.executor.call(
            lambda: self.client.createTable(desc, split_keys))
コード例 #11
0
ファイル: table.py プロジェクト: YutSean/thbase
    def scan(self, scan):
        # type: (Scan) -> List[Cell]
        """
        Send a Scan request to the thrift server.
        Args:
            scan: A single Scan object.

        Returns:If success: a list of cells.
                 If success but not matched data: an empty list.
                 If the start row do not exists, it will raise an IllegalArgument error.
                 If scan failed: False.

        """
        type_check(scan, Scan)
        return self._results_format(self._client._scan(table_name=self.name, scan=scan))
コード例 #12
0
    def get_user_permissions(self, domain_name):
        """

        Args:
            domain_name:
            scope:

        Returns:

        """
        type_check(domain_name, str)
        scope = TPermissionScope.TABLE if domain_name[
            0] != '@' else TPermissionScope.NAMESPACE
        return self.executor.call(
            lambda: self.client.getUserPermission(domain_name, scope))
コード例 #13
0
ファイル: table.py プロジェクト: YutSean/thbase
    def get(self, get):
        # type: (Get) -> List[Cell]
        """
        Send a single Get operation to the thrift server.
        Args:
            get: A customized Get object.

        Returns: If success: a list of cells.
                 If success but not matched data: an empty list.
                 If get failed: False.

        """
        type_check(get, Get)
        result = self._client._get_row(table_name=self.name, get=get)
        # if result is False, that means the operation failed after retry N times.
        # if result is [], that means there is no matched cell in hbase.
        if not result:
            return []
        return self._results_format(result)
コード例 #14
0
    def get_columnDescriptor(self, table_name, cf):
        """
        Return a column descriptor for specific table with the given cf name.
        Args:
            table_name:
            cf:

        Returns:

        """
        type_check(cf, str)
        td = self.get_tableDescriptor(table_name)
        check_none(td, "Unknown table.")
        for col in td.columns:
            if to_str(col.name) == cf:
                return col
        raise RuntimeError(
            "The table does not contain a column family with name {}".format(
                cf))
コード例 #15
0
ファイル: table.py プロジェクト: YutSean/thbase
    def delete_batch(self, batch):
        # type: (List[Delete]) -> bool
        """
        Send a list of Delete requests to the thrift server.
        The requests will be sent batch by batch.
        The logger will log the failed position if one batch of requests failed.
        Args:
            batch: a list of Delete objects.

        Returns: True if successes, False otherwise.

        """
        type_check(batch, (list, tuple))
        for delete in batch:
            type_check(delete, Delete)
        for i in range(0, len(batch), self.conf.batch_size):
            if not self._client._delete_batch(table_name=self.name,
                                              deletes=batch[i: i + self.conf.batch_size]):
                logger.error("Delete_batch failed at index {}, the delete requests after {} (inclusive) are not sent.".format(i, i))
                return False
        return True
コード例 #16
0
ファイル: table.py プロジェクト: YutSean/thbase
    def put_batch(self, puts):
        # type: (List[Put]) -> bool
        """
        Send multiple Put requests to the server at one time.
        The requests will be sent batch by batch.
        The logger will log the failed position if one batch of requests failed.
        Args:
            puts: A list of Put objects

        Returns: True if successes, False otherwise.

        """
        type_check(puts, list)
        for put in puts:
            type_check(put, Put)
        for i in range(0, len(puts), self.conf.batch_size):
            result = self._client._put_rows(table_name=self.name, puts=puts[i: i + self.conf.batch_size])
            if not result:
                logger.error("An error occurs at index {}, the Put requests after {} (inclusive) failed.".format(i, i))
                return False
        return True
コード例 #17
0
 def copy_from_exist(self, desc):
     type_check(desc, TColumnFamilyDescriptor)
     self.name = desc.name
     self.attributes = desc.attributes
     self.configuration = desc.configuration
     self.blockSize = desc.blockSize
     self.bloomnFilterType = desc.bloomnFilterType
     self.compressionType = desc.compressionType
     self.dfsReplication = desc.dfsReplication
     self.dataBlockEncoding = desc.dataBlockEncoding
     self.keepDeletedCells = desc.keepDeletedCells
     self.maxVersions = desc.maxVersions
     self.minVersions = desc.minVersions
     self.scope = desc.scope
     self.timeToLive = desc.timeToLive
     self.blockCacheEnabled = desc.blockCacheEnabled if desc.blockCacheEnabled else None
     self.cacheBloomsOnWrite = desc.cacheBloomsOnWrite if desc.cacheBloomsOnWrite else None
     self.cacheDataOnWrite = desc.cacheDataOnWrite if desc.cacheDataOnWrite else None
     self.cacheIndexesOnWrite = desc.cacheIndexesOnWrite if desc.cacheIndexesOnWrite else None
     self.compressTags = desc.compressTags if desc.compressTags else None
     self.evictBlocksOnClose = desc.evictBlocksOnClose
     self.inMemory = desc.inMemory if desc.inMemory else None
コード例 #18
0
 def __init__(self, name=None):
     type_check(name, str)
     self.name = name
     self.attributes = {}
     self.configuration = {}
     self.blockSize = None
     self.bloomnFilterType = None
     self.compressionType = None
     self.dfsReplication = None
     self.dataBlockEncoding = None
     self.keepDeletedCells = None
     self.maxVersions = None
     self.minVersions = None
     self.scope = None
     self.timeToLive = None
     self.blockCacheEnabled = None
     self.cacheBloomsOnWrite = None
     self.cacheDataOnWrite = None
     self.cacheIndexesOnWrite = None
     self.compressTags = None
     self.evictBlocksOnClose = None
     self.inMemory = None
コード例 #19
0
 def set_blockSize(self, bs):
     type_check(bs, int)
     if bs < 1:
         raise RuntimeError("Illegal block size " + bs)
     self.blockSize = bs
     return self
コード例 #20
0
 def set_keepDeletedCells(self, kdc):
     type_check(kdc, bool)
     self.keepDeletedCells = kdc
     return self
コード例 #21
0
 def set_inMemory(self, value):
     type_check(value, bool)
     self.inMemory = value
     return self
コード例 #22
0
 def set_evictBlocksOnClose(self, value):
     type_check(value, bool)
     self.evictBlocksOnClose = value
     return self
コード例 #23
0
 def set_compressTags(self, value):
     type_check(value, bool)
     self.compressTags = value
     return self
コード例 #24
0
 def set_cacheDataOnWrite(self, value):
     type_check(value, bool)
     self.cacheBloomsOnWrite = value
     return self
コード例 #25
0
 def set_blockCacheEnabled(self, enabled):
     type_check(enabled, bool)
     self.blockCacheEnabled = enabled
     return self
コード例 #26
0
 def set_timeToLive(self, ttl):
     type_check(ttl, int)
     if ttl < 1:
         raise RuntimeError("Illegal TTL value {}".format(ttl))
     self.timeToLive = ttl
     return self
コード例 #27
0
 def copy_from_exist(self, desc):
     type_check(desc, TTableDescriptor)
     self.name = ':'.join(
         [to_str(desc.tableName.ns),
          to_str(desc.tableName.qualifier)])
     self.columns = desc.columns
コード例 #28
0
 def set_dfsReplication(self, hr):
     type_check(hr, int)
     if hr < 1:
         raise RuntimeError(
             "Illegal number of dfs replication {}".format(hr))
     self.dfsReplication = hr
コード例 #29
0
 def set_cacheIndexesOnWrite(self, value):
     type_check(value, bool)
     self.cacheIndexesOnWrite = value
     return self
コード例 #30
0
 def set_minVersions(self, mv):
     type_check(mv, int)
     if mv < 0:
         raise RuntimeError("Illegal min versions number {}".format(mv))
     self.minVersions = mv
     return self