ClickHouse icon indicating copy to clipboard operation
ClickHouse copied to clipboard

To select a json object from mongodb in clickhouse.

Open HitendraSinghRathore opened this issue 1 year ago • 1 comments

I have a nested object in my mongo db table the column is affiliate_bag_details

{
"test": 12,
"obj": {
 "nested": [1,2,4]
}
}

while fetching the same using the function MongoDB

SELECT 
    bag_id, 
    display_name, 
    affiliate_bag_details
FROM mongodb(
    '<IP>:host', 
    'db', 
    'collection',
    'username',
    'password!2018',
    'affiliate_bag_details String',
    'connectTimeoutMS=10000'
) 
LIMIT 10;

Getting the following error Exception: Type mismatch, expected String, got type id = 3 for column affiliate_bag_details: While executing MongoDB. Can anyone please suggest what is an alternative schema that i can use to perform the above operation?

HitendraSinghRathore avatar May 19 '24 04:05 HitendraSinghRathore

Tried using

SELECT 
    bag_id, 
    display_name, 
    affiliate_bag_details.test
FROM mongodb(
    '<IP>:host', 
    'db', 
    'collection',
    'username',
    'password!2018',
    'affiliate_bag_details Nested( test String)',
    'connectTimeoutMS=10000'
) 
LIMIT 10;

This does not throw error but date comes as [] event tho source table has values present.

HitendraSinghRathore avatar May 20 '24 08:05 HitendraSinghRathore

Looks like an easy fixable bug: we just need to support struct ElementTraits<Document::Ptr> in https://github.com/ClickHouse/ClickHouse/blob/44c4892a588480288f3f259761ed7a192480748f/src/Processors/Sources/MongoDBSource.cpp#L242-L255

kssenii avatar May 21 '24 19:05 kssenii

Will it be able to read JSON objects from mongoDB as is (by mentioning Nested or JSON in schema), or will it still need to read it as String then cast post read?

HitendraSinghRathore avatar May 23 '24 04:05 HitendraSinghRathore

Hi @kssenii will it be fixed soon? maybe is it possible to add this hotfix to next release?

jakczer avatar May 24 '24 07:05 jakczer

Any updates on this?

HitendraSinghRathore avatar Jun 18 '24 07:06 HitendraSinghRathore

As far as i know there seems to be an active PR for this. Hopefully it will be closed with that

HitendraSinghRathore avatar Jul 05 '24 09:07 HitendraSinghRathore

As far as i know there seems to be an active PR for this.

which one?

Any updates on this?

No, fix was not made yet.

kssenii avatar Jul 05 '24 11:07 kssenii

@kssenii PR link This is the pr.

HitendraSinghRathore avatar Jul 05 '24 15:07 HitendraSinghRathore