Skip to content

Instantly share code, notes, and snippets.

@brunatm
Created January 9, 2017 12:27
Show Gist options
  • Save brunatm/2c7b8b7a56c4a4a5ca96167b9bdb2786 to your computer and use it in GitHub Desktop.
Save brunatm/2c7b8b7a56c4a4a5ca96167b9bdb2786 to your computer and use it in GitHub Desktop.
import com.typesafe.config.Config;
import org.kitesdk.morphline.api.Command;
import org.kitesdk.morphline.api.MorphlineContext;
import org.kitesdk.morphline.api.Record;
import org.kitesdk.morphline.scriptengine.java.ScriptEvaluator;
import org.slf4j.Logger;
import javax.script.ScriptException;
/**
* Created by brunatm on 6.1.17.
*/
public final class TestScriptEvaluator {
public static void main(String[] args) throws ScriptException {
// this javaCodeBlock throws: Exception in thread "main" javax.script.ScriptException: Cannot compile script: byte[] bytes = (byte[]) record.getFirstValue("time");
// Object obj = org.apache.phoenix.schema.types.PLong.INSTANCE.toObject(bytes);long time = (Long)obj;
// return child.process(record); caused by java.lang.NoSuchMethodException: edu.umd.cs.findbugs.annotations.SuppressWarnings.eval(org.kitesdk.morphline.api.Record, com.typesafe.config.Config, org.kitesdk.morphline.api.Command, org.kitesdk.morphline.api.Command, org.kitesdk.morphline.api.MorphlineContext, org.slf4j.Logger)
// at org.kitesdk.morphline.scriptengine.java.ScriptEvaluator.throwScriptCompilationException(ScriptEvaluator.java:141)
// at org.kitesdk.morphline.scriptengine.java.ScriptEvaluator.<init>(ScriptEvaluator.java:108)
// at TestScriptEvaluator.main(TestScriptEvaluator.java:30)
// at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
// at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
// at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
// at java.lang.reflect.Method.invoke(Method.java:498)
// at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
String javaCodeBlock = "byte[] bytes = (byte[]) record.getFirstValue(\"time\");\n" +
"Object obj = org.apache.phoenix.schema.types.PLong.INSTANCE.toObject(bytes);" +
"long time = (Long)obj;\n" +
"return child.process(record);";
// this javaCodeBlock is ok
// String javaCodeBlock = "byte[] bytes = (byte[]) record.getFirstValue(\"time\");\n" +
// "Object obj = 1483964571000L;" +
// "long time = (Long)obj;\n" +
// "return child.process(record);";
new ScriptEvaluator<Boolean>(
"import java.util.*;",
javaCodeBlock,
Boolean.class,
new String[] {"record", "config", "parent", "child", "context", "logger"},
new Class[] {Record.class, Config.class, Command.class, Command.class, MorphlineContext.class, Logger.class},
javaCodeBlock
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment