#NEWLINE# def test_ast_with_aggregation_join_filter( self ) : #NEWLINE# #INDENT# table = self . con . table ( 'test1' ) #NEWLINE# table2 = self . con . table ( 'test2' ) #NEWLINE# filter_pred = ( table [ 'f' ] > 0 ) #NEWLINE# table3 = table [ filter_pred ] #NEWLINE# join_pred = ( table3 [ 'g' ] == table2 [ 'key' ] ) #NEWLINE# joined = table2 . inner_join ( table3 , [ join_pred ] ) #NEWLINE# met1 = ( table3 [ 'f' ] - table2 [ 'value' ] ) . mean ( ) . name ( 'foo' ) #NEWLINE# result = joined . aggregate ( [ met1 , table3 [ 'f' ] . sum ( ) . name ( 'bar' ) ] , by = [ table3 [ 'g' ] , table2 [ 'key' ] ] ) #NEWLINE# ast = build_ast ( result ) #NEWLINE# stmt = ast . queries [ 0 ] #NEWLINE# ex_pred = [ ( table3 [ 'g' ] == table2 [ 'key' ] ) ] #NEWLINE# expected_table_set = table2 . inner_join ( table3 , ex_pred ) #NEWLINE# assert stmt . table_set . equals ( expected_table_set ) #NEWLINE# ex_metrics = [ ( table3 [ 'f' ] - table2 [ 'value' ] ) . mean ( ) . name ( 'foo' ) , table3 [ 'f' ] . sum ( ) . name ( 'bar' ) ] #NEWLINE# ex_by = [ table3 [ 'g' ] , table2 [ 'key' ] ] #NEWLINE# for ( res , ex ) in zip ( stmt . select_set , ( ex_by + ex_metrics ) ) : #NEWLINE# #INDENT# assert res . equals ( ex ) #NEWLINE# #UNINDENT# for ( res , ex ) in zip ( stmt . group_by , ex_by ) : #NEWLINE# #INDENT# assert stmt . select_set [ res ] . equals ( ex ) #NEWLINE# #UNINDENT# assert ( len ( stmt . where ) == 0 )