Search in sources :

Example 86 with InterpreterResult

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

the class ElasticsearchInterpreterTest method testMisc.

@Theory
public void testMisc(ElasticsearchInterpreter interpreter) {
    InterpreterResult res = interpreter.interpret(null, null);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("   \n \n ", null);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Theory(org.junit.experimental.theories.Theory)

Example 87 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult 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 88 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult 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)

Example 89 with InterpreterResult

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

the class CassandraInterpreterTest method should_interpret_simple_select.

@Test
public void should_interpret_simple_select() throws Exception {
    //Given
    //When
    final InterpreterResult actual = interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE + " LIMIT 10;", intrContext);
    //Then
    assertThat(actual).isNotNull();
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(actual.message().get(0).getData()).isEqualTo("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" + "Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t[Dance, Electro]\tPerson\n" + "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n" + "Sheryl Crow\t1962-02-11\tUSA\tnull\tFemale\t[Classic, Rock, Country, Blues, Pop, Folk]\tPerson\n" + "Doof\t1968-08-31\tUnited Kingdom\tnull\tnull\t[Unknown]\tPerson\n" + "House of Large Sizes\t1986-01-01\tUSA\t2003\tnull\t[Unknown]\tGroup\n" + "Fanfarlo\t2006-01-01\tUnited Kingdom\tnull\tnull\t[Rock, Indie, Pop, Classic]\tGroup\n" + "Jeff Beck\t1944-06-24\tUnited Kingdom\tnull\tMale\t[Rock, Pop, Classic]\tPerson\n" + "Los Paranoias\tnull\tUnknown\tnull\tnull\t[Unknown]\tnull\n" + "…And You Will Know Us by the Trail of Dead\t1994-01-01\tUSA\tnull\tnull\t[Rock, Pop, Classic]\tGroup\n");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 90 with InterpreterResult

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

the class CassandraInterpreterTest method should_fail_when_executing_a_removed_prepared_statement.

@Test
public void should_fail_when_executing_a_removed_prepared_statement() throws Exception {
    //Given
    String prepare_first = "@prepare[to_be_removed]=INSERT INTO zeppelin.users(login,deceased) VALUES(?,?)";
    interpreter.interpret(prepare_first, intrContext);
    String remove_prepared = "@remove_prepare[to_be_removed]\n" + "@bind[to_be_removed]='bind_bool'";
    //When
    final InterpreterResult actual = interpreter.interpret(remove_prepared, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.ERROR);
    assertThat(actual.message().get(0).getData()).isEqualTo("The statement 'to_be_removed' can not be bound to values. " + "Are you sure you did prepare it with @prepare[to_be_removed] ?");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Aggregations

InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)153 Test (org.junit.Test)63 Properties (java.util.Properties)17 File (java.io.File)10 IOException (java.io.IOException)9 AlluxioURI (alluxio.AlluxioURI)8 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)7 Theory (org.junit.experimental.theories.Theory)7 FileWriter (java.io.FileWriter)6 PrintStream (java.io.PrintStream)5 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 Code (org.apache.zeppelin.interpreter.InterpreterResult.Code)5 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)4 FileInStream (alluxio.client.file.FileInStream)3 JsonObject (com.google.gson.JsonObject)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3