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

feat(functions): add new function: map_pick #15573

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hanxuanliang
Copy link
Contributor

@hanxuanliang hanxuanliang commented May 18, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

part of #15295

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label May 18, 2024
@hanxuanliang
Copy link
Contributor Author

Currently, it has been implemented:

  • map_pick(map, [key...])

@b41sh b41sh self-requested a review May 18, 2024 12:35
|_, _, _| Value::Scalar(()),
);

registry.register_passthrough_nullable_2_arg(
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, I have implemented: map_pick(map, keys...). However, at the same time, is it possible to directly remove the register_passthrough_nullable_2_arg, and also need to support ArrayType args in the factory method?

Copy link
Member

Choose a reason for hiding this comment

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

yes, please remove register_passthrough_nullable_2_arg, and support array type in the factory.

@hanxuanliang hanxuanliang force-pushed the feat/15295_map_pick branch 2 times, most recently from 0f8276d to b3bff22 Compare May 23, 2024 01:18
|_, _, _| Value::Scalar(()),
);

registry.register_passthrough_nullable_2_arg(
Copy link
Member

Choose a reason for hiding this comment

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

yes, please remove register_passthrough_nullable_2_arg, and support array type in the factory.

src/query/functions/src/scalars/map.rs Show resolved Hide resolved
src/query/functions/src/scalars/map.rs Show resolved Hide resolved
src/query/functions/src/scalars/map.rs Outdated Show resolved Hide resolved
return None;
}

if !matches!(args_type[0], DataType::Map(_) | DataType::EmptyMap) {
Copy link
Member

Choose a reason for hiding this comment

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

check args_type[0].remove_nullable(), as the type may be nullable map.

_ => None,
};
let key_match = match args_type.len() {
2 => args_type.get(1).map_or(false, |t| match t {
Copy link
Member

Choose a reason for hiding this comment

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

if the arguments number is two, the second argument may be an array type or a key type.

};
let key_match = match args_type.len() {
2 => args_type.get(1).map_or(false, |t| match t {
DataType::Array(_) => inner_key_type.map_or(false, |key_type| {
Copy link
Member

Choose a reason for hiding this comment

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

the data type may be nullable array, we need use remove_nullable function to get the inner type.

_ => unreachable!(),
},
ValueRef::Column(Column::Map(c)) => {
KvPair::<GenericType<0>, GenericType<1>>::try_downcast_column(&c.values).unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

the column may be a nullable map column

builder.put_item((k.clone(), v.clone()));
}
}
builder.commit_row();
Copy link
Member

Choose a reason for hiding this comment

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

those code logic seems not correct, arg.as_scalar() will panic if the value is a column. and the builder need to work for every row, not only the first value.

@b41sh
Copy link
Member

b41sh commented Jun 6, 2024

Hi @hanxuanliang It's been a long time since last update, have you made any progress recently?

@hanxuanliang
Copy link
Contributor Author

I'm sorry that the issue has been delayed recently due to personal matters. I will finish the following pr content at the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants