Search code examples
azurekqlazure-data-explorer

Why does tolong not work with a string coming from strcat?


Why do tolong(s) and tolong(ss) not produce the same output?

let s = '0x0000000000000000000000000000000a';
let ss = strcat('0x', '0000000000000000000000000000000a');
print
    s = s,
    ss = ss,
    s_equal_ss = (s == ss),
    tolong_s = tolong(s),
    tolong_ss = tolong(ss)

enter image description here


tl;dr of answer: It's a bug.


Solution

  • Why does tolong not work with a string coming from strcat?

    I have reproduced in my environment and below are my observations:

    No, tolong() works on strcat() (hexadecimal or non-hexadecimal strings whose length should not exceed 18)

    Example:

    let s = strcat('1', '23');
    print(tolong(s));
    

    enter image description here

    When you concat with 18 digits or less than that you will get output as i have got:

    let s = '0x0000000000000000000000000000000a';
    let x = strcat('0x', '000000000000000a');
    print
        tolong(x),
        tolong(s),
        strlen(x)
    

    enter image description here

    More than 18 it is null:

    let s = '0x0000000000000000000000000000000a';
    let x = strcat('0x', '0000000000000000a');
    print
        tolong(x),
        tolong(s),
        strlen(x)
    

    enter image description here

    When you work with strcat on hexadecimal string with more than 18 characters, it gives you null as it cannot convert:

    let s = '0x0000000000000000000000000000000a';
    let x = strcat('0x', '0000000000000000000000000000000a');
    print
        tolong(x),
        tolong(s)
    

    enter image description here