[英]Druid SQL: get substring issue
There is the table column which holds the comma-separated values, eg:有一个包含逗号分隔值的表格列,例如:
abc321,rd512,spwewr
I need to extract the substring which starts from the user-defined pattern.我需要提取从用户定义的模式开始的 substring。 Example:
例子:
Input Pattern | Expected result
abc abc321
r rd512
spwe spwewr
b NULL
Following fails in Druid SQL:以下在德鲁伊 SQL 中失败:
SELECT SUBSTRING('abc321,rd512,spwewr', POSITION('r' IN 'abc321,rd512,spwewr'), 2)
This is the known Druid bug: " Substring operator converter does not handle non-constant literals correctly":这是已知的 Druid 错误:“ Substring 运算符转换器无法正确处理非常量文字”:
https://issues.apache.org/jira/browse/CALCITE-2226 https://issues.apache.org/jira/browse/CALCITE-2226
I think the way to go is to use REGEXP_EXTRACT() or REGEXP_LIKE() but I cannot figure out the specific syntax.我认为 go 的方法是使用 REGEXP_EXTRACT() 或 REGEXP_LIKE() 但我无法弄清楚具体的语法。
select regexp_extract('abc321,rd512,spwewr', 'rd[^,]+', 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.