Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions certified-connectors/Snowflake v2/script.csx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class Script : ScriptBase
private const string Snowflake_Type_Time = "time";

private const string QueryString_Partition = "partition";
private const string QueryString_Nullable = "nullable";


#endregion

Expand Down Expand Up @@ -85,6 +87,14 @@ public class Script : ScriptBase
return matchAccount.Success;
}

private bool UseRealNulls()
{
var query = HttpUtility.ParseQueryString(Context.Request.RequestUri.Query);
var nullable = query[QueryString_Nullable] ?? "false";
Context.Logger.LogInformation("Use Real Nulls: " + nullable);
return (nullable == "true");
}

private bool IsTransformable()
{
if (Context.OperationId == OP_EXECUTE_SQL)
Expand Down Expand Up @@ -136,6 +146,7 @@ public class Script : ScriptBase
var rows = JArray.Parse(contentAsJson[Attr_Data].ToString());

JArray newRows = new JArray();
JToken tokenNull = JValue.CreateNull();

foreach (var row in rows)
{
Expand All @@ -148,10 +159,13 @@ public class Script : ScriptBase
string type = col[Attr_Column_Type].ToString();
if (newRow.ContainsKey(name)) name = name + "_" + Convert.ToString(i);
JToken token = row[i];
JToken tokenNull = JValue.CreateNull();
if (token == null || Convert.ToString(token) == "null")
if (token.Type == JTokenType.Null || token == null)
{
newRow.Add(new JProperty(name.ToString(), tokenNull));
}
else if (!UseRealNulls() && Convert.ToString(token) == "null") // This mirrors the behavior of the API which returns the string "null" for null values when nullable is false.
{
newRow.Add(new JProperty(name.ToString(), row[i]));
newRow.Add(new JProperty(name.ToString(), token));
}
else
{
Expand Down Expand Up @@ -236,7 +250,7 @@ public class Script : ScriptBase

var responseObj = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = CreateJsonContent(JsonConvert.SerializeObject(result,Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Include}))
Content = CreateJsonContent(JsonConvert.SerializeObject(result))
};

return responseObj;
Expand Down