U-SQL 试图从嵌套的 JSON 对象中提取整数列表
U-SQL trying to Extract a list of ints from nested JSON object
我正在尝试从该结构中提取 ErrorReasons 以及 State 和 Id
{
"id": "abcGuid",
"RegistrationStatus": {
"State": 2,
"ErrorReasons": [
1,2,3
]
},
}
我可以提取 Id、RegistrationStatus 和 State,但是我很难从 ErrorReasons 列表中获取整数列表。
我的起始提取物
@result =
EXTRACT
[id] string
,[RegistrationStatus] string
FROM @inputFileDaily
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
然后我把State和ErrorReasons拉出来放到自己的字段里
@pre =
SELECT JsonFunctions.JsonTuple(RegistrationStatus) ["State"] AS State,
JsonFunctions.JsonTuple(RegistrationStatus) ["ErrorReasons"] AS ErrorReasons_data
FROM @result;
@pre =
SELECT State,
JsonFunctions.JsonTuple(ErrorReasons_data).Values AS ErrorReasons_Array
FROM @pre;
@CreateJSONTuple =
SELECT State,
JsonFunctions.JsonTuple(ErrorReasons)["0"] AS ErrorReason
FROM @pre
CROSS APPLY
EXPLODE(ErrorReasons_Array) AS c(ErrorReasons);
这当然什么也得不到,因为它正在寻找字段“0”
如果我遗漏了 ["0"],那么它会抱怨将 sqlmap 输出到 csv。我试过 .Value, .Values, ["1"], [0], [1]
.Values 当然也不适合我。
我觉得我真的很接近,只是缺少一个关键操作来从 Error Reasons
中提取值列表
经过一点橡皮回避,我想通了,
@CreateJSONTuple =
SELECT
A.ErrorReason AS Reason
FROM @pre
CROSS APPLY
EXPLODE (ErrorReasons_Array) AS A(ErrorReason);
并找到了正确的文档以供参考
https://docs.microsoft.com/en-us/u-sql/data-types/built-in/complex-built-in-u-sql-types
我正在尝试从该结构中提取 ErrorReasons 以及 State 和 Id
{
"id": "abcGuid",
"RegistrationStatus": {
"State": 2,
"ErrorReasons": [
1,2,3
]
},
}
我可以提取 Id、RegistrationStatus 和 State,但是我很难从 ErrorReasons 列表中获取整数列表。
我的起始提取物
@result =
EXTRACT
[id] string
,[RegistrationStatus] string
FROM @inputFileDaily
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
然后我把State和ErrorReasons拉出来放到自己的字段里
@pre =
SELECT JsonFunctions.JsonTuple(RegistrationStatus) ["State"] AS State,
JsonFunctions.JsonTuple(RegistrationStatus) ["ErrorReasons"] AS ErrorReasons_data
FROM @result;
@pre =
SELECT State,
JsonFunctions.JsonTuple(ErrorReasons_data).Values AS ErrorReasons_Array
FROM @pre;
@CreateJSONTuple =
SELECT State,
JsonFunctions.JsonTuple(ErrorReasons)["0"] AS ErrorReason
FROM @pre
CROSS APPLY
EXPLODE(ErrorReasons_Array) AS c(ErrorReasons);
这当然什么也得不到,因为它正在寻找字段“0”
如果我遗漏了 ["0"],那么它会抱怨将 sqlmap
经过一点橡皮回避,我想通了,
@CreateJSONTuple =
SELECT
A.ErrorReason AS Reason
FROM @pre
CROSS APPLY
EXPLODE (ErrorReasons_Array) AS A(ErrorReason);
并找到了正确的文档以供参考 https://docs.microsoft.com/en-us/u-sql/data-types/built-in/complex-built-in-u-sql-types