Skip to content

Instantly share code, notes, and snippets.

Avatar

Jess Panni jesspanni

  • endjin
View GitHub Profile
@jesspanni
jesspanni / LoadFunction.cs
Created Apr 24, 2019
SnowflakeLoadAzureFunction
View LoadFunction.cs
[FunctionName("Load")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/load")]
HttpRequestMessage req,
ILogger logger,
ExecutionContext context)
{
ServiceProvider serviceProvider = Initializer.Initialize(context);
string body = await req.Content.ReadAsStringAsync().ConfigureAwait(false);
View LoadCommand.cs
public class LoadCommand
{
public string Database { get; set; }
public string Schema { get; set; }
public string Warehouse { get; set; }
public string Stage { get; set; }
public string TargetTable { get; set; }
public string[] Files { get; set; }
public bool Force { get; set; }
View UnloadCommand.cs
public class UnloadCommand
{
public string Database { get; set; }
public string Schema { get; set; }
public string Warehouse { get; set; }
public string Stage { get; set; }
public string Query { get; set; }
public string FilePrefix { get; set; }
public bool SingleFile { get; set; }
public bool Overwrite { get; set; }
View SnowflakeClientExtensions.cs
public static class SnowflakeClientExtensions
{
/// <summary>
/// Instructs Snowflake to load data from a stage into a target table.
/// </summary>
public static int Load(this SnowflakeClient client, string stage, string targetTable, string[] files = null, string warehouse = null, string database = null, string schema = null, bool force = false)
{
IList<string> commands = DefineSnowflakeQueryContext(warehouse, database, schema);
commands.Add(LoadSnowflakeCommand(stage, targetTable, files, force));
return client.ExecuteNonQuery(commands.ToArray());
View batchsql.sql
USE DATABASE SALES;
USE SCHEMA SALES;
SELECT * FROM LINEITEMS;
@jesspanni
jesspanni / SnowflakeClientExtensions.cs
Last active Apr 24, 2019
SnowflakeClientExtensions
View SnowflakeClientExtensions.cs
public static class SnowflakeClientExtensions
{
/// <summary>
/// Instructs Snowflake to load data from a stage into a target table.
/// </summary>
public static int Load(this SnowflakeClient client, string stage, string targetTable, string[] files = null, string warehouse = null, string database = null, string schema = null, bool force = false)
{
IList<string> commands = DefineSnowflakeQueryContext(warehouse, database, schema);
commands.Add(LoadSnowflakeCommand(stage, targetTable, files, force));
return client.ExecuteNonQuery(commands.ToArray());
View SnowflakeClient.cs
/// <summary>
/// A client for submitting queries to Snowflake.
/// </summary>
public class SnowflakeClient
{
private readonly string connectionString;
/// <summary>
/// Initializes a new instance of the <see cref="SnowflakeClient"/> class.
/// </summary>