Skip to content

[Bug] NPE in BTreeFileMetaSelector when btree global index contains empty string key #7811

@zhoulii

Description

@zhoulii

Search before asking

  • I searched in the issues and found nothing similar.

Paimon version

1.14

Compute Engine

flink 1.18

Minimal reproduce step

@Test
    public void testMetaSelectorWithEmptyStringKey() {
        // Simulate the real NPE scenario: btree index file with empty string as firstKey
        KeySerializer stringSerializer = KeySerializer.create(new VarCharType());
        byte[] emptyKey = stringSerializer.serialize(BinaryString.EMPTY_UTF8);
        byte[] normalKey = stringSerializer.serialize(BinaryString.fromString("www.example.com"));

        BTreeIndexMeta metaWithEmptyFirstKey = new BTreeIndexMeta(emptyKey, normalKey, false);
        BTreeIndexMeta metaWithNormalKeys =
                new BTreeIndexMeta(
                        stringSerializer.serialize(BinaryString.fromString("aaa.com")),
                        stringSerializer.serialize(BinaryString.fromString("zzz.com")),
                        false);
        BTreeIndexMeta metaOnlyNulls = new BTreeIndexMeta(null, null, true);

        List<GlobalIndexIOMeta> files =
                Arrays.asList(
                        new GlobalIndexIOMeta(
                                new Path("file_empty"), 1, metaWithEmptyFirstKey.serialize()),
                        new GlobalIndexIOMeta(
                                new Path("file_normal"), 1, metaWithNormalKeys.serialize()),
                        new GlobalIndexIOMeta(
                                new Path("file_nulls"), 1, metaOnlyNulls.serialize()));

        FieldRef ref = new FieldRef(1, "page_host", new VarCharType());
        BTreeFileMetaSelector selector = new BTreeFileMetaSelector(files, stringSerializer);

        // visitEqual should not throw NPE
        Optional<List<GlobalIndexIOMeta>> result =
                selector.visitEqual(ref, BinaryString.fromString("www.example.com"));
        Assertions.assertThat(result).isNotEmpty();
        assertFiles(result.get(), Arrays.asList("file_empty", "file_normal"));

        // visitLessThan should not throw NPE
        result = selector.visitLessThan(ref, BinaryString.fromString("bbb.com"));
        Assertions.assertThat(result).isNotEmpty();
        assertFiles(result.get(), Arrays.asList("file_empty", "file_normal"));

        // visitGreaterThan should not throw NPE
        result = selector.visitGreaterThan(ref, BinaryString.fromString("www.example.com"));
        Assertions.assertThat(result).isNotEmpty();

        // visitIn should not throw NPE
        result =
                selector.visitIn(
                        ref,
                        Arrays.asList(
                                BinaryString.fromString("www.example.com"),
                                BinaryString.fromString("zzz.com")));
        Assertions.assertThat(result).isNotEmpty();

        // visitBetween should not throw NPE
        result =
                selector.visitBetween(
                        ref, BinaryString.EMPTY_UTF8, BinaryString.fromString("zzz.com"));
        Assertions.assertThat(result).isNotEmpty();
    }

What doesn't meet your expectations?

When querying a table with a btree global index on a STRING/VARCHAR column, a NullPointerException is thrown:
Image

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions