Created
June 3, 2022 05:07
-
-
Save dubeyji10/ce513f8171c0dc69e77dccb04a139683 to your computer and use it in GitHub Desktop.
create shards of tabes and save payloads(indexed)
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 mysql.connector | |
from mysql.connector import Error | |
import logging | |
import re | |
print('creating shards of huge amount of data\n') | |
sizeOfShard = 100 | |
index = 0 | |
counter = 0 | |
lastIndex = 1000 | |
alpha = re.compile(r"[a-z|A-Z]|[!@#$%^&*/]") | |
clients = 'select * from clients' | |
leads = 'select * from leads' | |
conversation = 'select * from conversation' | |
invoiceInfo = 'select * from invoice_info' | |
invoiceItems = 'select * from invoice_items' | |
for i in range(index , lastIndex ,sizeOfShard): | |
print(' ------------- {} -------------- '.format(counter)) | |
# print('{} -> running for limit {},{}'.format(counter,i,sizeOfShard)) | |
print('{} -> limit {} OFFSET {}'.format(counter,sizeOfShard , i)) | |
offSet = ' LIMIT {} OFFSET {} '.format(sizeOfShard,i) | |
with mysql.connector.connect() as connectPointer: | |
with connectPointer.cursor() as aCursor: | |
query = clients+offSet | |
print('running - ',query) | |
clientsFile = 'clients/clients_data_{}.json'.format(i) | |
print(f' . .. writing to {clientsFile}') | |
with mysql.connector.connect() as connectPointer: | |
with connectPointer.cursor() as aCursor: | |
query = leads+offSet | |
print('running - ',query) | |
# aCursor.execute(query) | |
# result = aCursor.fetchall() | |
print(f' . .. writing to {clientsFile}') | |
leadsFile = 'leads/leads_data_{}.json'.format(i) | |
print(f' . .. writing to {leadsFile}') | |
with mysql.connector.connect() as connectPointer: | |
with connectPointer.cursor() as aCursor: | |
query = conversation+offSet | |
print('running - ',query) | |
# aCursor.execute(query) | |
# result = aCursor.fetchall() | |
conversationFile = 'conversations/conversation_data_{}.json'.format(i) | |
print(f' . .. writing to {conversationFile}') | |
with mysql.connector.connect() as connectPointer: | |
with connectPointer.cursor() as aCursor: | |
query = invoiceInfo + offSet | |
print('running - ',query) | |
# aCursor.execute(query) | |
# result = aCursor.fetchall() | |
invoiceInfoFile = 'invoiceInfo/invoiceInfo_data_{}.json'.format(i) | |
print(f' . .. writing to {invoiceInfoFile}') | |
with mysql.connector.connect() as connectPointer: | |
with connectPointer.cursor() as aCursor: | |
query = invoiceItems+offSet | |
print('running - ',query) | |
# aCursor.execute(query) | |
# result = aCursor.fetchall() | |
invoiceItemsFile = 'invoiceItems/invoiceItems_data_{}.json'.format(i) | |
print(f' . .. writing to {invoiceItemsFile}') | |
counter+=1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment