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

Map field missing parts of values into respose #106

Closed
Maksim-Burtsev opened this issue Dec 31, 2023 · 1 comment
Closed

Map field missing parts of values into respose #106

Maksim-Burtsev opened this issue Dec 31, 2023 · 1 comment

Comments

@Maksim-Burtsev
Copy link
Contributor

  1. First example i found in the tests (in current state of master 1 test test_fetchrow_with_empties didnt pass):
expected: {'hello': {'inner': "world {'"}}
received: {'hello': {'inner': 'world {'}} 

' from world {' is missing.

  1. Second one is more interesting.
    Lest create table with nested Map and one them have value with Array type:
CREATE TABLE default.map_map_map
(
    `data` Map(String, Map(String, Array(String)))
)
ENGINE = MergeTree
ORDER BY data
SETTINGS index_granularity = 8192

INSERT INTO map_map_map VALUES ({'key1': {'key2': ['123', '456']}})

Expected result from SELECT query:

SELECT *
FROM map_map_map

Query id: 6a946fc5-e9c4-4a8d-96b8-727df58f0a6c

┌─data────────────────────────────┐
│ {'key1':{'key2':['123','456']}} │
└─────────────────────────────────┘

Real result:

In [1]: dict(await ch_client.fetchrow("select * from map_map_map"))
Out[1]: {'data': {'key1': {'key2': []}}}

So values of key2 are dissapeared.
And i can tell you why.

Because array type has slice [1:-1] there:

    def p_type(self, string: str) -> list:
        return [
            self.type.p_type(self.decode(val.encode()))
            for val in self.seq_parser(string[1:-1])
        ]

and its meant for string argument (which actually have str) type to remove quoutes of it, but in this case after json.loads(string) (323 line in types.py) in this method was passed list and slice just removed first and last items :)

And its confirmed with list of 3+ elements:

INSERT INTO map_map_map VALUES ({'key1': {'key2': ['123', '456', '789']}})
In [1]: dict(await ch_client.fetchrow("select * from map_map_map order by data desc"))
Out[1]: {'data': {'key1': {'key2': ['456']}}}

So right now MapType not working properly and need some fixes.

@Maksim-Burtsev
Copy link
Contributor Author

Maksim-Burtsev commented Jan 1, 2024

This PR closes this issue — #108

  1. No more missing quotes:
In [1]: dict(await ch_client.fetchrow("select map_map from all_types"))
Out[1]: {'map_map': {'hello': {'inner': "world {'"}}}
                                               ~~~
  1. No more missing values from Array:
In [2]: dict(await ch_client.fetchrow("select * from map_map_map"))
Out[2]: {'data': {'key1': {'key2': ['123', '456']}}}

maximdanilchenko added a commit that referenced this issue Jan 4, 2024
Update MapType p_type method (closes issue #106)
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

No branches or pull requests

1 participant