Skip to content

Instantly share code, notes, and snippets.

View vvgsrk's full-sized avatar

Venkata Gowri Sai Rakesh Kumar Varanasi vvgsrk

View GitHub Profile
@vvgsrk
vvgsrk / one_hour_interval_average_load_with_credits_and_query_count.sql
Created April 10, 2020 08:08
1 Hour Interval Average Load with Credits and Query count
WITH wlh as (
SELECT DATE_TRUNC('hour', wl.start_time) start_time_trunced_at_hour, HOUR(wl.start_time) start_time_hour,
AVG(avg_running) avg_running, AVG(avg_queued_load) avg_queued_load,
AVG(avg_queued_provisioning) avg_queued_provisioning, AVG(avg_blocked) avg_blocked
FROM snowflake.account_usage.warehouse_load_history wl
WHERE DATE_TRUNC('DAY', wl.start_time) = '2020-03-26'
AND wl.warehouse_name = 'PUT_YOUR_WAREHOUSE_NAME'
GROUP BY start_time_trunced_at_hour, start_time_hour
ORDER BY start_time_trunced_at_hour asc
),
@vvgsrk
vvgsrk / Parse_Fixed_Width_Text_File_Using_Pandas.ipynb
Created April 12, 2020 09:52
Parse fixed width text file using Pandas library read_fwf method
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
CREATE OR REPLACE STREAM db_dev.revenue.od_forecast_booking_stream
ON TABLE db_dev.revenue.od_forecast_booking
APPEND_ONLY = TRUE;
SHOW STREAMS LIKE 'od_forecast_booking_stream' IN db_dev.revenue;
DESCRIBE STREAM db_dev.revenue.od_forecast_booking_stream;
SELECT * FROM db_dev.revenue.od_forecast_booking_stream;
CREATE OR REPLACE VIEW db_dev.revenue.fleet_assigner_vw
AS
SELECT
airline_code || LPAD(flight_number, 4, 0) ||
TO_CHAR(depature_date, 'ddMMyyyy') ||
depature_airport ||
arrival_airport ||
flight_cabin ||
booking_class
AS FA_OUT
AWSTemplateFormatVersion: 2010-09-09
Description: 'Cloudformation Stack to create a outbound bucket for Fleet Assigner Data'
Resources:
DataBucketDev:
Type: 'AWS::S3::Bucket'
Properties:
AccessControl: Private
PublicAccessBlockConfiguration:
@vvgsrk
vvgsrk / snowflake_stage_for_fleet_assigner.sql
Last active June 27, 2020 14:22
Snowflake Stage to unload fleet assigner output CSV to S3 bucket
CREATE STAGE db_dev.stage.dev_data_outbound_fleetassigner
URL = 's3://dev-outbound-fleetassigner'
CREDENTIALS = (AWS_KEY_ID = 'YOUR_ACCESS_KEY' AWS_SECRET_KEY = 'YOUR_SECRET_KEY')
COMMENT = 'This stage is for Fleet Assigner data unload from Snowflake';
create or replace procedure db_dev.revenue.fa_unload_sp()
returns string not null
language javascript
as
$$
// Get Current Date
var date_now = new Date()
// Get Year as YYYY
var full_year = date_now.getFullYear()
CREATE OR REPLACE TASK db_dev.revenue.fa_unload_task
WAREHOUSE = LOAD_DEV
SCHEDULE = 'USING CRON 0 18 * * * UTC'
WHEN
SYSTEM$STREAM_HAS_DATA('OD_FORECAST_BOOKING_STREAM')
AS
call db_dev.revenue.fa_unload_sp();
ALTER TASK IF EXISTS db_dev.revenue.fa_unload_task RESUME;