| 29 | namespace { |
| 30 | |
| 31 | avro::ValidSchema GetAvroSchema( |
| 32 | ::google::cloud::bigquery::storage::v1::AvroSchema const& schema) { |
| 33 | // Create a valid reader schema. |
| 34 | std::istringstream schema_bytes(schema.schema(), std::ios::binary); |
| 35 | avro::ValidSchema valid_schema; |
| 36 | avro::compileJsonSchema(schema_bytes, valid_schema); |
| 37 | |
| 38 | // [optional] Write the schema to a file. This could be useful if you want to |
| 39 | // re-use the schema elsewhere. |
| 40 | std::ofstream output("schema.avsc"); |
| 41 | if (output.is_open()) { |
| 42 | valid_schema.toJson(output); |
| 43 | output.close(); |
| 44 | } else { |
| 45 | std::cerr << "Error opening the file!" << std::endl; |
| 46 | } |
| 47 | return valid_schema; |
| 48 | } |
| 49 | |
| 50 | void ProcessRowsInAvroFormat( |
| 51 | avro::ValidSchema const& valid_schema, |