Commits

Miki Tebeka committed 61e5069

Seems to work

Comments (0)

Files changed (7)

 DEFAULT_PORT = 10000
 
 from .hive_service import ThriftHive
-from .thrift.transport import TSocket, TTransport
-from .thrift.protocol import TBinaryProtocol
+from thrift.transport import TSocket, TTransport
+from thrift.protocol import TBinaryProtocol
 
 def connect(host=DEFAULT_HOST, port=DEFAULT_PORT):
     transport = TSocket.TSocket(host, port)
+#!/usr/bin/env python
+
+from . import connect
+from .hive_service import ThriftHive
+import re
+from os import environ
+
+HOST = environ.get('HIVE_HOST', 'localhost')
+PORT = int(environ.get('HIVE_PORT', '10000'))
+
+
+def fix_hql(hql):
+    # 'SHOW TABLES;' -> 'SHOW TABLES'
+    return re.sub('\s*;+\s*$', '', hql, re.M|re.S)
+
+def repl(client):
+    import readline
+    readline.parse_and_bind("tab: complete")
+    while True:
+        try:
+            hql = raw_input('[hive] ').strip()
+        except (KeyboardInterrupt, EOFError):
+            return
+
+        hql = fix_hql(hql)
+        try:
+            client.execute(hql)
+            for line in client.fetchAll():
+                print(line)
+        except ThriftHive.HiveServerException as e:
+            print('ERROR: {}'.format(e))
+
+def script(client, filename):
+    with open(filename) as fo:
+        hql = fo.read()
+
+    hql = fix_hql(hql)
+
+    if hql.endswith(';'):
+        hql = hql[:-1]
+
+    client.execute(hql)
+    for line in client.fetchAll():
+        print(line)
+
+
+def main(argv=None):
+    import sys
+    from argparse import ArgumentParser
+
+    argv = argv or sys.argv
+
+    parser = ArgumentParser(description='')
+    parser.add_argument('--host', default=HOST)
+    parser.add_argument('--port', default=PORT, type=int)
+    parser.add_argument('script', help='script file', nargs='?')
+    args = parser.parse_args(argv[1:])
+
+    client = connect(args.host, args.port)
+
+    if args.script:
+        script(client, args.script)
+    else:
+        repl(client)
+
+if __name__ == '__main__':
+    main()

hive/fb303/FacebookService.py

 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 #
 
-from ..thrift.Thrift import *
+from thrift.Thrift import *
 from ttypes import *
-from ..thrift.Thrift import TProcessor
-from ..thrift.transport import TTransport
-from ..thrift.protocol import TBinaryProtocol
+from thrift.Thrift import TProcessor
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
 try:
-  from ..thrift.protocol import fastbinary
+  from thrift.protocol import fastbinary
 except:
   fastbinary = None
 

hive/hive_metastore/ThriftHiveMetastore.py

 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 #
 
-from ..thrift.Thrift import *
-from ..fb303 import FacebookService as fb303_FacebookServer
+from thrift.Thrift import *
+from ..fb303 import FacebookService as fb303_FacebookService
 from ttypes import *
-from ..thrift.Thrift import TProcessor
-from ..thrift.transport import TTransport
-from ..thrift.protocol import TBinaryProtocol, TProtocol
+from thrift.Thrift import TProcessor
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol, TProtocol
 try:
-  from ..thrift.protocol import fastbinary
+  from thrift.protocol import fastbinary
 except:
   fastbinary = None
 

hive/hive_metastore/ttypes.py

 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 #
 
-from ..thrift.Thrift import *
+from thrift.Thrift import *
 
 
-from ..thrift.transport import TTransport
-from ..thrift.protocol import TBinaryProtocol, TProtocol
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol, TProtocol
 try:
-  from ..thrift.protocol import fastbinary
+  from thrift.protocol import fastbinary
 except:
   fastbinary = None
 

hive/hive_service/ThriftHive.py

 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 #
 
-from ..thrift.Thrift import *
+from thrift.Thrift import *
+from .. import hive_metastore
 from ..hive_metastore import ThriftHiveMetastore
+from .. import queryplan
 from ttypes import *
-from ..thrift.Thrift import TProcessor
-from ..thrift.transport import TTransport
-from ..thrift.protocol import TBinaryProtocol, TProtocol
+from thrift.Thrift import TProcessor
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol, TProtocol
 try:
-  from ..thrift.protocol import fastbinary
+  from thrift.protocol import fastbinary
 except:
   fastbinary = None
 
 
-class Iface(ThriftHiveMetastore.Iface):
+class Iface(hive_metastore.ThriftHiveMetastore.Iface):
   def execute(self, query):
     """
     Parameters:
   """
 
   thrift_spec = (
-    (0, TType.STRUCT, 'success', (ttypes.Schema, hive_metastore.ttypes.Schema.thrift_spec), None, ), # 0
+    (0, TType.STRUCT, 'success', (hive_metastore.ttypes.Schema, hive_metastore.ttypes.Schema.thrift_spec), None, ), # 0
     (1, TType.STRUCT, 'ex', (HiveServerException, HiveServerException.thrift_spec), None, ), # 1
   )
 
   """
 
   thrift_spec = (
-    (0, TType.STRUCT, 'success', (ttypes.Schema, hive_metastore.ttypes.Schema.thrift_spec), None, ), # 0
+    (0, TType.STRUCT, 'success', (hive_metastore.ttypes.Schema, hive_metastore.ttypes.Schema.thrift_spec), None, ), # 0
     (1, TType.STRUCT, 'ex', (HiveServerException, HiveServerException.thrift_spec), None, ), # 1
   )
 

hive/hive_service/ttypes.py

 #
 
 from thrift.Thrift import *
-import fb303.ttypes
-import hive_metastore.ttypes
-import queryplan.ttypes
+from ..fb303 import ttypes as fb303_ttypes
+from ..hive_metastore import ttypes as ms_ttypes
+from ..queryplan import ttypes as qp_ttypes
 
 
 from thrift.transport import TTransport
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.