Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run the examples #15

Open
blueRegen opened this issue Jan 8, 2021 · 2 comments
Open

Unable to run the examples #15

blueRegen opened this issue Jan 8, 2021 · 2 comments

Comments

@blueRegen
Copy link

@0x26res thank you for your guidance.

I am trying to run the sample code in the read me . Not able to. both code. (simple or "another"

import avro.io
from avro import schema
from avro.schema import SchemaFromJSONData as make_avsc_object
from avro_json_serializer import AvroJsonSerializer

PS C:\a\Python\W\CSV> python dumpsa.py
Traceback (most recent call last):
File "dumpsa.py", line 44, in
avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
AttributeError: module 'avro.schema' has no attribute 'make_avsc_object'

PS C:\a\Python\W\CSV> python --version
Python 3.8.6

@romaninozemtsev
Copy link
Contributor

was it in examples?
given how you imported

from avro.schema import SchemaFromJSONData as make_avsc_object

you should do

make_avsc_object(schema_dict, avro.schema.Names())

without avro.schema

@blueRegen
Copy link
Author

blueRegen commented Jan 24, 2021

Still unable to run.

#########Code################

import avro.io
from avro import schema
from avro.schema import SchemaFromJSONData as make_avsc_object
from avro_json_serializer import AvroJsonSerializer

need to serialize this data

data = {
"ffloat": 1.0,
"funion_null": None,
"flong": 1,
"fdouble": 2.0,
"ffixed": "1234567890123456",
"fint": 1,
"fstring": "hi there",
"frec": {
"subfint": 2
}
}

according to this schema:

schema_dict = {
"fields": [{"name": "fint", "type": "int"},
{"name": "flong", "type": "long"},
{"name": "fstring", "type": "string"},
{"name": "ffixed",
"size": 16,
"type": {"name": "fixed_16", "size": 16, "type": "fixed"}},
{"name": "frec",
"type": {"fields": [{"name": "subfint", "type": "int"}],
"name": "Rec",
"type": "record"}},
{"name": "funion_null", "type": ["int", "null"]},
{"name": "ffloat", "type": "float"},
{"name": "fdouble", "type": "double"}],
"name": "all_field",
"namespace": "com.some.thing",
"type": "record"
}

avro_schema = make_avsc_object(schema_dict, avro.schema.Names())

serializer = AvroJsonSerializer(avro_schema)
json_str = serializer.to_json(data)

print (json_str)

################## ERROR ##################

PS C:\a\Python\ven\ven1\w\json> python jdumps1.py
Traceback (most recent call last):
File "jdumps1.py", line 47, in
json_str = serializer.to_json(data)
File "C:\a\Python\lib\site-packages\avro_json_serializer_init_.py", line 226, in to_json
result = self.to_ordered_dict(datum)
File "C:\a\Python\lib\site-packages\avro_json_serializer_init_.py", line 223, in to_ordered_dict
return self._process_data(self.avro_schema, datum)
File "C:\a\Python\lib\site-packages\avro_json_serializer_init
.py", line 140, in _process_data
raise AvroTypeException(schema, datum)
avro.io.AvroTypeException: The datum {'ffloat': 1.0, 'funion_null': None, 'flong': 1, 'fdouble': 2.0, 'ffixed': '1234567890123456', 'fint': 1, 'fstring': 'hi there', 'frec': {'subfint': 2}} is not an example of the schema {
"type": "record",
"name": "all_field",
"namespace": "com.some.thing",
"fields": [
{
"type": "int",
"name": "fint"
},
{
"type": "long",
"name": "flong"
},
{
"type": "string",
"name": "fstring"
},
{
"size": 16,
"type": {
"type": "fixed",
"name": "fixed_16",
"namespace": "com.some.thing",
"size": 16
},
"name": "ffixed"
},
{
"type": {
"type": "record",
"name": "Rec",
"namespace": "com.some.thing",
"fields": [
{
"type": "int",
"name": "subfint"
}
]
},
"name": "frec"
},
{
"type": [
"int",
"null"
],
"name": "funion_null"
},
{
"type": "float",
"name": "ffloat"
},
{
"type": "double",
"name": "fdouble"
}
]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants