[Java] DictionaryEncoder doesn't crash when decoding index outside of Dictionary

未关闭 适合新手
#1,158 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
java
领域
data

调研方向

从 DictionaryEncoder.decode 开始,并使用提供的 testReferencingIndexOutOfBounds 测试复现该行为。确认当编码后的索引等于字典值数量时会抛出带有预期消息的 IllegalArgumentException,同时有效索引仍能正常解码。

由索引模型根据 Issue 内容生成。

描述

Type: bug
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/arrow-java 的其他 Issue

查看 apache/arrow-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。