-
Notifications
You must be signed in to change notification settings - Fork 178
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
Initial attempt at enabling reading the columns from the datasource #45
Merged
graysonarts
merged 8 commits into
tableau:development
from
graysonarts:feature-get-fields
Jul 1, 2016
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3a120b
Initial attempt at enabling reading the columns from the datasource
b86e869
Fixing pep8 errors for EOFEOL
a4cf3b3
Changing to OrderedDict for getting columns
99d6ccd
Add documentation for the various column attributes
bf284d4
rename column to field
d80696c
Fixed #46 encode apostrophes in field names
2de54b1
Enable multilook up for Fields
2deb58d
Rename properties on the field based on feedback given in #45
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
def _resolve_value(key, value): | ||
try: | ||
retval = value.get(key, None) | ||
if retval is None: | ||
retval = value.getattr(key, None) | ||
except AttributeError: | ||
retval = None | ||
return retval | ||
|
||
|
||
def _build_index(key, d): | ||
return {_resolve_value(key, v): k | ||
for k, v in d.items() | ||
if _resolve_value(key, v) is not None} | ||
|
||
|
||
# TODO: Improve this to be more generic | ||
class MultiLookupDict(dict): | ||
def __init__(self, args=None): | ||
if args is None: | ||
args = {} | ||
super(MultiLookupDict, self).__init__(args) | ||
self._indexes = { | ||
'alias': {}, | ||
'caption': {} | ||
} | ||
self._populate_indexes() | ||
|
||
def _populate_indexes(self): | ||
self._indexes['alias'] = _build_index('alias', self) | ||
self._indexes['caption'] = _build_index('caption', self) | ||
|
||
def __setitem__(self, key, value): | ||
alias = _resolve_value('alias', value) | ||
caption = _resolve_value('caption', value) | ||
if alias is not None: | ||
self._indexes['alias'][alias] = key | ||
if caption is not None: | ||
self._indexes['caption'][caption] = key | ||
|
||
dict.__setitem__(self, key, value) | ||
|
||
def __getitem__(self, key): | ||
if key in self._indexes['alias']: | ||
key = self._indexes['alias'][key] | ||
elif key in self._indexes['caption']: | ||
key = self._indexes['caption'][key] | ||
|
||
return dict.__getitem__(self, key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
import os.path | ||
import functools | ||
|
||
from tableaudocumentapi.multilookup_dict import MultiLookupDict | ||
|
||
|
||
class MLDTests(unittest.TestCase): | ||
def setUp(self): | ||
self.mld = MultiLookupDict({ | ||
'[foo]': { | ||
'alias': 'bar', | ||
'caption': 'baz', | ||
'value': 1 | ||
}, | ||
'[bar]': { | ||
'caption': 'foo', | ||
'value': 2 | ||
}, | ||
'[baz]': { | ||
'value': 3 | ||
} | ||
}) | ||
|
||
def test_multilookupdict_name_only(self): | ||
actual = self.mld['[baz]'] | ||
self.assertEqual(3, actual['value']) | ||
|
||
def test_multilookupdict_alias_overrides_everything(self): | ||
actual = self.mld['bar'] | ||
self.assertEqual(1, actual['value']) | ||
|
||
def test_mutlilookupdict_caption_overrides_id(self): | ||
actual = self.mld['foo'] | ||
self.assertEqual(2, actual['value']) | ||
|
||
def test_mutlilookupdict_can_still_find_id_even_with_alias(self): | ||
actual = self.mld['[foo]'] | ||
self.assertEqual(1, actual['value']) | ||
|
||
def test_mutlilookupdict_can_still_find_caption_even_with_alias(self): | ||
actual = self.mld['baz'] | ||
self.assertEqual(1, actual['value']) | ||
|
||
def test_mutlilookupdict_can_still_find_id_even_with_caption(self): | ||
actual = self.mld['[bar]'] | ||
self.assertEqual(2, actual['value']) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't address the renaming, I'm working on that next.