<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Nifi convert text file consisting of key value pairs to avro in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229466#M191319</link>
    <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/10750/edmundprout.html" nodeid="10750"&gt;@Ed Prout&lt;/A&gt;,&lt;/P&gt;if you are having text file consists of key value pairs, &lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;You need to split the text first as line by line using SplitText Processor&lt;/LI&gt;&lt;LI&gt;use regex to extract values by using ExtractText processor, it will results values as attributes for the each flow file.&lt;/LI&gt;&lt;LI&gt;ReplaceText processor to replace the attributes as contents of the flowfile.&lt;/LI&gt;&lt;LI&gt;InferAvroSchema processor to get schema of the flowfile content.&lt;/LI&gt;&lt;LI&gt;ConvertCSVToAvro processor to convert the flowfile contents into Avro format&lt;/LI&gt;&lt;LI&gt;Publish Kafka processor to publish Avro data to the topic&lt;BR /&gt;&lt;STRONG&gt;Configurations for the Processors:-&lt;BR /&gt;SplitText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34576-splittext.png"&gt;splittext.png&lt;/A&gt;&lt;BR /&gt;ExtractText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34577-extracttext.png"&gt;extracttext.png&lt;BR /&gt;&lt;/A&gt;ReplaceText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34579-replcetext.png"&gt;replcetext.png&lt;/A&gt;&lt;BR /&gt;InferAvroSchema:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34580-inferavroschema.png"&gt;inferavroschema.png&lt;/A&gt;&lt;BR /&gt;ConvertCSVToAvro:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34581-convertcsvtoavro.png"&gt;convertcsvtoavro.png&lt;/A&gt;&lt;BR /&gt;Note:- &lt;/STRONG&gt;&lt;P style="display: inline !important;"&gt;i have used pipe(|) as delimiter in ReplaceText processor for replacement value, you can use any delimiter as you like. But the delimiter needs to match with InferAvroSchema csv header definition&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;i have taken a few key value pairs as input.
Input:- 
status:"400" body_bytes_sent:"174" referer:"google.com" 
Output after convertCSVToAvro Processor:- 
Obj...avro.schema..{
	"type": "record",
	"name": "sample",
	"doc": "Schema generated by Kite",
	"fields": [{
		"name": "status",
		"type": "long",
		"doc": "Type inferred from '400'"
	},
	{
		"name": "body_bytes_sent",
		"type": "long",
		"doc": "Type inferred from '174'"
	},
	{
		"name": "reference",
		"type": "string",
		"doc": "Type inferred from 'google.com'"
	}]
}.avro.codec.snappy...y...Zf....N*...*.8.....google.com*.e...y...Zf....N*
&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Wed, 30 Aug 2017 05:16:02 GMT</pubDate>
    <dc:creator>Shu_ashu</dc:creator>
    <dc:date>2017-08-30T05:16:02Z</dc:date>
    <item>
      <title>Nifi convert text file consisting of key value pairs to avro</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229465#M191318</link>
      <description>&lt;P&gt;I have a text file I'm reading into a Nifi flow, which consists of key value pairs that look like the following:&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;status:"400" body_bytes_sent:"174" referer:"google.com" user_agent:"safari" host:"8.8.4.4" query_string:"devices"&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;status:"400" body_bytes_sent:"172" referer:"yahoo.com" user_agent:"Chrome" host:"8.8.4.3" query_string:"books"&lt;/P&gt;&lt;P&gt;Currently the tailfile processor is successfully reading these files as they are created and append to. However, I want to output them as avro files to Kafka. Any idea what processor(s) I need to convert these text files into avro format in my flow? What would the configuration look like for these processors?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 07:12:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229465#M191318</guid>
      <dc:creator>edmund_prout</dc:creator>
      <dc:date>2017-08-29T07:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi convert text file consisting of key value pairs to avro</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229466#M191319</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/10750/edmundprout.html" nodeid="10750"&gt;@Ed Prout&lt;/A&gt;,&lt;/P&gt;if you are having text file consists of key value pairs, &lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;You need to split the text first as line by line using SplitText Processor&lt;/LI&gt;&lt;LI&gt;use regex to extract values by using ExtractText processor, it will results values as attributes for the each flow file.&lt;/LI&gt;&lt;LI&gt;ReplaceText processor to replace the attributes as contents of the flowfile.&lt;/LI&gt;&lt;LI&gt;InferAvroSchema processor to get schema of the flowfile content.&lt;/LI&gt;&lt;LI&gt;ConvertCSVToAvro processor to convert the flowfile contents into Avro format&lt;/LI&gt;&lt;LI&gt;Publish Kafka processor to publish Avro data to the topic&lt;BR /&gt;&lt;STRONG&gt;Configurations for the Processors:-&lt;BR /&gt;SplitText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34576-splittext.png"&gt;splittext.png&lt;/A&gt;&lt;BR /&gt;ExtractText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34577-extracttext.png"&gt;extracttext.png&lt;BR /&gt;&lt;/A&gt;ReplaceText:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34579-replcetext.png"&gt;replcetext.png&lt;/A&gt;&lt;BR /&gt;InferAvroSchema:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34580-inferavroschema.png"&gt;inferavroschema.png&lt;/A&gt;&lt;BR /&gt;ConvertCSVToAvro:-&lt;BR /&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/34581-convertcsvtoavro.png"&gt;convertcsvtoavro.png&lt;/A&gt;&lt;BR /&gt;Note:- &lt;/STRONG&gt;&lt;P style="display: inline !important;"&gt;i have used pipe(|) as delimiter in ReplaceText processor for replacement value, you can use any delimiter as you like. But the delimiter needs to match with InferAvroSchema csv header definition&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;i have taken a few key value pairs as input.
Input:- 
status:"400" body_bytes_sent:"174" referer:"google.com" 
Output after convertCSVToAvro Processor:- 
Obj...avro.schema..{
	"type": "record",
	"name": "sample",
	"doc": "Schema generated by Kite",
	"fields": [{
		"name": "status",
		"type": "long",
		"doc": "Type inferred from '400'"
	},
	{
		"name": "body_bytes_sent",
		"type": "long",
		"doc": "Type inferred from '174'"
	},
	{
		"name": "reference",
		"type": "string",
		"doc": "Type inferred from 'google.com'"
	}]
}.avro.codec.snappy...y...Zf....N*...*.8.....google.com*.e...y...Zf....N*
&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Wed, 30 Aug 2017 05:16:02 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229466#M191319</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2017-08-30T05:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi convert text file consisting of key value pairs to avro</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229467#M191320</link>
      <description>&lt;P&gt;This worked nicely. Thanks Yash!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 02:59:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-convert-text-file-consisting-of-key-value-pairs-to-avro/m-p/229467#M191320</guid>
      <dc:creator>edmund_prout</dc:creator>
      <dc:date>2017-09-07T02:59:10Z</dc:date>
    </item>
  </channel>
</rss>

