Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jesspanni's full-sized avatar

Jess Panni jesspanni

  • MakerX
View GitHub Profile
@jesspanni
jesspanni / LoadFunction.cs
Created April 24, 2019 13:24
SnowflakeLoadAzureFunction
[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);
@jesspanni
jesspanni / LoadCommand.cs
Created April 24, 2019 13:11
LoadCommand
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; }
@jesspanni
jesspanni / UnloadCommand.cs
Created April 24, 2019 13:10
UnloadCommand
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; }
@jesspanni
jesspanni / SnowflakeClientExtensions.cs
Created April 24, 2019 12:56
SnowflakeClientExtensions
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());
@jesspanni
jesspanni / batchsql.sql
Created April 24, 2019 12:46
BatchSQLScript
USE DATABASE SALES;
USE SCHEMA SALES;
SELECT * FROM LINEITEMS;
@jesspanni
jesspanni / SnowflakeClient.cs
Last active April 24, 2019 12:45
Snowflake Client
/// <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>
@jesspanni
jesspanni / SnowflakeClientExtensions.cs
Last active April 24, 2019 12:37
SnowflakeClientExtensions
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());