MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / GetAvroSchema

Function GetAvroSchema

bigquery/read/avro/avro_read.cc:31–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29namespace {
30
31avro::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
50void ProcessRowsInAvroFormat(
51 avro::ValidSchema const& valid_schema,

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected