mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
[ZEPPELIN-1999] skip fields of paragraph
This commit is contained in:
parent
ea9c6a37fd
commit
a10dc0ea67
4 changed files with 11 additions and 7 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
|
@ -42,7 +42,7 @@ Zeppelin interpreter setting is the configuration of a given interpreter on Zepp
|
|||
<img src="../assets/themes/zeppelin/img/screenshots/interpreter_setting.png" width="500px">
|
||||
|
||||
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.
|
||||
|
||||
<img src="../assets/themes/zeppelin/img/screenshots/interpreter_setting_with_context_parameters.png" width="500px">
|
||||
|
|
|
|||
|
|
@ -310,6 +310,7 @@ public abstract class Interpreter {
|
|||
InterpreterContext interpreterContext = InterpreterContext.get();
|
||||
if (interpreterContext != null) {
|
||||
String markerTemplate = "#\\{%s\\}";
|
||||
List<String> 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()),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue