use of org.apache.druid.js.JavaScriptConfig in project druid by druid-io.
the class JavaScriptParseSpecTest method testMakeParser.
@Test
public void testMakeParser() {
final JavaScriptConfig config = JavaScriptConfig.getEnabledInstance();
JavaScriptParseSpec spec = new JavaScriptParseSpec(new TimestampSpec("abc", "iso", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Collections.singletonList("abc"))), "function(str) { var parts = str.split(\"-\"); return { one: parts[0], two: parts[1] } }", config);
final Parser<String, Object> parser = spec.makeParser();
final Map<String, Object> obj = parser.parseToMap("x-y");
Assert.assertEquals(ImmutableMap.of("one", "x", "two", "y"), obj);
}
use of org.apache.druid.js.JavaScriptConfig in project druid by druid-io.
the class ThriftInputRowParserTest method testDisableJavaScript.
@Test
public void testDisableJavaScript() {
final JavaScriptParseSpec parseSpec = new JavaScriptParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("dim1", "dim2"))), "func", new JavaScriptConfig(false));
ThriftInputRowParser parser = new ThriftInputRowParser(parseSpec, "example/book.jar", "org.apache.druid.data.input.thrift.Book");
expectedException.expect(CoreMatchers.instanceOf(IllegalStateException.class));
expectedException.expectMessage("JavaScript is disabled");
// noinspection ResultOfMethodCallIgnored (this method call will trigger the expected exception)
parser.parseBatch(ByteBuffer.allocate(1)).get(0);
}
use of org.apache.druid.js.JavaScriptConfig in project druid by druid-io.
the class StringInputRowParserTest method testDisableJavaScript.
@Test
public void testDisableJavaScript() {
final JavaScriptParseSpec parseSpec = new JavaScriptParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("dim1", "dim2"))), "func", new JavaScriptConfig(false));
final StringInputRowParser parser = new StringInputRowParser(parseSpec, "UTF-8");
expectedException.expect(CoreMatchers.instanceOf(IllegalStateException.class));
expectedException.expectMessage("JavaScript is disabled");
parser.startFileFromBeginning();
}
use of org.apache.druid.js.JavaScriptConfig in project druid by druid-io.
the class JavaScriptPostAggregatorTest method testComputeJavaScriptNotAllowed.
@Test
public void testComputeJavaScriptNotAllowed() {
JavaScriptPostAggregator aggregator = new JavaScriptPostAggregator("absPercent", Lists.newArrayList("delta", "total"), ABS_PERCENT_FUNCTION, new JavaScriptConfig(false));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("JavaScript is disabled");
aggregator.compute(new HashMap<>());
}
use of org.apache.druid.js.JavaScriptConfig in project druid by druid-io.
the class JavaScriptExtractionFnTest method testJavascriptNotAllowed.
@Test
public void testJavascriptNotAllowed() {
String function = "function(str) { return str.substring(0,3); }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, new JavaScriptConfig(false));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("JavaScript is disabled");
extractionFn.apply("hey");
Assert.assertTrue(false);
}
Aggregations