[Java] DictionaryEncoder doesn't crash when decoding index outside of Dictionary
还没有人认领这个 Issue。
评估
调研方向
从 DictionaryEncoder.decode 开始,并使用提供的 testReferencingIndexOutOfBounds 测试复现该行为。确认当编码后的索引等于字典值数量时会抛出带有预期消息的 IllegalArgumentException,同时有效索引仍能正常解码。
由索引模型根据 Issue 内容生成。
描述
Describe the bug, including details regarding any error messages, version, and platform.
Background
When manually creating an encoded vector, with values referencing indices in a Dictionary, it is possible to have values equal to valueCount of the Dictionary vector i.e. one index out of bounds. This is interpreted as a null value in the Dictionary.
Example
Dictionary
| Index | Original Value |
|---|---|
| 0 | Foo |
Encoded Vector - 1
| Index | Encoded Value | Expected Decode Outcome | Actual Outcome |
|---|---|---|---|
| 0 | 0 | Return the original value | Returns the original value |
Encoded Vector - 2
| Index | Encoded Value | Expected Decode Outcome | Actual Outcome |
|---|---|---|---|
| 0 | 1 | Raise IllegalArgumentException |
Returns null |
Encoded Vector - 3
| Index | Encoded Value | Expected Decode Outcome | Actual Outcome |
|---|---|---|---|
| 0 | 2 | Raise IllegalArgumentException |
Raises IllegalArgumentException |
Test to reproduce the error
@Test
public void testReferencingIndexOutOfBounds() {
// Index at which the original value will be stored at in the dictionary
var encodedIndex = 0;
// The encoded value that references an index in the dictionary
var indexReferenced = 1;
try (final IntVector encodedVector = new IntVector("encodings", allocator);
final VarCharVector dictionaryVector = newVarCharVector("dict", allocator); ) {
var originalValue = "Foo";
dictionaryVector.allocateNew(1);
dictionaryVector.setValueCount(1);
dictionaryVector.set(encodedIndex, originalValue.getBytes(StandardCharsets.UTF_8));
encodedVector.allocateNew(1);
encodedVector.setValueCount(1);
encodedVector.set(0, indexReferenced);
Dictionary dictionary =
new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null));
try (ValueVector decoded = DictionaryEncoder.decode(encodedVector, dictionary)) {
fail("There should be an exception when decoding index outside dictionary's range.");
} catch (Exception e) {
assertEquals("Provided dictionary does not contain value for index " + indexReferenced, e.getMessage());
}
}
}
- 主要语言
- Java
- 星标
- 95
- 派生
- 154
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 9
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/arrow-java 的其他 Issue
-
Type: bug
难度 2/5 1-3 小时 新手友好度 78/100
apache/arrow-java#1300 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
apache/arrow-java#1261 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/arrow-java#1236 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/arrow-java#1230 ·
-
Type: bug
难度 2/5 1-3 小时 新手友好度 85/100
apache/arrow-java#1205 ·
查看 apache/arrow-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
infinispan/infinispan#18150 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
-
untriaged
难度 2/5 1-3 小时 新手友好度 82/100
opensearch-project/k-NN#3597 ·
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100