This file contains hidden or 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
import sqlite3 as sql | |
from contextlib import closing | |
class dal: | |
def __init__(self, dbname): | |
self.dbname = dbname | |
@staticmethod | |
def __connection(dbname): |
This file contains hidden or 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
import psycopg2 | |
dsn = dict( | |
dbname='dbname', | |
host='hostname', | |
password='password', | |
port=5432, | |
user='username' | |
) | |
conn = psycopg2.connect(**dsn) |
This file contains hidden or 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
import functools | |
def excuteImmediately(fn): | |
@functools.wraps(fn) | |
def wrapper(*args, **kwargs): | |
return fn(*args, **kwargs) | |
return wrapper() | |
example: |
This file contains hidden or 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
########################################################################### | |
# | |
## @file postgres.py | |
# | |
########################################################################### | |
import psycopg2 | |
########################################################################### | |
# |
This file contains hidden or 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
import MySQLdb | |
import MySQLdb.cursors | |
from config import config | |
class Cursor(object): | |
def __init__(self, mysql_cursor): | |
self.cursor = mysql_cursor | |
def __iter__(self): |
This file contains hidden or 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
from psycopg2 import sql | |
import queries | |
pg_session = queries.Session( | |
queries.uri( | |
host='localhost', | |
port='5439', | |
dbname='postgres', | |
user='postgres', | |
password='password' |
This file contains hidden or 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
{ | |
"paragraphs": [ | |
{ | |
"text": "%md\n### Run simple queries to check the count of both the iotdata and iotrollup tables.\nClick the play button within each of the paragraphs to rerun/update the content\n", | |
"user": "admin", | |
"dateUpdated": "2018-10-05T19:03:40-0400", | |
"config": { | |
"tableHide": false, | |
"editorSetting": { | |
"language": "markdown", |
This file contains hidden or 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
--set up your environment | |
create database my_test_db; | |
create schema my_test_db.witsml; | |
use schema my_test_db.witsml; | |
--create the staging table where all WITSML files are loaded to by Snowpipe | |
create table witsml_temp (col1 variant); | |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<template encoding-version="1.2"> | |
<description>Workflow to monitor Snowflake credit consumption and report to Slack. Full article can be found here https://snowflakecomputing.atlassian.net/wiki/spaces/RT/pages/771200336/Creating+a+Snowflake+usage+report+using+Apache+Nifi | |
Requires existing tables and apps defined in your Snowflake account and your Slack account</description> | |
<groupId>be279da7-0167-1000-6a67-4d0cb36decc6</groupId> | |
<name>SnowflakeCreditMonitoring</name> | |
<snippet> | |
<connections> | |
<id>1d50d3ac-3446-3e09-0000-000000000000</id> |
This file contains hidden or 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
--create a table to hold the metrics you wish to monitor and their threshold values | |
CREATE TABLE "MY_TEST_DB"."PUBLIC"."THRESHOLDS" ("SERVICE_TYPE" STRING NOT NULL, "CREDITS_BILLED" DOUBLE NOT NULL) COMMENT = 'Used for the Nifi alerting demo'; | |
--insert some sample records into the thresholds table | |
insert into "MY_TEST_DB"."PUBLIC"."THRESHOLDS" values ('AUTO_CLUSTERING', 10),('PIPE', 10),('MATERIALIZED_VIEW', 10),('WAREHOUSE_METERING', 10); | |
--query to compare current metrics to threshold values | |
--This is used for the HOURLY report | |
select a.*, iff(b.credits_billed is null, 0, b.credits_billed)::string as credits_billed from | |
"MY_TEST_DB"."PUBLIC"."THRESHOLDS" a left join |