def populate_schema_objects(self, schema, obj_type): """Returns a list of SchemaObjects representing tables, views, funcs schema is the schema qualification input by the user (if any) """ return [ SchemaObject(name=obj, schema=(self._maybe_schema(schema=sch, parent=schema)), function=(obj_type == 'functions')) for sch in self._get_schemas(obj_type, schema) for obj in self.metadata[obj_type][sch].keys() ]
def populate_functions(self, schema, filter_func): """Returns a list of function names filter_func is a function that accepts a FunctionMetadata namedtuple and returns a boolean indicating whether that function should be kept or discarded """ # Because of multiple dispatch, we can have multiple functions # with the same name, which is why `for meta in metas` is necessary # in the comprehensions below return [ SchemaObject(name=func, schema=(self._maybe_schema(schema=sch, parent=schema)), function=True) for sch in self._get_schemas('functions', schema) for (func, metas) in self.metadata['functions'][sch].items() for meta in metas if filter_func(meta) ]
def get_table_matches(self, suggestion, word_before_cursor, alias=False): tables = self.populate_schema_objects(suggestion.schema, 'tables') tables.extend(SchemaObject(tbl.name) for tbl in suggestion.local_tables) tables = [self._make_cand(t, alias, suggestion) for t in tables] return self.find_matches(word_before_cursor, tables, meta='table')