Search code examples
c#deserializationu-sqlconstantfolding

Deserialize JSON Map in a constant-foldable way C#


I need to pass a string representation of a <string,string> map into my U-SQL program, and deserialize it into a C# Dictionary<string,string> so I can then turn it to a U-SQL SqlMap. I need to do it in a constant-foldable way. My most recent attempt:

DECLARE @MapStr string = "{\"key\": \"val\"}";
DECLARE CONST @map = new SqlMap<string,string>(JsonConvert.DeserializeObject<Dictionary<string, string>>(@MapStr));

Fails with "E_CSC_USER_EXPRESSIONNOTCONSTANTFOLDABLE: Expression cannot be constant folded."

I have found numerous ways to deserialize a string into a map, but none so far were constant foldable. I can't find a list of constant-foldable c# expressions, which would also be helpful here.


Solution

  • In case anyone else was curious, I believe this is not possible:

    • Only String and built-in type expressions are constant-foldable, excluding Objects (such as arrays and maps). (see other answer for links on this)
    • There are no built-in expressions or String expressions that evaluate to a SqlMap
    • Therefore there are no constant-foldable expressions that evaluate to a SqlMap

    For my specific purposes, I was able to use a configuration file that created CONST SqlMaps and use this, but that would not be a possibility if we had more than a finite set of possible inputs.