diff --git a/docs/assets/themes/zeppelin/img/screenshots/interpreter_setting_with_context_parameters.png b/docs/assets/themes/zeppelin/img/screenshots/interpreter_setting_with_context_parameters.png index 815877c60f..17c83b6c6e 100644 Binary files a/docs/assets/themes/zeppelin/img/screenshots/interpreter_setting_with_context_parameters.png and b/docs/assets/themes/zeppelin/img/screenshots/interpreter_setting_with_context_parameters.png differ diff --git a/docs/manual/interpreters.md b/docs/manual/interpreters.md index aae0410045..8fea817884 100644 --- a/docs/manual/interpreters.md +++ b/docs/manual/interpreters.md @@ -42,7 +42,7 @@ Zeppelin interpreter setting is the configuration of a given interpreter on Zepp Properties are exported as environment variable when property name is consisted of upper characters, numbers and underscore ([A-Z_0-9]). Otherwise set properties as JVM property. -You may use parameters from the context of interpreter by add #{contextParameterName} in value, parameter can be of the following types: string, number, boolean. The list of available context parameters can be viewed in the class [InterpreterContext.java](https://github.com/apache/zeppelin/blob/master/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java) + parameter #{user}. +You may use parameters from the context of interpreter by add #{contextParameterName} (except fields of paragraph) in value, parameter can be of the following types: string, number, boolean. The list of available context parameters can be viewed in the class [InterpreterContext.java](https://github.com/apache/zeppelin/blob/master/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java) + parameter #{user}. If context parameter is null then replaced by empty string. diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java index bb2dd7ccec..20263ebb32 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java @@ -310,6 +310,7 @@ public abstract class Interpreter { InterpreterContext interpreterContext = InterpreterContext.get(); if (interpreterContext != null) { String markerTemplate = "#\\{%s\\}"; + List skipFields = Arrays.asList("paragraphTitle", "paragraphId", "paragraphText"); List typesToProcess = Arrays.asList(String.class, Double.class, Float.class, Short.class, Byte.class, Character.class, Boolean.class, Integer.class, Long.class); for (String key : properties.stringPropertyNames()) { @@ -317,7 +318,8 @@ public abstract class Interpreter { if (StringUtils.isNotEmpty(p)) { for (Field field : InterpreterContext.class.getDeclaredFields()) { Class clazz = field.getType(); - if (typesToProcess.contains(clazz) || clazz.isPrimitive()) { + if (!skipFields.contains(field.getName()) && (typesToProcess.contains(clazz) + || clazz.isPrimitive())) { try { Object value = FieldUtils.readField(field, interpreterContext, true); p = p.replaceAll(String.format(markerTemplate, field.getName()), diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java index 0fab9c9e32..a9ac1fc268 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java @@ -56,12 +56,14 @@ public class InterpreterTest { public void testPropertyWithReplacedContextFields() { String noteId = "testNoteId"; String paragraphTitle = "testParagraphTitle"; + String paragraphText = "testParagraphText"; + String paragraphId = "testParagraphId"; String user = "username"; InterpreterContext.set(new InterpreterContext(noteId, - null, + paragraphId, null, paragraphTitle, - null, + paragraphText, new AuthenticationInfo("testUser", "testTicket"), null, null, @@ -70,7 +72,7 @@ public class InterpreterTest { null, null)); Properties p = new Properties(); - p.put("p1", "paragraphTitle #{noteId}, #{paragraphTitle}, #{replName}, #{noteId}, #{user}," + + p.put("p1", "replName #{noteId}, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, #{replName}, #{noteId}, #{user}," + " #{authenticationInfo}"); MockInterpreterA intp = new MockInterpreterA(p); intp.setUserName(user); @@ -78,8 +80,8 @@ public class InterpreterTest { InterpreterContext.remove(); assertEquals( - String.format("paragraphTitle %s, %s, , %s, %s, #{authenticationInfo}", noteId, - paragraphTitle, noteId, user), + String.format("replName %s, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, , %s, %s, #{authenticationInfo}", noteId, + noteId, user), actual ); }