virtualdvid
virtualdvid

Reputation: 2421

Az Data Factory: The function 'int' was invoked with a parameter that is not valid

How to convert a string to a int data type in Azure Data Factory Data Flow activity to set a parameter?

I have been trying to get a value from a json file in a gen2 data lake:

{
    "firstRow": {
        "schema_name": "my_schema",
        "table_name": "my_table",
        "reserved_space_MB": 138.808,
        "unused_space_MB": 1.392,
        "data_space_MB": 136.848,
        "index_space_MB": 0.568,
        "row_count": 916300
    },
    ...
}

But got this error in the last activty:

{
    "errorCode": "InvalidTemplate",
    "message": "The function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type",
    "failureType": "UserError",
    "target": "_split_file_from_table",
    "details": ""
}

I have been following the documentation and also these stack overflow questions:
Azure Data Factory split file by file size
Convert Row Count to INT in Azure Data Factory
But I'm getting the same error no matter what I do.

How to reproduce

  1. Use a Lookup activity in a pipeline:

  1. start variable table_size_var as a string data type

  1. Set Variable activity to get the data_space_MB value:
    @string(activity('read_json').output.firstRow.data_space_MB)

  1. Set parameter table_size_mb in a Data Flow:

  1. Set the value from the variable table_size_var to the parameter table_size_mb:
    @int(variables('table_size_var'))

  1. Run the pipeline - results:

lookup

Set Variable

Data Flow

Upvotes: 0

Views: 6350

Answers (1)

Leon Yue
Leon Yue

Reputation: 16431

I tried and get the same error.

The int() function only works for covert int string to integer, the parameter must be an int String! For example string '100' to integer 100. It can not convert decimal string '136.848' to integer 136.848.

I'm using int() and split() function to get integer 138 , then the pipeline works well. Expression:

@int(split(variables('num'),'.')[1])
  1. The variable will split into an array, '138' and '848', using [1] to get the first element.
  2. Then using int() to convert '138' to integer 138.

enter image description here

Upvotes: 2

Related Questions