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

Aperta Adatta ai principianti
#1,158 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
data

Direzione di ricerca

Parti da DictionaryEncoder.decode e riproduci il comportamento con il test testReferencingIndexOutOfBounds fornito. Verifica che un indice codificato uguale al numero di valori del dizionario generi IllegalArgumentException con il messaggio previsto, mentre gli indici validi continuino a essere decodificati normalmente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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());
            }
        }
    }

Lingua principale
Java
Stelle
95
Fork
154
Merge medio
2g 16h
PR unite (30g)
9

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-java

Tutte le issue di apache/arrow-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.