def _filter_schemas(self, env: Environment, query: Select) -> Select: if not self._filters.schema_keys: return query return query.filter( DataBlockMetadata.nominal_schema_key.in_( [d.key for d in self.get_schemas(env)]) # type: ignore )
def _filter_unprocessed( self, env: Environment, query: Select, ) -> Select: if not self._filters.unprocessed_by_node_key: return query if self._filters.allow_cycle: # Only exclude blocks processed as INPUT filter_clause = and_( DataBlockLog.direction == Direction.INPUT, DataFunctionLog.node_key == self._filters.unprocessed_by_node_key, ) else: # No block cycles allowed # Exclude blocks processed as INPUT and blocks outputted filter_clause = (DataFunctionLog.node_key == self._filters.unprocessed_by_node_key) already_processed_drs = ( Query(DataBlockLog.data_block_id).join( DataFunctionLog).filter(filter_clause).filter( DataBlockLog.invalidated == False) # noqa .distinct()) return query.filter( not_(DataBlockMetadata.id.in_(already_processed_drs)))
def _ignore_domains_filter(query: Select) -> Select: """Add a filter to ignore domains we do not fetch history for.""" return query.filter( and_(*[ ~States.entity_id.like(entity_domain) for entity_domain in IGNORE_DOMAINS_ENTITY_ID_LIKE ]))
def _filter_inputs( self, env: Environment, query: Select, ) -> Select: if not self._filters.node_keys: return query eligible_input_drs = ( Query(DataBlockLog.data_block_id).join(SnapLog).filter( DataBlockLog.direction == Direction.OUTPUT, SnapLog.node_key.in_(self._filters.node_keys), ).filter(DataBlockLog.invalidated == False) # noqa .distinct()) return query.filter(DataBlockMetadata.id.in_(eligible_input_drs))
def _filter_data_block(self, env: Environment, query: Select) -> Select: if not self._filters.data_block_id: return query return query.filter( DataBlockMetadata.id == self._filters.data_block_id)