+class PyTablesConnector(dc.Connector):
+ connector_type = 'pytables'
+ connection_class = PyTablesConnection
+
+ operators = {
+ 'eq': '==',
+ 'neq': '!=',
+ 'gt': '>',
+ 'gte': '>=',
+ 'lt': '<',
+ 'lte': '<=',
+ 'and': '&',
+ 'or': '|',
+ 'binary_and': '&',
+ 'binary_or': '|',
+ }
+
+ def _serialize_table_name(self, table_name):
+ return table_name.replace('/', '%')
+
+ def _deserialize_table_name(self, table_name):
+ return table_name.replace('%', '/')
+
+ def table_names(self):
+ return [
+ self._serialize_table_name(node._v_pathname)
+ for node in self.conn.h5file
+ if not(isinstance(node, tables.group.Group))
+ ]
+
+ def table_count(self, table_name):
+ table = self.conn.h5file.get_node(self._deserialize_table_name(table_name))
+ return int(table.nrows)
+
+ def table_info(self, table_name):
+ table = self.conn.h5file.get_node(self._deserialize_table_name(table_name))
+ columns = [
+ {
+ 'name': 'value',
+ 'type': table.dtype.name,
+ }
+ ]
+ if isinstance(table, tables.table.Table):
+ columns = [
+ {
+ 'name': colname,
+ 'type': table.coltypes[colname],
+ }
+ for colname in table.colnames
+ ]
+
+ return [
+ {
+ 'cid': cid,
+ 'name': column['name'],
+ 'type': column['type'],
+ 'notnull': True,
+ 'default_value': None,
+ 'is_pk': False,
+ }
+ for cid, column in enumerate(columns)
+ ]
+
+ def hidden_table_names(self):
+ return []
+
+ def detect_spatialite(self):
+ return False
+
+ def view_names(self):
+ return []
+
+ def detect_fts(self, table_name):
+ return False
+
+ def foreign_keys(self, table_name):
+ return []
+
+ def table_exists(self, table_name):
+ try:
+ self.conn.h5file.get_node(self._deserialize_table_name(table_name))
+ return True
+ except:
+ return False
+
+ def table_definition(self, table_type, table_name):
+ table_name = self._deserialize_table_name(table_name)
+ table = self.conn.h5file.get_node(table_name)
+ colnames = ['value']