Exemplo n.º 1
0
    def __init__(self, schema: AggregateSchema, identity: str,
                 evaluation_context: EvaluationContext) -> None:
        super().__init__(schema, identity, evaluation_context)

        self._dimension_fields: Dict[str, Field] = {
            name: TypeLoader.load_item(item_schema.type)(item_schema, self._evaluation_context)
            for name, item_schema in self._schema.dimension_fields.items()
        }

        # Also add the dimension fields to regular fields so that they get processed by other
        # functions such as snapshot, restore, etc as per normal.
        # We don't add self._dimension_fields here as we want these fields to be separate objects.
        self._fields.update({
            name: TypeLoader.load_item(item_schema.type)(item_schema, self._evaluation_context)
            for name, item_schema in self._schema.dimension_fields.items()
        })
        self._existing_key = None
Exemplo n.º 2
0
 def __init__(self, schema: BaseSchemaCollection,
              evaluation_context: EvaluationContext) -> None:
     super().__init__(schema, evaluation_context)
     self._fields: Dict[str, Type[BaseItem]] = {
         name:
         TypeLoader.load_item(item_schema.type)(item_schema,
                                                self._evaluation_context)
         for name, item_schema in self._schema.nested_schema.items()
     }
Exemplo n.º 3
0
 def __init__(self, schema: TransformerSchema, identity: str) -> None:
     super().__init__(schema, copy(schema.schema_context.context))
     # Load the nested items into the item
     self._aggregates: Dict[str, Aggregate] = {
         name: TypeLoader.load_item(item_schema.type)(item_schema, identity,
                                                      self._evaluation_context)
         for name, item_schema in schema.nested_schema.items()
     }
     self._identity = identity
     self._evaluation_context.global_add('identity', self._identity)
     self._evaluation_context.global_context.merge(self._nested_items)
Exemplo n.º 4
0
 def _load_blocks(self, blocks: List[Tuple[Key,
                                           Any]]) -> List[TimeAggregate]:
     """
     Converts [(Key, block)] to [BlockAggregate]
     :param blocks: List of (Key, block) blocks.
     :return: List of BlockAggregate
     """
     return [
         TypeLoader.load_item(self._schema.source.type)(
             self._schema.source, self._identity,
             EvaluationContext()).run_restore(block)
         for (_, block) in blocks
     ]
Exemplo n.º 5
0
    def __init__(self, schema: AggregateSchema, identity: str,
                 evaluation_context: EvaluationContext) -> None:
        """
        Initializes the data group with the inherited context and adds
        its own nested items into the local context for execution
        :param schema: Schema for initializing the data group
        :param evaluation_context: Context dictionary for evaluation
        """
        super().__init__(schema, evaluation_context)
        self._identity = identity

        self._fields: Dict[str, Type[BaseItem]] = {
            name: TypeLoader.load_item(item_schema.type)(item_schema, self._evaluation_context)
            for name, item_schema in self._schema.nested_schema.items()
        }
        self._store = None
        if self._schema.store_schema:
            self._store = self._schema.schema_loader.get_store(
                self._schema.store_schema.fully_qualified_name)
Exemplo n.º 6
0
    def get_store(self, fully_qualified_name: str) -> Optional['Store']:
        """
        Used to generate a store object from the given fully_qualified_name.
        :param fully_qualified_name: The fully qualified name of the store object needed.
        :return: An initialized store object
        """

        if fully_qualified_name not in self._store_cache:
            schema = self.get_schema_object(fully_qualified_name)
            if not schema:
                return None

            if Type.is_store_type(schema.type):
                self._store_cache[fully_qualified_name] = TypeLoader.load_item(
                    schema.type)(schema)
            else:
                self.add_errors(
                    InvalidTypeError(fully_qualified_name, {}, ATTRIBUTE_TYPE,
                                     InvalidTypeError.Reason.INCORRECT_BASE,
                                     schema.type,
                                     InvalidTypeError.BaseTypes.STORE))

        return self._store_cache.get(fully_qualified_name, None)
Exemplo n.º 7
0
    def get_schema_object(self, fully_qualified_name: str) -> 'BaseSchema':
        """
        Used to generate a schema object from the given fully_qualified_name.
        :param fully_qualified_name: The fully qualified name of the object needed.
        :return: An initialized schema object
        """

        if fully_qualified_name not in self._schema_cache:
            spec = self.get_schema_spec(fully_qualified_name)

            if spec:
                try:
                    self._schema_cache[
                        fully_qualified_name] = TypeLoader.load_schema(
                            spec.get(ATTRIBUTE_TYPE,
                                     None))(fully_qualified_name, self)
                except TypeLoaderError as err:
                    self.add_errors(
                        InvalidTypeError(
                            fully_qualified_name, spec, ATTRIBUTE_TYPE,
                            InvalidTypeError.Reason.TYPE_NOT_LOADED,
                            err.type_class_name))

        return self._schema_cache.get(fully_qualified_name, None)