ImpalaService-remote 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.9.0)
  4. #
  5. # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  6. #
  7. # options string: py:new_style
  8. #
  9. import sys
  10. import pprint
  11. from urlparse import urlparse
  12. from thrift.transport import TTransport
  13. from thrift.transport import TSocket
  14. from thrift.transport import THttpClient
  15. from thrift.protocol import TBinaryProtocol
  16. import ImpalaService
  17. from ttypes import *
  18. if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  19. print ''
  20. print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
  21. print ''
  22. print 'Functions:'
  23. print ' TStatus Cancel(QueryHandle query_id)'
  24. print ' TStatus ResetCatalog()'
  25. print ' TInsertResult CloseInsert(QueryHandle handle)'
  26. print ' void PingImpalaService()'
  27. print ''
  28. sys.exit(0)
  29. pp = pprint.PrettyPrinter(indent = 2)
  30. host = 'localhost'
  31. port = 9090
  32. uri = ''
  33. framed = False
  34. http = False
  35. argi = 1
  36. if sys.argv[argi] == '-h':
  37. parts = sys.argv[argi+1].split(':')
  38. host = parts[0]
  39. if len(parts) > 1:
  40. port = int(parts[1])
  41. argi += 2
  42. if sys.argv[argi] == '-u':
  43. url = urlparse(sys.argv[argi+1])
  44. parts = url[1].split(':')
  45. host = parts[0]
  46. if len(parts) > 1:
  47. port = int(parts[1])
  48. else:
  49. port = 80
  50. uri = url[2]
  51. if url[4]:
  52. uri += '?%s' % url[4]
  53. http = True
  54. argi += 2
  55. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  56. framed = True
  57. argi += 1
  58. cmd = sys.argv[argi]
  59. args = sys.argv[argi+1:]
  60. if http:
  61. transport = THttpClient.THttpClient(host, port, uri)
  62. else:
  63. socket = TSocket.TSocket(host, port)
  64. if framed:
  65. transport = TTransport.TFramedTransport(socket)
  66. else:
  67. transport = TTransport.TBufferedTransport(socket)
  68. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  69. client = ImpalaService.Client(protocol)
  70. transport.open()
  71. if cmd == 'Cancel':
  72. if len(args) != 1:
  73. print 'Cancel requires 1 args'
  74. sys.exit(1)
  75. pp.pprint(client.Cancel(eval(args[0]),))
  76. elif cmd == 'ResetCatalog':
  77. if len(args) != 0:
  78. print 'ResetCatalog requires 0 args'
  79. sys.exit(1)
  80. pp.pprint(client.ResetCatalog())
  81. elif cmd == 'CloseInsert':
  82. if len(args) != 1:
  83. print 'CloseInsert requires 1 args'
  84. sys.exit(1)
  85. pp.pprint(client.CloseInsert(eval(args[0]),))
  86. elif cmd == 'PingImpalaService':
  87. if len(args) != 0:
  88. print 'PingImpalaService requires 0 args'
  89. sys.exit(1)
  90. pp.pprint(client.PingImpalaService())
  91. else:
  92. print 'Unrecognized method %s' % cmd
  93. sys.exit(1)
  94. transport.close()