"Can not parse attribute value as date" in Nifi UpdateAttribute processor - apache-nifi

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<template encoding-version="1.3">
<description></description>
<groupId>de9048c5-0171-1000-4355-5efd185aa6ad</groupId>
<name>Update_Attribute_Date</name>
<snippet>
<processors>
<id>61a62c99-d8fc-3810-0000-000000000000</id>
<parentGroupId>b055aedb-ad9e-374d-0000-000000000000</parentGroupId>
<position>
<x>0.0</x>
<y>0.0</y>
</position>
<bundle>
<artifact>nifi-update-attribute-nar</artifact>
<group>org.apache.nifi</group>
<version>1.11.4</version>
</bundle>
<config>
<bulletinLevel>WARN</bulletinLevel>
<comments></comments>
<concurrentlySchedulableTaskCount>1</concurrentlySchedulableTaskCount>
<descriptors>
<entry>
<key>Delete Attributes Expression</key>
<value>
<name>Delete Attributes Expression</name>
</value>
</entry>
<entry>
<key>Store State</key>
<value>
<name>Store State</name>
</value>
</entry>
<entry>
<key>Stateful Variables Initial Value</key>
<value>
<name>Stateful Variables Initial Value</name>
</value>
</entry>
<entry>
<key>canonical-value-lookup-cache-size</key>
<value>
<name>canonical-value-lookup-cache-size</name>
</value>
</entry>
<entry>
<key>created_date</key>
<value>
<name>created_date</name>
</value>
</entry>
<entry>
<key>modified_date</key>
<value>
<name>modified_date</name>
</value>
</entry>
<entry>
<key>schema.name</key>
<value>
<name>schema.name</name>
</value>
</entry>
<entry>
<key>statement.type</key>
<value>
<name>statement.type</name>
</value>
</entry>
</descriptors>
<executionNode>ALL</executionNode>
<lossTolerant>false</lossTolerant>
<penaltyDuration>30 sec</penaltyDuration>
<properties>
<entry>
<key>Delete Attributes Expression</key>
</entry>
<entry>
<key>Store State</key>
<value>Do not store state</value>
</entry>
<entry>
<key>Stateful Variables Initial Value</key>
</entry>
<entry>
<key>canonical-value-lookup-cache-size</key>
<value>100</value>
</entry>
<entry>
<key>created_date</key>
<value>${created_date:toDate("EEE MMM dd HH:mm:ss z yyyy"):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")}</value>
</entry>
<entry>
<key>modified_date</key>
<value>${modified_date:toDate("EEE MMM dd HH:mm:ss z yyyy"):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")}</value>
</entry>
<entry>
<key>schema.name</key>
<value>village</value>
</entry>
<entry>
<key>statement.type</key>
<value>${cdc.event.type}</value>
</entry>
</properties>
<runDurationMillis>0</runDurationMillis>
<schedulingPeriod>0 sec</schedulingPeriod>
<schedulingStrategy>TIMER_DRIVEN</schedulingStrategy>
<yieldDuration>1 sec</yieldDuration>
</config>
<executionNodeRestricted>false</executionNodeRestricted>
<name>Schema=village & Statement Type</name>
<relationships>
<autoTerminate>false</autoTerminate>
<name>success</name>
</relationships>
<state>RUNNING</state>
<style/>
<type>org.apache.nifi.processors.attributes.UpdateAttribute</type>
</processors>
</snippet>
<timestamp>06/13/2020 22:39:36 IST</timestamp>
</template>
I am trying to insert records from source to destination db using the CaptureChangeMySQL processor. Date value from source table "2020-03-31 23:08:47" is getting changed to a format "Tue Mar 31 23:08:47 IST 2020" when processed in "CaptureChangeMySQL". The change value could not be loaded in the destination table since the data type is DateTime and getting an error "truncation due to length". So I am trying to convert the input value to correct format "yyyy-MM-dd HH:mm:ss" in the "UpdateAttribute" processor. Getting error as in the attachment. Please suggest how this issue could be fixed.

#Ganesh Kumar the expression language you are looking for is as follows:
${testValue:toDate("EEE MMM dd HH:mm:ss z yyyy"):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")}
In my NiFi test, I set testValue = "Tue Mar 31 23:08:47 IST 2020" in updateAttribute 1, then direct to another updateAttribute 2. I did notice that my output is 3 hours off, but suspect that is just my local timezone difference.
The flowfile Output is:
test1
2020-03-31 21:08:47.000
testValue
Tue Mar 31 23:08:47 IST 2020
Edited 6/17/2020 After Comments Above:
Access your json array in EvaluateJsonPath for each element as follows:
$[0].created_date
Then use the ${created_date} attribute with the Expression Language we tested above in updateAttribute as follows:
${created_date:toDate("EEE MMM dd HH:mm:ss z yyyy"):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")}
You can find a template demo at (right side flow):
https://github.com/steven-dfheinz/NiFi-Templates/blob/master/NiFI_EvaluateJsonPath_Demo.xml

Related

Create application/atom+xml result

I have an API on GoogleCloud and need to define an endpoint which returns a feed usable in Excel PowerPivot and Power BI. I have found this library using feed.ToAtom(), but the created feed does not work in PoverPivot, I get the following error: The payload kind 'Value' of the given data feed is not supported. but I can't find any information.
How can I create the needed result?
Here a snipped of the current result:
<?xml version="1.0" encoding="UTF-8"?>
<feed
xmlns="http://www.w3.org/2005/Atom">
<title>dfhfdhsfdh.net blog</title>
<id>http://dfhfdhsfdh.net/blojhlkjluizg</id>
<updated>2022-05-19T07:51:07+02:00</updated>
<rights>sdfsdf</rights>
<subtitle>discussion about tech, footie, photos</subtitle>
<link href="http://dfhfdhsfdh.net/blojhlkjluizg"></link>
<author>
<name>ergsrdg sdfgsfdg</name>
<email>dfhfdhsfdh#dfhfdhsfdh.net</email>
</author>
<entry>
<title>22906201</title>
<updated>2022-05-19T07:51:07+02:00</updated>
<id>http://dfhfdhsfdh.net/sdfsdfblog</id>
<link href="http://dfhfdhsfdh.net/blfghjghjog" rel="alternate"></link>
<summary type="html"></summary>
</entry>
<entry>
<title>22906197</title>
<updated>2022-05-19T07:51:07+02:00</updated>
<id>http://dfhfdhsfdh.net/sdfsdfblog</id>
<link href="http://dfhfdhsfdh.net/blfghjghjog" rel="alternate"></link>
<summary type="html"></summary>
</entry>
</feed>
I have also created the result by my self, the result is the following, but still get that error:
<?xml version="1.0" encoding="UTF-8"?>
<feed
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">Guest Requests</title>
<id>http://localhost:4444/requests/GuestRequests/</id>
<updated>2022-05-19T09:33:40+02:00</updated>
<entry>
<id>http://localhost:4444/requests/22906201</id>
<title type="text">22906201</title>
<updated>2022-05-19T09:33:40+02:00</updated>
<author>
<name>TODO</name>
</author>
<content type="application/xml">
<m:properties>
<d:id>22906201</d:id>
<d:title>22906201</d:title>
</m:properties>
</content>
</entry>
</feed>

Codeigniter/xml-rpc - How to customise the XML request format?

I am new to Codeigniter, but I have been googling since the last 3 days but no chance.
Here is what the distant server is supposed to receive
Header content
(
[0] => Content-type: text/xml
[1] => Content-length: XXX
[2] => User-Agent: XXXXX/4.1/1.0
[3] => Authorization: Basic base64_encode("login:password");
)
<?xml version="1.0"?>
<methodCall>
<methodName>UpdateBalanceAndDate</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>originNodeType</name>
<value>
<string>EXT</string>
</value>
</member>
<member>
<name>originHostName</name>
<value>
<string>XXXX</string>
</value>
</member>
<member>
<name>originTransactionID</name>
<value>
<string>XXXXXX</string>
</value>
</member>
<member>
<name>originTimeStamp</name>
<value>
<dateTime.iso8601>XXXXXXX</dateTime.iso8601>
</value>
</member>
<member>
<name>subscriberNumber</name>
<value>
<string>XXXXXXX</string>
</value>
</member>
<member>
<name>transactionCurrency</name>
<value>
<string>XOF</string>
</value>
</member>
<member>
<name>adjustmentAmountRelative</name>
<value>
<string>XXXXX</string>
</value>
</member>
<member>
<name>transactionCode</name>
<value>
<string>11</string>
</value>
</member>
<member>
<name>transactionType</name>
<value>
<string>XXXX</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
<?xml version="1.0" encoding="utf-8"?>
And this is my code:
$this->load->library('xmlrpc');
$this->xmlrpc->server('server_ip_adress', 80);
$this->xmlrpc->method('UpdateBalanceAndDate');
$request = array('My Photoblog', 'http://www.my-site.com/photoblog/');
$request = array(
array(
array(
'originNodeType' => 'EXT',
'originHostName'=>'XXXX',
'originTransactionID'=>'XXXXXX',
'originTimeStamp'=>'XXXXXXX',
'transactionCurrency'=>'XOF',
'adjustmentAmountRelative'=>'XXXXX',
'transactionCode'=>'11',
'transactionType'=>'XXXX'
),
'struct'
)
);
$this->xmlrpc->request($request);
if ( ! $this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
Something is going wrong but I don't receive any error message from the server, I am checking the followings.
I need to customise the XML format of the request by adding a header
to the default XML format. Is this possible in Codeigniter? How?
Is there any function in Codeigniter (or generally in PHP) which
allows me to check the XML request before sending to the server?
(Something like var_dump() or print_r() ).
Thanks

How to avoid scentific notation in Saiku Attribute

I define saiku(3.8) schema as below:
<?xml version="1.0" encoding="utf-8"?>
<Schema name="Zeus Offline Data" metamodelVersion='4.0'>
<PhysicalSchema>
<Table name="ZEUS_OFFLINE_DATA">
<Key>
<Column name='FB_ACCOUNT_ID'/>
</Key>
</Table>
</PhysicalSchema>
<Cube name="OfflineData">
<Dimensions>
<Dimension name="AdAccount" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="account_id" keyColumn="FB_ACCOUNT_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
<Dimension name="BM" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="bm_id" keyColumn="BM_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
</Dimensions>
<MeasureGroups>
<MeasureGroup name="Stats" table="ZEUS_OFFLINE_DATA">
<Measures>
<Measure name="clicks" column="CLICKS" aggregator="sum" formatString="#,###"/>
</Measures>
<DimensionLinks>
<FactLink dimension="AdAccount"/>
<FactLink dimension="BM"/>
</DimensionLinks>
</MeasureGroup>
</MeasureGroups>
It contains two dimension "bm_id" and "fb_account_id", and one measure "clicks".In database backend, bm_id and fb_account_id are int type. When I make query in Saiku, the result of bm_id and fb_account_id are shown in scientific notation mode, which I don't want.
Result:
bm_id clicks
1.71141391154125E14 1,091,234
Which I want:
171141391154125 1,091,234
I don't know which attribute should be changed for that, any help appreaciated
Thanks

Derive value using single xpath expression

I have an xml:
<?xml version="1.0"?>
<library>
<ChildEntity>
<EntityID>9099-77-005</EntityID>
<ChildEntity>
<EntityID>005</EntityID>
</ChildEntity>
<ChildEntity>
<CharacteristicUse>
<Value>
<ValueID>123</ValueID>
</Value>
<Value>
<ValueID>567</ValueID>
</Value>
</CharacteristicUse>
<CharacteristicUse>
<Value>
<ValueID>555</ValueID>
</Value>
<Value>
<ValueID>5677</ValueID>
</Value>
</CharacteristicUse>
</ChildEntity>
</ChildEntity>
<ChildEntity>
<EntityID>8888-77-005</EntityID>
<ChildEntity>
<EntityID>88005</EntityID>
</ChildEntity>
<ChildEntity>
<CharacteristicUse>
<Value>
<ValueID>99123</ValueID>
</Value>
<Value>
<ValueID>59967</ValueID>
</Value>
</CharacteristicUse>
</ChildEntity>
</ChildEntity>
</library>
out of which i want to derive the tags:
<Value>
<ValueID>567</ValueID>
</Value>
such that this will be then used to remove from the xml later on.
The logic should be such that, derive and remove the tags which has EntityID = 9099-77-005 and it should pick only that tag whose immediate sibling Value/ValueID!=123.
I am new to Xpath and so far have only been able code:
/library/ChildEntity[EntityID='9099-77-005']/ChildEntity/CharacteristicUse[Value[ValueID='123']] | /Value[ValueID!=123]
Can someone please help?

Referencing specific element(s) in a RelaxNG schema with externalRef

So I have one RelaxNG schema that references another:
<define name="review">
<element name="review">
<externalRef href="other.rng"/>
</element>
</define>
other.rng:
<start>
<choice>
<ref name="good"/>
<ref name="bad"/>
</choice>
</start>
<define name="good">
<element name="good"/>
</define>
<define name="bad">
<element name="bad"/>
</define>
Is there any way I can import only <good>, but not allow <bad>? The goal being:
<review><good/></review>: valid
<review><bad/></review>: invalid
The grammar you import with externalRef can't be modified. To achieve the kind of validation you're after, I see this method :
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href="other.rng">
<start combine="choice">
<ref name="review"/>
</start>
</include>
<define name="review">
<element name="review">
<ref name="good"/>
</element>
</define>
</grammar>
You include the other schema.
You override the start element in the include (good and bad elements won't be possible root).
The specification says :
If the include element has a start component, then all start
components are removed from the grammar element.
You make a reference to the good element in your review definition.

Resources