class QueryThread(threading.Thread): def set_query(self, q, async): self.runner = QueryRunner() self.q = q self.async = async def run(self): self.runner.run_query(self.q, self.async)
def main(): runner = QueryRunner() try: while True: cmd = raw_input("tweeql> ") process_command(runner, cmd) except (KeyboardInterrupt, EOFError): print '\nGoodbye!'
def main(): import patch import functions from tweeql.exceptions import TweeQLException from tweeql.query_runner import QueryRunner if not options.where: parser.parse_args(['-h']) runner = QueryRunner() params = dict( where=options.where and 'WHERE %s' % options.where or '', table=options.where and 'twitter' or 'twitter_sample' ) query = '''select url(text) as id, screen_name, text, created_at, entities('hashtags') as cat, entities('user_mentions') as user_mentions, tweetLatLng("lat") as latitude, tweetLatLng("lng") as longitude from %(table)s %(where)s;''' % params if config.DEBUG: print >> sys.stderr, ' ', query runner.run_query(query, False)
def process_command(cmd): runner = QueryRunner() try: logging.debug('starting') runner.run_query(cmd, False) except KeyboardInterrupt: logging.debug('interrupted') runner.stop_query() except TweeQLException, e: runner.stop_query() if settings.DEBUG: traceback.print_exc() else: print e
def set_query(self, q, async): self.runner = QueryRunner() self.q = q self.async = async
print q, 1, to_stream if to_stream != False: locks.locks[to_stream] = threading.Event() print q, 2, from_stream if from_stream != False: locks.locks[from_stream].wait() print q, 3 qt = QueryThread() qt.set_query(q, False) qt.start() print q, 4 try: query1 = "SELECT text FROM twitter INTO STREAM STREAMONE WHERE text CONTAINS \"game\"" #query1 = "SELECT text FROM twitter WHERE text CONTAINS \"game\"" qr1 = QueryRunner() qr1.run_query(query1, True) query2 = "SELECT text FROM STREAMONE INTO STREAM STREAMTWO WHERE text CONTAINS \"the\"" qr2 = QueryRunner() qr2.run_query(query2, True) print 'FINISHED TWOTWOTWOTWOTWO' query3 = "SELECT text FROM STREAMTWO" print 'RUNNING THRETHRETHREHTEHRHETHERHETHERHETHEHREHR' qr3 = QueryRunner() qr3.run_query(query3, True) except KeyboardInterrupt: qr1.stop_query() qr2.stop_query() qr3.stop_query()
from tweeql.exceptions import TweeQLException from tweeql.field_descriptor import ReturnType from tweeql.function_registry import FunctionInformation, FunctionRegistry from tweeql.query_runner import QueryRunner class StringLength(): return_type = ReturnType.INTEGER @staticmethod def factory(): return StringLength().strlen def strlen(self, tuple_data, val): """ Returns the length of val, which is a string """ return len(val) fr = FunctionRegistry() fr.register( "stringlength", FunctionInformation(StringLength.factory, StringLength.return_type)) runner = QueryRunner() runner.run_query("SELECT stringlength(text) AS len FROM twitter_sample;", False)
from tweeql.exceptions import TweeQLException from tweeql.field_descriptor import ReturnType from tweeql.function_registry import FunctionInformation, FunctionRegistry from tweeql.query_runner import QueryRunner class StringLength(): return_type = ReturnType.INTEGER @staticmethod def factory(): return StringLength().strlen def strlen(self, tuple_data, val): """ Returns the length of val, which is a string """ return len(val) fr = FunctionRegistry() fr.register("stringlength", FunctionInformation(StringLength.factory, StringLength.return_type)) runner = QueryRunner() runner.run_query("SELECT stringlength(text) AS len FROM twitter_sample;", False)
from tweeql.exceptions import TweeQLException from tweeql.query_runner import QueryRunner runner = QueryRunner() runner.run_query("SELECT text FROM twitter_sample;", False) #runner.stop_query()