/historical/hive_indra_null.py
Python | 89 lines | 47 code | 15 blank | 27 comment | 5 complexity | 1573677e9211dcf24fa702aed57989aa MD5 | raw file
1# 2# $LicenseInfo:firstyear=2010&license=mit$ 3# 4# Copyright (c) 2010, Linden Research, Inc. 5# 6# Permission is hereby granted, free of charge, to any person obtaining a copy 7# of this software and associated documentation files (the "Software"), to deal 8# in the Software without restriction, including without limitation the rights 9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10# copies of the Software, and to permit persons to whom the Software is 11# furnished to do so, subject to the following conditions: 12# 13# The above copyright notice and this permission notice shall be included in 14# all copies or substantial portions of the Software. 15# 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22# THE SOFTWARE. 23# $/LicenseInfo$ 24# 25 26from optparse import OptionParser 27 28import filtertools 29import hive 30import hive_mysql 31import sqlfilters 32 33class IndraNullWorker(hive_mysql.MySQLWorker): 34 def __init__(self, options, arguments): 35 hive_mysql.MySQLWorker.__init__(self, options, arguments) 36 self._first_filters = [] 37 self._all_filters = [] 38 self._at_start = True 39 40 if options.f_schema: 41 self._first_filters.append( 42 sqlfilters.PrependSchema(options.mysql_db)) 43 44 def start(self): 45 #hive_mysql.MySQLWorker.start(self) 46 self._at_start = True 47 48 def event(self, data): 49 hive_mysql.MySQLWorker.event(self, data) 50 self._at_start = False 51 52 def end(self): 53 return "200 OK" 54 55 def execute_sql(self, sql): 56 statements = [sql] 57 if self._at_start: 58 statements = filtertools.filterthru(statements, self._first_filters) 59 statements = filtertools.filterthru(statements, self._all_filters) 60 for s in statements: 61 #hive_mysql.MySQLWorker.execute_sql(self, s) 62 pass 63 64class IndraNullCentral(hive_mysql.MySQLCentral): 65 def __init__(self, options, arguments): 66 hive_mysql.MySQLCentral.__init__(self, options, arguments) 67 68 def start(self, seq): 69 pass 70 71 def event(self, seq, data): 72 pass 73 74 def end(self, seq): 75 pass 76 77class IndraNullHive(hive_mysql.MySQLHive): 78 def __init__(self): 79 hive_mysql.MySQLHive.__init__(self, worker_cls=IndraNullWorker) #, central_cls=IndraNullCentral) 80 #hive_mysql.MySQLHive.__init__(self, worker_cls=IndraNullWorker, central_cls=IndraNullCentral) 81 82 def add_options(self, parser): 83 hive_mysql.MySQLHive.add_options(self, parser) 84 parser.add_option('--f-schema', 85 action='store_true', default=False, 86 help='infer schema for statements (default: off)') 87 88if __name__ == '__main__': 89 IndraNullHive().main()