ImpalaService-remote 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 ' TStatus ResetTable(TResetTableReq request)'
  26. print ' string GetRuntimeProfile(QueryHandle query_id)'
  27. print ' TInsertResult CloseInsert(QueryHandle handle)'
  28. print ' TPingImpalaServiceResp PingImpalaService()'
  29. print ''
  30. sys.exit(0)
  31. pp = pprint.PrettyPrinter(indent = 2)
  32. host = 'localhost'
  33. port = 9090
  34. uri = ''
  35. framed = False
  36. http = False
  37. argi = 1
  38. if sys.argv[argi] == '-h':
  39. parts = sys.argv[argi+1].split(':')
  40. host = parts[0]
  41. if len(parts) > 1:
  42. port = int(parts[1])
  43. argi += 2
  44. if sys.argv[argi] == '-u':
  45. url = urlparse(sys.argv[argi+1])
  46. parts = url[1].split(':')
  47. host = parts[0]
  48. if len(parts) > 1:
  49. port = int(parts[1])
  50. else:
  51. port = 80
  52. uri = url[2]
  53. if url[4]:
  54. uri += '?%s' % url[4]
  55. http = True
  56. argi += 2
  57. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  58. framed = True
  59. argi += 1
  60. cmd = sys.argv[argi]
  61. args = sys.argv[argi+1:]
  62. if http:
  63. transport = THttpClient.THttpClient(host, port, uri)
  64. else:
  65. socket = TSocket.TSocket(host, port)
  66. if framed:
  67. transport = TTransport.TFramedTransport(socket)
  68. else:
  69. transport = TTransport.TBufferedTransport(socket)
  70. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  71. client = ImpalaService.Client(protocol)
  72. transport.open()
  73. if cmd == 'Cancel':
  74. if len(args) != 1:
  75. print 'Cancel requires 1 args'
  76. sys.exit(1)
  77. pp.pprint(client.Cancel(eval(args[0]),))
  78. elif cmd == 'ResetCatalog':
  79. if len(args) != 0:
  80. print 'ResetCatalog requires 0 args'
  81. sys.exit(1)
  82. pp.pprint(client.ResetCatalog())
  83. elif cmd == 'ResetTable':
  84. if len(args) != 1:
  85. print 'ResetTable requires 1 args'
  86. sys.exit(1)
  87. pp.pprint(client.ResetTable(eval(args[0]),))
  88. elif cmd == 'GetRuntimeProfile':
  89. if len(args) != 1:
  90. print 'GetRuntimeProfile requires 1 args'
  91. sys.exit(1)
  92. pp.pprint(client.GetRuntimeProfile(eval(args[0]),))
  93. elif cmd == 'CloseInsert':
  94. if len(args) != 1:
  95. print 'CloseInsert requires 1 args'
  96. sys.exit(1)
  97. pp.pprint(client.CloseInsert(eval(args[0]),))
  98. elif cmd == 'PingImpalaService':
  99. if len(args) != 0:
  100. print 'PingImpalaService requires 0 args'
  101. sys.exit(1)
  102. pp.pprint(client.PingImpalaService())
  103. else:
  104. print 'Unrecognized method %s' % cmd
  105. sys.exit(1)
  106. transport.close()