<s> from raco import RACompiler <EOL> from raco . compile import compile <EOL> from raco . backends . radish import GrappaSymmetricHashJoin <EOL> from raco . backends . radish import GrappaShuffleHashJoin <EOL> import raco . viz as viz <EOL> import logging <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def comment ( s ) : <EOL> return "<STR_LIT>" % str ( s ) <EOL> def hack_plan ( alg , plan ) : <EOL> newRule = None <EOL> if plan == "<STR_LIT>" : <EOL> alg . set_join_type ( GrappaSymmetricHashJoin ) <EOL> elif plan == "<STR_LIT>" : <EOL> alg . set_join_type ( GrappaShuffleHashJoin ) <EOL> def emitCode ( query , name , algType , plan = None , emit_print = None , dir = '<STR_LIT:.>' ) : <EOL> if emit_print is not None : <EOL> alg = algType ( emit_print ) <EOL> else : <EOL> alg = algType ( ) <EOL> hack_plan ( alg , plan ) <EOL> LOG . info ( "<STR_LIT>" , name , query ) <EOL> dlog = RACompiler ( ) <EOL> dlog . fromDatalog ( query ) <EOL> LOG . info ( "<STR_LIT>" , dlog . logicalplan ) <EOL> print dlog . logicalplan <EOL> logical_dot = viz . operator_to_dot ( dlog . logicalplan ) <EOL> with open ( "<STR_LIT>" % ( name ) , '<STR_LIT:w>' ) as dwf : <EOL> dwf . write ( logical_dot ) <EOL> dlog . optimize ( target = alg ) <EOL> LOG . info ( "<STR_LIT>" , dlog . physicalplan ) <EOL> print dlog . physicalplan <EOL> physical_dot = viz . operator_to_dot ( dlog . physicalplan ) <EOL> with open ( "<STR_LIT>" % ( name ) , '<STR_LIT:w>' ) as dwf : <EOL> dwf . write ( physical_dot ) <EOL> code = "<STR_LIT>" <EOL> code += comment ( "<STR_LIT>" + query ) <EOL> code += compile ( dlog . physicalplan ) <EOL> fname = '<STR_LIT>' . format ( dir = dir , name = name ) <EOL> with open ( fname , '<STR_LIT:w>' ) as f : <EOL> f . write ( code ) <EOL> return fname </s>
