Hi,
I am really hoping there is a genius in here that can help me, I've been stuck on this for 3 days now.
I have a MongoDB collection, sample of a document is:
{
"_id" : "58c879787f4fd6a4982f3039",
"Actions" : [
{
"What" : {
"_t" : [
"TargetBase",
"UserTarget",
"CreatedTarget"
],
"Who" : {
"TontoUserId" : 12345,
"EmailAddress" : "someuser@test.com.au",
"Name" : "some-user"
}
},
"When" : ISODate("2017-03-14T23:49:06.585Z"),
"Reason" : "some text",
"Wrapup" : null
}
]
}
I have created an external table in hive:
create external table if not exists x (my_serial string, actions array<struct<what:struct<_t
:array, who:struct<tontouserid:string, emailaddress:string, name:string>>, when
:string, reason:string, wrapup:string>>)
STORED BY 'com.mongodb.hadoop.hive.MongoStorageHandler'
WITH SERDEPROPERTIES('mongo.columns.mapping'='{"my_serial":"_id", "actions":"Actions"}')
TBLPROPERTIES('mongo.uri'='mongodb://testuser:testpwd@test-mongo.test.com.au:27017/somedb.somecollection?authSource=admin');
I don't get any errors when running the above, but when I query the table the only data that I get is the my_serial column:
select * from x limit 1;
58c879787f4fd6a4982f3039 [{"what":null,"when":null,"reason":null,"wrapup":null}]
Similar story when I try to explode the actions array:
select my_serial, actionstuff.what._t
from x
LATERAL VIEW explode(actions) actionstable as actionstuff
limit 1;
If I try a different tack on creating the external table:
create external table if not exists x (my_serial string, actions array)
STORED BY 'com.mongodb.hadoop.hive.MongoStorageHandler'
WITH SERDEPROPERTIES('mongo.columns.mapping'='{"my_serial":"_id", "actions":"Actions"}')
TBLPROPERTIES('mongo.uri'='mongodb://testuser:testpwd@test-mongo.test.com.au:27017/somedb.somecollection?authSource=admin');
I get data, but I can't do anything with it:
58c879787f4fd6a4982f3039 ["{ "What" : { "_t" : [ "TargetBase" , "UserTarget" , "CreatedTarget"] , "Who" : { "TontoUserId" : 12345 , "EmailAddress" : "someuser@test.com.au" , "Name" : "some-user"}} , "When" : { "$date" : "2017-03-14T23:15:04.047Z"} , "Reason" : "some text" , "Wrapup" : null }"]
Anyone able to tell me what I'm doing wrong?
Much appreciated.