You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
data-maker/bridge.py

263 lines
10 KiB
Python

5 years ago
"""
Create pseudonyms map as follows :
table, field,value,enc,filter
"""
import pandas as pd
import numpy as np
from google.oauth2 import service_account
from google.cloud import bigquery as bq
import json
import threading
import sys
import os
import itertools
DATASET_SUFFIX = '_pseudo'
PSEUDO_TABLENAME = 'map'
SYS_ARGS = {'context':''}
if len(sys.argv) > 1:
N = len(sys.argv)
for i in range(1,N):
value = None
if sys.argv[i].startswith('--'):
key = sys.argv[i].replace('-','')
if i + 1 < N:
value = sys.argv[i + 1] = sys.argv[i+1].strip()
if key and value:
SYS_ARGS[key] = value
if key == 'context':
SYS_ARGS[key] = ('/'+value).replace('//','/')
i += 2
class void :
pass
class pseudonym :
@staticmethod
def meta(**args) :
"""
:key Bigquery private key (service account)
:dataset dataset of the input table
:table table name
:filter optional filter (SQL statement)
"""
credentials = service_account.Credentials.from_service_account_file(args['key'])
SQL = ["SELECT * FROM :dataset.:table"]
# if 'filter' in args :
# SQL += ['WHERE',args['filter']]
5 years ago
else:
5 years ago
SQL += ['FROM :dataset.:table']
5 years ago
--export will export data to a specified location
"""
has_basic = 'dataset' in SYS_ARGS.keys() and 'table' in SYS_ARGS.keys() and 'key' in SYS_ARGS.keys()
has_action= 'export' in SYS_ARGS.keys() or 'pseudo' in SYS_ARGS.keys()
if has_basic and has_action :
builder = Builder()
if 'export' in SYS_ARGS :
print ()
print ("exporting ....")
if not os.path.exists(SYS_ARGS['export']) :
os.mkdir(SYS_ARGS['export'])
SQL = builder.encode(**SYS_ARGS)