ApachePig如何根据条件采取行动

z9smfwbn  于 2021-05-27  发布在  Hadoop
关注(0)|答案(0)|浏览(226)

文件status.log有一个字段status,可以是{issue,resolved,chat}之一。我想根据行的状态字段将文件中的每一行推送到三个mongodb集合中的一个(与rdbms中的表并行)。但是,如果c1、c2或c3为空/null,下面的代码将抛出异常。如果文件没有status=chat或resolution或issue的行,则可能发生这种情况。想知道是否有任何方法来检查之前,试图存储在mongo收集。例如,如果c1不是空的,则将c1存储在问题集合中。

define MongoInsertStorage com.mongodb.hadoop.pig.MongoInsertStorage();
a2 = LOAD 'status.log' using PigStorage(',') AS (timestamp:Long, student_id:charArray, status:charArray); 
b2 = FOREACH a2 GENERATE *; 
SPLIT b2 INTO c1 IF (status=='issue'), c2 IF (status=='resolved'), c3 IF (status=='chat');

/*Can we check if c1 is not empty before storing it. Otherwise, we get error*/
store c1 into 'mongodb://localhost:27017/mydb.issue_log' using MongoInsertStorage();
store c2 into 'mongodb://localhost:27017/mydb.resolved_log' using MongoInsertStorage();
store c3 into 'mongodb://localhost:27017/mydb.chat_log' using MongoInsertStorage();

非常感谢您的帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题