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

Nested maps, tuples, enums don't work #328

Open
FraterCRC opened this issue Jul 23, 2024 · 2 comments
Open

Nested maps, tuples, enums don't work #328

FraterCRC opened this issue Jul 23, 2024 · 2 comments

Comments

@FraterCRC
Copy link

Describe the bug
When you nest Tuple(Tuple) or Map(Enum) you get error

To Reproduce
CREATE TABLE color_map (
id UInt32,
colors Map(Enum('hello' = 1, 'world' = 2), String)
) ENGINE = Memory;
And try to compile type.
Expected behavior
Should be Map(Enum, String), we get error.

Versions
0.2, but code still wrong in new versions
python 3.10

@FraterCRC
Copy link
Author

FraterCRC commented Jul 29, 2024

I see problem here:

elif spec.startswith('Tuple'):
          inner = spec[6:-1]
          coltype = self.ischema_names['_tuple']
          inner_types = [
              self._get_column_type(name, t.strip())
              for t in inner.split(',')
          ]
          return coltype(*inner_types)

      elif spec.startswith('Map'):
          inner = spec[4:-1]
          coltype = self.ischema_names['_map']
          inner_types = [
              self._get_column_type(name, t.strip())
              for t in inner.split(',', 1)
          ]
          return coltype(*inner_types)

It wont work good if the type is Tuple(Map(Type, Type), Type) because it will strip by ',' to ['Map(Type', 'Type)', 'Type']

@FraterCRC
Copy link
Author

I wrote a function to split it and we use it in production.

@staticmethod
    def _split_inner(inner: str):
        start = 0
        result_split = []
        num_in_brackets = 0
        for idx, char in enumerate(inner):
            if char == ',' and not num_in_brackets:
                result_split.append(inner[start:idx].strip())
                start = idx + 1
            if char == ')' and num_in_brackets:
                num_in_brackets -= 1
            if char == '(':
                num_in_brackets += 1
        # asserting that there is something after last comma
        result_split.append(inner[start:].strip())
        return result_split

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