question

ryan-1 avatar image
ryan-1 asked

Query Snowflake from cloud script?

I've set up snowflake and can successfully run the query I need using their web interface; but I'm not quite sure how to initiate the query, and use it's results, from a scheduled cloud script. I figured I'd be able to use snowflake's node.js SDK, but it seems cloud scripts do not use node.js (?).

The following is the query in question:

select

p:levelSeed as levelSeed,

coalesce(count(case when p:result = 'didWin' then 1 end), 0) as winCount,

coalesce(count(case when p:result = 'didLose' then 1 end), 0) as loseCount,

coalesce(count(case when p:result = 'didQuit' then 1 end), 0) as quitCount

from PLAYFAB_SHARED.PLAYFAB_SHARED.PLAYFAB_ARCHIVE_SHARED

where event_namespace = 'title.[myTitleID]' and event_name = 'player_completed_game'

group by levelSeed

Am I overlooking something in the server API (or elsewhere) that allows me to query my snowflake add-on in a cloud script?

Any suggestions would be appreciated, thanks.

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Correct, Cloud Script is not build on Node - it is specifically a V8 JavaScript engine. Also though, Cloud Script is intended for relatively lightweight operations, so it has a fairly short execution time limit. A query such as you describe, if Snowflake were to provide a Web API for the query, would take a variable amount of time, depending on the total number of events in your game, so it could very easily exceed that time limit.

Snowflake recommends running scheduled queries via an AWS Lambda scheduled task. Using that, you could easily make the query and write the results to Title Data in PlayFab (assuming this is only run occasionally - Title Data isn't meant to be updated frequently).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.