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 use FROM_UNIXTIME and UNIX_TIMESTAMP in Spark Sql

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to use FROM_UNIXTIME and UNIX_TIMESTAMP in Spark Sql". In daily operation, I believe many people have doubts about how to use FROM_UNIXTIME and UNIX_TIMESTAMP in Spark Sql. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use FROM_UNIXTIME and UNIX_TIMESTAMP in Spark Sql". Next, please follow the editor to study!

As we all know, digital integers are used for size comparison and calculation much faster than character types, so some businesses need to convert the time field into integers to facilitate the fast calculation and arrival of business. This shaping number is the number of seconds from the selected date to the UTC time '1970-01-01 00 UTC'. It is currently 10 digits, such as 1234567890, which is commonly used as an example, but after all, the number is not easy to observe. Later, you need to convert these time numbers into real time fields.

Here you need two functions to convert UNIX_TIMESTAMP and FROM_UNIXTIME

Let's introduce them one by one.

UNIX_TIMESTAMP

Is to convert the time field into an integer. It should be noted that some databases need to specify the type of time field.

For example, in MySQL, you can directly UNIX_TIMESTAMP ('20200223'), while some big data platforms need UNIX_TIMESTAMP ('20200223).

FROM_UNIXTIME

As the name implies, the time integer is cracked from the integer to the desired time format, and the format can be specified when using it.

What is often used in this is the combination of UNIX_TIMESTAMP and FROM_UNIXTIME, for example, to collect and calculate a time field: '2020-02-23 01-02-23 01-02-23 01-02-23 01-02-23 01-02-23 01-22 are all integrated with' 2020-02-23 01-01purl 0322'.

Select FROM_UNIXTIME (unix_timestamp ('20200223') + 5*60*floor ((substr ('2020-02-23 00 rig 01lv 02lv 02LJ 12L2) * 60+substr (' 2020-02-2300 Ru 01lv 01lv 02lt 15 Jue 15) / 5) time1

Add the following format conversion:

% an abbreviated week name% b abbreviated month name% c month, value% D day of month with English prefix% d month, value (00-31)% e-month day, value (0-31)% f microsecond% H-hour (00-23)% h-hour (01-12)% I-hour (01-12)% I minute Value (00-59)% j year days (001-366)% k hours (0-23)% l hours (1-12)% M month name% m months, value (00-12)% p AM or PM%r time 12-hour (hh:mm:ss AM or PM)% S seconds (00-59)% s seconds (00-59)% T time, 24-hours (hh:mm:ss)% U week (00-53) Sunday is the first day of the week% u week (00-53) Monday is the first day of the week% V week (01-53) Sunday is the first day of the week With% X using% v week (01-53) Monday is the first day of the week, with% x using% W week name% w week (0 = Sunday, 6 = Saturday)% X year, where Sunday is the first day of the week, 4 digits, and% V using% x year, where Monday is the first day of the week, 4 digits, and% v using% Y year 4% y year, 2 here, the study on "how to use FROM_UNIXTIME and UNIX_TIMESTAMP in Spark Sql" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report