Database Reference
In-Depth Information
tabledata: tabledata collection client
project_id: project ID of the destination table.
dataset_id: dataset ID of the destination table.
table_id: table ID of the destination table.
'''
pos = 0
rows = []
while True:
# If the file has additional data available and
there are less than
# 10 buffered rows then fetch the next available
line.
line = infile.readline() if len(rows) < 10 else
None
# If the line is a complete line buffer it.
if line and line[−1] == '\n':
# Record the end of the last full line.
pos = infile.tell()
ts, label, count = line.split(',')
rows.append({
'insertId': '%s%d' % (sys.argv[1], pos),
'json': {
'ts': int(ts.strip()),
'label': label.strip(),
'count': int(count.strip())
}
})
# 10 buffered rows or no new data so flush buffer
by positing it.
else:
if rows:
tabledata.insertAll(
projectId=project_id,
datasetId=dataset_id,
tableId=table_id,
body={'rows': rows}).execute()
del rows[:]
else:
Search WWH ::




Custom Search