如何在hive中获取所有可能的模式

fhg3lkii  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(280)

我有下表:

+----------+----+
|customerID|name|
+----------+----+
|         1| Ram|
+----------+----+

我希望输出为(列值的所有可能值):

+----------+----+
|customerID|name|
+----------+----+
|         1| Ram|
|         2| Arm|
|         3| Mar|
|         .| ...|
|         .| ...|
+----------+----+
xhv8bpkk

xhv8bpkk1#

拆分字符串、分解数组并使用交叉连接查找所有可能的组合:

with s as (select col 
              from (select explode( split(lower('Ram'),'')) as col)s 
             where col <>''
           ) 
 select concat(upper(s1.col), s2.col, s3.col) as name, 
        row_number() over() as customerId
   from s s1 
        cross join s s2 
        cross join s s3
where s1.col<>s2.col and s2.col<>s3.col;

结果:

OK
name    customerid
Mam     1
Mar     2
Mrm     3
Mra     4
Ama     5
Amr     6
Arm     7
Ara     8
Rma     9
Rmr     10
Ram     11
Rar     12
Time taken: 185.638 seconds, Fetched: 12 row(s)

没有最后一个 WHERE s1.col<>s2.col and s2.col<>s3.col 你会得到所有的组合像 Aaa , Arr , Rrr 等等。

相关问题