PageRenderTime 86ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/historical/hive_indra.py

https://bitbucket.org/lindenlab/apiary/
Python | 72 lines | 37 code | 11 blank | 24 comment | 4 complexity | 3cb04cae87b2ec044ae30f0b4b56453a 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 IndraWorker(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 execute_sql(self, sql):
  46. statements = [sql]
  47. if self._at_start:
  48. statements = filtertools.filterthru(statements, self._first_filters)
  49. statements = filtertools.filterthru(statements, self._all_filters)
  50. for s in statements:
  51. hive_mysql.MySQLWorker.execute_sql(self, s)
  52. class IndraHive(hive_mysql.MySQLHive):
  53. def __init__(self):
  54. hive_mysql.MySQLHive.__init__(self, worker_cls=IndraWorker)
  55. def add_options(self, parser):
  56. hive_mysql.MySQLHive.add_options(self, parser)
  57. parser.add_option('--f-schema',
  58. action='store_true', default=False,
  59. help='infer schema for statements (default: off)')
  60. if __name__ == '__main__':
  61. IndraHive().main()