Search in sources :

Example 6 with InterpreterContext

use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testCount.

@Theory
public void testCount(ElasticsearchInterpreter interpreter) {
    final InterpreterContext ctx = buildContext("testCount");
    InterpreterResult res = interpreter.interpret("count /unknown", ctx);
    assertEquals(Code.ERROR, res.code());
    res = interpreter.interpret("count /logs", ctx);
    assertEquals(Code.SUCCESS, res.code());
    assertEquals("50", res.message().get(0).getData());
    assertNotNull(ctx.getAngularObjectRegistry().get("count_testCount", null, null));
    assertEquals(50l, ctx.getAngularObjectRegistry().get("count_testCount", null, null).get());
    res = interpreter.interpret("count /logs { \"query\": { \"match\": { \"status\": 500 } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Theory(org.junit.experimental.theories.Theory)

Example 7 with InterpreterContext

use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testGet.

@Theory
public void testGet(ElasticsearchInterpreter interpreter) {
    final InterpreterContext ctx = buildContext("get");
    InterpreterResult res = interpreter.interpret("get /logs/http/unknown", ctx);
    assertEquals(Code.ERROR, res.code());
    res = interpreter.interpret("get /logs/http/unknown/unknown", ctx);
    assertEquals(Code.ERROR, res.code());
    res = interpreter.interpret("get /unknown/unknown/unknown", ctx);
    assertEquals(Code.ERROR, res.code());
    res = interpreter.interpret("get /logs/http/very/strange/id#1", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("get /logs/http/4", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("get /logs/_all/4", ctx);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Theory(org.junit.experimental.theories.Theory)

Example 8 with InterpreterContext

use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.

the class JDBCInterpreterTest method setUp.

@Before
public void setUp() throws Exception {
    Class.forName("org.h2.Driver");
    Connection connection = DriverManager.getConnection(getJdbcConnection());
    Statement statement = connection.createStatement();
    statement.execute("DROP TABLE IF EXISTS test_table; " + "CREATE TABLE test_table(id varchar(255), name varchar(255));");
    PreparedStatement insertStatement = connection.prepareStatement("insert into test_table(id, name) values ('a', 'a_name'),('b', 'b_name'),('c', ?);");
    insertStatement.setString(1, null);
    insertStatement.execute();
    interpreterContext = new InterpreterContext("", "1", null, "", "", new AuthenticationInfo(), null, null, null, null, null, null);
}
Also used : InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Before(org.junit.Before)

Example 9 with InterpreterContext

use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testSearch.

@Theory
public void testSearch(ElasticsearchInterpreter interpreter) {
    final InterpreterContext ctx = buildContext("search");
    InterpreterResult res = interpreter.interpret("size 10\nsearch /logs *", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("search /logs {{{hello}}}", ctx);
    assertEquals(Code.ERROR, res.code());
    res = interpreter.interpret("search /logs { \"query\": { \"match\": { \"status\": 500 } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("search /logs status:404", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("search /logs { \"fields\": [ \"date\", \"request.headers\" ], \"query\": { \"match\": { \"status\": 500 } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Theory(org.junit.experimental.theories.Theory)

Example 10 with InterpreterContext

use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testAgg.

@Theory
public void testAgg(ElasticsearchInterpreter interpreter) {
    final InterpreterContext ctx = buildContext("agg");
    // Single-value metric
    InterpreterResult res = interpreter.interpret("search /logs { \"aggs\" : { \"distinct_status_count\" : " + " { \"cardinality\" : { \"field\" : \"status\" } } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
    // Multi-value metric
    res = interpreter.interpret("search /logs { \"aggs\" : { \"content_length_stats\" : " + " { \"extended_stats\" : { \"field\" : \"content_length\" } } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
    // Single bucket
    res = interpreter.interpret("search /logs { \"aggs\" : { " + " \"200_OK\" : { \"filter\" : { \"term\": { \"status\": \"200\" } }, " + "   \"aggs\" : { \"avg_length\" : { \"avg\" : { \"field\" : \"content_length\" } } } } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
    // Multi-buckets
    res = interpreter.interpret("search /logs { \"aggs\" : { \"status_count\" : " + " { \"terms\" : { \"field\" : \"status\" } } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("search /logs { \"aggs\" : { " + " \"length\" : { \"terms\": { \"field\": \"status\" }, " + "   \"aggs\" : { \"sum_length\" : { \"sum\" : { \"field\" : \"content_length\" } }, \"sum_status\" : { \"sum\" : { \"field\" : \"status\" } } } } } }", ctx);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Theory(org.junit.experimental.theories.Theory)

Aggregations

InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)21 Properties (java.util.Properties)9 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 Before (org.junit.Before)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)6 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)5 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 GUI (org.apache.zeppelin.display.GUI)4 Theory (org.junit.experimental.theories.Theory)4 AngularObjectWatcher (org.apache.zeppelin.display.AngularObjectWatcher)3 Interpreter (org.apache.zeppelin.interpreter.Interpreter)3 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)3 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)3 AngularObject (org.apache.zeppelin.display.AngularObject)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1