C++ Avro: how to initialize ValidSchema with auto generated schema?
I have an auto generated avro schema which I can encode and decode to avro memory streams.
Now, I would like to write to a file, and I have to some how activate my file writer with the following:
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
#include "avro/ValidSchema.hh"
#include "avro/Compiler.hh"
#include "avro/DataFile.hh
avro::ValidSchema loadSchema(const char* filename)
std::ifstream ifs(filename);
avro::ValidSchema result;
avro::compileJsonSchema(ifs, result);
return result;
int
main()
avro::ValidSchema cpxSchema = loadSchema("cpx.json");
avro::DataFileWriter<c::cpx> dfw("test.bin", cpxSchema);
c::cpx c1;
for (int i = 0; i < 100; i++)
c1.re = i * 100;
c1.im = i + 100;
dfw.write(c1);
dfw.close();
avro::DataFileReader<c::cpx> dfr("test.bin", cpxSchema);
c::cpx c2;
while (dfr.read(c2))
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
So, I have my auto-generated file in auto_generated.hh (command: avrogencpp -i schema.json -o auto_generated.hh -n auto_generated) and I have included all relevant files therein, and short of loading the schema from my json file (which seems to be beside the point if I have already auto-generated everything), I have tried the following:
#include "auto_generated.hh"
int main()
/*
auto_generated::schema() is going to produce the datum which I am
storing.
auto_generated::schema is the struct which contains the data
members which will be set during the course of data output.
*/
//avro::ValidSchema vs; vs.setSchema(auto_generated::schema);
// auto_generated::schema schema = auto_generated::schema();
// avro::ValidSchema vs(schema);
// avro::ValidSchema vs;
// auto_generated::schema schema = auto_generated::schema();
// vs.setSchema(schema);
avro::ValidSchema vs;
avro::Schema s = auto_generated::schema(); // or without ()
vs.setSchema(s);
// etc.
avro::DataFileWriter<auto_generated::schema> dfw("foo",vs);
How do I initialize the ValidSchema and construct the DataFileWriter so as to write my data to a file?
c++ avro
add a comment |
I have an auto generated avro schema which I can encode and decode to avro memory streams.
Now, I would like to write to a file, and I have to some how activate my file writer with the following:
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
#include "avro/ValidSchema.hh"
#include "avro/Compiler.hh"
#include "avro/DataFile.hh
avro::ValidSchema loadSchema(const char* filename)
std::ifstream ifs(filename);
avro::ValidSchema result;
avro::compileJsonSchema(ifs, result);
return result;
int
main()
avro::ValidSchema cpxSchema = loadSchema("cpx.json");
avro::DataFileWriter<c::cpx> dfw("test.bin", cpxSchema);
c::cpx c1;
for (int i = 0; i < 100; i++)
c1.re = i * 100;
c1.im = i + 100;
dfw.write(c1);
dfw.close();
avro::DataFileReader<c::cpx> dfr("test.bin", cpxSchema);
c::cpx c2;
while (dfr.read(c2))
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
So, I have my auto-generated file in auto_generated.hh (command: avrogencpp -i schema.json -o auto_generated.hh -n auto_generated) and I have included all relevant files therein, and short of loading the schema from my json file (which seems to be beside the point if I have already auto-generated everything), I have tried the following:
#include "auto_generated.hh"
int main()
/*
auto_generated::schema() is going to produce the datum which I am
storing.
auto_generated::schema is the struct which contains the data
members which will be set during the course of data output.
*/
//avro::ValidSchema vs; vs.setSchema(auto_generated::schema);
// auto_generated::schema schema = auto_generated::schema();
// avro::ValidSchema vs(schema);
// avro::ValidSchema vs;
// auto_generated::schema schema = auto_generated::schema();
// vs.setSchema(schema);
avro::ValidSchema vs;
avro::Schema s = auto_generated::schema(); // or without ()
vs.setSchema(s);
// etc.
avro::DataFileWriter<auto_generated::schema> dfw("foo",vs);
How do I initialize the ValidSchema and construct the DataFileWriter so as to write my data to a file?
c++ avro
add a comment |
I have an auto generated avro schema which I can encode and decode to avro memory streams.
Now, I would like to write to a file, and I have to some how activate my file writer with the following:
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
#include "avro/ValidSchema.hh"
#include "avro/Compiler.hh"
#include "avro/DataFile.hh
avro::ValidSchema loadSchema(const char* filename)
std::ifstream ifs(filename);
avro::ValidSchema result;
avro::compileJsonSchema(ifs, result);
return result;
int
main()
avro::ValidSchema cpxSchema = loadSchema("cpx.json");
avro::DataFileWriter<c::cpx> dfw("test.bin", cpxSchema);
c::cpx c1;
for (int i = 0; i < 100; i++)
c1.re = i * 100;
c1.im = i + 100;
dfw.write(c1);
dfw.close();
avro::DataFileReader<c::cpx> dfr("test.bin", cpxSchema);
c::cpx c2;
while (dfr.read(c2))
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
So, I have my auto-generated file in auto_generated.hh (command: avrogencpp -i schema.json -o auto_generated.hh -n auto_generated) and I have included all relevant files therein, and short of loading the schema from my json file (which seems to be beside the point if I have already auto-generated everything), I have tried the following:
#include "auto_generated.hh"
int main()
/*
auto_generated::schema() is going to produce the datum which I am
storing.
auto_generated::schema is the struct which contains the data
members which will be set during the course of data output.
*/
//avro::ValidSchema vs; vs.setSchema(auto_generated::schema);
// auto_generated::schema schema = auto_generated::schema();
// avro::ValidSchema vs(schema);
// avro::ValidSchema vs;
// auto_generated::schema schema = auto_generated::schema();
// vs.setSchema(schema);
avro::ValidSchema vs;
avro::Schema s = auto_generated::schema(); // or without ()
vs.setSchema(s);
// etc.
avro::DataFileWriter<auto_generated::schema> dfw("foo",vs);
How do I initialize the ValidSchema and construct the DataFileWriter so as to write my data to a file?
c++ avro
I have an auto generated avro schema which I can encode and decode to avro memory streams.
Now, I would like to write to a file, and I have to some how activate my file writer with the following:
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
#include "avro/ValidSchema.hh"
#include "avro/Compiler.hh"
#include "avro/DataFile.hh
avro::ValidSchema loadSchema(const char* filename)
std::ifstream ifs(filename);
avro::ValidSchema result;
avro::compileJsonSchema(ifs, result);
return result;
int
main()
avro::ValidSchema cpxSchema = loadSchema("cpx.json");
avro::DataFileWriter<c::cpx> dfw("test.bin", cpxSchema);
c::cpx c1;
for (int i = 0; i < 100; i++)
c1.re = i * 100;
c1.im = i + 100;
dfw.write(c1);
dfw.close();
avro::DataFileReader<c::cpx> dfr("test.bin", cpxSchema);
c::cpx c2;
while (dfr.read(c2))
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
So, I have my auto-generated file in auto_generated.hh (command: avrogencpp -i schema.json -o auto_generated.hh -n auto_generated) and I have included all relevant files therein, and short of loading the schema from my json file (which seems to be beside the point if I have already auto-generated everything), I have tried the following:
#include "auto_generated.hh"
int main()
/*
auto_generated::schema() is going to produce the datum which I am
storing.
auto_generated::schema is the struct which contains the data
members which will be set during the course of data output.
*/
//avro::ValidSchema vs; vs.setSchema(auto_generated::schema);
// auto_generated::schema schema = auto_generated::schema();
// avro::ValidSchema vs(schema);
// avro::ValidSchema vs;
// auto_generated::schema schema = auto_generated::schema();
// vs.setSchema(schema);
avro::ValidSchema vs;
avro::Schema s = auto_generated::schema(); // or without ()
vs.setSchema(s);
// etc.
avro::DataFileWriter<auto_generated::schema> dfw("foo",vs);
How do I initialize the ValidSchema and construct the DataFileWriter so as to write my data to a file?
c++ avro
c++ avro
edited Nov 14 '18 at 21:28
bordeo
asked Nov 14 '18 at 21:22
bordeobordeo
7,643114074
7,643114074
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308917%2fc-avro-how-to-initialize-validschema-with-auto-generated-schema%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308917%2fc-avro-how-to-initialize-validschema-with-auto-generated-schema%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown