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

bug/60 mapcolumn cant nested types that have a comma #61

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion proton_driver/columns/mapcolumn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import re
from .base import Column
from .intcolumn import UInt64Column
from ..util.helpers import pairwise

comma_re = re.compile(r',(?![^()]*\))')


class MapColumn(Column):
py_types = (dict, )
Expand Down Expand Up @@ -51,7 +54,9 @@ def write_items(self, items, buf):


def create_map_column(spec, column_by_spec_getter):
key, value = spec[4:-1].split(',')
# Match commas outside of parentheses, so we don't match the comma in
# Decimal types.
key, value = comma_re.split(spec[4:-1])
Yibo-Chen13 marked this conversation as resolved.
Show resolved Hide resolved
key_column = column_by_spec_getter(key.strip())
value_column = column_by_spec_getter(value.strip())

Expand Down
22 changes: 21 additions & 1 deletion tests/columns/test_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tests.testcase import BaseTestCase
from decimal import Decimal


class MapTestCase(BaseTestCase):
Expand All @@ -22,7 +23,7 @@ def _sorted_dicts(self, text):
return '\n'.join(items) + '\n'

def test_simple(self):
with self.create_stream('a map(string, uint64)'):
with self.create_stream('a map(string, int)'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

why change to int?

please remove the commented tests below if they are invalid.

data = [
({},),
({'key1': 1}, ),
Expand Down Expand Up @@ -100,3 +101,22 @@ def test_array(self):
)
inserted = self.client.execute(query)
self.assertEqual(inserted, data)

def test_decimal(self):
with self.create_stream('a map(string, Decimal(9, 2))'):
data = [
({'key1': Decimal('123.45')}, ),
({'key2': Decimal('234.56')}, ),
({'key3': Decimal('345.67')}, )
]
self.client.execute('INSERT INTO test (a) VALUES', data)
query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(
inserted,
"{'key1':123.45}\n"
"{'key2':234.56}\n"
"{'key3':345.67}\n"
)
inserted = self.client.execute(query)
self.assertEqual(inserted, data)