@dispatch(Reduction)
def group_apply(expr):
 key = expr._name
 col = ('$' + expr._child._name)
 if isinstance(expr, count):
  return {key: {'$sum': 1}}
 if isinstance(expr, sum):
  return {key: {'$sum': col}}
 if isinstance(expr, max):
  return {key: {'$max': col}}
 if isinstance(expr, min):
  return {key: {'$min': col}}
 if isinstance(expr, mean):
  return {key: {'$avg': col}}
 raise NotImplementedError(('Reduction %s not yet supported in MongoDB' % type(expr).__name__))

@ dispatch ( Reduction ) def group_apply ( expr ) : key = expr . _name col = ( '$' + expr . _child . _name ) if isinstance ( expr , count ) : return { key : { '$sum' : 1 } } if isinstance ( expr , sum ) : return { key : { '$sum' : col } } if isinstance ( expr , max ) : return { key : { '$max' : col } } if isinstance ( expr , min ) : return { key : { '$min' : col } } if isinstance ( expr , mean ) : return { key : { '$avg' : col } } raise NotImplementedError ( ( 'Reduction %s not yet supported in MongoDB' % type ( expr ) . __name__ ) )
dictionary corresponding to apply part of split-apply-combine operation .