Skip to content

Commit fd73b0d

Browse files
authored
Merge pull request #90 from Hitesh-Maplelabs/PNDA-4772
PNDA-4772: Fix to run the hive query
2 parents 39c4730 + 45a41ff commit fd73b0d

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

api/src/main/resources/deployer_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def fill_hadoop_env_hdp(env):
180180

181181
elif role_name == "HIVE_SERVER":
182182
env['hive_server'] = '%s' % component_host(component_detail)
183-
env['hive_port'] = '10000'
183+
env['hive_port'] = '10001'
184184

185185
def fill_hadoop_env_cdh(env):
186186
# pylint: disable=E1103

api/src/main/resources/hbase_descriptor.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525
import logging
2626
import starbase
27-
import pyhs2
27+
import subprocess
2828

2929

3030
def create(descriptor_path, environment):
@@ -35,20 +35,21 @@ def create(descriptor_path, environment):
3535
logging.debug("_deploy_hbase: %s", descriptor)
3636
hbase = starbase.Connection(host=environment['hbase_rest_server'], port=int(environment['hbase_rest_port']))
3737
hive_host = environment['hive_server']
38-
hive_port = environment['hive_port']
39-
hive = pyhs2.connect(
40-
host=hive_host,
41-
port=hive_port,
42-
authMechanism="PLAIN",
43-
user='hdfs',
44-
password='test',
45-
database='default')
46-
38+
hive_port = int(environment['hive_port'])
39+
4740
for element in descriptor:
4841
if 'table' in element and 'col_family' in element:
4942
table = hbase.table('%s' % element['table'])
5043
table.create(element['col_family'])
5144
for qry in element['hive_schema']:
52-
hive.cursor().execute(qry)
45+
beeline_output = run_hive_query(qry, hive_host, hive_port)
46+
logging.info(beeline_output)
47+
5348

54-
hive.close()
49+
def run_hive_query(query, hive_host, hive_port):
50+
beeline_output = subprocess.check_output([
51+
"beeline",
52+
"-u", "jdbc:hive2://%s:%s/;transportMode=http;httpPath=cliservice" % (hive_host, hive_port),
53+
"-e",
54+
query])
55+
return beeline_output

api/src/main/resources/test_hbase_descriptor.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929

3030
class TestHbaseDescriptor(unittest.TestCase):
3131
@patch('starbase.Connection')
32-
@patch('pyhs2.connect')
33-
def test_normal_use(self, pyhs_mock, hbase_mock):
34-
pyhs_mock.return_value = Mock()
32+
def test_normal_use(self, hbase_mock):
3533

3634
my_text = '[{"table":"a_table", "col_family":"a_cf", "hive_schema":[]}]'
3735
mocked_open_function = mock_open(read_data=my_text)
@@ -49,10 +47,11 @@ def test_normal_use(self, pyhs_mock, hbase_mock):
4947
hbase_mock.return_value.table.return_value.create.assert_called_once_with('a_cf')
5048

5149
@patch('starbase.Connection')
52-
@patch('pyhs2.connect')
53-
def test_with_impala_schema(self, pyhs_mock, hbase_mock):
54-
my_text = '[{"table":"a_table", "col_family":"a_cf", "hive_schema":["some ddl","more ddl"]}]'
50+
@patch('subprocess.check_output')
51+
def test_with_impala_schema(self, subprocess_mock, hbase_mock):
52+
my_text = '[{"table":"a_table", "col_family":"a_cf", "hive_schema":["some ddl"]}]'
5553
mocked_open_function = mock_open(read_data=my_text)
54+
subprocess_mock.return_value = 'something'
5655

5756
with patch("__builtin__.open", mocked_open_function):
5857
environment = {
@@ -65,5 +64,4 @@ def test_with_impala_schema(self, pyhs_mock, hbase_mock):
6564
hbase_mock.assert_called_once_with(host='1.2.3.4', port=2231)
6665
hbase_mock.return_value.table.assert_called_once_with('a_table')
6766
hbase_mock.return_value.table.return_value.create.assert_called_once_with('a_cf')
68-
pyhs_mock.return_value.cursor.return_value.execute.assert_any_call('some ddl')
69-
pyhs_mock.return_value.cursor.return_value.execute.assert_any_call('more ddl')
67+
subprocess_mock.assert_called_once_with(["beeline", "-u", "jdbc:hive2://5.6.7.8:9876/;transportMode=http;httpPath=cliservice", "-e", "some ddl"])

0 commit comments

Comments
 (0)