Необходимо учитывать, что массив также состоит из сложных типов. Кроме того, вы не можете просто использовать нотацию типа EXTRACT [custom.dimensions] string
, для этого нужно добавить промежуточные шаги, например:
@json =
EXTRACT location String,
device String,
custom String
FROM @InputFile
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("context");
@CreateJSONTuple =
SELECT JsonFunctions.JsonTuple(location) AS LocationData,
JsonFunctions.JsonTuple(device) AS DeviceData,
JsonFunctions.JsonTuple(custom, "dimensions[0]") AS DimensionData
FROM @json;
@result =
SELECT LocationData["country"] ?? "N/A" AS Country,
LocationData["province"] ?? "N/A" AS Province,
LocationData["city"] ?? "N/A" AS City,
DeviceData["osVersion"] ?? "N/A" AS OsVersion,
DeviceData["roleName"] ?? "N/A" AS RoleName,
DimensionData["dimensions[0]"] AS CategoryDimension
FROM @CreateJSONTuple;
@result =
SELECT Country,
Province,
City,
OsVersion,
RoleName,
JsonFunctions.JsonTuple(CategoryDimension) AS CategoryDimension
FROM @result;
@result =
SELECT Country,
Province,
City,
OsVersion,
RoleName,
CategoryDimension["Category"] AS Category
FROM @result;
OUTPUT @result
TO @output
USING Outputters.Csv(outputHeader : true, quoting : true);
Это выводит:
"Страна" "Провинция" "Город" "OsVersion" "RoleName" "Категория"
"Сингапур" "N / A" "N / A" "Microsoft Windows NT 6.1.7601 с пакетом обновления 1" "Connexx" "Noah Version"