You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@predictionio.apache.org by do...@apache.org on 2016/08/09 21:43:37 UTC
[29/52] [abbrv] incubator-predictionio git commit: Fix util method
for importing events batch
Fix util method for importing events batch
Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/commit/e4c23bc6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/tree/e4c23bc6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/diff/e4c23bc6
Branch: refs/heads/develop
Commit: e4c23bc63e0b90b99d823fe41ded097b7cffeede
Parents: c1ecef5
Author: Chan Lee <ch...@gmail.com>
Authored: Mon Aug 1 13:59:51 2016 -0700
Committer: Marcin Ziemi\u0144ski <zi...@gmail.com>
Committed: Wed Aug 3 14:41:19 2016 -0700
----------------------------------------------------------------------
utils.py | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/e4c23bc6/utils.py
----------------------------------------------------------------------
diff --git a/utils.py b/utils.py
index b93582d..d837984 100644
--- a/utils.py
+++ b/utils.py
@@ -108,18 +108,25 @@ def send_events_batch(events, test_context, access_key):
def import_events_batch(events, test_context, appid, channel=None):
- """ Imports events from file in batch with `pio import`
+ """ Imports events in batch from file with `pio import`
Args:
events: a list of json-like dictionaries for events
test_context (obj: `TestContext`)
appid (int): application's id
channel (str):
"""
+ # Writing events list to temporary file.
+ # `pio import` requires each line of input file to be a JSON string
+ # representing an event. Also, empty lines are not allowed.
+ contents = ''
+ for ev in events:
+ contents += '{}\n'.format(json.dumps(ev))
+ contents.rstrip('\n')
+
file_path = pjoin(test_context.data_directory, 'events.json.tmp')
try:
with open(file_path, 'w') as f:
- for ev in events:
- f.write(json.dumps(ev))
+ f.write(contents)
srun('pio import --appid {} --input {} {}'.format(
appid,
file_path,