Filter with quotes as string

Aditya Raj 286 Reputation points
2021-06-17T13:59:40.637+00:00

I have a filter condition in which it is given as string e.g, if columnName is firstname then filter condition is firstname = 'xyz'. I am trying to add this filter in source query in data flow.
I am reading this filter condition from table where filtercondition is defined as text column
I am getting parsing error

{"StatusCode":"DF-Executor-ParseError","Message":"Job failed due to reason: Expression cannot be parsed","Details":""}

106647-image.png

106633-image.png

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,974 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShaikMaheer-MSFT 38,321 Reputation points Microsoft Employee
    2021-06-21T07:38:57.973+00:00

    Hi @Aditya Raj ,

    Thank you for response. You need to handle adding \ symbols before single quote in your filter value using expressions. Please check detailed expression to do the same.

    Step1: Create a below two variables.
    FilterColVal - will hold your data from table
    ModifiedFilter - to hold modified filter contidion with \ symbols in it to escape single quote
    107445-variables.gif

    Step2: Use set variable activity to store value with modified filter data(with \ symbol in it to escape single quote) using expressions
    Expression used:

    @concat(  
       substring(  
         variables('FilterColVal'),0,indexof(variables('FilterColVal'),'''')  
       ),  
       '\',  
       substring(  
         variables('FilterColVal'),  
         indexof(variables('FilterColVal'),''''),  
         sub(  
           lastindexof(variables('FilterColVal'),''''),indexof(variables('FilterColVal'),'''')  
         )  
       ),  
       '\',  
       substring(  
         variables('FilterColVal'),lastindexof(variables('FilterColVal'),''''),1  
       )  
     )  
    

    107514-expression.png

    Hope this helps. Thank you

    -----------------

    • Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.
    • Want a reminder to come back and check responses? Here is how to subscribe to a email-notifications.

1 additional answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,321 Reputation points Microsoft Employee
    2021-06-18T12:39:08.92+00:00

    Hi @Aditya Raj ,

    Thank you for posting query in Microsoft Q&A Platform.

    I found the resolution.

    If we have single quotes in dynamic content then we should escape them with \ symbol.

    If we have Filter condition(name = 'maheer') as dynamic then we should make sure to escape single quotes with \ symbol.

    In below example, I am created two variables one is for TableName and another is for Filter. If you observer values in Filter I used \ symbol to escape single quote. Kindly check below detailed steps to understand

    Step1: Created two variables to have my TableName and Filter condition. Please note I escaped single quotes here with \ symbol.
    107084-variablescreation.gif
    Step 2: Data Flow activity
    107085-dataflowactivity.gif
    Step 3: Parameters in Dataflow
    107094-dataflowparameters.gif
    Step 4: Source Transformation with Dynamic Query
    107086-sorucetransformation.gif
    Hope this helps you.


    • Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.
    • Want a reminder to come back and check responses? Here is how to subscribe to a email-notifications
    1 person found this answer helpful.