Skip to content

Revisit enum DDL semantics w.r.t. proto3 enum specs #3329

Open
@hatyo

Description

@hatyo

When we create an Enum type in SQL, the DDL starts assigning the enumeration values with numbers starting from 0

final List<DataType.EnumType.EnumValue> enumValues = new ArrayList<>(ctx.STRING_LITERAL().size());
for (int i = 0; i < ctx.STRING_LITERAL().size(); i++) {
enumValues.add(DataType.EnumType.EnumValue.of(Assert.notNullUnchecked(getDelegate().normalizeString(ctx.STRING_LITERAL(i).getText())), i));
}

which could have unexpected side-effects considering how proto3 attributes special semantics to the enumeration value with number 0.

Enum Default Value
The default value for the SearchRequest.corpus field is CORPUS_UNSPECIFIED because that is the first value defined in the enum.
In proto3, the first value defined in an enum definition must have the value zero and should have the name ENUM_TYPE_NAME_UNSPECIFIED or ENUM_TYPE_NAME_UNKNOWN. This is because:
There must be a zero value, so that we can use 0 as a numeric default value.
The zero value needs to be the first element, for compatibility with the proto2 semantics where the first enum value is the default unless a different value is explicitly specified.
It is also recommended that this first, default value have no semantic meaning other than “this value was unspecified”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrelationalissues related to relational FDB

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions