

{"id":22264,"date":"2018-08-09T07:15:36","date_gmt":"2018-08-09T07:15:36","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=22264"},"modified":"2018-08-09T07:15:36","modified_gmt":"2018-08-09T07:15:36","slug":"avro-reference-api","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/","title":{"rendered":"AVRO Reference API &#8211; Classes and Methods"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Today, in this <strong>Apache Avro tutorial<\/strong>, we will see Avro reference API. There are some classes and methods which we use in the serialization as well as deserialization of Avro schemas. <\/span><\/p>\n<p><span style=\"font-weight: 400\">So, in this Avro article, &#8220;AVRO Reference API: Classes and Methods&#8221; we will learn all such important classes and methods in detail. <\/span><\/p>\n<p><span style=\"font-weight: 400\">So, let&#8217;s begin with Introduction to AVRO Reference API.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">What is AVRO Reference API<\/span><\/h2>\n<p><span style=\"font-weight: 400\">So, here is the list of some important classes and methods or AVRO Reference API:<\/span><\/p>\n<h3><span style=\"font-weight: 400\">a. SpecificDatumWriter Class<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The class &#8220;SpecificDatumWriter Class&#8221; belongs to org.apache.avro.specific package.\u00a0 In order to convert <strong>Java objects<\/strong> into an in-memory serialized format, this class implements\u00a0an interface called DatumWriter interface. Basically, that interface play role of a converter here.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SpecificDatumWriter(Schema schema)<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Method<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SpecificData getSpecificData(): <\/span><br \/>\n<span style=\"font-weight: 400\">This method\u00a0gets the SpecificData implementation, which the writer uses.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">b. SpecificDatumReader Class<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The class &#8220;SpecificDatumReader Class&#8221; belongs to <strong>org.apache.avro.specific package.<\/strong> Basically, in order to read the data of a schema and to determine in-memory data representation, this method implements\u00a0a DatumReader interface. In addition, this class supports generated java classes.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\">SpecificDatumReader(Schema schema):\u00a0 <\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Where both the writer&#8217;s and reader&#8217;s schemas are the same, this constructor constructs.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> SpecificData getSpecificData():\u00a0<\/span><\/li>\n<\/ol>\n<p>This method gets the contained SpecificData.<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> void setSchema(Schema actual):<\/span><\/li>\n<\/ol>\n<p>In order to set the writer&#8217;s schema, we use this method.<\/p>\n<h3><span style=\"font-weight: 400\">c. DataFileWriter<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Simply put, it instantiates DataFileWrite for emp class. Moreover, along with the schema in a file, this class writes a sequence of serialized records of data conforming to a schema.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">DataFileWriter(DatumWriter&lt;D&gt; dout)<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> void append(D datum):\u00a0<\/span><\/li>\n<\/ol>\n<p>This method appends a datum to a file<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> DataFileWriter&lt;D&gt; appendTo(File file):\u00a0<\/span><\/li>\n<\/ol>\n<p>In order to open a writer appending to an existing file, we use this method.<\/p>\n<h3><span style=\"font-weight: 400\">d. Data FileReader<\/span><\/h3>\n<p><span style=\"font-weight: 400\">In order to access the files which are written with DataFileWriter randomly, we use this class. Basically, it inherits the class DataFileStream.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">DataFileReader(File file, DatumReader&lt;D&gt; reader))<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> next():\u00a0<\/span><\/li>\n<\/ol>\n<p>This method reads the next datum in the file.<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> Boolean hasNext():<\/span><\/li>\n<\/ol>\n<p>Whereas, this method gets true if more entries remain in this file.<\/p>\n<h3><span style=\"font-weight: 400\">e. Class Schema.parser<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Especially, for JSON-format schemas, this class is a parser. It\u00a0consists of various methods to parse the schema and this class belongs to the package: org.apache.avro.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Schema.Parser()<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> parse (File file):\u00a0<\/span><\/li>\n<\/ol>\n<p>Basically, this method parses the schema which is provided in the given file.<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> parse (InputStream in):<\/span><\/li>\n<\/ol>\n<p>Moreover, this method [arses the schema which is provided in the given InputStream.<\/p>\n<ol start=\"3\">\n<li><span style=\"font-weight: 400\"> parse (String s):\u00a0<\/span><\/li>\n<\/ol>\n<p>And, this method parses the schema which is provided in the given String.<\/p>\n<h3><span style=\"font-weight: 400\">f. Interface GenricRecord<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The &#8220;Interface GenricRecord&#8221; offers methods to access the fields by name and index as well.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> Object get(String key):\u00a0<\/span><\/li>\n<\/ol>\n<p>The method &#8220;Object get(String key)&#8221;, gets the value of a field given.<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> void put(String key, Object v):\u00a0<\/span><\/li>\n<\/ol>\n<p>And this method sets the value of a field given its name.<\/p>\n<h3><span style=\"font-weight: 400\">g. Class GenericData.Record<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constructor<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">GenericData.Record(Schema schema)<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Methods<\/span><\/li>\n<\/ul>\n<ol>\n<li><span style=\"font-weight: 400\"> Object get(String key)<\/span><\/li>\n<\/ol>\n<p>Basically,\u00a0this method gets the value of a field of the given name.<\/p>\n<ol start=\"2\">\n<li><span style=\"font-weight: 400\"> Schema getSchema()<\/span><\/li>\n<\/ol>\n<p>Further, this method\u00a0gets the schema of this instance.<\/p>\n<ol start=\"3\">\n<li><span style=\"font-weight: 400\"> void put(int i, Object v)<\/span><\/li>\n<\/ol>\n<p>Moreover, this method sets the value of a field, given its position in the schema.<\/p>\n<ol start=\"4\">\n<li><span style=\"font-weight: 400\"> void put(String key, Object value)<\/span><\/li>\n<\/ol>\n<p>And, this method sets the value of a field, given its name.<br \/>\nSo, this was all in Apache Avro Reference API. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion: AVRO Reference API<\/span><\/h2>\n<p>Hence, in this Avro reference AOI tutorial, we have seen all\u00a0the important Classes and Methods which we use in the serialization as well as deserialization of Avro schemas, in detail. Hope it helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, in this Apache Avro tutorial, we will see Avro reference API. There are some classes and methods which we use in the serialization as well as deserialization of Avro schemas. So, in this&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":22323,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[743,1301,2526,2532,2537,3308,3534,6876,8685,13182,13183],"class_list":["post-22264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-avro","tag-apache-avro-tutorial","tag-avro-reference-api","tag-class-genericdata-record","tag-class-schema-parser","tag-classes-in-apache-avro","tag-data-filereader","tag-datafilewriter","tag-interface-genricrecord","tag-methods-in-apache-avro","tag-specificdatumreader-class","tag-specificdatumwriter-class"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AVRO Reference API - Classes and Methods - DataFlair<\/title>\n<meta name=\"description\" content=\"Apache Avro reference API:classes in Avro,Methods in Avro,Reference Api in Avro,avro example,Apache Avro tutorial, Class GenericData.Record\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/avro-reference-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AVRO Reference API - Classes and Methods - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Apache Avro reference API:classes in Avro,Methods in Avro,Reference Api in Avro,avro example,Apache Avro tutorial, Class GenericData.Record\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/avro-reference-api\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-09T07:15:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AVRO Reference API - Classes and Methods - DataFlair","description":"Apache Avro reference API:classes in Avro,Methods in Avro,Reference Api in Avro,avro example,Apache Avro tutorial, Class GenericData.Record","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/","og_locale":"en_US","og_type":"article","og_title":"AVRO Reference API - Classes and Methods - DataFlair","og_description":"Apache Avro reference API:classes in Avro,Methods in Avro,Reference Api in Avro,avro example,Apache Avro tutorial, Class GenericData.Record","og_url":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-08-09T07:15:36+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"AVRO Reference API &#8211; Classes and Methods","datePublished":"2018-08-09T07:15:36+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/"},"wordCount":637,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg","keywords":["Apache Avro Tutorial","AVRO Reference API","Class GenericData.Record","Class Schema.parser","Classes in Apache Avro","Data FileReader","DataFileWriter","Interface GenricRecord","Methods in Apache Avro","SpecificDatumReader Class","SpecificDatumWriter Class"],"articleSection":["AVRO Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/avro-reference-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/","url":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/","name":"AVRO Reference API - Classes and Methods - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg","datePublished":"2018-08-09T07:15:36+00:00","description":"Apache Avro reference API:classes in Avro,Methods in Avro,Reference Api in Avro,avro example,Apache Avro tutorial, Class GenericData.Record","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/avro-reference-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/AVRO-Reference-API-01.jpg","width":1200,"height":628,"caption":"AVRO Reference API - Classes and Methods"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/avro-reference-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"AVRO Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/avro\/"},{"@type":"ListItem","position":3,"name":"AVRO Reference API &#8211; Classes and Methods"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=22264"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22264\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/22323"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=22264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=22264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=22264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}