In this example we will create a table to store events:
CREATE TABLE dbo.Events
(
Event string
,INDEX cIX_EVENT CLUSTERED(Event ASC) DISTRIBUTED BY HASH(Event)
);
Then when it comes to extracting the json and inserting it into the database:
You first have to extract the lines using a simple text extractor, then you can parse it. For example, give a file with json objects separated with new lines
{ "Event": "One" }
{ "Event": "Tow" }
{ "Event": "Three"}
then this script will extract the events:
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
USING Microsoft.Analytics.Samples.Formats.Json;
@RawExtract = EXTRACT [RawString] string
FROM @input
USING Extractors.Text(delimiter:'\b', quoting : false);
@ParsedJSONLines = SELECT JsonFunctions.JsonTuple([RawString]) AS JSONLine
FROM @RawExtract;
INSERT INTO Events
SELECT JSONLine["Event"] AS Event
FROM @ParsedJSONLines;
Later on you can read from the table like this:
@result =
SELECT Event
FROM Events;
OUTPUT @result
TO @output
USING Outputters.Csv(outputHeader : true, quoting : true);
Now, since it is an INSERT IMTO
data will be appended to the table.
Resources:
GitHub Examples
More GitHub Examples