apply trim before copy using azure data factory - azure-data-factory-2

I have a pipeline that copies files from azure datalake to azure SQL
Gets Meta Data of files in a specific path in Datalake
Loops through the output and copies the file into a database table.
file A.csv is copied to dbo.[A]
file B.csv is copied to dbo.[B]
Question
Is there a generic way to define a trim on the column values being copied ?

To apply a trim rule across ALL string columns in a dataset in ADF, use Mapping Data Flows with a column pattern.
In a Derived Column, set your matching rule to "type == 'string'".
In the Column Name, keep it the same using $$.
In the Value, set trim ($$,'...')
Reference docs:
Matching Patterns: https://learn.microsoft.com/en-us/azure/data-factory/concepts-data-flow-column-pattern
Derived Column: https://learn.microsoft.com/en-us/azure/data-factory/data-flow-derived-column

trim feature is supported by ADF expressions.(link)
e.g.:
trim('!--!wor!ld!', '-!') -> 'wor!ld'
Trims a string of leading and trailing characters. If second parameter is unspecified, it trims whitespace. Else it trims any character specified in the second parameter

Related

SSIS - Text Qualifier Purpose

What is the purpose of adding a text qualifier to a SSIS flat text file output?
I'm pulling data out of a SQL database that has quotes/commas/pipes/and many other common delimiters in the data.
Extreme example of a data point in a column:
"Johnson"|Smith,Jones
I set up the export as a comma delimited, with a double quote " text qualifier. I assumed it would export the data like so, and it did:
,""Johnson"|Smith,Jones",
Now i'm testing re-importing the data back in, as a comma delimited, with a double quote text qualifier. I got errors saying SSIS couldn't find the delimiter. I thought it would recognize the combination comma, and double quote, essentially as a more complex delimiter.
If adding a text delimiter to the output doesn't help with the problem of having the characters in the actual data, what does it do?
Assuming the person receiving the data might use a tool like Excel to process the data, which doesn't seem to be able to handle a complex multi character delimiter like |", is the best way to handle this by removing the most common delimiter from my data, and using that as the delimiter? Probably pipe in my case, instead of comma.
Text qualifier is used in the event that delimiters are contained within the row cell. Typically, the text qualifier is a double quote. In the event that the cell contains a delimiter and a text qualifier is not used, then the data that occurs after the delimiter will spill into the next column. From there, the data row can potentially blow up and none of the columns will line up afterwards. It can be a real mess.
Additionally, you will not see the text qualifier in applications, like Excel. However, if you open the file in Notepad++, then you will see the text qualifiers. There can be a lot of data (e.g., text qualifiers, new line characters, column delimiters, etc.) that is contained within a file but is not displayed in certain applications. This data typically is used to define the structure of the data as opposed to being the actual data.
For your problem, you will need to remove the double quotes from the source data or use a different text qualifier. You could use a single quote, but what if you have data like Jones's? The idea here is that the text qualifier should be unique in defining the data structure, which, as I understand it, means that you cannot have a text qualifier that is actually a part of the data (see note from Microsoft below - emphasis mine).
Per Microsoft:
Specify a text qualifier character. Each column can be configured to
recognize a text qualifier.
The use of a qualifier character to embed a qualifier character into a
qualified string is supported by the Flat File Connection Manager. The
double instance of a text qualifier is interpreted as a literal,
single instance of that string. For example, if the text qualifier is
a single quote and the input data is 'abc', 'def', 'g'hi', the output
data is abc, def, g'hi. However, an instance of a qualifier embedded
in a qualified string causes the Flat File Source to fail with the
error DTS_E_PRIMEOUTPUTFAILED.
References
Flat File Connection Manager official documentation

Removing or preserving unmatched quotes in Dataweave

We're currently reading in a client's tab-delimited file row by row and using Dataweave to handle the transforming of the data to models for persisting to the database.
The issue we're having is that single double-quotes are causing problems with the mapping to the models.
Is there a way to handle unmatched double-quotes in Dataweave? We have a short term option of removing the offending quotes or removing all quotes entirely.
The other, preferred option is to preserve the data as is, single double-quotes and all, so the database data matches the original source data.
Can I achieve either of these results in Dataweave alone?
Many thanks.
Unmatched double quote will cause issue, if possible you can changed it to \"unmatched so that it can passes as it is to downstream. Other options which you mentioned will alter the source data. Use of escape character prevent data alteration.

Leading zeros not retained reading csv with ACE OleDb

Leading zeros not retaining while reading comma separated value(csv) file by Microsoft ACE Ole Db means if col value is 0000123456, i am getting only 123456 only, while reading programmatically in vb.net. i don't want to put any condition while preparing the comma separated value(csv) file i.e. used of apostrophe before the zeros etc.
Data structure is like below in comma separated value(csv) file
Name,ID
John,0001234
moon,0001235
but i am getting id as 1234 , 1235 but i want with zeros using Microsoft ACE Ole Db
Please guys any idea.Thanks in advance
The Text File driver used by OleDb to read CSV files is unable to accurately determine the datatype of the columns. In your case, your second column is misunderstood to be a numeric column because it contains only digits, thus the leading zero are removed.
You can give a strong hint to OleDb creating a file called SCHEMA.INI that explains what is the content of the file.
In your case you could create one in the same folder of the file (I assume temp.csv for this example) and write these lines:
[temp.csv]
Format=CSVDelimited
ColNameHeader=True
Col1=Name Text
Col2=ID Text
DecimalSymbol=.
Notice that I need to specify the DecimalSymbol being a point because in my locale the comma is used as separator between the decimal and the integer part of a number (thus we use CSV files separated by semicolons)

Importing File WIth Field Terminators In Data

I've been given some csv files that I want to turn into tables in a SQL database. However, the genius who created the files used comma delimiters, even though several data fields contain commas. So when I try to BCP the data into the database, I get a whole bunch of errors.
Is there a way that I can escape the commas that aren't field separators? At the moment I'm tempted to write a script to manually replace every comma in each file with a pipe, and then go through and manually change the affected rows back.
The only way to fix this is to write a script or program that fixes the data.
If the bad data is limited to a single field the process should be trivial:
You consume the row from either side by the count of good delimiters and replace with a new unique delimiter and what remains is the column with the extra old delimiters that you would just leave as is.
If you have two bad fields straddling good fields, you would need some kind of advanced logic, for instance I had XML data with delimiters, I had to parse the XML until I found a terminating tag and then process the other delimiters as needed.

Comma delimited flat file source

I have a text file that is split using commas
Simple enough to do in SSIS but i have the following row in my source flat file:
Desc,Curr,Desc,ID,Quantity
05969A105 ,CU,BANCORP INC, THE DEL COMMON ,1,2126
there is a comma in my Desc column and im not sure how i can ignore that comma
AFAIK, you can't do anything in SSIS (or any other app that I have ever used) to handle this, because it is simply bad data. If you need to persist with comma delimiters then you will need to get the data provider to use text-delimiters, e.g. double-quotes, to wrap the data. SSIS can be told what is the text delimiter and will strip these chars off the data automatically.
Of course this may raise the issue of 'but the text may need to contain a double-quote!', in which case you would be better off getting the delimiter changed to something else, such as a tab or pipe.