Search in sources :

Example 1 with ParamOption

use of org.apache.zeppelin.display.Input.ParamOption in project zeppelin by apache.

the class ZeppelinContext method tuplesToParamOptions.

private ParamOption[] tuplesToParamOptions(scala.collection.Iterable<Tuple2<Object, String>> options) {
    int n = options.size();
    ParamOption[] paramOptions = new ParamOption[n];
    Iterator<Tuple2<Object, String>> it = asJavaIterable(options).iterator();
    int i = 0;
    while (it.hasNext()) {
        Tuple2<Object, String> valueAndDisplayValue = it.next();
        paramOptions[i++] = new ParamOption(valueAndDisplayValue._1(), valueAndDisplayValue._2());
    }
    return paramOptions;
}
Also used : Tuple2(scala.Tuple2) AngularObject(org.apache.zeppelin.display.AngularObject) ParamOption(org.apache.zeppelin.display.Input.ParamOption)

Example 2 with ParamOption

use of org.apache.zeppelin.display.Input.ParamOption in project zeppelin by apache.

the class InputTest method testFormExtraction.

@Test
public void testFormExtraction() {
    // input form
    String script = "${input_form=}";
    Map<String, Input> forms = Input.extractSimpleQueryParam(script);
    assertEquals(1, forms.size());
    Input form = forms.get("input_form");
    assertEquals("input_form", form.name);
    assertNull(form.displayName);
    assertEquals("", form.defaultValue);
    assertNull(form.options);
    // input form with display name & default value
    script = "${input_form(Input Form)=xxx}";
    forms = Input.extractSimpleQueryParam(script);
    form = forms.get("input_form");
    assertEquals("xxx", form.defaultValue);
    // selection form
    script = "${select_form(Selection Form)=op1,op1|op2(Option 2)|op3}";
    form = Input.extractSimpleQueryParam(script).get("select_form");
    assertEquals("select_form", form.name);
    assertEquals("op1", form.defaultValue);
    assertArrayEquals(new ParamOption[] { new ParamOption("op1", null), new ParamOption("op2", "Option 2"), new ParamOption("op3", null) }, form.options);
    // checkbox form
    script = "${checkbox:checkbox_form=op1,op1|op2|op3}";
    form = Input.extractSimpleQueryParam(script).get("checkbox_form");
    assertEquals("checkbox_form", form.name);
    assertEquals("checkbox", form.type);
    assertArrayEquals(new Object[] { "op1" }, (Object[]) form.defaultValue);
    assertArrayEquals(new ParamOption[] { new ParamOption("op1", null), new ParamOption("op2", null), new ParamOption("op3", null) }, form.options);
    // checkbox form with multiple default checks
    script = "${checkbox:checkbox_form(Checkbox Form)=op1|op3,op1(Option 1)|op2|op3}";
    form = Input.extractSimpleQueryParam(script).get("checkbox_form");
    assertEquals("checkbox_form", form.name);
    assertEquals("Checkbox Form", form.displayName);
    assertEquals("checkbox", form.type);
    assertArrayEquals(new Object[] { "op1", "op3" }, (Object[]) form.defaultValue);
    assertArrayEquals(new ParamOption[] { new ParamOption("op1", "Option 1"), new ParamOption("op2", null), new ParamOption("op3", null) }, form.options);
    // checkbox form with no default check
    script = "${checkbox:checkbox_form(Checkbox Form)=,op1(Option 1)|op2(Option 2)|op3(Option 3)}";
    form = Input.extractSimpleQueryParam(script).get("checkbox_form");
    assertEquals("checkbox_form", form.name);
    assertEquals("Checkbox Form", form.displayName);
    assertEquals("checkbox", form.type);
    assertArrayEquals(new Object[] {}, (Object[]) form.defaultValue);
    assertArrayEquals(new ParamOption[] { new ParamOption("op1", "Option 1"), new ParamOption("op2", "Option 2"), new ParamOption("op3", "Option 3") }, form.options);
}
Also used : ParamOption(org.apache.zeppelin.display.Input.ParamOption) Test(org.junit.Test)

Example 3 with ParamOption

use of org.apache.zeppelin.display.Input.ParamOption in project zeppelin by apache.

the class InterpreterLogicTest method should_extract_variable_and_choices.

@Test
public void should_extract_variable_and_choices() throws Exception {
    //Given
    AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
    when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
    when(intrContext.getGui().select(eq("name"), eq("'Paul'"), optionsCaptor.capture())).thenReturn("'Jack'");
    //When
    final String actual = helper.maybeExtractVariables("SELECT * FROM zeppelin.artists WHERE name={{name='Paul'|'Jack'|'Smith'}}", intrContext);
    //Then
    assertThat(actual).isEqualTo("SELECT * FROM zeppelin.artists WHERE name='Jack'");
    final List<ParamOption> paramOptions = asList(optionsCaptor.getValue());
    assertThat(paramOptions.get(0).getValue()).isEqualTo("'Paul'");
    assertThat(paramOptions.get(1).getValue()).isEqualTo("'Jack'");
    assertThat(paramOptions.get(2).getValue()).isEqualTo("'Smith'");
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) ParamOption(org.apache.zeppelin.display.Input.ParamOption) Test(org.junit.Test)

Aggregations

ParamOption (org.apache.zeppelin.display.Input.ParamOption)3 Test (org.junit.Test)2 AngularObject (org.apache.zeppelin.display.AngularObject)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 Tuple2 (scala.Tuple2)1