gpt4 book ai didi

regex - hive 中的正则表达式

转载 作者:行者123 更新时间:2023-12-01 08:49:28 25 4
gpt4 key购买 nike

我正在学习 Hive 中的简单正则表达式。我正在学习教程,但简单的 hql 语句出错?

select REGEXP_EXTRACT( 'Hello, my name is Ben. Please visit' , 'Ben' )

这是我收到的错误消息:

错误的参数“Ben”:org.apache.hadoop.hive.ql.metadata.HiveException:无法执行方法 public java.lang.String org.apache.hadoop.hive.ql.udf。类 org.apache.hadoop.hive.ql.udf.UDFRegExpExtract 的对象 org.apache.hadoop.hive.ql.udf.UDFRegExpExtract@ec0c06f 上的 UDFRegExpExtract.evaluate(java.lang.String,java.lang.String) 带参数{你好,我的名字是本。请访问:java.lang.String, Ben:java.lang.String} of size 2

它适用于其他语言,但我想在 Hive 中学习它。任何帮助将不胜感激。

最佳答案

您必须提供第三个参数,即要提取的组索引。

要提取完整匹配,请使用 0:

select REGEXP_EXTRACT( 'Hello, my name is Ben. Please visit' , 'Ben', 0)

要提取捕获组值,请使用组索引,例如

select REGEXP_EXTRACT( 'Hello, my name is Ben. Please visit' , 'name is (\\w+)', 1)

将提取Ben

this reference :

regexp_extract(string subject, string pattern, int index)
Returns the string extracted using the pattern. For example, regexp_extract('foothebar', 'foo(.*?)(bar)', 2) returns 'bar.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc. The 'index' parameter is the Java regex Matcher group() method index. See docs/api/java/util/regex/Matcher.html for more information on the 'index' or Java regex group() method.

关于regex - hive 中的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46060475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com