def query(self, query):
        """
        try and optimize the ast query into a sql query, leveraging the
        ast node sql() method
        """

        full_query = '%s: %s' % (self.name, query)
        builder = opencenter.webapp.ast.FilterBuilder(
            opencenter.webapp.ast.FilterTokenizer(),
            full_query, api=self.api)

        root = builder.build()

        sql_filter = None

        try:
            sql_filter = self._ast_to_sqlalchemy(root)
        except ValueError:
            self.logger.error('could not convert %s to native sql' % (query))

        if sql_filter is not None:
            r = self.model.query.filter(sql_filter)
            if not r:
                return None
            else:
                return [x.jsonify(api=self.api) for x in r]

        return builder.filter()
dataset/ETHPy150Open rcbops/opencenter/opencenter/db/abstraction.py/SqlAlchemyAbstraction.query/original