Exemplo n.º 1
0
        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"]);
            JObject        result;

            try
            {
                result = 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 <JObject>(HttpStatusCode.OK, result));
        }
Exemplo n.º 2
0
        public async Task InitNewSession()
        {
            var snowflakeClient = new SnowflakeClient(_conectionInfo.User, _conectionInfo.Password, _conectionInfo.Account, _conectionInfo.Region);

            var sessionInitialized = await snowflakeClient.InitNewSessionAsync();

            Assert.IsTrue(sessionInitialized);
            Assert.IsNotNull(snowflakeClient.SnowflakeSession);
        }
Exemplo n.º 3
0
        public SnowflakeQueriesTest()
        {
            var configJson     = File.ReadAllText("testconfig.json");
            var testParameters = JsonSerializer.Deserialize <TestConfiguration>(configJson, new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            });
            var conectionInfo = testParameters.Connection;

            _snowflakeClient = new SnowflakeClient(conectionInfo.User, conectionInfo.Password, conectionInfo.Account, conectionInfo.Region);
        }
Exemplo n.º 4
0
        public async Task RenewSession()
        {
            var snowflakeClient = new SnowflakeClient(_conectionInfo.User, _conectionInfo.Password, _conectionInfo.Account, _conectionInfo.Region);

            var sessionInitialized = await snowflakeClient.InitNewSessionAsync();

            var firstSessionToken = snowflakeClient.SnowflakeSession.SessionToken;

            var sessionRenewed = await snowflakeClient.RenewSessionAsync();

            var secondSessionToken = snowflakeClient.SnowflakeSession.SessionToken;

            Assert.IsTrue(sessionInitialized);
            Assert.IsTrue(sessionRenewed);
            Assert.IsTrue(firstSessionToken != secondSessionToken);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var                       serviceCollection = new ServiceCollection();
            ServiceProvider           serviceProvider   = ConfigureServices(serviceCollection);
            ILogger <SnowflakeClient> logger            = serviceProvider.GetService <ILogger <SnowflakeClient> >();

            try
            {
                Console.WriteLine("Example of how to use the Snowflake client to load and unload data");
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Ensure you have run Snowflake/Setup.ps1 before continuing");
                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine("Enter your Snowflake connection string:");
                Console.WriteLine("HINT.. its usually in the format 'ACCOUNT=<account-name>;HOST=<account-name>.<account-region>.azure.snowflakecomputing.com;USER=<user>;PASSWORD=<password>;ROLE=<role>'");
                var client = new SnowflakeClient(Console.ReadLine());

                Console.WriteLine();
                Console.WriteLine("Enter your database name:");
                string database = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("Enter name of the warehouse you want to use:");
                string dataWarehouse = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("Enter the input path of the data to load (relative to storage container:");
                string inputPath = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("Enter the output path of the data to unload to (relative to storage container:");
                string outputPath = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("Loading data from Azure into Snowflake SALES.LINEITEM...");
                string schema = "SALES";
                client.Load("azure_adf_stage", "LINEITEM", new[] { inputPath }, dataWarehouse, database, schema, true);
                Console.WriteLine("Load complete");

                Console.WriteLine();
                Console.WriteLine("Unloading aggregate data from Snowflake to Azure...");
                client.Unload("azure_adf_stage", "select * from SupplierAgg", $"{outputPath}.gzip", dataWarehouse, database, schema, true, true);
                Console.WriteLine("Unload complete");

                serviceProvider.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("Ooops... something went wrong...");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Console.WriteLine("Please check your inputs and try again");
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("\r\nPress any key to continue");
            Console.ReadKey();
        }