Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Functions #2793

Merged
merged 4 commits into from
Dec 15, 2021
Merged

Enum Functions #2793

merged 4 commits into from
Dec 15, 2021

Conversation

pdet
Copy link
Contributor

@pdet pdet commented Dec 13, 2021

Issue: #2741 and #2740

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good. Some comments:

src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
idx_t EnumType::GetValuePosition(const Value &val) {
switch (val.type().InternalType()) {
case PhysicalType::UINT8:
return val.value_.utinyint;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val.GetValue<uint32_t>() should cover all these three cases so the switch is no longer required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't but i've moved it there.

src/function/function.cpp Outdated Show resolved Hide resolved
src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
src/function/scalar/enum/enum_functions_implementation.cpp Outdated Show resolved Hide resolved
}

void EnumFirst::RegisterFunction(BuiltinFunctions &set) {
set.AddFunction(ScalarFunction("enum_first", {LogicalType::ANY}, LogicalType::VARCHAR, EnumFirstFunction, false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you have a binder, but maybe ANY should be ENUM? I'm not sure how the candidate functions will be displayed in the situation where there are too many or too few arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that the creation and equality of enum types are associated with the enum categories. I guess we could to these matches on LogicalTypeIDs, but I think @Mytherin prefers these binding setups

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding on an empty type is how the list functions do this, e.g. unnest binds on {LogicalTypeId::LIST}. Perhaps this should indeed bind on LogicalTypeId::ENUM instead of ANY.

test/sql/function/enum/test_enum_range.test Show resolved Hide resolved
@Mytherin Mytherin merged commit dd2f405 into duckdb:master Dec 15, 2021
@Mytherin
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants