Skip to content

Commit

Permalink
Allow multiple fields to be mapped to the same output column
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Gaudin committed Jan 18, 2018
1 parent 5aa1643 commit 95daef9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions mongo_connector/doc_managers/sql.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf8

import logging
import unicodedata

import re
import unicodedata
from builtins import chr

from future.utils import iteritems
from past.builtins import long, basestring
from psycopg2._psycopg import AsIs
Expand Down Expand Up @@ -49,7 +49,7 @@ def sql_drop_table(cursor, tableName):

def sql_create_table(cursor, tableName, columns):
columns.sort()
sql = u"CREATE TABLE {0} {1}".format(tableName.lower(), to_sql_list(columns))
sql = u"CREATE TABLE {0} {1}".format(tableName.lower(), to_sql_list(unique(columns)))
cursor.execute(sql)


Expand All @@ -60,12 +60,11 @@ def sql_bulk_insert(cursor, mappings, namespace, documents):
db, collection = db_and_collection(namespace)

primary_key = mappings[db][collection]['pk']
keys = [
keys = unique([
v['dest'] for k, v in iteritems(mappings[db][collection])
if 'dest' in v and v['type'] != ARRAY_TYPE
and v['type'] != ARRAY_OF_SCALARS_TYPE
]
keys.sort()
and v['type'] != ARRAY_OF_SCALARS_TYPE
])

values = []

Expand Down Expand Up @@ -179,3 +178,7 @@ def to_sql_value(value):

def object_id_adapter(object_id):
return AsIs(to_sql_value(object_id))


def unique(input_list):
return sorted(list(set(input_list)))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='mongo-connector-postgresql',
version='1.1.0',
version='1.3.0-retro',
description='Doc Manager Postgresl for Mongo connector Distribution Utilities',
keywords=['mongo-connector', 'mongo', 'mongodb', 'postgresql'],
platforms=["any"],
Expand Down

0 comments on commit 95daef9

Please sign in to comment.