【问题标题】:Replace a character from all columns in Hive tables替换 Hive 表中所有列中的字符
【发布时间】:2019-04-15 22:30:12
【问题描述】:

我需要对我的 Hive 表中的所有列执行正则表达式替换功能。 有没有办法在不单独调用每一列的情况下对所有列执行操作?

【问题讨论】:

  • 你可以写一个shell脚本来做。

标签: hive


【解决方案1】:

使用 regexp_replace。以下是 Hive REGEXP_REPLACE 函数的语法。 regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT);

【讨论】:

    【解决方案2】:
        val col : DataFrame = hiveContext.sql("show columns in dbname.table_name")
        val arry  = col.collectAsList().toArray
    
        def regexpReplace(x: AnyRef): String =
        return "select regexp_replace(" + x + ",[^0-9a-zA-Z]," + "' ')  from dbname.tbl_name"
    
      for(  col <- arry)
        {
          val res = regexpReplace(col.toString.substring(1,x.toString.length-1))
          sqlContext.sql(res)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-26
      • 2018-04-03
      • 2020-07-15
      • 2017-02-06
      • 2018-04-08
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多