Skip to content

Map DuckDB enums by label instead of underlying ordinal#331

Draft
Copilot wants to merge 5 commits into
developfrom
copilot/fix-invalidoperationexception-enumvector
Draft

Map DuckDB enums by label instead of underlying ordinal#331
Copilot wants to merge 5 commits into
developfrom
copilot/fix-invalidoperationexception-enumvector

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2026

DuckDB.NET was writing enum values by casting their underlying numeric value directly into DuckDB’s enum storage. That only works when the CLR enum is dense and ordinal-aligned with the DuckDB enum definition; sparse enums and [Flags] enums could mis-map or throw unexpectedly.

  • Appender enum mapping

    • Change enum writes to resolve the CLR enum member name and map it to the DuckDB enum dictionary label.
    • Remove the ordinal-based fallback so appends fail fast when labels do not match instead of silently writing the wrong enum.
  • [Flags] handling

    • Reject [Flags] enums during append with an explicit InvalidOperationException.
    • This avoids unsupported composite values being coerced into a single DuckDB enum label.
  • Reader alignment

    • Resolve DuckDB enum labels back to CLR enum members by name when reading typed enums.
    • Stop falling back to raw ordinals for typed enum materialization, which reintroduced the same sparse-enum assumption in reverse.
  • Focused coverage

    • Add appender tests for:
      • non-consecutive enum values
      • [Flags] enum rejection
    • Keep existing dense-enum behavior covered by current tests.

Example of the supported sparse-enum case:

enum Mood : byte
{
    Happy = 1,
    Sad = 2,
    Neutral = 4
}

// DuckDB enum labels: 'Happy', 'Sad', 'Neutral'
row.AppendValue(Mood.Neutral); // now maps by label, not by underlying value 4

Copilot AI changed the title [WIP] Fix InvalidOperationException for non-consecutive enum values Map DuckDB enums by label instead of underlying ordinal May 28, 2026
Copilot AI requested a review from Giorgi May 28, 2026 21:29
Copilot finished work on behalf of Giorgi May 28, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnumVectorDataWriter throws InvalidOperationException if given an enum with non-consecutive values.

2 participants