Skip to content

Update Stream Analytics commands in setup script #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 17 additions & 46 deletions dotnet/setup/labSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,7 @@ function Add-EventHub($resourceGroupName, $location, $eventHubNS, $eventHubName,
function Add-StreamProcessor($resourceGroupName, $location, $eventHubNS, $jobName) {
# NOTE - Creating a Power BI Output is not supported via scripting

$jobDefinition = @"
{
"location": "$location",
"properties": {
"sku":{
"name": "standard"
},
"eventsOutOfOrderPolicy": "adjust",
"eventsOutOfOrderMaxDelayInSeconds": 10,
"compatibilityLevel": 1.1
}
}
"@

$jobDefinition | Out-File JobDefinition.json

New-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -File "JobDefinition.json" -Name $jobName
New-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -Name $jobName -Location $location -SkuName Standard -EventsOutOfOrderPolicy adjust -EventsOutOfOrderMaxDelayInSecond 10 -CompatibilityLevel 1.1

$inputDefintion = @"
{
Expand Down Expand Up @@ -351,35 +335,22 @@ function Add-StreamProcessor($resourceGroupName, $location, $eventHubNS, $jobNam

$inputDefintion | Out-File InputDefinition.json

New-AzStreamAnalyticsInput -ResourceGroupName $resourceGroupName -JobName $jobName -File "InputDefinition.json"

$transformationDefintiion = @"
{
"properties": {
"streamingUnits": 1,
"query": "/*TOP 5*/\r\n WITH Counter AS\r\n (\r\n SELECT Item, Price, Action, COUNT(*) AS
countEvents\r\n FROM cartinput\r\n WHERE Action = 'Purchased'\r\n GROUP BY Item, Price, Action,
TumblingWindow(second,300)\r\n ), \r\n top5 AS\r\n (\r\n SELECT DISTINCT\r\n CollectTop(5) OVER
(ORDER BY countEvents) AS topEvent\r\n FROM Counter\r\n GROUP BY TumblingWindow(second,300)\r\n ),
\r\n arrayselect AS \r\n (\r\n SELECT arrayElement.ArrayValue\r\n FROM top5\r\n CROSS APPLY
GetArrayElements(top5.topevent) AS arrayElement\r\n ) \r\n SELECT arrayvalue.value.item,
arrayvalue.value.price, arrayvalue.value.countEvents\r\n INTO top5Output\r\n FROM
arrayselect\r\n\r\n /*REVENUE*/\r\n SELECT System.TimeStamp AS Time, SUM(Price)\r\n INTO
incomingRevenueOutput\r\n FROM cartinput\r\n WHERE Action = 'Purchased'\r\n GROUP BY
TumblingWindow(minute, 5)\r\n\r\n /*UNIQUE VISITORS*/\r\n SELECT System.TimeStamp AS Time,
COUNT(DISTINCT CartID) as uniqueVisitors\r\n INTO uniqueVisitorCountOutput\r\n FROM cartinput\r\n
GROUP BY TumblingWindow(second, 30)\r\n\r\n /*AVERAGE PRICE*/ \r\n SELECT System.TimeStamp
AS Time, Action, AVG(Price) \r\n INTO averagePriceOutput \r\n FROM cartinput \r\n GROUP BY
Action, TumblingWindow(second,30) "
},
"name": "Transformation",
"type": "Microsoft.StreamAnalytics/streamingjobs/transformations"
}
"@

$transformationDefintiion | Out-File TransformationDefinition.json

New-AzStreamAnalyticsTransformation -ResourceGroupName $resourceGroupName -JobName $jobName -File "TransformationDefinition.json"
New-AzStreamAnalyticsInput -ResourceGroupName $resourceGroupName -JobName $jobName -File "InputDefinition.json" -Name "cartInput"

New-AzStreamAnalyticsTransformation -ResourceGroupName $resourceGroupName -JobName $jobName -Name "Transformation" -StreamingUnit 1 -Query "/*TOP 5*/\r\n WITH Counter AS\r\n (\r\n SELECT Item, Price, Action, COUNT(*) AS
countEvents\r\n FROM cartinput\r\n WHERE Action = 'Purchased'\r\n GROUP BY Item, Price, Action,
TumblingWindow(second,300)\r\n ), \r\n top5 AS\r\n (\r\n SELECT DISTINCT\r\n CollectTop(5) OVER
(ORDER BY countEvents) AS topEvent\r\n FROM Counter\r\n GROUP BY TumblingWindow(second,300)\r\n ),
\r\n arrayselect AS \r\n (\r\n SELECT arrayElement.ArrayValue\r\n FROM top5\r\n CROSS APPLY
GetArrayElements(top5.topevent) AS arrayElement\r\n ) \r\n SELECT arrayvalue.value.item,
arrayvalue.value.price, arrayvalue.value.countEvents\r\n INTO top5Output\r\n FROM
arrayselect\r\n\r\n /*REVENUE*/\r\n SELECT System.TimeStamp AS Time, SUM(Price)\r\n INTO
incomingRevenueOutput\r\n FROM cartinput\r\n WHERE Action = 'Purchased'\r\n GROUP BY
TumblingWindow(minute, 5)\r\n\r\n /*UNIQUE VISITORS*/\r\n SELECT System.TimeStamp AS Time,
COUNT(DISTINCT CartID) as uniqueVisitors\r\n INTO uniqueVisitorCountOutput\r\n FROM cartinput\r\n
GROUP BY TumblingWindow(second, 30)\r\n\r\n /*AVERAGE PRICE*/ \r\n SELECT System.TimeStamp
AS Time, Action, AVG(Price) \r\n INTO averagePriceOutput \r\n FROM cartinput \r\n GROUP BY
Action, TumblingWindow(second,30) "
}

##################
Expand Down