<?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: Convert the Unix time to date time using QueryRecord in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392987#M248304</link>
    <description>&lt;P&gt;Thanks a lot,&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp; for the technical suggestion!&lt;/P&gt;&lt;P&gt;Please find below our comments on both the proposed solutions,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;Solution 1: Using Sql Calcite function TIMESTAMPADD&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This method does not perform the conversion. Please refer to the below screenshot for more details and let us know if we are making any mistakes.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_0-1725340839021.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41634i511131EB94036C19/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_0-1725340839021.png" alt="NagendraKumar_0-1725340839021.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It returned the same output&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_1-1725340917324.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41635i0DE15E69642EEACE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_1-1725340917324.png" alt="NagendraKumar_1-1725340917324.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;Solution 2: Using Expression Language&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This solution works fine when we pass the data directly into the query record. However, we wanted to apply this conversion for the batch of data in the CSV input file. Please refer below for the complete flow&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Complete NiF Flow :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_2-1725341106471.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41636i064744E8E239DA31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_2-1725341106471.png" alt="NagendraKumar_2-1725341106471.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Input File :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Id,username,load_date&lt;BR /&gt;1,test@test.com,1725000090&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Error Message :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;QueryRecord[id=2cc603e4-0191-1000-f3c7-ef830564cf72] Unable to query FlowFile[filename=convertfunctionsample.csv] due to org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: select '${literal(load_date):multiply(1000):format('yyyy-MM-dd HH:mm:ss')}' mytimestamp from flowfile due to Unexpected token 'load_date' at line 1, column 10. Query: ${literal(load_date):multiply(1000):format(yyyy-MM-dd HH:mm:ss)}: {}&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_3-1725341231875.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41637i1187D999B285B13B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_3-1725341231875.png" alt="NagendraKumar_3-1725341231875.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please help us with your expertise if there is any way to pass the column from the flowfile to the&amp;nbsp;Expression language. Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2024 05:41:56 GMT</pubDate>
    <dc:creator>NagendraKumar</dc:creator>
    <dc:date>2024-09-03T05:41:56Z</dc:date>
    <item>
      <title>Convert the Unix time to date time using QueryRecord</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392857#M248275</link>
      <description>&lt;P&gt;We are working on converting the Unix time into date-time using the&amp;nbsp;QueryRecord processor. We understand that&amp;nbsp;QueryRecord is built with the&amp;nbsp;calcite SQL syntax and tried to use the&amp;nbsp;DATE_FROM_UNIX_DATE function. We are receiving the below error. Please help us resolve this issue with your expertise.&lt;/P&gt;&lt;P&gt;We can achieve this conversion using the update attribute but we wanted this as part of the Query record as we wanted to apply this conversion on the completed dataset.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;SELECT DATE_FROM_UNIX_DATE(1724851471) FROM FLOWFile&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Error :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;QueryRecord[id=2cc603e4-0191-1000-f3c7-ef830564cf72] Unable to query FlowFile[filename=convertfunctionsample.csv] due to org.apache.nifi.processor.exception.ProcessException: java.sql.SQLException: Error while preparing statement [SELECT DATE_FROM_UNIX_DATE(1724851471) FROM FLOWFile]&lt;BR /&gt;- Caused by: java.sql.SQLException: Error while preparing statement [SELECT DATE_FROM_UNIX_DATE(1724851471) FROM FLOWFile]&lt;BR /&gt;- Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 38: No match found for function signature DATE_FROM_UNIX_DATE(&amp;lt;NUMERIC&amp;gt;)&lt;BR /&gt;- Caused by: org.apache.calcite.sql.validate.SqlValidatorException: No match found for function signature DATE_FROM_UNIX_DATE(&amp;lt;NUMERIC&amp;gt;): {}&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_0-1725026832656.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41616iE93CD14A4E95445B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_0-1725026832656.png" alt="NagendraKumar_0-1725026832656.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 14:15:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392857#M248275</guid>
      <dc:creator>NagendraKumar</dc:creator>
      <dc:date>2024-08-30T14:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the Unix time to date time using QueryRecord</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392919#M248283</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/112177"&gt;@NagendraKumar&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;Im not sure that you can use the function "DATE_FROM_UNIX_DATE"&amp;nbsp; since according to the sqlcalcite &lt;A href="https://calcite.apache.org/docs/reference.html" target="_self"&gt;documentation&lt;/A&gt; its not a standard function. If I may recommend two approaches to solve this problem:&lt;/P&gt;&lt;P&gt;1- Using Sql Calcite function TIMESTAMPADD:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select TIMESTAMPADD(SECOND, 1724851471,cast('1970-01-01 00:00:00' as timestamp)) mytimestamp from flowfile&lt;/LI-CODE&gt;&lt;P&gt;2- Using Expression Language:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select '${literal('1724851471'):multiply(1000):format('yyyy-MM-dd HH:mm:ss')}' mytimestamp from flowfile&lt;/LI-CODE&gt;&lt;P&gt;In both cases you have to be aware of the timezone that the timestamp is converted into I think one uses local while the other uses GMT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;If it helps please accept the solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 31 Aug 2024 17:19:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392919#M248283</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-08-31T17:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the Unix time to date time using QueryRecord</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392987#M248304</link>
      <description>&lt;P&gt;Thanks a lot,&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp; for the technical suggestion!&lt;/P&gt;&lt;P&gt;Please find below our comments on both the proposed solutions,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;Solution 1: Using Sql Calcite function TIMESTAMPADD&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This method does not perform the conversion. Please refer to the below screenshot for more details and let us know if we are making any mistakes.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_0-1725340839021.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41634i511131EB94036C19/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_0-1725340839021.png" alt="NagendraKumar_0-1725340839021.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It returned the same output&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_1-1725340917324.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41635i0DE15E69642EEACE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_1-1725340917324.png" alt="NagendraKumar_1-1725340917324.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;Solution 2: Using Expression Language&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This solution works fine when we pass the data directly into the query record. However, we wanted to apply this conversion for the batch of data in the CSV input file. Please refer below for the complete flow&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Complete NiF Flow :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_2-1725341106471.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41636i064744E8E239DA31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_2-1725341106471.png" alt="NagendraKumar_2-1725341106471.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Input File :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Id,username,load_date&lt;BR /&gt;1,test@test.com,1725000090&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Error Message :&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;QueryRecord[id=2cc603e4-0191-1000-f3c7-ef830564cf72] Unable to query FlowFile[filename=convertfunctionsample.csv] due to org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: select '${literal(load_date):multiply(1000):format('yyyy-MM-dd HH:mm:ss')}' mytimestamp from flowfile due to Unexpected token 'load_date' at line 1, column 10. Query: ${literal(load_date):multiply(1000):format(yyyy-MM-dd HH:mm:ss)}: {}&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NagendraKumar_3-1725341231875.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41637i1187D999B285B13B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NagendraKumar_3-1725341231875.png" alt="NagendraKumar_3-1725341231875.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please help us with your expertise if there is any way to pass the column from the flowfile to the&amp;nbsp;Expression language. Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 05:41:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392987#M248304</guid>
      <dc:creator>NagendraKumar</dc:creator>
      <dc:date>2024-09-03T05:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the Unix time to date time using QueryRecord</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392999#M248305</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My Apologies. I think I forgot to mention that in both cases you need to set the Timestamp Format in the CSVRecordWriter to the target format as follows since by default it converts the datetime to epoch time:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1725346972085.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41638i109933CEFDCBA04E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1725346972085.png" alt="SAMSAL_0-1725346972085.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The point from the conversion in the QueryRecord is to tell the CSVReader that this is a datetime , however without setting the format in the writer it was converting it back to epoch time as the &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.26.0/org.apache.nifi.csv.CSVRecordSetWriter/index.html" target="_self"&gt;documentation&lt;/A&gt; states:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_1-1725347222813.png" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41639i7BF6D2BB88EAD11B/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAMSAL_1-1725347222813.png" alt="SAMSAL_1-1725347222813.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Setting the format there is critical to get the desired output.&lt;/P&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 20:23:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/392999#M248305</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-09-03T20:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert the Unix time to date time using QueryRecord</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/393424#M248449</link>
      <description>&lt;P&gt;Thanks a lot,&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;! The proposed solution worked for us.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2024 13:22:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-the-Unix-time-to-date-time-using-QueryRecord/m-p/393424#M248449</guid>
      <dc:creator>NagendraKumar</dc:creator>
      <dc:date>2024-09-12T13:22:22Z</dc:date>
    </item>
  </channel>
</rss>

