Hive substr 函数启动索引问题

Hive substr function start Index Issue

我在 Apache spark 1.6.2 中使用 hive 2.11(hive 上下文)。 我正在观察配置单元 substr 函数的意外行为。

文档说:-

substr(string|binary A, int start, int len) substring(string|binary A, int start, int len) Returns the substring or slice of the byte array of A starting from start position with length len. For example, substr('foobar', 4, 1) results in 'b' (see [http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr]).

我的观察:-

1. select substr('Sakila' ,0,3) from <table>; => returns 'Sak'

2. select substr('Sakila' ,1,3) from <table>; => returns 'Sak'

所以我的问题是:-

  1. 我的起始索引 0 或 1 是什么?
  2. 这是一个已知问题吗?

我尝试在此处执行上述查询:http://demo.gethue.com/beeswax/#query 但得到了相同的结果。

在foobar例子中可以看到,第一个字母的索引是1。

如果您有一个非正数 m,则您的子字符串从第 m 个位置 'left' 开始,共 1 个。

示例:

select substring('abcdefgh',-1,3)
h

从这个角度看,1 左边的 0 个位置仍然是 1,因此命令给出相同的结果。