How to use the avro.schema.make_avsc_object function in avro

To help you get started, we’ve selected a few avro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NCI-GDC / psqlgraph / test / test_avro_validation.py View on Github external
def test_edge_validation_with_union_schema_fails(self):
        schema_dicts = [self.make_avro_edge_schema("derived_from",
                                                   {"aliquot": "analyte"}),
                        self.make_avro_edge_schema("member_of",
                                                   {"file": "archive"})]
        schema = make_avsc_object(schema_dicts)
        self.driver.edge_validator = AvroEdgeValidator(schema)
        self.insert_edge("derived_from", "aliquot", "analyte")
        self.insert_edge("member_of", "file", "archive")
        with self.assertRaises(ValidationError):
            self.insert_edge("random_edge", "file", "archive")
        with self.assertRaises(ValidationError):
            self.insert_edge("member_of", "file", "analyte")
github NCI-GDC / psqlgraph / test / test_avro_validation.py View on Github external
def test_edge_validation_with_union_schema_succeeds(self):
        schema_dicts = [self.make_avro_edge_schema("derived_from",
                                                   {"aliquot": "analyte"}),
                        self.make_avro_edge_schema("member_of",
                                                   {"file": "archive"})]
        schema = make_avsc_object(schema_dicts)
        self.driver.edge_validator = AvroEdgeValidator(schema)
        self.insert_edge("derived_from", "aliquot", "analyte")
        self.insert_edge("member_of", "file", "archive")
github universalcore / elastic-git / elasticgit / commands / avro.py View on Github external
>>> from elasticgit.commands.avro import deserialize
    >>> schema = {
    ... 'name': 'Foo',
    ... 'type': 'record',
    ... 'fields': [{
    ...         'name': 'some_field',
    ...         'type': 'int',
    ...     }]
    ... }
    >>> deserialize(schema)
    
    >>>

    """
    schema_loader = SchemaLoader()
    schema = avro.schema.make_avsc_object(data, avro.schema.Names()).to_json()
    model_code = schema_loader.generate_model(schema)
    model_name = schema['name']

    if module_name is not None:
        mod = imp.new_module(module_name)
        scope = mod.__dict__
    else:
        scope = {}

    exec model_code in scope

    return scope.pop(model_name)
github cloudera / hue / desktop / core / ext-py / avro-1.8.2 / src / avro / protocol.py View on Github external
def _parse_response(self, response, names):
    if isinstance(response, basestring) and names.has_name(response, None):
      return names.get_name(response, None)
    else:
      return schema.make_avsc_object(response, names)
github common-workflow-language / common-workflow-language / reference / cwltool / process.py View on Github external
c["type"] = c["type"]

                if key == "inputs":
                    self.inputs_record_schema["fields"].append(c)
                elif key == "outputs":
                    self.outputs_record_schema["fields"].append(c)

        try:
            self.inputs_record_schema = schema_salad.schema.make_valid_avro(self.inputs_record_schema, {}, set())
            avro.schema.make_avsc_object(self.inputs_record_schema, self.names)
        except avro.schema.SchemaParseException as e:
            raise validate.ValidationException("Got error `%s` while prcoessing inputs of %s:\n%s" % (str(e), self.tool["id"], json.dumps(self.inputs_record_schema, indent=4)))

        try:
            self.outputs_record_schema = schema_salad.schema.make_valid_avro(self.outputs_record_schema, {}, set())
            avro.schema.make_avsc_object(self.outputs_record_schema, self.names)
        except avro.schema.SchemaParseException as e:
            raise validate.ValidationException("Got error `%s` while prcoessing outputs of %s:\n%s" % (str(e), self.tool["id"], json.dumps(self.outputs_record_schema, indent=4)))
github Yelp / data_pipeline_avro_util / data_pipeline_avro_util / util.py View on Github external
def get_avro_schema_object(schema):
    """ Helper function to simplify dealing with the three ways avro schema may
        be represented:
        - a json string
        - a dictionary (parsed json string)
        - a parsed `avro.schema.Schema` object

        In all cases this returns the `avro.schema.Schema` object form
    """
    if isinstance(schema, avro.schema.Schema):
        return schema
    elif isinstance(schema, basestring):
        return avro.schema.parse(schema)
    else:
        return avro.schema.make_avsc_object(schema)
github Yelp / schematizer / schematizer / models / avro_schema.py View on Github external
def _create_schema_elements_from_json(cls, avro_schema_json):
        avro_schema_obj = schema.make_avsc_object(avro_schema_json)
        schema_elements = []
        schema_elements_queue = deque([(avro_schema_obj, None)])
        while schema_elements_queue:
            schema_obj, parent_key = schema_elements_queue.popleft()
            element_cls = _schema_to_element_map.get(schema_obj.__class__)
            if not element_cls:
                continue

            _schema_element = element_cls(schema_obj, parent_key)
            schema_elements.append((_schema_element, schema_obj))
            parent_key = _schema_element.key
            for nested_schema in _schema_element.nested_schema_objects:
                schema_elements_queue.append((nested_schema, parent_key))
        return schema_elements
github Yelp / data_pipeline_avro_util / data_pipeline_avro_util / avro_builder.py View on Github external
def end(self):
        if not self._schema_tracker:
            # this is the top level schema; do the schema validation
            schema_obj = schema.make_avsc_object(self._schema_json)
            self._schema_json = None
            return schema_obj.to_json()

        current_schema_json = self._schema_json
        self._restore_current_schema()
        return current_schema_json
github common-workflow-language / cwltool / reference / cwltool / avro_ld / schema.py View on Github external
def schema(j):
    names = avro.schema.Names()
    j = extend_avro(j)
    for t in j:
        if not t.get("abstract"):
            avro.schema.make_avsc_object(t, names)
    return names
github common-workflow-language / common-workflow-language / reference / cwltool / process.py View on Github external
if "type" not in c:
                    raise validate.ValidationException("Missing `type` in parameter `%s`" % c["name"])

                if "default" in c and "null" not in aslist(c["type"]):
                    c["type"] = ["null"] + aslist(c["type"])
                else:
                    c["type"] = c["type"]

                if key == "inputs":
                    self.inputs_record_schema["fields"].append(c)
                elif key == "outputs":
                    self.outputs_record_schema["fields"].append(c)

        try:
            self.inputs_record_schema = schema_salad.schema.make_valid_avro(self.inputs_record_schema, {}, set())
            avro.schema.make_avsc_object(self.inputs_record_schema, self.names)
        except avro.schema.SchemaParseException as e:
            raise validate.ValidationException("Got error `%s` while prcoessing inputs of %s:\n%s" % (str(e), self.tool["id"], json.dumps(self.inputs_record_schema, indent=4)))

        try:
            self.outputs_record_schema = schema_salad.schema.make_valid_avro(self.outputs_record_schema, {}, set())
            avro.schema.make_avsc_object(self.outputs_record_schema, self.names)
        except avro.schema.SchemaParseException as e:
            raise validate.ValidationException("Got error `%s` while prcoessing outputs of %s:\n%s" % (str(e), self.tool["id"], json.dumps(self.outputs_record_schema, indent=4)))