Skip to content
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
22 changes: 20 additions & 2 deletions PyRDF/Operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Operation(object):
print(PyRDF.current_backend.supported_operations)
"""

Types = Enum("Types", "ACTION TRANSFORMATION INSTANT_ACTION")
Types = Enum("Types", "ACTION TRANSFORMATION INSTANT_ACTION INFO")

def __init__(self, name, *args, **kwargs):
"""
Expand Down Expand Up @@ -80,7 +80,15 @@ def _classify_operation(self, name):
'Take': ops.ACTION,
'Graph': ops.ACTION,
'Snapshot': ops.INSTANT_ACTION,
'Foreach': ops.INSTANT_ACTION
'Foreach': ops.INSTANT_ACTION,
'Alias': ops.INFO,
'GetColumnNames': ops.INFO,
'GetDefinedColumnNames': ops.INFO,
'GetColumnType': ops.INFO,
'GetColumnTypeNamesList': ops.INFO,
'GetFilterNames': ops.INFO,
'Display': ops.INFO,
'SaveGraph': ops.INFO
}

op_type = operations_dict.get(name)
Expand All @@ -107,3 +115,13 @@ def is_transformation(self):
False otherwise.
"""
return self.op_type == Operation.Types.TRANSFORMATION

def is_info(self):
"""
Checks if the current operation is an info.

Returns:
bool: True if the current operation is an info,
False otherwise.
"""
return self.op_type == Operation.Types.INFO
32 changes: 31 additions & 1 deletion PyRDF/Proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABCMeta, abstractmethod
from PyRDF.Operation import Operation
from PyRDF.Node import Node
import ROOT
# Abstract class declaration
# This ensures compatibility between Python 2 and 3 versions, since in
# Python 2 there is no ABC class
Expand Down Expand Up @@ -89,6 +90,28 @@ def _call_action_result(self, *args, **kwargs):
return getattr(self.GetValue(), self._cur_attr)(*args, **kwargs)


def _trigger_info_operation(node, op, *args, **kwargs):
"""
Function to retrieve the PyROOT node objects defined by the user
up to the point of calling an Info operation. This function triggers the
creation of PyROOT objects in order to call the ROOT function issued by the
user.
"""
generator = CallableGenerator(node.get_head())

mapper = generator.get_callable() # Get the callable

# Create a PyROOT RDataFrame
pyroot_rdf = ROOT.ROOT.RDataFrame(*generator.head_node.args)

# Execute the mapper function
mapper(pyroot_rdf)

# Call the function on the PyROOT object with the arguments provided by
# the user.
return getattr(node.pyroot_node, op.name)(*args, **kwargs)


class TransformationProxy(Proxy):
"""
A proxy object to an non-action node. It implements acces to attributes
Expand Down Expand Up @@ -133,8 +156,15 @@ def _create_new_op(self, *args, **kwargs):
# Add the new node as a child of the current node
self.proxied_node.children.append(newNode)

# Return the appropriate proxy object for the node
# Behave accordingly to the type of the operation
if op.is_action():
return ActionProxy(newNode)
elif op.is_info():
return _trigger_info_operation(
self.proxied_node,
op,
*args,
**kwargs
)
else:
return TransformationProxy(newNode)
10 changes: 9 additions & 1 deletion PyRDF/backend/Backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ class Backend(ABC):
'Foreach',
'Reduce',
'Aggregate',
'Graph'
'Graph',
'Alias',
'GetColumnNames',
'GetDefinedColumnNames',
'GetColumnType',
'GetColumnTypeNamesList',
'GetFilterNames',
'Display',
'SaveGraph'
]

initialization = staticmethod(lambda: None)
Expand Down
8 changes: 8 additions & 0 deletions PyRDF/backend/Local.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def __init__(self, config={}):
'Foreach',
'Reduce',
'Aggregate',
'Alias',
'GetColumnNames',
'GetDefinedColumnNames',
# 'GetColumnType',
'GetColumnTypeNamesList',
'GetFilterNames',
'Display',
'SaveGraph'
]
if ROOT.ROOT.IsImplicitMTEnabled():
# Add `Range` operation only if multi-threading
Expand Down