Skip to content

Introduce mapContains, mapKeys, mapValues functions for Map data type#18788

Merged
nikitamikhaylov merged 6 commits intoClickHouse:masterfrom
hexiaoting:map_functions
Jan 21, 2021
Merged

Introduce mapContains, mapKeys, mapValues functions for Map data type#18788
nikitamikhaylov merged 6 commits intoClickHouse:masterfrom
hexiaoting:map_functions

Conversation

@hexiaoting
Copy link
Copy Markdown
Contributor

@hexiaoting hexiaoting commented Jan 6, 2021

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add three functions for map data type:

  1. mapContains(map, key) to check weather map.keys include the second parameter key.
  2. mapKeys(map) return all the keys in Array format
  3. mapValues(map) return all the values in Array format

Note: mapContains(map, key) equals has(mapKeys(map), key)

Detailed description / Documentation draft:
Add three functions for map data type:

  1. mapContains(map, key) to check weather map.keys include the second parameter key.
    accept 2 parameters, the first one is a map datatype, the second one should the the same type with map's key type.
    return 1 or 0.
  2. mapKeys(map) return all the keys in Array format
    accept 2 parameters, the first one is a map datatype
    return an array.
  3. mapValues(map) return all the keys in Array format
    accept 2 parameters, the first one is a map datatype
    return an array.

select mapContains(a, 'abc') from table_map;
select mapContains(a, b) from table_map;
select mapContains(a, 10) from table_map; -- { serverError 43 }
select mapKeys(a) from table_map;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also need tests for mapValues :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I forget this.
Added now.

}
};

struct NameMapContains { static constexpr auto name = "mapContains"; };
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alexey-milovidov I think we cannot remove this line, because line199 needs this struct to call FunctionArrayIndex.executeImpl.

select mapContains(a, 'abc') from table_map;
select mapContains(a, b) from table_map;
select mapContains(a, 10) from table_map; -- { serverError 43 }
select mapKeys(a) from table_map;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I forget this.
Added now.

@qoega
Copy link
Copy Markdown
Member

qoega commented Jan 11, 2021

Do we need array version i.e. mapContains(map, keys_array) that returns array of 0/1? Or mapContainsAll?

@hexiaoting
Copy link
Copy Markdown
Contributor Author

hexiaoting commented Jan 11, 2021

Do we need array version i.e. mapContains(map, keys_array) that returns array of 0/1? Or mapContainsAll?

Yes, if this is needed, then we will implement it.
And now we can use ArrayMap to get the result too: arrayMap(x->mapCOntains(map, x) , keys_array)

@nikitamikhaylov nikitamikhaylov self-assigned this Jan 13, 2021
@hexiaoting
Copy link
Copy Markdown
Contributor Author

@nikitamikhaylov ready to review.

@nikitamikhaylov
Copy link
Copy Markdown
Member

#19376

@nikitamikhaylov nikitamikhaylov merged commit b93732e into ClickHouse:master Jan 21, 2021
@sundy-li
Copy link
Copy Markdown
Contributor

Server crashed , cc @hexiaoting

select map( 'aa', 4, '44' , 5) as c, mapKeys(c)


Query id: 0d737d61-ae11-4665-ae34-d70fa0237342

[ubuntu] 2021.01.23 04:12:52.627166 [ 22526 ] {0d737d61-ae11-4665-ae34-d70fa0237342} <Fatal> : Logical error: 'Empty column was returned by function mapKeys'.
[ubuntu] 2021.01.23 04:12:52.628855 [ 22774 ] <Fatal> BaseDaemon: ########################################
[ubuntu] 2021.01.23 04:12:52.629351 [ 22774 ] <Fatal> BaseDaemon: (version 21.2.1.1, build id: 76E32BBFC1D058D6) (from thread 22526) (query_id: 0d737d61-ae11-4665-ae34-d70fa0237
342) Received signal Aborted (6)
[ubuntu] 2021.01.23 04:12:52.629945 [ 22774 ] <Fatal> BaseDaemon:
[ubuntu] 2021.01.23 04:12:52.630908 [ 22774 ] <Fatal> BaseDaemon: Stack trace: 0x7f3f513a918b 0x7f3f51388859 0x7f3f549f2145 0x7f3f549f2209 0x7f3f55d20741 0x7f3f475dba8c 0x7f3f47
5dc9ff 0x7f3f3d9ca0b6 0x7f3f3d9c9b41 0x7f3f3ddd0f83 0x7f3f3ddd9120 0x7f3f3ddd432e 0x7f3f3ddd12e7 0x7f3f3ddd4c48 0x7f3f3ddd1353 0x7f3f3e1b292b 0x7f3f3e1a55f1 0x7f3f3e1ab232 0x7f3f3e1ae74
1 0x7f3f3e62ef70 0x7f3f3e62b5fe 0x7f3f3e628234 0x7f3f3e626ff7 0x7f3f3e6a8bdc 0x7f3f3e6a6626 0x7f3f3e6a5f31 0x7f3f3e5da8d7 0x7f3f3e5d90ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants