<?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: Conversion from STRING to DATE - CSV to AVRO conversion in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Conversion-from-STRING-to-DATE-CSV-to-AVRO-conversion/m-p/376800#M243010</link>
    <description>&lt;P&gt;I managed to solve my issue using UpdateRecord with Literal Value replacement strategy. I have defined the following EL:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; ${field.value:toDate('dd-MMM-yy'):format('yyyy-MM-dd')}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;On the other hand, the avro schema remained the same, "type": "int" and "logicalType": "date".&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;As for replacing the month letters, I have hard coded a very ugly IF-ELSE statement:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;${field.value:contains('IAN'):ifElse(${field.value:replace('IAN','JAN')},${field.value:contains('IUN'):ifElse(${field.value:replace('IUN','JUN')},${field.value:contains('IUL'):ifElse(${field.value:replace('IUL','JUL')},${field.value})})}):toDate('dd-MMM-yy'):format('yyyy-MM-dd')}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;PS: this link helped me a lot: &lt;A href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" target="_blank"&gt;https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Sep 2023 17:11:44 GMT</pubDate>
    <dc:creator>cotopaul</dc:creator>
    <dc:date>2023-09-25T17:11:44Z</dc:date>
    <item>
      <title>Conversion from STRING to DATE - CSV to AVRO conversion</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Conversion-from-STRING-to-DATE-CSV-to-AVRO-conversion/m-p/376770#M243005</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;So I have been struggling with a data conversion and I can't really figure out how to achieve what I am trying to achieve.&lt;BR /&gt;I have a CSV File which comes into my flow as follows:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 MONTH
0182 Tel set W27 0 2200 31-IAN-22
0183 Apa cai W27 0 2200 30-SEP-22
0185 HDM set MT8 1 2200 28-FEB-22
0185 Apa alo MT8 0 2200 31-OCT-22
0186 HDM set HG5 1 2200 30-IUN-22
0188 Fus alo HG5 1 2200 30-APR-22&lt;/LI-CODE&gt;&lt;P&gt;I am using afterwards an ConvertRecord to transform the CSV into an AVRO File, using the following schema:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
"type": "record",
"name": "nifiRecord",
"namespace": "org.apache.nifi",
"fields": [
{
"name": "COLUMN1",
"type": [
"string",
"null"
]
},
{
"name": "COLUMN2",
"type": [
"string",
"null"
]
},
{
"name": "COLUMN3",
"type": [
"string",
"null"
]
},
{
"name": "COLUMN4",
"type": [
"string",
"null"
]
},
{
"name": "COLUMN5",
"type": [
"string",
"null"
]
},
{
"name": "COLUMN6",
"type": [
"int",
"null"
]
},
{
"name": "MONTH",
"type": [
"string",
"null"
]
}
]
}&lt;/LI-CODE&gt;&lt;P&gt;Now, in the next step, I would like to transform the MONTH from STRING into DATE, so I could insert this value into a BigQuery Table (target column is DATE).&lt;BR /&gt;For that, I am using an UpdateRecord Processor in which I tried several NiFi Expression Language tests, but neither work for me.&lt;BR /&gt;Basically, the schema will have to change into:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
"name": "MONTH",
"type": [
"null",
{
"type": "int",
"logicalType": "date"
}
]
}&lt;/LI-CODE&gt;&lt;P&gt;Unfortunately, when trying to convert that string date into a normal date, i keep on encountering strange errors.&lt;BR /&gt;What I am trying to have is 31-IAN-22 as 31-JAN-22 (or 31-01-22) in the generated AVRO File as an INT-DATE.&lt;BR /&gt;As you can see, the month itself is not necessary written in english.&lt;BR /&gt;I have tried several ELs:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;${field.value:replace('SEP', '09'):toDate('dd-MM-yy'):format('dd-MMM-yy'):toDate('dd-MMM-yy'):toNumber()}
${field.value:toDate('dd-MM-yy'):format('dd-MMM-yy'):toDate('dd-MMM-yy'):toNumber()}
${field.value:toDate('dd-MM-yy'):format('dd-MMM-yy'):toNumber()}
${field.value:toDate('dd-MM-yy'):toNumber()}&lt;/LI-CODE&gt;&lt;P&gt;Every time I receives some strange errors:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;org.apache.nifi.attribute.expression.language.exception.IllegalAttributeException: Cannot parse attribute value as a date; date format: yyyy-mm-dd; attribute value: 30-SEP-23
java.lang.NullPointerException: null
org.apache.nifi.serialization.record.util.IllegalTypeConversionException: Failed Conversion of Field [MONTH] from String [1696021200000] to LocalDate&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Does anybody know how I could achieve this?&lt;BR /&gt;&lt;BR /&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 09:45:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Conversion-from-STRING-to-DATE-CSV-to-AVRO-conversion/m-p/376770#M243005</guid>
      <dc:creator>cotopaul</dc:creator>
      <dc:date>2023-09-25T09:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conversion from STRING to DATE - CSV to AVRO conversion</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Conversion-from-STRING-to-DATE-CSV-to-AVRO-conversion/m-p/376800#M243010</link>
      <description>&lt;P&gt;I managed to solve my issue using UpdateRecord with Literal Value replacement strategy. I have defined the following EL:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; ${field.value:toDate('dd-MMM-yy'):format('yyyy-MM-dd')}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;On the other hand, the avro schema remained the same, "type": "int" and "logicalType": "date".&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;As for replacing the month letters, I have hard coded a very ugly IF-ELSE statement:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;${field.value:contains('IAN'):ifElse(${field.value:replace('IAN','JAN')},${field.value:contains('IUN'):ifElse(${field.value:replace('IUN','JUN')},${field.value:contains('IUL'):ifElse(${field.value:replace('IUL','JUL')},${field.value})})}):toDate('dd-MMM-yy'):format('yyyy-MM-dd')}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;PS: this link helped me a lot: &lt;A href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" target="_blank"&gt;https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 17:11:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Conversion-from-STRING-to-DATE-CSV-to-AVRO-conversion/m-p/376800#M243010</guid>
      <dc:creator>cotopaul</dc:creator>
      <dc:date>2023-09-25T17:11:44Z</dc:date>
    </item>
  </channel>
</rss>

