hadoop - 如何在配置单元中获取所有可能的模式

标签 hadoop hive hiveql

我有下表:

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

我希望输出为(列值的所有可能值):
+----------+----+
|customerID|name|
+----------+----+
|         1| Ram|
|         2| Arm|
|         3| Mar|
|         .| ...|
|         .| ...|
+----------+----+

最佳答案

分割字符串,爆炸数组,并使用交叉连接自身查找所有可能的组合:

 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,您将获得AaaArrRrr等所有组合。

关于hadoop - 如何在配置单元中获取所有可能的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47208360/

相关文章:

hadoop - 分析 Hadoop

hadoop - 在hbase中写入数据

hadoop - hive SQL为字符串中的每个字母搜索模式

hadoop - 获取 Hive 中日期的月份并按部门分组

ubuntu - Hadoop 2.5.1 MapReduce卡住

java - 尝试在 Apache Kylin 中为示例数据构建多维数据集时出现 java.io.FileNotFoundException : File does not exist: hive-exec-2. 1.0.jar 错误

Hive sql 上映射步骤的 Java 堆大小内存

hadoop - 纱作业失败,出现ClassNotFound异常,但在HADOOP_CLASSPATH中添加了jar

hadoop - 使用 HDFS 更改更新 Hive 外部表

hadoop - Hive:尝试创建动态分区时出现 fatal error