#NEWLINE# def test_double_nested_subquery_no_aliases( self ) : #NEWLINE# #INDENT# t = api . table ( [ ( 'key1' , 'string' ) , ( 'key2' , 'string' ) , ( 'key3' , 'string' ) , ( 'value' , 'double' ) ] , 'foo_table' ) #NEWLINE# agg1 = t . aggregate ( [ t . value . sum ( ) . name ( 'total' ) ] , by = [ 'key1' , 'key2' , 'key3' ] ) #NEWLINE# agg2 = agg1 . aggregate ( [ agg1 . total . sum ( ) . name ( 'total' ) ] , by = [ 'key1' , 'key2' ] ) #NEWLINE# agg3 = agg2 . aggregate ( [ agg2 . total . sum ( ) . name ( 'total' ) ] , by = [ 'key1' ] ) #NEWLINE# result = to_sql ( agg3 ) #NEWLINE# expected = 'SELECT `key1`, sum(`total`) AS `total`\nFROM (\n  SELECT `key1`, `key2`, sum(`total`) AS `total`\n  FROM (\n    SELECT `key1`, `key2`, `key3`, sum(`value`) AS `total`\n    FROM foo_table\n    GROUP BY 1, 2, 3\n  ) t1\n  GROUP BY 1, 2\n) t0\nGROUP BY 1' #NEWLINE# assert ( result == expected )