#NEWLINE# def testRewriteQuery( self ) : #NEWLINE# #INDENT# master_key = test_util . GetMasterKey ( ) #NEWLINE# schema = test_util . GetCarsSchema ( ) #NEWLINE# query = 'SELECT Year from test_dataset.cars WHERE Year > 1990 GROUP BY Year ORDER BY Year LIMIT 2' #NEWLINE# clauses = parser . ParseQuery ( query ) #NEWLINE# rewritten_query = ( 'SELECT Year AS %s0_ FROM test_dataset.cars WHERE (Year > 1990) GROUP BY %s0_ LIMIT 2' % ( util . UNENCRYPTED_ALIAS_PREFIX , util . UNENCRYPTED_ALIAS_PREFIX ) ) #NEWLINE# self . assertEqual ( query_lib . RewriteQuery ( clauses , schema , master_key , _TABLE_ID ) [ 0 ] , rewritten_query ) #NEWLINE# query = 'SELECT SUM(Year) from test_dataset.cars having SUM(Year) > 7000' #NEWLINE# clauses = parser . ParseQuery ( query ) #NEWLINE# rewritten_query = ( 'SELECT SUM(Year) AS %s0_ FROM test_dataset.cars HAVING (SUM(Year) > 7000)' % util . UNENCRYPTED_ALIAS_PREFIX ) #NEWLINE# self . assertEqual ( query_lib . RewriteQuery ( clauses , schema , master_key , _TABLE_ID ) [ 0 ] , rewritten_query ) #NEWLINE# query = 'SELECT Price + 1 from test_dataset.cars' #NEWLINE# clauses = parser . ParseQuery ( query ) #NEWLINE# rewritten_query = ( 'SELECT %sPrice AS %sPrice FROM test_dataset.cars' % ( util . PROBABILISTIC_PREFIX , util . PROBABILISTIC_PREFIX ) ) #NEWLINE# self . assertEqual ( query_lib . RewriteQuery ( clauses , schema , master_key , _TABLE_ID ) [ 0 ] , rewritten_query ) #NEWLINE# query = 'SELECT SUM(Invoice_Price), GROUP_CONCAT(Make) FROM test_dataset.cars' #NEWLINE# clauses = parser . ParseQuery ( query ) #NEWLINE# rewritten_query = ( "SELECT COUNT(%sInvoice_Price), %s%sInvoice_Price), '\\x44\\x08\\xb5\\xaa\\xcc\\x3f\\xf6\\xb3\\x36\\xe4\\xb2\\xec\\xc7\\x75\\x1f\\xb2\\xdb\\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\x4d\\x6a\\x41\\xfb\\x06\\x6a\\x1c\\xf4\\x54\\x59\\xfe\\xb1\\xc3\\xec\\x11'))), GROUP_CONCAT(%sMake) FROM test_dataset.cars" % ( util . HOMOMORPHIC_INT_PREFIX , util . PAILLIER_SUM_PREFIX , util . HOMOMORPHIC_INT_PREFIX , util . PSEUDONYM_PREFIX ) ) #NEWLINE# self . assertEqual ( query_lib . RewriteQuery ( clauses , schema , master_key , _TABLE_ID ) [ 0 ] , rewritten_query )