2017-05-16 5 views
0

Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple을 사용하여 일부 데이터를 가져올 수 있지만 전체 파일을 병합하는 데 문제가 있습니다.USQL을 사용하여 CSV로 JSON을 병합하는 방법

{ 
"SourceUrl":"http://www.unittest.org/test.html", 
"Title":"Unit Test File", 
"Guest":"Unit Test Guest", 
"PublishDate":"2017-05-15T00:00:00", 
"TranscriptionSections":[ 
    { 
    "SectionStartTime":"00:00:03", 
    "Sentences":[ 
     { 
      "Text":"Intro." 
     }, 
     { 
      "Text":"Sentence one" 
     }, 
     { 
      "Text":"Sentence two" 
     } 
    ] 
    }, 
    { 
    "SectionStartTime":"00:04:46", 
    "Sentences":[ 
     { 
      "Text":"Sentence three" 
     }, 
     { 
      "Text":"Sentence four" 
     } 
    ] 
    } 
], 
"Categories":null 
} 

은 내가 얻으려고하는 것은 그것의 'SectionStartTime'모두 최고 수준의 특성을 포함하여 텍스트 당 행 (그 5)이다 (': 여기

내가 함께 일하고 있어요 파일 형식입니다 PublishDate ','Guest '...).

지금까지 나는이를 사용하여 'SectionStartTime'당 행을 얻을 수 있습니다 :

DECLARE @input string = "/input/data.json"; 

REFERENCE ASSEMBLY JSONBlog.[Newtonsoft.Json]; 
REFERENCE ASSEMBLY JSONBlog.[Microsoft.Analytics.Samples.Formats]; 

USING Microsoft.Analytics.Samples.Formats.Json; 

@data = 
EXTRACT SourceUrl string, 
     Title string, 
     Guest string, 
     PublishDate DateTime, 
     TranscriptionSections string, 
     Categories string 
FROM @input 
USING new JsonExtractor(); 

@data = 
SELECT SourceUrl, 
     Title, 
     Guest, 
     PublishDate, 
     Categories, 
     JsonFunctions.JsonTuple(transcription_section) AS ts_map 
FROM @data 
CROSS APPLY 
    EXPLODE(JsonFunctions.JsonTuple(TranscriptionSections).Values) AS T(transcription_section); 

@data = 
SELECT SourceUrl, 
     Title, 
     Guest, 
     PublishDate, 
     Categories, 
     ts_map["SectionStartTime"]AS SectionStartTime, 
     JsonFunctions.JsonTuple(text_item) ["Text"]AS text 
FROM @data 
     CROSS APPLY 
     EXPLODE(JsonFunctions.JsonTuple(ts_map["Sentences"]).Values) AS S(text_item); 

OUTPUT @data 
TO "/output/jsondata.csv" 
USING Outputters.Csv(outputHeader : true); 
: 여기
USE econosphere; 

REFERENCE ASSEMBLY [Newtonsoft.Json]; 
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats]; 

DECLARE @in string="adl://abc.azuredatalakestore.net/data/20170515UnitTest.json"; 

DECLARE @out 
string="adl://abc.azuredatalakestore.net/processed/20170515UnitTest.csv"; 

@ep = EXTRACT 
Title string, 
SourceUrl string, 
Guest string, 
PublishDate DateTime, 
TranscriptionSections string 
FROM @in 
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor(); 

@epAndTransctripts = 
    SELECT Title, 
     SourceUrl, 
     Guest, 
     PublishDate, 
     Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple(TranscriptionSections).Values AS TranscriptionSections_arr 
    FROM @ep; 

@all = 
    SELECT 
     Title, 
     SourceUrl, 
     Guest, 
     PublishDate, 
     Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple(sects)["SectionStartTime"] AS TranscriptionSectionTimes 

    FROM @epAndTransctripts 
    CROSS APPLY 
     EXPLODE(TranscriptionSections_arr) AS t(sects); 


OUTPUT @all 
TO @out 
USING Outputters.Csv(); 

답변

1

나를 위해 일한 솔루션입니다