def query(connection): # Get the physical plan for a test query catalog = MyriaCatalog(connection) servers = catalog.get_num_servers() parser = myrialparser.Parser() processor = interpreter.StatementProcessor(catalog, True) program = """ books = scan(Brandon:Demo:MoreBooks); longerBooks = [from books where pages > 300 emit name]; store(longerBooks, Brandon:Demo:LongerBooks); """ statement_list = parser.parse(program) processor.evaluate(statement_list) pd = processor.get_physical_plan(target_alg=MyriaLeftDeepTreeAlgebra()) json = processor.get_json_from_physical_plan(pd) return {'rawQuery': program, 'logicalRa': 'empty', 'fragments': json}
def get_plan(query, language, plan_type, connection, multiway_join=False, push_sql=False): catalog = None if multiway_join: catalog = MyriaCatalog(connection) assert catalog.get_num_servers() # Fix up the language string if language is None: language = "datalog" language = language.strip().lower() if multiway_join: target_algebra = MyriaHyperCubeAlgebra(catalog) else: target_algebra = MyriaLeftDeepTreeAlgebra() if language == "datalog": dlog = RACompiler() dlog.fromDatalog(query) if not dlog.logicalplan: raise SyntaxError("Unable to parse Datalog") if plan_type == 'logical': return dlog.logicalplan elif plan_type == 'physical': dlog.optimize(target=target_algebra, push_sql=push_sql) return dlog.physicalplan else: raise NotImplementedError('Datalog plan type %s' % plan_type) elif language in ["myrial", "sql"]: # We need a (global) lock on the Myrial parser because yacc # .. is not Threadsafe and App Engine uses multiple threads. with myrial_parser_lock: parsed = myrial_parser.parse(query) processor = MyrialInterpreter.StatementProcessor( MyriaCatalog(connection)) processor.evaluate(parsed) if plan_type == 'logical': return processor.get_physical_plan(target_alg=OptLogicalAlgebra()) elif plan_type == 'physical': return processor.get_physical_plan(target_alg=target_algebra, multiway_join=multiway_join, push_sql=push_sql) else: raise NotImplementedError('Myria plan type %s' % plan_type) raise NotImplementedError('Language %s is not supported' % language)
def _get_plan(self, query, language, plan_type, **kwargs): catalog = MyriaCatalog(self) algebra = MyriaHyperCubeAlgebra(catalog) \ if kwargs.get('multiway_jon', False) \ else MyriaLeftDeepTreeAlgebra() if language.lower() == "datalog": return self._get_datalog_plan(query, plan_type, algebra, **kwargs) elif language.lower() in ["myrial", "sql"]: return self._get_myrial_or_sql_plan(query, plan_type, catalog, algebra, **kwargs) else: raise NotImplementedError('Language %s not supported' % language)
def __init__(self, parent, query, connection=None): """ Create a new fluent query :param parent: The parent fluent instance used to create this one :param query: The query associated with this fluent instance :param connection: The connection associated with this fluent instance """ self.parent = parent self.query = query self.connection = connection if connection else parent.connection self.catalog = MyriaCatalog(self.connection) self.result = None self.udfs = [ f.to_dict() for f in MyriaFunction.get_all(self.connection) ]
def _scan(self, components): """ Scan a relation with the given name components """ return Scan( RelationKey(*components), MyriaCatalog(self.connection).get_scheme(RelationKey(*components)))
def rel_info(connection): cat = MyriaCatalog(connection) key = RelationKey('Brandon', 'Demo', 'MoreBooks') return cat.num_tuples(key), cat.partitioning(key)