日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

superset数据集birth_names的负时间戳处理

發(fā)布時(shí)間:2023/12/31 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 superset数据集birth_names的负时间戳处理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

處理負(fù)時(shí)間戳

superset有個(gè)數(shù)據(jù)集叫birth_names.json

里面的ds這一欄全是負(fù)的

這個(gè)數(shù)據(jù)集的時(shí)間范圍其實(shí)是:

1965-01-01 08:00:00~2008-01-01 08:00:00

下面的方案來自[2],但是有個(gè)要命的問題就是無法處理負(fù)時(shí)間戳

mysql> create table foo(id INT, mytimestamp INT(11)); Query OK, 0 rows affected (0.02 sec) Insert some valuesmysql> insert into foo values(1, 1381262848); Query OK, 1 row affected (0.01 sec) Take a lookmysql> select * from foo; +------+-------------+ | id | mytimestamp | +------+-------------+ | 1 | 1381262848 | +------+-------------+ 1 row in set (0.00 sec) Convert the number to a timestamp:mysql> select id, from_unixtime(mytimestamp) from foo; +------+----------------------------+ | id | from_unixtime(mytimestamp) | +------+----------------------------+ | 1 | 2013-10-08 16:07:28 | +------+----------------------------+ 1 row in set (0.00 sec) Convert it into a readable format:mysql> select id, from_unixtime(mytimestamp, '%Y %D %M %H:%i:%s') from foo; +------+-------------------------------------------------+ | id | from_unixtime(mytimestamp, '%Y %D %M %H:%i:%s') | +------+-------------------------------------------------+ | 1 | 2013 8th October 04:07:28 | +------+-------------------------------------------------+ 1 row in set (0.00 sec)

?

?

苦思冥想,最后將[3]中的命令修改如下:

SELECT DATE_ADD('1970-01-01 00:00:00',INTERVAL ds/1000 SECOND) from birth_names;

如果想要全部展示,那么:

SELECT DATE_ADD('1970-01-01 00:00:00',INTERVAL ds/1000 SECOND), gender,name,num ,state,sum_boys,sum_girls from birth_names;

?

處理后建立新的表格

如果想把查詢結(jié)果另外新建一張表格,那么:

①導(dǎo)出為csv(注意不要修改導(dǎo)出路徑)

SELECT DATE_ADD('1970-01-01 00:00:00',INTERVAL ds/1000 SECOND), gender,name,num ,state,sum_boys,sum_girls from birth_names into outfile '/var/lib/mysql-files/birth_names.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';

導(dǎo)出之后發(fā)現(xiàn)日期格式變成這樣了:

不用擔(dān)心,因?yàn)槿绻胹ublime打開的話,依然和查詢結(jié)果一致

②csv通過datagrip導(dǎo)入mysql

先把老的表格刪除:

drop table birth_names;

然后新建個(gè)表格:

create table birth_names (ds datetime null,gender text null,name text null,num int null,state text null,sum_boys int null,sum_girls int null );

?

右鍵表格->Import Data from file:

?

最終效果如下:

?

?

?

Reference:

[1]https://tool.lu/timestamp/

[2]Convert timestamp to date in MySQL query

[3]Converting negative values from FROM_UNIXTIME

總結(jié)

以上是生活随笔為你收集整理的superset数据集birth_names的负时间戳处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。