-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
715 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
.project | ||
.settings/* | ||
*.log | ||
*.png | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env bash | ||
BIN=`dirname "$0"` | ||
BASE=$BIN/../core | ||
java -Xmx4g -cp "$BASE/config:$BASE/target/classes:$BASE/target/*" \ | ||
java -Xmx4g -cp "$BASE/target/classes:$BASE/target/*" \ | ||
edu.stanford.futuredata.macrobase.cli.CliRunner "$@" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"pipeline": "CubePipeline", | ||
|
||
"inputURI": "https://raw.githubusercontent.com/stanford-futuredata/macrobase/master/core/demo/sample_cubed_quantiles.csv", | ||
"restHeader": {}, | ||
"usePost": false, | ||
"classifier": "quantile", | ||
"countColumn": "count", | ||
"meanColumn": "mean", | ||
"quantileColumns": { | ||
"min": 0.0, | ||
"p10": 0.1, | ||
"p50": 0.5, | ||
"p90": 0.9, | ||
"max": 1.0 | ||
}, | ||
"cutoff": 1.0, | ||
"includeLo": true, | ||
"includeHi": false, | ||
|
||
"attributes": ["location", "version"], | ||
"minSupport": 0.2, | ||
"minRatioMetric": 10.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
core/src/main/java/edu/stanford/futuredata/macrobase/ingest/RESTDataFrameLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package edu.stanford.futuredata.macrobase.ingest; | ||
|
||
import edu.stanford.futuredata.macrobase.datamodel.DataFrame; | ||
import edu.stanford.futuredata.macrobase.datamodel.Schema; | ||
import okhttp3.*; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVParser; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class RESTDataFrameLoader implements DataFrameLoader{ | ||
private String baseURL; | ||
private Map<String, String> headerParams; | ||
|
||
private boolean usePost = true; | ||
private String jsonBody; | ||
private Map<String, String> getParams; | ||
private Map<String, Schema.ColType> types; | ||
|
||
private OkHttpClient client; | ||
|
||
public RESTDataFrameLoader( | ||
String url, | ||
Map<String, String> headerParams | ||
) { | ||
this.baseURL = url; | ||
this.headerParams = headerParams; | ||
|
||
OkHttpClient.Builder b = new OkHttpClient.Builder(); | ||
b.hostnameVerifier((hostname, session) -> true); | ||
b.connectTimeout(20, TimeUnit.SECONDS); | ||
this.client = b.build(); | ||
} | ||
public void setUsePost(boolean flag) { | ||
this.usePost = flag; | ||
} | ||
public void setJsonBody(String jsonBody) { | ||
this.jsonBody = jsonBody; | ||
} | ||
public void setGetParams(Map<String, String> getParams) { | ||
this.getParams = getParams; | ||
} | ||
|
||
private String postRequest() throws IOException { | ||
URL url = new URL(baseURL); | ||
MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | ||
RequestBody body = RequestBody.create(JSON, jsonBody); | ||
Request.Builder requestBuilder = new Request.Builder() | ||
.url(url) | ||
.post(body); | ||
for (String headerKey: headerParams.keySet()) { | ||
requestBuilder.addHeader(headerKey, headerParams.get(headerKey)); | ||
} | ||
Request request = requestBuilder.build(); | ||
Response response = this.client.newCall(request).execute(); | ||
return response.body().string(); | ||
} | ||
|
||
private String getRequest() throws IOException { | ||
URL url = new URL(baseURL); | ||
HttpUrl.Builder httpBuilder = HttpUrl.get(url).newBuilder(); | ||
if (getParams != null) { | ||
for (String paramName : getParams.keySet()) { | ||
httpBuilder.addQueryParameter(paramName, getParams.get(paramName)); | ||
} | ||
} | ||
HttpUrl fullURL = httpBuilder.build(); | ||
|
||
Request.Builder requestBuilder = new Request.Builder() | ||
.url(fullURL) | ||
.get(); | ||
for (String headerKey: headerParams.keySet()) { | ||
requestBuilder.addHeader(headerKey, headerParams.get(headerKey)); | ||
} | ||
Request request = requestBuilder.build(); | ||
Response response = this.client.newCall(request).execute(); | ||
return response.body().string(); | ||
} | ||
|
||
|
||
@Override | ||
public DataFrameLoader setColumnTypes(Map<String, Schema.ColType> types) { | ||
this.types = types; | ||
return this; | ||
} | ||
|
||
@Override | ||
public DataFrame load() throws Exception { | ||
String response; | ||
if (usePost) { | ||
response = postRequest(); | ||
} else { | ||
response = getRequest(); | ||
} | ||
|
||
CSVParser csvParser = CSVParser.parse( | ||
response, | ||
CSVFormat.DEFAULT.withHeader() | ||
); | ||
CSVDataFrameParser dfParser = new CSVDataFrameParser(csvParser); | ||
dfParser.setColumnTypes(types); | ||
return dfParser.load(); | ||
} | ||
} |
Oops, something went wrong.