Skip to content

Commit

Permalink
Merge pull request #91 from eliranmoyal/master
Browse files Browse the repository at this point in the history
Join limited support and more features
  • Loading branch information
eliranmoyal committed Sep 28, 2015
2 parents 8841a76 + d8f1e0e commit eb94cb3
Show file tree
Hide file tree
Showing 341 changed files with 3,637 additions and 35,655 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Elasticsearch-SQL
Query elasticsearch using familiar SQL syntax.
You can also use ES functions in SQL.

**Check out our [wiki!](https://github.com/NLPchina/elasticsearch-sql/wiki)**


## Web frontend overview
Expand All @@ -17,7 +18,7 @@ Install as plugin:

### Elasticsearch 1.6.X
````
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.3.5/elasticsearch-sql-1.3.5.zip --install sql
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4/elasticsearch-sql-1.4.zip --install sql
````

After doing this, you need to restart the Elasticsearch server. Otherwise you may get errors like `Invalid index name [sql], must not start with '']; ","status":400}`.
Expand Down
52 changes: 43 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nlpcn</groupId>
<artifactId>elasticsearch-sql</artifactId>
<version>1.3.5</version>
<version>1.4</version>
<packaging>jar</packaging>
<description>Query elasticsearch using SQL</description>
<name>elasticsearch-sql</name>
Expand Down Expand Up @@ -66,13 +66,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand All @@ -87,6 +80,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.15</version>
</dependency>


<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -124,7 +131,34 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>druid.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
66 changes: 62 additions & 4 deletions src/_site/controllers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

var elasticsearchSqlApp = angular.module('elasticsearchSqlApp', ["ngAnimate", "ngSanitize"]);

elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce) {
Expand All @@ -7,9 +8,61 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
$scope.resultsRows = [];
$scope.searchLoading = false;
$scope.explainLoading = false;
$scope.nextLoading = false;
$scope.resultExplan = false;

$scope.scrollId = null;
$scope.gotNext = false;

$scope.nextSearch = function(){
$scope.error = "";
$scope.nextLoading = true;
$scope.$apply();


if($scope.scrollId == null || $scope.scrollId == "" ){
$scope.error = "tryed scrolling with empty scrollId";
return;
}

$http.get($scope.url + "_search/scroll?scroll=1m&scroll_id=" + $scope.scrollId)
.success(function(data, status, headers, config) {
var handler = ResultHandlerFactory.create(data);
var body = handler.getBody()

if(body.length ==null || body.length == 0){
$scope.gotNext=false;
}
else
{
$scope.scrollId = handler.getScrollId();
}

if($scope.resultsRows.length > 0){
$scope.resultsRows = $scope.resultsRows.concat(handler.getBody());
}
else {
$scope.resultsColumns = handler.getHead();
$scope.resultsRows = handler.getBody();

}


})
.error(function(data, status, headers, config) {
if(data == "") {
$scope.error = "Error occured! response is not avalible.";
}
else {
$scope.error = JSON.stringify(data);
$scope.scrollId = null;
}
})
.finally(function() {
$scope.nextLoading = false;
$scope.$apply()
});

}

$scope.search = function() {
// Reset results and error box
Expand All @@ -27,6 +80,10 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
$http.post($scope.url + "_sql", query)
.success(function(data, status, headers, config) {
var handler = ResultHandlerFactory.create(data);
if(handler.isScroll){
$scope.gotNext=true;
$scope.scrollId = handler.getScrollId();
}
$scope.resultsColumns = handler.getHead();
$scope.resultsRows = handler.getBody();

Expand Down Expand Up @@ -88,7 +145,8 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
data += map2csvStr(columns,rows[i],',') ;

}
window.location='data:text/csv;charset=utf8,' + encodeURIComponent(data);
var plain = 'data:text/csv;charset=utf8,' + encodeURIComponent(data);
download(plain, "query_result.csv", "text/plain");
return true;
}

Expand All @@ -109,10 +167,10 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
}

function map2csvStr(columns,arr,op){
var data = arr[columns[0]];
var data = JSON.stringify(arr[columns[0]]);
for(var i=1; i<columns.length ; i++){
data += op;
data += arr[columns[i]] ;
data += JSON.stringify(arr[columns[i]]) ;
}
return data ;
}
Expand Down
5 changes: 5 additions & 0 deletions src/_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ <h1 class="page-header">SQL Query</h1>
</button>

<button type="button" ng-click="explain()" id="explainButton" class="btn btn-info explain-button" ng-bind-html="getButtonContent(explainLoading,'Explain')" ng-cloak>
</button>

<button type="next" ng-click="nextSearch()" id="nextButton" class="btn btn-warning next-button" ng-show="gotNext" ng-bind-html="getButtonContent(nextLoading,'Next')" ng-cloak>
</button>
</div>

Expand Down Expand Up @@ -172,10 +175,12 @@ <h2 class="sub-header">Results</h2>
<script src="vendor/codemirror/addon/hint/sql-hint.js"></script>

<!-- AngularJS -->
<script src="vendor/download/download.min.js"></script>
<script src="vendor/angularjs/angular.min.js"></script>
<script src="vendor/angularjs/angular-animate.min.js"></script>
<script src="vendor/angularjs/angular-sanitize.min.js"></script>


<script src="editor.js"></script>
<script src="query.js"></script>
<script src="controllers.js"></script>
Expand Down
11 changes: 11 additions & 0 deletions src/_site/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@ var DefaultQueryResultHandler = function(data) {

this.data = data
this.head = createScheme()
this.scrollId = data["_scroll_id"]
this.isScroll = this.scrollId!=null && this.scrollId!="";
};

DefaultQueryResultHandler.prototype.isScroll = function() {
return this.isScroll;
};

DefaultQueryResultHandler.prototype.getScrollId = function() {
return this.scrollId;
};


DefaultQueryResultHandler.prototype.getHead = function() {
return this.head
};
Expand Down
6 changes: 6 additions & 0 deletions src/_site/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ body {
}


.next-button {
float:left;
margin-top: 10px;
}


.keyboardSection {
margin-top:35px;
}
Expand Down
137 changes: 137 additions & 0 deletions src/_site/vendor/download/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//download.js v4.0, by dandavis; 2008-2015. [CCBY2] see http://danml.com/download.html for tests/usage
// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
// v4 adds AMD/UMD, commonJS, and plain browser support
// https://github.com/rndme/download

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.download = factory();
}
}(this, function () {

return function download(data, strFileName, strMimeType) {

var self = window, // this script is only for browsers anyway...
u = "application/octet-stream", // this default mime also triggers iframe downloads
m = strMimeType || u,
x = data,
D = document,
a = D.createElement("a"),
z = function(a){return String(a);},
B = (self.Blob || self.MozBlob || self.WebKitBlob || z);
B=B.call ? B.bind(self) : Blob ;
var fn = strFileName || "download",
blob,
fr;


if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
x=[x, m];
m=x[0];
x=x[1];
}




//go ahead and download dataURLs right away
if(String(x).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/)){
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
navigator.msSaveBlob(d2b(x), fn) :
saver(x) ; // everyone else can save dataURLs un-processed
}//end if dataURL passed?

blob = x instanceof B ?
x :
new B([x], {type: m}) ;


function d2b(u) {
var p= u.split(/[:;,]/),
t= p[1],
dec= p[2] == "base64" ? atob : decodeURIComponent,
bin= dec(p.pop()),
mx= bin.length,
i= 0,
uia= new Uint8Array(mx);

for(i;i<mx;++i) uia[i]= bin.charCodeAt(i);

return new B([uia], {type: t});
}

function saver(url, winMode){

if ('download' in a) { //html5 A[download]
a.href = url;
a.setAttribute("download", fn);
a.innerHTML = "downloading...";
D.body.appendChild(a);
setTimeout(function() {
a.click();
D.body.removeChild(a);
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(a.href);}, 250 );}
}, 66);
return true;
}

if(typeof safari !=="undefined" ){ // handle non-a[download] safari as best we can:
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, u);
if(!window.open(url)){ // popup blocked, offer direct download:
if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; }
}
return true;
}

//do iframe dataURL download (old ch+FF):
var f = D.createElement("iframe");
D.body.appendChild(f);

if(!winMode){ // force a mime that will download:
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, u);
}
f.src=url;
setTimeout(function(){ D.body.removeChild(f); }, 333);

}//end saver




if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
return navigator.msSaveBlob(blob, fn);
}

if(self.URL){ // simple fast and modern way using Blob and URL:
saver(self.URL.createObjectURL(blob), true);
}else{
// handle non-Blob()+non-URL browsers:
if(typeof blob === "string" || blob.constructor===z ){
try{
return saver( "data:" + m + ";base64," + self.btoa(blob) );
}catch(y){
return saver( "data:" + m + "," + encodeURIComponent(blob) );
}
}

// Blob but not URL:
fr=new FileReader();
fr.onload=function(e){
saver(this.result);
};
fr.readAsDataURL(blob);
}
return true;
}; /* end download() */
}));
2 changes: 2 additions & 0 deletions src/_site/vendor/download/download.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb94cb3

Please sign in to comment.