def test_get_functions(self, vector, unique_database): impala_cluster = ImpalaCluster() catalogd = impala_cluster.catalogd.service trans_type = 'buffered' if pytest.config.option.use_kerberos: trans_type = 'kerberos' transport = create_transport(host=catalogd.hostname, port=catalogd.service_port, service='impala', transport_type=trans_type) transport.open() protocol = TBinaryProtocol.TBinaryProtocol(transport) catalog_client = CatalogService.Client(protocol) request = TGetFunctionsRequest() request.db_name = unique_database response = catalog_client.GetFunctions(request) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 0 self.client.execute("create function %s.fn() RETURNS int " "LOCATION '%s/libTestUdfs.so' SYMBOL='Fn'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert len(response.functions) == 1 assert len(response.functions[0].arg_types) == 0 assert response.functions[0].name.db_name == unique_database assert response.functions[0].name.function_name == 'fn' assert response.functions[0].aggregate_fn is None assert response.functions[0].scalar_fn is not None assert '/test-warehouse/libTestUdfs.so' in response.functions[0].hdfs_location # Add another scalar function with overloaded parameters ensure it shows up. self.client.execute("create function %s.fn(int) RETURNS double "\ "LOCATION '%s/libTestUdfs.so' SYMBOL='Fn'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 2 functions = [fn for fn in response.functions] # Sort by number of arg in the function (ascending) functions.sort(key=lambda fn: len(fn.arg_types)) assert len(functions[0].arg_types) == 0 assert len(functions[1].arg_types) == 1 assert functions[0].signature == 'fn()' assert functions[1].signature == 'fn(INT)' # Verify aggregate functions can also be retrieved self.client.execute("create aggregate function %s.agg_fn(int, string) RETURNS int " "LOCATION '%s/libTestUdas.so' UPDATE_FN='TwoArgUpdate'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 3 functions = [fn for fn in response.functions if fn.aggregate_fn is not None] # Should be only 1 aggregate function assert len(functions) == 1 # Negative test cases for database name request.db_name = unique_database + "_does_not_exist" response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.GENERAL assert 'Database does not exist: ' in str(response.status) request = TGetFunctionsRequest() response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.GENERAL assert 'Database name must be set' in str(response.status)
def test_get_functions(self, vector, unique_database): impala_cluster = ImpalaCluster() catalogd = impala_cluster.catalogd.service trans_type = 'buffered' if pytest.config.option.use_kerberos: trans_type = 'kerberos' transport = create_transport(host=catalogd.hostname, port=catalogd.service_port, service='impala', transport_type=trans_type) transport.open() protocol = TBinaryProtocol.TBinaryProtocol(transport) catalog_client = CatalogService.Client(protocol) request = TGetFunctionsRequest() request.db_name = unique_database response = catalog_client.GetFunctions(request) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 0 self.client.execute("create function %s.fn() RETURNS int " "LOCATION '%s/libTestUdfs.so' SYMBOL='Fn'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert len(response.functions) == 1 assert len(response.functions[0].arg_types) == 0 assert response.functions[0].name.db_name == unique_database assert response.functions[0].name.function_name == 'fn' assert response.functions[0].aggregate_fn is None assert response.functions[0].scalar_fn is not None assert '/test-warehouse/libTestUdfs.so' in response.functions[ 0].hdfs_location # Add another scalar function with overloaded parameters ensure it shows up. self.client.execute("create function %s.fn(int) RETURNS double "\ "LOCATION '%s/libTestUdfs.so' SYMBOL='Fn'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 2 functions = [fn for fn in response.functions] # Sort by number of arg in the function (ascending) functions.sort(key=lambda fn: len(fn.arg_types)) assert len(functions[0].arg_types) == 0 assert len(functions[1].arg_types) == 1 assert functions[0].signature == 'fn()' assert functions[1].signature == 'fn(INT)' # Verify aggregate functions can also be retrieved self.client.execute( "create aggregate function %s.agg_fn(int, string) RETURNS int " "LOCATION '%s/libTestUdas.so' UPDATE_FN='TwoArgUpdate'" % (unique_database, WAREHOUSE)) response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.OK assert len(response.functions) == 3 functions = [ fn for fn in response.functions if fn.aggregate_fn is not None ] # Should be only 1 aggregate function assert len(functions) == 1 # Negative test cases for database name request.db_name = unique_database + "_does_not_exist" response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.GENERAL assert 'Database does not exist: ' in str(response.status) request = TGetFunctionsRequest() response = catalog_client.GetFunctions(request) LOG.debug(response) assert response.status.status_code == TErrorCode.GENERAL assert 'Database name must be set' in str(response.status)