Data Flow Library Function Error - Cannot evaluate constant value with this type\n\tat

Sujit Purkayastha Das 20 Reputation points
2024-08-10T22:37:16.44+00:00

I am getting below error in Data flow library function, parseDouble:

Cannot evaluate constant value with this type\n\t

Below is the Data flow library function:

toDecimal(concat(toString(toLong(substring(i1, 1, i2))), '.', toString(toLong(substring(i1, i2 + 1, i3)))), i2 + i3, i3)

i1 is type string, i2 and i3 is of type integer

The calling Data Flow is:

parseDouble(trim(substring(value, 236, 18)), 9, 9) where i2=9 and i3=9

The function works fine if I hard code i2 and i3 in it.

toDecimal(concat(toString(toLong(substring(i1, 1, 9))), '.', toString(toLong(substring(i1, 10, 9)))), 18, 9)

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.
5,373 questions
{count} votes

Accepted answer
  1. phemanth 15,755 Reputation points Microsoft External Staff Moderator
    2024-08-13T11:43:44.41+00:00

    @Sujit Purkayastha Das

    Thanks for using MS Q&A platform and posting your query.

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Ask: I am getting below error in Data flow library function, parseDouble:

    Cannot evaluate constant value with this type\n\t

    Below is the Data flow library function:

    toDecimal(concat(toString(toLong(substring(i1, 1, i2))), '.', toString(toLong(substring(i1, i2 + 1, i3)))), i2 + i3, i3)

    i1 is type string, i2 and i3 is of type integer

    The calling Data Flow is:

    parseDouble(trim(substring(value, 236, 18)), 9, 9) where i2=9 and i3=9

    The function works fine if I hard code i2 and i3 in it.

    toDecimal(concat(toString(toLong(substring(i1, 1, 9))), '.', toString(toLong(substring(i1, 10, 9)))), 18, 9)

    **Solution:**On further investigation, it looks like the precision and scalar arguments toDecimal function is causing an issue. If I remove them then it works though the resultant number has only 2 decimal places. Below works:

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    )

    )

    If I add them back (snippet below) then I get the same error.

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    ),

    toInteger(i2) + toInteger(i3),

    toInteger(i3)

    )

    Please note that the input to the function remains same for both.

    parseDouble(trim(substring(value, 236, 18)), 9, 9)

    It works when I pass constant values for precision and scalar arguments as below:

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    ),

    9 + 9,

    9

    )

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.


    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Bouhmidi, Asmaa 0 Reputation points
    2024-08-10T23:01:01.92+00:00

    Hello, you need to ensure that i2 and i3 are evaluated as constants or properly converted to the expected types before being used in the substring or other functions

    try to cast the two variables as follow

    toDecimal(
      concat(
    
        toString(toLong(substring(i1, 1, toInteger(i2)))), 
    
        '.', 
    
        toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))
    
      ), 
    
      toInteger(i2) + toInteger(i3), 
    
      toInteger(i3)
    )
    ```Please mark my answer as accepted if it helped
    
    

  2. Sujit Purkayastha Das 20 Reputation points
    2024-08-12T19:29:34.8666667+00:00

    Thanks @phemanth

    On further investigation, it looks like the precision and scalar arguments toDecimal function is causing an issue. If I remove them then it works though the resultant number has only 2 decimal places. Below works:

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    )

    )

    If I add them back (snippet below) then I get the same error.

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    ),

    toInteger(i2) + toInteger(i3),

    toInteger(i3)

    )

    Please note that the input to the function remains same for both.

    parseDouble(trim(substring(value, 236, 18)), 9, 9)

    It works when I pass constant values for precision and scalar arguments as below:

    toDecimal(

    concat(

    toString(toLong(substring(i1, 1, toInteger(i2)))),

    '.',

    toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))

    ),

    9 + 9,

    9

    )


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.