Exemplo n.º 1
0
 def add_configuration(self, key, value):
     check_none(key, "Configuration key is None.")
     if value is None and key in self.configuration:
         self.configuration.pop(key)
     else:
         self.configuration[to_bytes(key)] = to_bytes(value)
     return self
Exemplo n.º 2
0
 def add_attribute(self, key, value):
     check_none(key, "Attribute name is None.")
     if value is None and key in self.attributes:
         self.attributes.pop(key)
     else:
         self.attributes[to_bytes(key)] = to_bytes(value)
     return self
Exemplo n.º 3
0
 def __init__(
         self,
         row=None,  # type: Union[str]
         family=None,  # type: Union[None, str]
         qualifier=None,  # type: Union[None, str, List[str]]
         value=None,  # type: Union[str, List[str]]
 ):
     super(Put, self).__init__(row, family, qualifier, value)
     check_none(self.row, "Row cannot be none for Put operation.")
     check_none(self.value, "Value cannot be none for Put operation.")
     column_values = []
     columns = _column_format(family, qualifier)
     if isinstance(value, str):
         for col in columns:
             column_values.append(
                 TColumnValue(family=to_bytes(col.family),
                              qualifier=to_bytes(col.qualifier),
                              value=self.value))
     elif isinstance(value, list) or isinstance(value, tuple):
         if len(columns) != len(value):
             raise ValueError(
                 "The number of columns mismatches the number of value list."
             )
         for i, col in enumerate(columns):
             column_values.append(
                 TColumnValue(family=col.family,
                              qualifier=col.qualifier,
                              value=to_bytes(value[i])))
     self.core = TPut(row=self.row, columnValues=column_values)
Exemplo n.º 4
0
 def add_attributes(self, key, value):
     check_none(key, "None key found.")
     if value is None:
         if key in self.attributes:
             self.attributes.pop(key)
     else:
         self.attributes[to_bytes(key)] = to_bytes(value)
     return self
Exemplo n.º 5
0
 def __init__(
         self,
         row=None,  # type: Union[str]
         family=None,  # type: Union[None, str]
         qualifier=None,  # type: Union[None, str]
         value=None,  # type: Union[None, str]
 ):
     super(Delete, self).__init__(row, family, qualifier, value)
     check_none(self.row, "Row cannot be none for Delete operation.")
     self.core = TDelete(
         row=self.row,
         columns=_column_format(self.family, self.qualifier),
     )
Exemplo n.º 6
0
 def __init__(
         self,
         row=None,  # type: Union[str]
         family=None,  # type: Union[None, str]
         qualifier=None,  # type: Union[None, str, List[str]]
         value=None,  # type: Union[None, str]
         max_versions=None  # type: Union[None, int]
 ):
     super(Get, self).__init__(row, family, qualifier, value)
     check_none(self.row, "Row cannot be none for Get operation.")
     self.maxVersions = max_versions
     self.core = TGet(row=self.row,
                      columns=_column_format(family, qualifier),
                      timestamp=None,
                      timeRange=None,
                      maxVersions=self.maxVersions)
Exemplo n.º 7
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))