#NEWLINE# def test_bug_project_multiple_times( self ) : #NEWLINE# #INDENT# customer = self . con . table ( 'tpch_customer' ) #NEWLINE# nation = self . con . table ( 'tpch_nation' ) #NEWLINE# region = self . con . table ( 'tpch_region' ) #NEWLINE# joined = customer . inner_join ( nation , [ ( customer . c_nationkey == nation . n_nationkey ) ] ) . inner_join ( region , [ ( nation . n_regionkey == region . r_regionkey ) ] ) #NEWLINE# proj1 = [ customer , nation . n_name , region . r_name ] #NEWLINE# step1 = joined [ proj1 ] #NEWLINE# topk_by = step1 . c_acctbal . cast ( 'double' ) . sum ( ) #NEWLINE# pred = step1 . n_name . topk ( 10 , by = topk_by ) #NEWLINE# proj_exprs = [ step1 . c_name , step1 . r_name , step1 . n_name ] #NEWLINE# step2 = step1 [ pred ] #NEWLINE# expr = step2 . projection ( self ) #NEWLINE# result = to_sql ( expr ) #NEWLINE# expected = 'SELECT t0.`c_name`, t2.`r_name`, t1.`n_name`\nFROM tpch_customer t0\n  INNER JOIN tpch_nation t1\n    ON t0.`c_nationkey` = t1.`n_nationkey`\n  INNER JOIN tpch_region t2\n    ON t1.`n_regionkey` = t2.`r_regionkey`\n  LEFT SEMI JOIN (\n    SELECT *\n    FROM (\n      SELECT t1.`n_name`, sum(CAST(t0.`c_acctbal` AS double)) AS `sum`\n      FROM tpch_customer t0\n        INNER JOIN tpch_nation t1\n          ON t0.`c_nationkey` = t1.`n_nationkey`\n        INNER JOIN tpch_region t2\n          ON t1.`n_regionkey` = t2.`r_regionkey`\n      GROUP BY 1\n    ) t4\n    ORDER BY `sum` DESC\n    LIMIT 10\n  ) t3\n    ON t1.`n_name` = t3.`n_name`' #NEWLINE# assert ( result == expected )