This file contains 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
#* @filter cors | |
cors <- function(res) { | |
res$setHeader("Access-Control-Allow-Origin", "*") # Or whatever | |
plumber::forward() | |
} |
This file contains 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
tokenstatus <- function(token){ | |
body <- list(token = token) | |
r <- POST(qm_url, body = body, encode = "json") | |
print(status_code(r)) | |
return(status_code(r)) | |
} |
This file contains 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
library(RPostgreSQL) | |
user = '<db_user>' | |
pw = '<db_pw>' | |
db_name='<db_name>' | |
db_host='<db_url>' | |
db_port=5432 | |
dbConnection <- function(.) { | |
# create a connection |
This file contains 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
rm(list=ls()) | |
# package | |
library(RPostgreSQL) | |
library(dplyr) | |
library(ggplot2) | |
library(lubridate) | |
library(dbplyr) | |
library(jsonlite) | |
library(plotly) |
This file contains 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
#* @get /add | |
add <- function(x, y){ | |
as.numeric(x) + as.numeric(y) | |
} |
This file contains 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
library(RPostgreSQL) | |
dbConnection <- function(.) { | |
# create a connection | |
# loads the PostgreSQL driver | |
drv <- PostgreSQL() | |
all_cons <- dbListConnections(PostgreSQL()) | |
# Cancel any existing connections |
This file contains 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
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
import pandas as pd | |
import requests | |
from datetime import datetime | |
import json | |
def get(url): |
This file contains 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
class BigQueryValidator: | |
"""Convert Jinja templated sql query to a regularly formatted query and validate it using BigQuery dry run. | |
Queries can be inputted as a string or by passing the file path to a sql file. | |
""" | |
def __init__(self, | |
use_query_cache=False): | |
self.bq_client = bigquery.Client() | |
self.params = self.load_params() |
This file contains 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
class BigqueryValidatorTest(unittest.TestCase): | |
bigquery_validator = BigQueryValidator() | |
def test_valid_query_returns_true(self): | |
query = "SELECT count(*) FROM `{{ params.project }}.samples.github_timeline`" | |
valid_sql, _ = self.bigquery_validator.validate_query(query) | |
self.assertTrue(valid_sql) | |
def test_valid_query_from_file_returns_true(self): |
This file contains 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 unittest | |
from bigquery_validator.bigquery_result import BigQueryResult | |
from bigquery_validator.bigquery_validator import BigQueryValidator | |
class BigqueryResultTest(unittest.TestCase): | |
bigquery_validator = BigQueryValidator(return_query_cost_as_dict=True) | |
def test_each_rows_contains_a_unique_user_id(self): |
OlderNewer