示例#1
0
    def writers_schema(self, parsed_writer_schema):
        '''Take a wrtiers schema object from the old avro API and run validation
        and schema reolution (if applicable)

        Since the old API would set this after object construction, we hook
        here so we can run schema validation and resolution once on assignment.
        This also makes the reader function for the resolved schema and uses
        that for data reading.
        '''
        self._writers_schema = parsed_writer_schema

        # create the reader function from the schema
        if hasattr(self, 'readers_schema'):
            # to_json is a terrible method name for something
            # that returns a python dict! :/
            resolved_schema = resolve(parsed_writer_schema.to_json(),
                                      self.readers_schema.to_json())
        else:
            # if no reader schema, then the resolved schema is just the writers
            # schema
            resolved_schema = parsed_writer_schema.to_json()
            self.readers_schema = parsed_writer_schema
        self.read_datum = get_reader(resolved_schema)

        # schema matching
        if not FastDatumReader.match_schemas(self.writers_schema,
                                             self.readers_schema):
            fail_msg = 'Schemas do not match.'
            raise SchemaResolutionException(fail_msg, self.writers_schema,
                                            self.readers_schema)
示例#2
0
 def read_data(self, writers_schema, readers_schema, decoder):
     resolved_schema = resolve(writers_schema.to_json(),
                               readers_schema.to_json())
     # try:
     #     datum_reader = self.schema_cache[str(schema)]
     # except KeyError:
     datum_reader = get_reader(resolved_schema)
     # self.schema_cache[str(schema)] = datum_reader
     return datum_reader(decoder.reader)
 def resolve_write_reader(self):
     with self.assertRaises(exception) as context:
         resolved = resolve(writer, reader)
 def resolve_write_reader(self):
     resolved = resolve(writer, reader)
     self.assertEqual(resolved, expected)