| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- mode: python -*- |
| 3 |
# -*- coding: utf-8 -*- |
| 4 |
|
| 5 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 6 |
# or more contributor license agreements. See the NOTICE file |
| 7 |
# distributed with this work for additional information |
| 8 |
# regarding copyright ownership. The ASF licenses this file |
| 9 |
# to you under the Apache License, Version 2.0 (the |
| 10 |
# "License"); you may not use this file except in compliance |
| 11 |
# with the License. You may obtain a copy of the License at |
| 12 |
# |
| 13 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 |
# |
| 15 |
# Unless required by applicable law or agreed to in writing, software |
| 16 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 |
# See the License for the specific language governing permissions and |
| 19 |
# limitations under the License. |
| 20 |
|
| 21 |
import sys |
| 22 |
|
| 23 |
from avro import datafile |
| 24 |
from avro import io |
| 25 |
from avro import schema |
| 26 |
|
| 27 |
|
| 28 |
DATUM = { |
| 29 |
'intField': 12, |
| 30 |
'longField': 15234324, |
| 31 |
'stringField': 'hey', |
| 32 |
'boolField': True, |
| 33 |
'floatField': 1234.0, |
| 34 |
'doubleField': -1234.0, |
| 35 |
'bytesField': '12312adf', |
| 36 |
'nullField': None, |
| 37 |
'arrayField': [5.0, 0.0, 12.0], |
| 38 |
'mapField': {'a': {'label': 'a'}, 'bee': {'label': 'cee'}}, |
| 39 |
'unionField': 12.0, |
| 40 |
'enumField': 'C', |
| 41 |
'fixedField': b'1019181716151413', |
| 42 |
'recordField': { |
| 43 |
'label': 'blah', |
| 44 |
'children': [{'label': 'inner', 'children': []}], |
| 45 |
}, |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
if __name__ == "__main__": |
| 50 |
interop_schema = schema.Parse(open(sys.argv[1], 'r').read()) |
| 51 |
writer = open(sys.argv[2], 'wb') |
| 52 |
datum_writer = io.DatumWriter() |
| 53 |
# NB: not using compression |
| 54 |
dfw = datafile.DataFileWriter(writer, datum_writer, interop_schema) |
| 55 |
dfw.append(DATUM) |
| 56 |
dfw.close() |