为什么这样输出,为什么第二行在第二列NULL
中给出select stack(2,'A',10,date '2015-01-01',1,'B',date '2015-02-02',2)
值:
0: jdbc:hive2://sandbox-hdp.hortonworks.com:1> select stack(2,'A',10,date '2015-01-01',1,'B',date '2015-02-02',2) as (col0,col1,col2,col3);
Error: Error while compiling statement: FAILED: UDFArgumentException Argument 2's type (int) should be equal to argument 6's type (date) (state=42000,code=40000)
0: jdbc:hive2://sandbox-hdp.hortonworks.com:1> select stack(2,'A',10,date '2015-01-01',1,'B',20,date '2015-02-02') as (col0,col1,col2,col3);
INFO : Compiling command(queryId=hive_20191225124022_380b3a4c-9870-4f5c-89c8-a696af39f985): select stack(2,'A',10,date '2015-01-01',1,'B',20,date '2015-02-02') as (col0,col1,col2,col3)
INFO : Semantic Analysis Completed (retrial = false)
INFO : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:col0, type:string, comment:null), FieldSchema(name:col1, type:int, comment:null), FieldSchema(name:col2, type:date, comment:null), FieldSchema(name:col3, type:int, comment:null)], properties:null)
INFO : Completed compiling command(queryId=hive_20191225124022_380b3a4c-9870-4f5c-89c8-a696af39f985); Time taken: 0.545 seconds
INFO : Executing command(queryId=hive_20191225124022_380b3a4c-9870-4f5c-89c8-a696af39f985): select stack(2,'A',10,date '2015-01-01',1,'B',20,date '2015-02-02') as (col0,col1,col2,col3)
INFO : Completed executing command(queryId=hive_20191225124022_380b3a4c-9870-4f5c-89c8-a696af39f985); Time taken: 0.006 seconds
INFO : OK
| col0 | col1 | col2 | col3 |
| A | 10 | 2015-01-01 | 1 |
| B | NULL | 2015-02-02 | 1 |
2 rows selected (0.594 seconds)
在Hive 1.2中,您的select语句引发异常:
select stack(2,'A',10,date '2015-01-01',1,'B',date '2015-02-02',2);
FAILED:UDFArgumentException参数2的类型(int)应该等于参数6的类型(日期)
堆栈(2)的第一个参数表示有两个元组。 这些元组应该具有相同的架构。第一个元组:
'A',10,date '2015-01-01',1 --this one contains 4 columns
第二个元组:
'B',date '2015-02-02',2 --this one contains 3 columns
在'B'之后添加int第二列以匹配第一个元组。它可以为null,但应位于第二个元组中。我加了20:
select stack(2,'A',10,date '2015-01-01',1,'B',20, date '2015-02-02',2);
OK
A 10 2015-01-01 1
B 20 2015-02-02 2
Time taken: 0.363 seconds, Fetched: 2 row(s)