Using hive to calculate the time difference between two adjacent data

Source: Internet
Author: User

1. Advanced usage of the hive row_number () function row_num displays the number of data entries by a field Partition

Select IMEI, ts, fuel_instant, gps_long1_, gps_latitude,Row_number () over (partition by IMEI order by ts ASC) as row_numFrom sample_data_2

2. row_num is continuous, join itself, and then subtract time to calculate the difference
Create Table obd_20140101

Select. IMEI,. row_num,. TS, coalesce (unix_timestamp (. TS, 'yyyy-mm-dd hh: mm: Ss. s '), 0)-unix_timestamp (B. TS, 'yyyy-mm-dd hh: mm: Ss. s ') as intervel,. fuel_instant,. gps_speed as obd_speed,. gps_status,. gps_longpolling,. gps_latitude,. direct_angle,. obdspeed from obddata_20140101 a join obddata_20140101 B on. IMEI = B. IMEI and. row_num = B. row_num + 1

Using hive to calculate the time difference between two adjacent data

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.