Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement in and not in clauses in hive

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to implement in and not in clauses in hive". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Hive example explains the implementation of in and not in clauses

Currently, hive does not support syntax that contains query clauses in in or not in, so it can only be implemented through left join.

Suppose you have a login table login (the same day's login record, only one uid), and a user registry regusers (the same day's registered user, with only one uid field), both tables contain a field, uid.

In query

If you want to query the registered users who logged in on the same day, you need to use in to query. The hive sql is as follows:

Select login.uid from login left outer join regusers on login.uid=regusers.uid where regusers.uid is not null

If the login table and regusers table are partitioned by day, and the field is dt, then query the registered users who logged in on January 1, 2013, and the hive sql is as follows:

Select login.uid from login day_login left outer join (select uid from regusers where dt='20130101') day_reguserson day_login.uid=day_regusers.uid where day_login.dt='20130101' and day_regusers.uid is not null

Not in query

If you want to query the regular users who logged in on the same day (it is assumed that users who are not registered on the same day are regular users), you need to use not in to query. The hive sql is as follows:

Select login.uid from login left outer join regusers on login.uid=regusers.uid where regusers.uid is null

If login table and regusers table are partitioned by day, and the field is dt, then query the regular users who logged in on January 1, 2013, and the hive sql is as follows:

Select login.uid from login day_login left outer join (select uid from regusers where dt='20130101') day_reguserson day_login.uid=day_regusers.uid where day_login.dt='20130101' and day_regusers.uid is null

This is the end of the content of "how hive implements in and not in clauses". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report