diff --git a/bubbles/backends/mongo/objects.py b/bubbles/backends/mongo/objects.py index e981e04..8a3acdd 100644 --- a/bubbles/backends/mongo/objects.py +++ b/bubbles/backends/mongo/objects.py @@ -36,6 +36,7 @@ def default_store(database, host, port): class MongoDBStore(DataStore): __identifier__ = "mongo" + __extension_name__ = "mongo" def __init__(self, database, host='localhost', port=27017, client=None): """Creates a MongoDB data object store.""" @@ -58,7 +59,7 @@ def objects(self, names=None): raise NotImplementedError def create(self, name, fields, replace=False): - obj = MongoDBCollection(name, fields=fields, store=self) + obj = MongoDBCollection(name, fields=fields, store=self, truncate=replace) if replace: # The only way how to check for collection existence is to look if @@ -81,7 +82,7 @@ class MongoDBCollection(DataObject): def __init__(self, collection, fields, truncate=False, expand=False, - database=None, host='localhsot', port=27017, + database=None, host='localhost', port=27017, store=None): """Creates a MongoDB data object. diff --git a/bubbles/backends/sql/ops.py b/bubbles/backends/sql/ops.py index 9a38267..7ff1dcf 100644 --- a/bubbles/backends/sql/ops.py +++ b/bubbles/backends/sql/ops.py @@ -82,7 +82,7 @@ def _(ctx, src, key, value, discard=False): @filter_by_range.register("sql") -def _(ctx, src, field, low, high, discard=False): +def _(ctx, src, key, low, high, discard=False): """Filter by range: field should be between low and high.""" statement = src.sql_statement() diff --git a/bubbles/extensions.py b/bubbles/extensions.py index 15ce3c8..8976522 100644 --- a/bubbles/extensions.py +++ b/bubbles/extensions.py @@ -20,7 +20,7 @@ _default_modules = { "store": { "sql":"bubbles.backends.sql.objects", - "mongo":"bubbles.backends.sql.mongo", + "mongo":"bubbles.backends.mongo.objects", "csv":"bubbles.backends.text.objects", "datapackage":"bubbles.datapackage", "datapackages":"bubbles.datapackage", diff --git a/bubbles/operation.py b/bubbles/operation.py index e41ec21..5ba1891 100644 --- a/bubbles/operation.py +++ b/bubbles/operation.py @@ -238,7 +238,7 @@ def resolution_order(self, representations): return matches - def register(self, *signature, name=None): + def register(self, *signatures, name=None): sig = None def register_function(func): @@ -256,8 +256,8 @@ def register_function(func): func.__name__ = self.name return func - if signature and callable(signature[0]): - func, *signature = signature + if signatures and callable(signatures[0]): + func, *signature = signatures # Create default signature if none is provided if not signature: @@ -266,7 +266,7 @@ def register_function(func): sig = Signature(*signature) return register_function(func) else: - sig = Signature(*signature) + sig = Signature(*signatures) return register_function def __str__(self): @@ -307,4 +307,3 @@ def decorator(func): return decorator - diff --git a/examples/hello_mongo.py b/examples/hello_mongo.py new file mode 100644 index 0000000..1a3d322 --- /dev/null +++ b/examples/hello_mongo.py @@ -0,0 +1,25 @@ +import bubbles + +# Follow the comments – there is a line to be uncommented + +URL = "https://raw.github.com/Stiivi/cubes/master/examples/hello_world/data.csv" + +# Prepare list of stores, we just need one temporary SQL store + +stores = { + "target": bubbles.open_store("mongo", database="sample", host='127.0.0.1', port=27017) +} + + +p = bubbles.Pipeline(stores=stores) +p.source_object("csv_source", resource=URL, encoding="utf8") +p.retype({"Amount (US$, Millions)": "integer"}) + +# We create a table +# Uncomment this line and see the difference in debug messages +p.create("target", "data") + +p.aggregate("Category", "Amount (US$, Millions)") +p.pretty_print() +p.run() +