<commit_before>define(['angular','services/module-name'], function (angular,moduleName) {
    angular.module(moduleName).factory('HiveService', ["$q","$http","$mdDialog","RestUrlService",function ($q, $http, $mdDialog, RestUrlService) {

        function createFilterForTable(query) {
            var lowercaseQuery = angular.lowercase(query);
            return function filterFn(tag) {
                return (tag.fullNameLower.indexOf(lowercaseQuery) != -1 );
            };
        }

        var data = {
            init: function () {
                this.allTables = undefined;
            },
            queryTablesSearch: function (query) {
                var self = this;
                if (self.allTables == undefined) {
                    var deferred = $q.defer();
                    var tables = self.getTables().then(function (response) {

                        self.allTables = self.parseTableResponse(response.data);

                        var results = query ? self.allTables.filter(createFilterForTable(query)) : self.allTables;
                        deferred.resolve(results);
                    });
                    return deferred.promise;
                }
                else {
                    var results = query ? self.allTables.filter(createFilterForTable(query)) : [];
                    return results;
                }
            },
            parseTableResponse: function (response) {
                var schemaTables = {};
                var allTables = [];
                if (response) {
                    angular.forEach(response, function (table) {
                        var schema = table.substr(0, table.indexOf("."));
                        var tableName = table.substr(table.indexOf(".") + 1);
                        if (schemaTables[schema] == undefined) {
                            schemaTables[schema] = [];
                        }
                        allTables.push({schema: schema, tableName: tableName, fullName: table, fullNameLower: table.toLowerCase()});
                    })
                }
                return allTables;
            },
            getTables: function () {
                var self = this;

                var successFn = function (response) {
                    return self.parseTableResponse(response.data);

                }
                var errorFn = function (err) {
                    self.loading = false;

                }
                var promise = $http.get(RestUrlService.HIVE_SERVICE_URL + "/tables");
                promise.then(successFn, errorFn);
                return promise;
            },
            queryResult: function (query) {
                var self = this;
                if (this.query != null) {
                    var successFn = function (response) {
                        var tableData = response.data;
                        return tableData;

                    }
                    var errorFn = function (err) {
                        self.loadingHiveSchemas = false;
                        $mdDialog.show(
                            $mdDialog.alert()
                                .parent(angular.element(document.querySelector('body')))
                                .clickOutsideToClose(true)
                                .title('Error executing the Query')
                                .textContent('Error querying the data for ' + query)
                                .ariaLabel('Error browsing the data')<commit_msg>fixed Hive table error with better response<commit_after>define(['angular','services/module-name'], function (angular,moduleName) {
    angular.module(moduleName).factory('HiveService', ["$q","$http","$mdDialog","RestUrlService",function ($q, $http, $mdDialog, RestUrlService) {

        function createFilterForTable(query) {
            var lowercaseQuery = angular.lowercase(query);
            return function filterFn(tag) {
                return (tag.fullNameLower.indexOf(lowercaseQuery) != -1 );
            };
        }

        var data = {
            init: function () {
                this.allTables = undefined;
            },
            queryTablesSearch: function (query) {
                var self = this;
                if (self.allTables == undefined) {
                    var deferred = $q.defer();
                    var tables = self.getTables().then(function (response) {

                        self.allTables = self.parseTableResponse(response.data);

                        var results = query ? self.allTables.filter(createFilterForTable(query)) : self.allTables;
                        deferred.resolve(results);
                    });
                    return deferred.promise;
                }
                else {
                    var results = query ? self.allTables.filter(createFilterForTable(query)) : [];
                    return results;
                }
            },
            parseTableResponse: function (response) {
                var schemaTables = {};
                var allTables = [];
                if (response) {
                    angular.forEach(response, function (table) {
                        var schema = table.substr(0, table.indexOf("."));
                        var tableName = table.substr(table.indexOf(".") + 1);
                        if (schemaTables[schema] == undefined) {
                            schemaTables[schema] = [];
                        }
                        allTables.push({schema: schema, tableName: tableName, fullName: table, fullNameLower: table.toLowerCase()});
                    })
                }
                return allTables;
            },
            getTables: function () {
                var self = this;

                var successFn = function (response) {
                    return self.parseTableResponse(response.data);

                }
                var errorFn = function (err) {
                    self.loading = false;

                }
                var promise = $http.get(RestUrlService.HIVE_SERVICE_URL + "/tables");
                promise.then(successFn, errorFn);
                return promise;
            },
            queryResult: function (query) {
                var self = this;
                if (this.query != null) {
                    var successFn = function (response) {
                        var tableData = response.data;
                        return tableData;

                    }
                    var errorFn = function (err) {
                        self.loadingHiveSchemas = false;
                        $mdDialog.show(
                            $mdDialog.alert()
                                .parent(angular.element(document.querySelector('body')))
                                .clickOutsideToClose(true)
                                .title('Error executing the Query')
                                .textContent('Error querying the data for ' + data + ' \n Hive reported the following error:' + err)
                                .ariaLabel('Error browsing the data')
{'fraction_non_alphanumeric': 0.0986749365661122, 'fraction_numerical': 0.0008457851705666761, 'mean_word_length': 1.2255332496863238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7152197', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1522, 'n_words': 332}