def refresh(self, *, universe: DimensionUniverse) -> None: # Docstring inherited from DatasetRecordStorageManager. byName = {} byId = {} c = self._static.dataset_type.columns for row in self._db.query( self._static.dataset_type.select()).fetchall(): name = row[c.name] dimensions = DimensionGraph.decode(row[c.dimensions_encoded], universe=universe) datasetType = DatasetType(name, dimensions, row[c.storage_class]) dynamic = self._db.getExistingTable( makeDynamicTableName(datasetType), makeDynamicTableSpec(datasetType, type(self._collections))) storage = ByDimensionsDatasetRecordStorage( db=self._db, datasetType=datasetType, static=self._static, dynamic=dynamic, dataset_type_id=row["id"], collections=self._collections) byName[datasetType.name] = storage byId[storage._dataset_type_id] = storage self._byName = byName self._byId = byId
def checkGraphInvariants(self, graph): elements = list(graph.elements) for n, element in enumerate(elements): # Ordered comparisons on graphs behave like sets. self.assertLessEqual(element.graph, graph) # Ordered comparisons on elements correspond to the ordering within # a DimensionUniverse (topological, with deterministic # tiebreakers). for other in elements[:n]: self.assertLess(other, element) self.assertLessEqual(other, element) for other in elements[n + 1:]: self.assertGreater(other, element) self.assertGreaterEqual(other, element) if isinstance(element, Dimension): self.assertEqual(element.graph.required, element.required) self.assertEqual(DimensionGraph(self.universe, graph.required), graph) self.assertCountEqual(graph.required, [ dimension for dimension in graph.dimensions if not any(dimension in other.graph.implied for other in graph.elements) ]) self.assertCountEqual(graph.implied, graph.dimensions - graph.required) self.assertCountEqual(graph.dimensions, [ element for element in graph.elements if isinstance(element, Dimension) ]) self.assertCountEqual(graph.dimensions, itertools.chain(graph.required, graph.implied)) # Check primary key traversal order: each element should follow any it # requires, and element that is implied by any other in the graph # follow at least one of those. seen = NamedValueSet() for element in graph.primaryKeyTraversalOrder: with self.subTest(required=graph.required, implied=graph.implied, element=element): seen.add(element) self.assertLessEqual(element.graph.required, seen) if element in graph.implied: self.assertTrue(any(element in s.implied for s in seen)) self.assertCountEqual(seen, graph.elements) # Test encoding and decoding of DimensionGraphs to bytes. encoded = graph.encode() self.assertEqual(len(encoded), self.universe.getEncodeLength()) self.assertEqual( DimensionGraph.decode(encoded, universe=self.universe), graph)