Skip to content

Commit

Permalink
made recommendations from @arikfr
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Alchemist committed Aug 12, 2019
1 parent 053c846 commit 5b804e1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions redash/query_runner/dgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ def reduce_item(reduced_item, key, value):
"""From https://github.com/vinay20045/json-to-csv"""
# Reduction Condition 1
if type(value) is list:
i = 0
for sub_item in value:
reduce_item(reduced_item, key+'/'+to_string(i), sub_item)
i = i+1
for i, sub_item in enumerate(value):
reduce_item(reduced_item, u'{}.{}'.format(key, i), sub_item)

# Reduction Condition 2
elif type(value) is dict:
sub_keys = value.keys()
for sub_key in sub_keys:
reduce_item(reduced_item, key+'/'+to_string(sub_key), value[sub_key])
reduce_item(reduced_item, u'{}.{}'.format(key, sub_key), value[sub_key])

# Base Condition
else:
reduced_item[to_string(key)] = to_string(value)
reduced_item[key] = value


class Dgraph(BaseQueryRunner):
Expand Down

0 comments on commit 5b804e1

Please sign in to comment.