将 Hive 导出为具有数据类型完整性的 CSV

Exporting Hive to CSV with data type integrity

Hive 中存在的 table 采用以下格式:

desc table_name;
col_id                double
col_ts                string
col_nm                string
cols_nm               string
col_cd                string
col_state_cd          string

我正在使用以下代码将其导出到 csv 文件:

 hive -e 'set hive.cli.print.header=true; select * from table_name' | sed 's/[\t]/,/g'  > /home/yourfile.csv

但是我通过R读取的时候,col_id的数据类型变成了字符串。 如何确保数据格式与 Hive 中的相同?

试试 Hadley Wickham 的 readr package -- 它非常擅长猜测数据类型。

require(readr)
demo_tables <- read_csv("my_table.csv")