Created
April 24, 2019 13:28
-
-
Save jesspanni/1460dcfc3d36b1bc6fc263a72cd19854 to your computer and use it in GitHub Desktop.
SnowflakeUnloadFunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<HttpResponseMessage> Run( | |
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/unload")] | |
HttpRequestMessage req, | |
ILogger logger, | |
ExecutionContext context) | |
{ | |
ServiceProvider serviceProvider = Initializer.Initialize(context); | |
string body = await req.Content.ReadAsStringAsync().ConfigureAwait(false); | |
UnloadCommand command = JsonConvert.DeserializeObject<UnloadCommand>(body); | |
if (!command.Validate(out string message)) | |
{ | |
return req.CreateResponse(HttpStatusCode.BadRequest, message); | |
} | |
IConfiguration config = serviceProvider.GetService<IConfiguration>(); | |
var client = new SnowflakeClient(config["ConnectionString"]); | |
try | |
{ | |
client.Unload(command.Stage, command.Query, command.FilePrefix, command.Warehouse, command.Database, command.Schema, command.SingleFile, command.Overwrite); | |
} | |
catch (Exception e) | |
{ | |
logger.LogError(e, "Error processing request"); | |
return req.CreateResponse(HttpStatusCode.InternalServerError, e.Message); | |
} | |
return req.CreateResponse(HttpStatusCode.OK); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment