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

Fixed 'key' is not defined in operator filter_by_range #26

Open
wants to merge 3 commits into
base: master
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
5 changes: 3 additions & 2 deletions bubbles/backends/mongo/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion bubbles/backends/sql/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bubbles/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions bubbles/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -307,4 +307,3 @@ def decorator(func):
return decorator



25 changes: 25 additions & 0 deletions examples/hello_mongo.py
Original file line number Diff line number Diff line change
@@ -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()