forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:0xdata/h2o
- Loading branch information
Showing
6 changed files
with
141 additions
and
43 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
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,51 +1,24 @@ | ||
package water.api; | ||
|
||
|
||
import java.io.*; | ||
|
||
import water.Boot; | ||
import water.exec.Function; | ||
import water.util.Log; | ||
import water.util.RString; | ||
|
||
import com.google.common.io.CharStreams; | ||
import com.google.common.io.Closeables; | ||
|
||
|
||
public class Console extends HTMLOnlyRequest { | ||
|
||
@Override | ||
protected String build(Response response) { | ||
RString rs = new RString(loadContent("/h2o/console.html")); | ||
@Override protected String build(Response response) { | ||
RString rs = new RString(Boot._init.loadContent("/h2o/console.html")); | ||
rs.replace("HELP", getHelp()); | ||
return rs.toString(); | ||
} | ||
|
||
private String getHelp() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("jqconsole.Write("); | ||
|
||
sb.append("'Access keys directly by name (for example `iris.hex`).\\n' +"); | ||
sb.append("'Available functions are:'+"); | ||
for(String s : Function.FUNCTIONS.keySet()) { | ||
for(String s : Function.FUNCTIONS.keySet()) | ||
sb.append("'\\n\\t").append(s).append("' +"); | ||
} | ||
sb.append("'\\n', 'jqconsole-output');"); | ||
return sb.toString(); | ||
} | ||
|
||
private String loadContent(String fromFile) { | ||
BufferedReader reader = null; | ||
StringBuilder sb = new StringBuilder(); | ||
try { | ||
InputStream is = Boot._init.getResource2(fromFile); | ||
reader = new BufferedReader(new InputStreamReader(is)); | ||
CharStreams.copy(reader, sb); | ||
} catch( IOException e ){ | ||
Log.err(e); | ||
} finally { | ||
Closeables.closeQuietly(reader); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
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,44 @@ | ||
package water.api; | ||
|
||
import water.exec.PositionedException; | ||
import water.util.Log; | ||
import water.*; | ||
import water.fvec.*; | ||
|
||
public class Exec2 extends Request2 { | ||
static final int API_WEAVER=1; // This file has auto-gen'd doc & json fields | ||
static public DocGen.FieldDoc[] DOC_FIELDS; // Initialized from Auto-Gen code. | ||
// This Request supports the HTML 'GET' command, and this is the help text for GET. | ||
static final String DOC_GET = "Executes a string."; | ||
@API(help="String to execute", required=true, filter=Default.class) | ||
String str; | ||
|
||
@API(help="Parsing error, if any") String error; | ||
@API(help="Result key" ) Key key; | ||
@API(help="Rows in result" ) long num_rows; | ||
@API(help="Columns in result" ) int num_cols; | ||
@API(help="Scalar result" ) double scalar; | ||
|
||
@API(help="Array of Column Summaries.") Inspect2.ColSummary cols[]; | ||
|
||
@Override protected Response serve() { | ||
if( str == null ) return RequestServer._http404.serve(); | ||
Exception e; | ||
try { | ||
Frame fr = water.exec.Exec2.exec(str); | ||
key = Key.make(".Last.value"); | ||
UKV.remove(key); | ||
UKV.put(key,fr); | ||
num_rows = fr.numRows(); | ||
num_cols = fr.numCols(); | ||
cols = new Inspect2.ColSummary[num_cols]; | ||
for( int i=0; i<num_cols; i++ ) | ||
cols[i] = new Inspect2.ColSummary(fr._names[i],fr.vecs()[i]); | ||
if( num_rows==1 && num_cols==1 ) scalar=fr.vecs()[0].at(0); | ||
return new Response(Response.Status.done, this, -1, -1, null); | ||
} | ||
catch( PositionedException pe ) { e=pe;} // No logging user typo's | ||
catch( Exception e2 ) { Log.err(e=e2); } | ||
return Response.error(e.getMessage()); | ||
} | ||
} |
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,79 @@ | ||
package water.exec; | ||
|
||
import water.fvec.*; | ||
import water.*; | ||
|
||
/** Execute a generic R string, in the context of an H2O Cloud | ||
* @author [email protected] | ||
*/ | ||
public class Exec2 { | ||
byte _buf[]; | ||
int _x; | ||
|
||
// Parse a string, execute it & return a Frame. | ||
// Grammer: | ||
// expr := ( expr ) | ||
// ( op_pre expr expr ... ) | ||
// key = expr | ||
// key/num | ||
// key/num op_in expr | ||
// val := key | num | ||
// key := any Key mapping to a Frame. | ||
// op_in:= + - * / % & | ...etc... | ||
// op_pre := min max ...etc... | ||
|
||
public static Frame exec( String str ) throws ParserException, EvaluationException { | ||
AST ast = new Exec2().parse(str); | ||
System.out.println(ast); | ||
return null; | ||
} | ||
private AST parse(String str) { | ||
_buf = str.getBytes(); | ||
return AST.parseExpr(this); | ||
} | ||
|
||
private void skipWS() { | ||
while( _x < _buf.length && _buf[_x] <= ' ' ) _x++; | ||
} | ||
// Skip whitespace. | ||
// If c is the next char, eat it & return true | ||
// Else return false. | ||
private boolean peek(char c) { | ||
if( _x ==_buf.length ) return false; | ||
while( _buf[_x] <= ' ' ) | ||
if( ++_x ==_buf.length ) return false; | ||
if( _buf[_x]!=c ) return false; | ||
_x++; | ||
return true; | ||
} | ||
|
||
abstract static private class AST { | ||
abstract String opStr(); | ||
static AST parseExpr(Exec2 E ) { | ||
if( E.peek('(') ) { throw H2O.unimpl(); } // op_pre or expr | ||
AST ast = ASTKey.parse(E); | ||
if( ast != null && E.peek('=') ) { throw H2O.unimpl(); } // assignment | ||
if( ast == null ) // Key parse optionally returns | ||
ast = ASTNum.parse(E); // Number parse either throws or valid returns | ||
return ASTInfix.parse(E,ast); // Infix op, or not? | ||
} | ||
} | ||
static private class ASTKey extends AST { | ||
Key _key; | ||
@Override String opStr() { return _key.toString(); } | ||
// Parse a valid H2O Frame Key, or return null; | ||
static ASTKey parse(Exec2 E) { throw H2O.unimpl(); } | ||
} | ||
static private class ASTNum extends AST { | ||
double _d; | ||
@Override String opStr() { return Double.toString(_d); } | ||
// Parse a number, or throw a parse error | ||
static ASTNum parse(Exec2 E) { throw H2O.unimpl(); } | ||
} | ||
static private class ASTInfix extends AST { | ||
@Override String opStr() { return "+"; } | ||
// Parse an infix operator, or return the original AST | ||
static ASTInfix parse(Exec2 E, AST ast) { throw H2O.unimpl(); } | ||
} | ||
|
||
} |