+class PyTablesConnection(dc.Connection):
+ def __init__(self, path, connector):
+ super().__init__(path, connector)
+ self.h5file = tables.open_file(path)
+
+
+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