예제 #1
0
def to_schema(cls):
    """Find an Avro schema object using a Python type."""

    if not isinstance(cls, type):
        cls = type(cls)
    try:
        return cls.__schema__
    except AttributeError:
        probe = PRIMITIVE.get(cls)
        if probe is None:
            raise TypeError('Cannot convert %r to schema.' % cls)
        return _s.PrimitiveSchema(probe)
예제 #2
0
    def test_primitive_types(self):
        primitives = dict(int=1,
                          float=2.0,
                          string='3.0',
                          bytes='4.0'.encode('utf-8'),
                          boolean=True,
                          long=5,
                          double=6.0,
                          null=None)

        for t, v in six.iteritems(primitives):
            test_schema = schema.PrimitiveSchema(t)
            self.assertEquals(self.converter.to_json_object(v, test_schema), v)
            self.assertEquals(self.converter.from_json_object(v, test_schema),
                              v)
예제 #3
0
def make_schema(defn, names=None):
    if callable(getattr(defn, 'get', None)):
        type = defn.get('type')
        name = defn.get('name')

        if type in _s.PRIMITIVE_TYPES:
            if name:
                ns = defn.get('namespace')
                return types.NamedPrimitive(type, name, ns, names)
            return _s.PrimitiveSchema(type)
        elif type == 'omap':
            return types.OMapSchema(defn.get('values'), names)
        elif type == 'set':
            return types.SetSchema(defn.get('items'), names)

    return _make_schema(defn, names)
 def create_primitive_schema(self, primitive_type):
     return schema.PrimitiveSchema(primitive_type)
예제 #5
0
파일: avro_tests.py 프로젝트: mvilim/bamboo
import bamboo_cpp_bind as bamboo_cpp
from bamboo import from_avro

from bamboo_tests.test_utils import df_equality


class PrimitiveSchemas:
    pass


primitive_schemas = PrimitiveSchemas()
if sys.version_info > (3, 0):
    from time import perf_counter as clock

    primitive_schemas.INT = schema.PrimitiveSchema(schema.INT)
    primitive_schemas.LONG = schema.PrimitiveSchema(schema.LONG)
    primitive_schemas.BOOLEAN = schema.PrimitiveSchema(schema.BOOLEAN)
    primitive_schemas.FLOAT = schema.PrimitiveSchema(schema.FLOAT)
    primitive_schemas.DOUBLE = schema.PrimitiveSchema(schema.DOUBLE)
    primitive_schemas.STRING = schema.PrimitiveSchema(schema.STRING)
    primitive_schemas.BYTES = schema.PrimitiveSchema(schema.BYTES)
    primitive_schemas.NULL = schema.PrimitiveSchema(schema.NULL)

    def make_field(field_name, field_schema, names=None):
        return schema.Field(field_schema, field_name, 0, False, names=names, default=None)

    def make_file_writer(out, datum_writer, datum_schema):
        return datafile.DataFileWriter(out, datum_writer, writer_schema=datum_schema)

    def make_array_schema(element_schema):