convert string to float in azure data factory in copy activity

Jamshed Salik 1 Reputation point
2021-12-31T07:31:59.58+00:00

I have a csv file in mapping all source column ha string type and in destination some column have float ,varchar ,int type. When i run the pipeline activity fail and show error.
Error message:
ErrorCode=TypeConversionFailure,Exception occurred when converting value '' for column name 'BENE_HIC_NUM' from type 'String' (precision:, scale:) to type 'Double' (precision:15, scale:255). Additional info: Input string was not in a correct format.
161621-image.png

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,890 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,858 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,565 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. svijay-MSFT 5,226 Reputation points Microsoft Employee
    2022-01-03T08:16:26.55+00:00

    Hello @Jamshed Salik ,

    Thanks for the question and using MS Q&A platform.

    From your error - it looks like there are null values in your field - '' - null string - is encountering the error while converting to float.

    You could try the @Nandan Hegde approach - if my understanding is correct he has not mentioned explicitly the type as float to perform the copy activity. If this is not working for you, we will have to make use of the Mapping Data flow.

    Because copy activity in Azure data factory only allow us to perform data movement as is. Handling type conversion from string to float directly is not available in copy activity. To do any kind of check or transformation we should consider data flows.

    You can consider derived column transformation for your case to check if value is empty or not and type cast using the toFloat function. For all other strings, you can set it as a zero or any value as per your requirement

    iif(isFloat(Field1),toFloat(Field1),0)  
    

    Hope this will help. Please let us know if any further queries.

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

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. 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 notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    1 person found this answer helpful.

  2. Nandan Hegde 32,026 Reputation points MVP
    2021-12-31T07:53:10.983+00:00

    Hey,
    Assuming all the values in that column can be explicitly cast into numerical data type and there are no string values that are causing the issue,
    you can use the mapping part in copy activity and us the below mapping example format :

    161574-image.png

    {"type":"TabularTranslator","mappings":[{"source":{"name":"Period_FYTD"},"sink":{"name":"Period_FYTD"}},{"source":{"name":"Col2","type": "Decimal"},"sink":{"name":"Col2"}}]}  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.