Search in sources :

Example 11 with JavaScriptConfig

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);
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) Test(org.junit.Test)

Example 12 with JavaScriptConfig

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);
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) JavaScriptParseSpec(org.apache.druid.data.input.impl.JavaScriptParseSpec) Test(org.junit.Test)

Example 13 with JavaScriptConfig

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();
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) Test(org.junit.Test)

Example 14 with JavaScriptConfig

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<>());
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) Test(org.junit.Test)

Example 15 with JavaScriptConfig

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);
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) Test(org.junit.Test)

Aggregations

JavaScriptConfig (org.apache.druid.js.JavaScriptConfig)17 Test (org.junit.Test)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Properties (java.util.Properties)2 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)2 JavaScriptParseSpec (org.apache.druid.data.input.impl.JavaScriptParseSpec)2 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 DoubleAnyAggregatorFactory (org.apache.druid.query.aggregation.any.DoubleAnyAggregatorFactory)1 FloatAnyAggregatorFactory (org.apache.druid.query.aggregation.any.FloatAnyAggregatorFactory)1 LongAnyAggregatorFactory (org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory)1 StringAnyAggregatorFactory (org.apache.druid.query.aggregation.any.StringAnyAggregatorFactory)1 CardinalityAggregatorFactory (org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)1 DoubleFirstAggregatorFactory (org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory)1 FloatFirstAggregatorFactory (org.apache.druid.query.aggregation.first.FloatFirstAggregatorFactory)1 LongFirstAggregatorFactory (org.apache.druid.query.aggregation.first.LongFirstAggregatorFactory)1 StringFirstAggregatorFactory (org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory)1 HyperUniquesAggregatorFactory (org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory)1 DoubleLastAggregatorFactory (org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory)1 FloatLastAggregatorFactory (org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory)1