[Python] group_by usage in asq

Source: Internet
Author: User

A. Comparison between native SQL statements and asq statements

Suppose there is an SQL query statement:

 
Select ID, IP, CH, date from TBL group by CH, date;

To use the group_by method of the asq module of Python, You can implement the following: (1) Obtain res_list through SQL query of all records; (2) then use the asq function:
Query (res_list). group_by (lambda P: P [2], Lambda P: P [3]). Select (lambda mem: Mem [0]). to_list ();

In fact, the main logic is to obtain all data through SQL, and then asq first groups, then selects the first record of each group, and finally returns the result list.
B. AdvantagesIn addition, if there is only one query statement, there is no need to use the asq module function, because the performance cannot be better than that of native SQL queries. Compared with native SQL queries, asq has the primary advantage of minimizing the number of table scans in some cases.

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.