In [1]:
import os, sys
sys.path.append(os.path.abspath('../../../main/python'))
import thalesians.tsa.q.qutils as qutils
In [2]:
import datetime as dt
import pandas as pd
In [3]:
from qpython import qconnection
In [4]:
df = pd.DataFrame({
'sym': ['foo', None, 'baz', 'qux', 'quux', 'quuz', 'corge'],
'tally': [3, 7, 5, 3, 8, 10, 12],
'price': [3.57, 10.87, 10.28, 3.22, 18.15, 29.29, 10.09],
'date': [
dt.date(2019, 5, 17), dt.date(2019, 5, 17), dt.date(2019, 5, 17),
dt.date(2019, 5, 17), dt.date(2019, 5, 17), dt.date(2019, 5, 17),
dt.date(2019, 5, 17)],
'time': [
dt.time(21, 43, 54, 357000), dt.time(21, 43, 54, 357000), dt.time(21, 43, 54, 357000),
dt.time(21, 43, 54, 357000), dt.time(21, 43, 54, 357000), dt.time(21, 43, 54, 357000),
dt.time(21, 43, 54, 357000)],
'datetime': [
dt.datetime(2019, 5, 17, 21, 43, 54, 357000), dt.datetime(2019, 5, 17, 21, 43, 54, 357000),
dt.datetime(2019, 5, 17, 21, 43, 54, 357000), dt.datetime(2019, 5, 17, 21, 43, 54, 357000),
dt.datetime(2019, 5, 17, 21, 43, 54, 357000), dt.datetime(2019, 5, 17, 21, 43, 54, 357000),
dt.datetime(2019, 5, 17, 21, 43, 54, 357000)]
})
In [5]:
df
Out[5]:
In [6]:
df.dtypes
Out[6]:
In [7]:
q_code = []
In [8]:
q_code.append(qutils.df_to_q_table_schema(df, 'sample'))
In [9]:
q_code.extend(qutils.df_to_upsert_statements(df, 'sample'))
In [10]:
q = qconnection.QConnection(host='localhost', port=2507, pandas=True)
q.open()
In [11]:
for q_line in q_code:
q(q_line)
In [12]:
q('select from sample')
Out[12]:
In [13]:
batches = qutils.df_to_batch_append_statements(df, 'sample', rows_per_batch=3)
In [14]:
len(batches)
Out[14]:
In [15]:
batches[0]
Out[15]:
In [16]:
batches[1]
Out[16]:
In [17]:
batches[2]
Out[17]:
In [18]:
q(qutils.df_to_q_table_schema(df, 'sample'))
In [19]:
for batch in batches:
q(batch)
In [20]:
q('select from sample')
Out[20]: