/historical/hive_indra_null.py

https://bitbucket.org/lindenlab/apiary/ · Python · 89 lines · 47 code · 15 blank · 27 comment · 4 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. from optparse import OptionParser
  26. import filtertools
  27. import hive
  28. import hive_mysql
  29. import sqlfilters
  30. class IndraNullWorker(hive_mysql.MySQLWorker):
  31. def __init__(self, options, arguments):
  32. hive_mysql.MySQLWorker.__init__(self, options, arguments)
  33. self._first_filters = []
  34. self._all_filters = []
  35. self._at_start = True
  36. if options.f_schema:
  37. self._first_filters.append(
  38. sqlfilters.PrependSchema(options.mysql_db))
  39. def start(self):
  40. #hive_mysql.MySQLWorker.start(self)
  41. self._at_start = True
  42. def event(self, data):
  43. hive_mysql.MySQLWorker.event(self, data)
  44. self._at_start = False
  45. def end(self):
  46. return "200 OK"
  47. def execute_sql(self, sql):
  48. statements = [sql]
  49. if self._at_start:
  50. statements = filtertools.filterthru(statements, self._first_filters)
  51. statements = filtertools.filterthru(statements, self._all_filters)
  52. for s in statements:
  53. #hive_mysql.MySQLWorker.execute_sql(self, s)
  54. pass
  55. class IndraNullCentral(hive_mysql.MySQLCentral):
  56. def __init__(self, options, arguments):
  57. hive_mysql.MySQLCentral.__init__(self, options, arguments)
  58. def start(self, seq):
  59. pass
  60. def event(self, seq, data):
  61. pass
  62. def end(self, seq):
  63. pass
  64. class IndraNullHive(hive_mysql.MySQLHive):
  65. def __init__(self):
  66. hive_mysql.MySQLHive.__init__(self, worker_cls=IndraNullWorker) #, central_cls=IndraNullCentral)
  67. #hive_mysql.MySQLHive.__init__(self, worker_cls=IndraNullWorker, central_cls=IndraNullCentral)
  68. def add_options(self, parser):
  69. hive_mysql.MySQLHive.add_options(self, parser)
  70. parser.add_option('--f-schema',
  71. action='store_true', default=False,
  72. help='infer schema for statements (default: off)')
  73. if __name__ == '__main__':
  74. IndraNullHive().main()