def get_equijoin_key_values(condition): # condition must be a *leaf* condition. if getattr(condition, 'op', None) != Condition.Op.EQ: return None # Get properties being accessed by left and right side of the # conditional. left_properties = get_properties_accessed_by_value(condition.left) right_properties = get_properties_accessed_by_value( condition.right) if not (left_properties and right_properties): return None # Only return getters if both sides of the conditional read from different # sources. You can't use this optimization say if the condition is # (left.x + right.y = 10) # XXX: This isn't kosher for non-deterministic functions. if (all(p.startswith('%s.' % left_alias) for p in left_properties) and all( p.startswith('%s.' % right_alias) for p in right_properties)): return {'left': condition.left, 'right': condition.right} if (all( p.startswith('%s.' % right_alias) for p in left_properties) and all( p.startswith('%s.' % left_alias) for p in right_properties)): return {'left': condition.right, 'right': condition.left} return None
def get_equijoin_key_values(condition): # condition must be a *leaf* condition. if getattr(condition, 'op', None) != Condition.Op.EQ: return None # Get properties being accessed by left and right side of the # conditional. left_properties = get_properties_accessed_by_value(condition.left) right_properties = get_properties_accessed_by_value(condition.right) if not (left_properties and right_properties): return None # Only return getters if both sides of the conditional read from different # streams. You can't use this optimization say if the condition is # (left.x + right.y = 10) # XXX: This isn't kosher for non-deterministic functions. if (all(p.startswith('%s.' % left_alias) for p in left_properties) and all(p.startswith('%s.' % right_alias) for p in right_properties)): return {'left': condition.left, 'right': condition.right} if (all(p.startswith('%s.' % right_alias) for p in left_properties) and all(p.startswith('%s.' % left_alias) for p in right_properties)): return {'left': condition.right, 'right': condition.left} return None
def test_get_properties_accessed_by_value(self): self.assertEqual(get_properties_accessed_by_value(Property('lolcat')), ['lolcat']) self.assertEqual(get_properties_accessed_by_value(Constant(0)), []) self.assertEqual( get_properties_accessed_by_value( Add([ Property('lolcat'), Constant(1), Add([Property('hello'), Constant(2)]) ])), ['lolcat', 'hello'])
def test_get_properties_accessed_by_value(self): self.assertEqual( get_properties_accessed_by_value(Property('lolcat')), ['lolcat']) self.assertEqual(get_properties_accessed_by_value(Constant(0)), []) self.assertEqual( get_properties_accessed_by_value( Add([Property('lolcat'), Constant(1), Add([Property('hello'), Constant(2)])]) ), ['lolcat', 'hello'])