Hive the way to implement pagination _hive paging

Source: Internet
Author: User

Hive does not implement pagination as limit start,end like MySQL, so it needs to be implemented in a different way.
Here are two ways I think of it: one, with a unique identification field

If a paginated table has a uniquely identified field, you can implement pagination by using this field: Get the first page of data:
Note: It is also necessary to record that the largest ID in these 10 bars is preid, as a condition for the next page.
SELECT * FROM table ORDER by ID ASC limit 10; Get second page data:
Note: Save the largest ID replacement Preid in the data at the same time.
SELECT * FROM table where ID >preid ORDER by ID ASC limit 10;

Subsequent pages get the same. Second, using the Row_number () function

If the paginated table does not have a uniquely identified field, you can implement pagination by using the row number () function. Use the Row_number () function to make this table an incremented unique identifier:
SELECT * FROM (select Row_number () over (order by XX) as Rnum, table.* from table) t where Rnum Betwneen 1 to 10;


Reference: Hive method of implementing pagination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.