如何在配置单元中爆炸分位数

时间:2019-03-19 09:01:47

标签: hive hiveql

我试图获取一个字段的分位数,我想爆炸它们,以便每个值都是单独的行,而不是所有的值组成一个数组。首先,我计算出20个分位数,如下所示:

select percentile_approx(probability, 
                                       array(0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 
                                             0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 
                                             0.8, 0.85, 0.9, 0.95, 1.0)) as quantiles
from my_table

上面的代码给出了下面的数组:

  

[0.17808226409449213,0.18250386256254247,0.18525207046272224,0.18800918537059694,0.1907743631982954,0.200154288105411,0.30419108474685375,0.3299437131426226,0.352433633041806,0.3589875791100745,0.37581775428218006,0.3825168120904496,0.3966342376441502,0.4173753044627164,0.43268994899295316,0.44015098935735575,0.461413042176578,0.4720422104416653,0.487852850513824,0.5050010622123932]

但是由于我想爆炸它,所以我尝试使用如下所示的侧面视图posexplode(实际上,我通过了上面代码的输出):

select i, x
lateral view posexplode([0.17808226409449213, 0.18250386256254247,0.18525207046272224, 0.18800918537059694, 
                    0.1907743631982954, 0.200154288105411, 0.30419108474685375, 0.3299437131426226, 
                    0.352433633041806, 0.3589875791100745, 0.37581775428218006, 0.3825168120904496, 
                    0.3966342376441502, 0.4173753044627164, 0.43268994899295316, 0.44015098935735575, 
                    0.461413042176578, 0.4720422104416653, 0.487852850513824, 0.5050010622123932]) q as i, x

但它显示以下错误消息:

  

ParseException:“ \下一个输入'['期望{'(',')','SELECT','FROM','ADD','AS','ALL','ANY','DISTINCT', 'WHERE','GROUP','BY','GROUPING','SET','CUBE','ROLLUP','ORDER','HAVING','LIMIT','AT','OR','AND ','IN',NOT,'NO','EXISTS','BETWEEN','LIKE',RLIKE,'IS','NULL','TRUE','FALSE','NULLS','ASC', 'DESC','FOR','INTERVAL','CASE','WHEN','THEN','ELSE','END','JOIN','CROSS','OUTER','INNER','LEFT” ','SEMI','RIGHT','FULL','NATURAL','ON','PIVOT','LATERAL','WINDOW','OVER','PARTITION','RANGE','ROWS', 'UNBOUNDED','PRECEDING','Following','CURRENT','FIRST','AFTER','LAST','ROW','WITH','VALUES','CREATE','TABLE','DIRECTORY' ”,“视图”,“替换”,“插入”,“删除”,“ INTO”,“ DESCRIBE”,“ EXPLAIN”,“ FORMAT”,“ LOGICAL”,“ CODEGEN”,“ COST”,“ CAST”, 'SHOW','TABLES','COLUMNS','COLUMN','USE','PARTITIONS','FUNCTIONS','DROP','UNION','EXCEPT','MINUS','INTERSECT','TO ”,“ TABLESAMPLE”,“ STRATIFY”,“ ALTER”,“ RENAME”,“ ARRAY”,“ MAP”,“ STRUCT”, '评论','设置','重置','数据','开始','交易','提交','回滚','宏','IGNORE','两者','领先','尾随','IF','POSITION','EXTRACT','+','-','*','DIV','〜','PERCENT','BUCKET','OUT','OF', '排序','群集','分发','覆盖','变换','减少','SERDE','SERDEPROPERTIES','RECORDREADER','RECORDWRITER','DELIMITED','FIELDS','TERMINATED ','COLLECTION','ITEMS','KEYS','ESCAPED','LINES','Separated','FUNCTION','EXTENDED','REFRESH','CLEAR','CACHE','UNCACHE', “ LAZY”,“ FORMATTED”,“ GLOBAL”,临时,“ OPTIONS”,“ UNSET”,“ TBLPROPERTIES”,“ DBPROPERTIES”,“ BUCKETS”,“ KEEWED”,“ STORED”,“ DIRECTORIES”,“ LOCATION”, 'EXCHANGE','ARCHIVE','UNARCHIVE','FILEFORMAT','TOUCH','COMPACT','CONCATENATE','CHANGE','CASCADE','RESTRICT','CLUSTERED','SORTED','PURGE ','INPUTFORMAT','OUTPUTFORMAT',DATABASE,DATABASE,'DFS','TRUNCATE','ANALYZE','COMPUTE','LIST','STATISTICS','PARTITIONED','EXTERNAL','DEFINED', 'REVOKE','GRANT','LOCK','U NLOCK”,“ MSCK”,“ REPAIR”,“ RECOVER”,“ EXPORT”,“ IMPORT”,“ LOAD”,“ ROLE”,“ ROLES”,“ COMPACTIONS”,“ PRINCIPALS”,“ TRANSACTIONS”,“ INDEX” ,'INDEXES','LOCKS','OPTION','ANTI','LOCAL','INPATH',STRING,BIGINT_LITERAL,SMALLINT_LITERAL,TINYINT_LITERAL,INTEGER_VALUE,DECIMAL_VALUE,DOUBLE_LITERAL,BIGDECIMAL_LITERAL,IDENTIFIER_ID,第3行, 24)\ n \ n == SQL == \ n \ n选择i,x \ n侧面视图posexplode([0.17808226409449213,0.18250386256254247,0.1852520704627222224,0.18800918537059694,\ n ---------------- -------- ^^^ \ n 0.1907743631982954、0.200154288105411、0.30419108474685375、0.3299437131426226,\ n 0.352433633041806、0.3589875791100745、0.37581775428218006、0.3825168120904496,\ n 0.3966342376441502、0.4173753044627164、0.43268994899295316、0.4528150634357 ])q作为i,x \ n“

另一方面,如果我在posexplode内部创建数组,如下所示,则可以正常工作:

select i, x
lateral view posexplode(array('a', 'b', 'c')) q as i, x

|  i|  x|
+---+---+
|  0|  a|
|  1|  b|
|  2|  c|
+---+---+

1 个答案:

答案 0 :(得分:1)

::cue {
  color: #FF0000;
  background-color: #00CC00;
  outline: thick double #32a1ce;
}