hive 新建表,写入查询结果

版权声明:本文为博主原创文章,转载请说明出处 https://blog.csdn.net/u010002184/article/details/89605768

 hive> create table sales_info_new_new 
    > as
    > select sku_id,sku_name,category_id3,price,sales_count,dt 
    > from sales_info where dt = '2019-04-26';

原表DDL:

CREATE TABLE `sales_info`(
`sku_id` string COMMENT '商品id', 
`sku_name` string COMMENT '商品名称', 
`category_id3` string COMMENT '三级分类id', 
`price` double COMMENT '销售价格', 
`sales_count` bigint COMMENT '销售数量'
)
COMMENT '商品销售信息表'
PARTITIONED BY(
`dt` string)
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',' 
NULL DEFINED AS '' 
STORED AS TEXTFILE
LOCATION
'hdfs://ns1/abc/sales_info'

 原表查询结果:

hive> select *  from sales_info;
OK
sku_id	sku_name	category_id3	price	sales_count	dt
12377	华为Mate10	31	999.0	20	2019-04-26
45677	华为Mate30	31	2999.0	30	2019-04-26
Time taken: 0.059 seconds, Fetched: 2 row(s)
hive> 

执行命令: 

hive> create table sales_info_new_new 
    > as
    > select sku_id,sku_name,category_id3,price,sales_count,dt 
    > from sales_info where dt = '2019-04-26';
Query ID = ....befd3cb26fa
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Start submit job !
Submit job success : job_1553682021014_352096
Starting Job = job_1553682021014_352096, Tracking URL = http://....53682021014_352096/
Kill Command = /..... job  -kill job_1553682021014_352096
Hadoop job(job_1553682021014_352096) information for Stage-1: number of mappers: 1; number of reducers: 0
2019-04-27 18:06:58,469 Stage-1(job_1553682021014_352096) map = 0%,  reduce = 0%
2019-04-27 18:07:22,819 Stage-1(job_1553682021014_352096) map = 100%,  reduce = 0%, Cumulative CPU 1.86 sec
MapReduce Total cumulative CPU time: 1 seconds 860 msec
Stage-1  Elapsed : 310296 ms  job_1553682021014_352096
Ended Job = job_1553682021014_352096
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to: hdfs://ns1.......9-1/-ext-10001
Moving data to: hdfs://ns1/user/abc/sales_info_new_new
chgrp: changing ownership of 'hdfs://ns1/abc/sales_info_new_new': User does not belong to a
读取 1 个统计文件信息用时: 3 ms
Table gdm.sales_info_new_new stats: [numFiles=1, numRows=2, totalSize=85, rawDataSize=83]
MapReduce Jobs Launched: 
Stage-1: job_1553682021014_352096 SUCCESS HDFS Read: 0.000 GB HDFS Write: 0.000 GB Elapsed : 5m10s296ms
Map: Total: 1 Success: 1 Killed: 0 Failed: 0 avgMapTime: 13s923ms
Reduce: Total: 0 Success: 0 Killed: 0 Failed: 0 avgReduceTime: 0ms avgShuffleTime: 0ms avgMergeTime: 0ms
JobHistory URL : http:......021014_352096

Total MapReduce CPU Time Spent: 1s860ms
Total Map: 1  Total Reduce: 0
Total HDFS Read: 0.000 GB  Written: 0.000 GB
OK
sku_id	sku_name	category_id3	price	sales_count	dt
Time taken: 317.863 seconds
hive> select *  from sales_info_new_new;
OK
sku_id	sku_name	category_id3	price	sales_count	dt
12377	华为Mate10	31	999.0	20	2019-04-26
45677	华为Mate30	31	2999.0	30	2019-04-26
Time taken: 0.038 seconds, Fetched: 2 row(s)
hive> show create table sales_info_new_new;
OK
createtab_stmt
CREATE TABLE `sales_info_new_new`(
  `sku_id` string, 
  `sku_name` string, 
  `category_id3` string, 
  `price` double, 
  `sales_count` bigint, 
  `dt` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://ns1/abc/sales_info_new_new'
TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='true', 
  'mart_name'='a', 
  'numFiles'='1', 
  'numRows'='2', 
  'rawDataSize'='83', 
  'totalSize'='85', 
  'transient_lastDdlTime'='1556363247')
Time taken: 0.107 seconds, Fetched: 23 row(s)

原表是分区表,自动创建的新表不是分区表。

猜你喜欢

转载自blog.csdn.net/u010002184/article/details/89605768