apache / apache/arrow-java

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

Aberta Para iniciantes
#1,158 0 comentários 0 reações 0 responsáveis Ver no GitHub
Type: bug
Linguagem predominante
Java
Estrelas
94
Forks
152
Merge médio
3d 16h
PRs com merge (30d)
11

Descrição

### 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
```java
@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());
}
}
}

```

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Start at DictionaryEncoder.decode and reproduce the behavior with the provided testReferencingIndexOutOfBounds test. Confirm that an encoded index equal to the dictionary value count raises IllegalArgumentException with the expected message, while valid indices still decode normally.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java
Domínio
data
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Pouca atividade
Clareza
Claramente especificada
Facilidade para iniciantes
74/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.