Skip to content

Commit 1c6196b

Browse files
committed
feature #19. also fix small bug in aggregations result cause to empty row
1 parent 55ed147 commit 1c6196b

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

src/_site/controllers.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var elasticsearchSqlApp = angular.module('elasticsearchSqlApp', ["ngAnimate", "ngSanitize"]);
22

33
elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce) {
4-
$scope.url = "http://localhost:9200";
4+
$scope.url = getUrl();
55
$scope.error = "";
66
$scope.resultsColumns = [];
77
$scope.resultsRows = [];
@@ -15,9 +15,11 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
1515
$scope.loading = true;
1616
$scope.$apply();
1717

18+
saveUrl()
19+
1820
var query = window.editor.getValue();
1921

20-
$http.post($scope.url + "/_sql", query)
22+
$http.post($scope.url + "_sql", query)
2123
.success(function(data, status, headers, config) {
2224
var handler = ResultHandlerFactory.create(data);
2325
$scope.resultsColumns = handler.getHead();
@@ -42,5 +44,28 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
4244
var loadingContent = "<span class=\"glyphicon glyphicon-refresh glyphicon-refresh-animate\"></span> Loading...";
4345
var returnValue = isLoading ? loadingContent : "Search";
4446
return $sce.trustAsHtml(returnValue);
47+
}
48+
49+
50+
function getUrl() {
51+
var url = localStorage.getItem("lasturl");
52+
if(url == undefined) {
53+
if(location.protocol == "file") {
54+
url = "http://localhost:9200"
55+
}
56+
else {
57+
url = location.protocol+'//' + location.hostname + (location.port ? ':'+location.port : '');
58+
}
59+
}
60+
61+
if(url.substr(url.length - 1, 1) != '/') {
62+
url += '/'
63+
}
64+
65+
return url
66+
}
67+
68+
function saveUrl() {
69+
localStorage.setItem("lasturl", $scope.url);
4570
}
4671
});

src/_site/query.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,23 @@ var AggregationQueryResultHandler = function(data) {
9191
}
9292
}
9393

94-
var obj = $.extend({}, additionalColumns)
95-
if(bucketName != undefined) {
96-
obj[bucketName] = bucket.key
97-
}
98-
99-
for(var field in bucket) {
100-
if(bucket[field].value != undefined) {
101-
obj[field] = bucket[field].value
94+
else {
95+
var obj = $.extend({}, additionalColumns)
96+
if(bucketName != undefined) {
97+
obj[bucketName] = bucket.key
10298
}
103-
else {
104-
continue;
99+
100+
for(var field in bucket) {
101+
if(bucket[field].value != undefined) {
102+
obj[field] = bucket[field].value
103+
}
104+
else {
105+
continue;
106+
}
105107
}
108+
rows.push(obj)
106109
}
107110

108-
rows.push(obj)
109111
return rows
110112
}
111113

src/_site/tests/spec/ResultHandlersSpec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ describe("AggregationQueryResultHandler", function() {
105105
});
106106

107107

108-
/* TODO make this test pass.
109-
Add test that take complex aggregation result with
110-
some buckets. */
111108
it("should return the expected body", function() {
112109
var body = handler.getBody();
113110
expect(angular.equals(body, expectedBody)).toBe(true);
114111
});
115112

113+
// TODO add nested aggregations test.
114+
116115
});

src/test/java/org/nlpcn/es4sql/MainTestSuite.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ private static InetSocketTransportAddress getTransportAddress() {
6161
String host = System.getenv("ES_TEST_HOST");
6262
String port = System.getenv("ES_TEST_PORT");
6363

64-
if(host == null || port == null) {
64+
if(host == null) {
6565
host = "localhost";
66-
port = "9300";
66+
System.out.println("ES_TEST_HOST enviroment variable does not exist. choose default 'localhost'");
67+
}
6768

68-
System.out.println("ES_TEST_HOST AND ES_TEST_PORT enviroment variables does not exist.");
69-
System.out.println(String.format("Using defaults. host: %s. port:%s.", host, port));
69+
if(port == null) {
70+
port = "9300";
71+
System.out.println("ES_TEST_PORT enviroment variable does not exist. choose default '9300'");
7072
}
7173

74+
System.out.println(String.format("Connection details: host: %s. port:%s.", host, port));
7275
return new InetSocketTransportAddress(host, Integer.parseInt(port));
7376
}
7477

0 commit comments

Comments
 (0)