Skip to content

Instantly share code, notes, and snippets.

@anthonylouisbsb
Created June 10, 2020 11:55
Show Gist options
  • Save anthonylouisbsb/6cfd618b58ca0fdc581f6d81404e9674 to your computer and use it in GitHub Desktop.
Save anthonylouisbsb/6cfd618b58ca0fdc581f6d81404e9674 to your computer and use it in GitHub Desktop.
import argparse
import asyncio
import time
from aspectlib import Aspect, weave
from shannondb import ShannonDBClient, columns
@Aspect(bind=True)
def print_debug_log(cutpoint, *args, **kwargs):
start_time = time.time()
try:
result = yield
except Exception as exception:
print(f"Raise an exception: {exception}")
raise
else:
stop_time = time.time()
print(f"Function execution: {cutpoint.__name__} - {stop_time - start_time}")
async def main(args):
client = await ShannonDBClient.create_client([("shannondb-presto", 1234)], origin="test")
database_id = int(args.i)
columns_parameters = get_columns_parameters(database_id)
await client.create_columns_in_bulk(columns_parameters)
def get_columns_parameters(database_id: int) -> list:
columns_parameters = [
{
'name': f'{database_id}_logs_organization-id',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries'
},
{
'name': f'{database_id}_logs_type-id',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries'
},
{
'name': f'{database_id}_logs_level',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries'
},
{
'name': f'{database_id}_logs_source',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries'
},
{
'name': f'{database_id}_logs_source-url',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
},
{
'name': f'{database_id}_logs_summary',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
},
{
'name': f'{database_id}_logs_details',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
}, {
'name': f'{database_id}_logs_api-address',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
}, {
'name': f'{database_id}_logs_generated-by',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
}, {
'name': f'{database_id}_logs_user-id',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries'
}, {
'name': f'{database_id}_logs_metadata',
'index': True,
'store': True,
'overwrite': False,
'type': 'timeseries'
}, {
'name': f'{database_id}_logs_request-response-time',
'index': True,
'store': True,
'overwrite': False,
'type': 'numerictimeseries',
'precision': 2
}, {
'name': f'{database_id}_logs_database-ids',
'index': True,
'store': True,
'overwrite': False,
'type': 'numeric',
}, {
'name': f'{database_id}_logs_table-ids',
'index': True,
'store': True,
'overwrite': False,
'type': 'numeric',
}, {
'name': f'{database_id}_logs_column-ids',
'index': True,
'store': True,
'overwrite': False,
'type': 'numeric',
}, {
'name': f'{database_id}_logs_data-connection-ids',
'index': True,
'store': True,
'overwrite': False,
'type': 'numeric',
},
]
return columns_parameters
"""Execute main method asynchronously"""
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-t', help='query help')
parser.add_argument('-i', help='query help')
args = parser.parse_args()
weaving_list = [ShannonDBClient,
columns.create_columns_in_bulk,
columns.create_single_column]
with weave(weaving_list, print_debug_log):
loop = asyncio.get_event_loop()
loop.run_until_complete(main(args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment