Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NiFI: how can i change space to underscore with ReplaceText

avatar
Explorer

Hello

 

I need to change the name of the columns.

Ex: 'item Type' became 'Item_Type'

 

RegionCountryItem TypeSales ChannelOrder PriorityOrder DateOrder IDShip DateUnits SoldUnit PriceUnit CostTotal RevenueTotal CostTotal Profit
Sub-Saharan AfricaChadOffice SuppliesOnlineL1/27/201129249452302/12/20114484651.21524.962920025.642353920.64566105.00
EuropeLatviaBeveragesOnlineC12/28/20153618255491/23/2016107547.4531.7951008.7534174.2516834.50
Middle East and North AfricaPakistanVegetablesOfflineC1/13/201114151576702/01/20116515154.0690.931003700.90592408.95411291.95
Sub-Saharan AfricaDemocratic Republic of the CongoHouseholdOnlineC09/11/201250036400510/06/20127683668.27502.545134318.413861014.821273303.59
EuropeCzech RepublicBeveragesOnlineC10/27/201512748159112/05/2015349147.4531.79165647.95110978.8954669.06

 

i'm trying to use the processor ReplaceText

Acbx_1-1621269833032.png

 

But this is the result

 

RegionCountryItem_TypeSales_ChannelOrder_PriorityOrder_DateOrder_IDShip_DateUnits_SoldUnit_PriceUnit_CostTotal_RevenueTotal_CostTotal_Profit__Sub-Saharan AfricaChadOffice SuppliesOnlineL1/27/201129249452302/12/20114484651.21524.962920025.642353920.64566105.00
EuropeLatviaBeveragesOnlineC12/28/20153618255491/23/2016107547.4531.7951008.7534174.2516834.50             
Middle East and North AfricaPakistanVegetablesOfflineC1/13/201114151576702/01/20116515154.0690.931003700.90592408.95411291.95             
Sub-Saharan AfricaDemocratic Republic of the CongoHouseholdOnlineC09/11/201250036400510/06/20127683668.27502.545134318.413861014.821273303.59             
EuropeCzech RepublicBeveragesOnlineC10/27/201512748159112/05/2015349147.4531.79165647.95110978.8954669.06             
Sub-Saharan AfricaSouth AfricaBeveragesOfflineH07/10/20124822923548/21/2012988047.4531.79468806.00314085.20154720.80             

 

Can someone help me please?

1 REPLY 1

avatar
Explorer

Hi,

 

Try using the replace text processor in "Literal Replace" mode for the Replacement Strategy setting.  It's no obvious, but I have placed a single space in the Search Value setting.

 

_mark__0-1621634057941.png

 

Alternatively, you could explore using an Avro schema to achieve this, and this links in nicely with your other question too.  For example, given a flow file with the content (I'm using the GenerateFlowFile to create this):

 

Using this flow as a test:

_mark__3-1621634539863.png

 

I've created content in the GenerateFlowFile of:

 

_mark__1-1621634278941.png

 

with an attribute called avro.schema:

_mark__7-1621635075850.png

 

Note the highlighted "name" attribute which defines the name you need on the output, and the "aliases" array value which is the input name value.

 

For reference, here's the GenerateFlowFile configuration:

 

_mark__4-1621634613915.png

The ConvertRecord has the following CSVReader configured:

 

_mark__5-1621634692840.png

 

And using an otherwise normally configured CSVRecordSetWriter I get the following output:

 

_mark__6-1621634753638.png

 

Also note that I have also changed the case using this approach, in fact you can rename the column to whatever you need.

 

I found working with Avro schemas a bit of a steep learning curve, but definitely worth the time investment.  I mention this in particular as it compliments your other question about date formats very well.

 

Hope that helps