disable javascript execution by default (#3818)

This commit is contained in:
Himanshu 2017-02-13 17:11:18 -06:00 committed by Fangjin Yang
parent 8cf7ad1e3a
commit 9dfcf0763a
49 changed files with 191 additions and 169 deletions

View File

@ -65,7 +65,7 @@ public class JavaScriptParseSpec extends ParseSpec
@Override @Override
public Parser<String, Object> makeParser() public Parser<String, Object> makeParser()
{ {
if (config.isDisabled()) { if (!config.isEnabled()) {
throw new ISE("JavaScript is disabled"); throw new ISE("JavaScript is disabled");
} }

View File

@ -19,31 +19,31 @@
package io.druid.js; package io.druid.js;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
public class JavaScriptConfig public class JavaScriptConfig
{ {
public static final int DEFAULT_OPTIMIZATION_LEVEL = 9; public static final int DEFAULT_OPTIMIZATION_LEVEL = 9;
private static final JavaScriptConfig DEFAULT = new JavaScriptConfig(false); private static final JavaScriptConfig ENABLED_INSTANCE = new JavaScriptConfig(true);
@JsonProperty @JsonProperty
private boolean disabled = false; private boolean enabled = false;
public JavaScriptConfig() @JsonCreator
public JavaScriptConfig(
@JsonProperty("enabled") Boolean enabled
)
{ {
if (enabled != null) {
this.enabled = enabled.booleanValue();
}
} }
public JavaScriptConfig(boolean disabled) public boolean isEnabled()
{ {
this.disabled = disabled; return enabled;
}
public boolean isDisabled()
{
return disabled;
} }
@Override @Override
@ -55,26 +55,29 @@ public class JavaScriptConfig
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
JavaScriptConfig config = (JavaScriptConfig) o;
return disabled == config.disabled; JavaScriptConfig that = (JavaScriptConfig) o;
return enabled == that.enabled;
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hash(disabled); return (enabled ? 1 : 0);
} }
@Override @Override
public String toString() public String toString()
{ {
return "JavaScriptConfig{" + return "JavaScriptConfig{" +
"disabled=" + disabled + "enabled=" + enabled +
'}'; '}';
} }
public static JavaScriptConfig getDefault() public static JavaScriptConfig getEnabledInstance()
{ {
return DEFAULT; return ENABLED_INSTANCE;
} }
} }

View File

@ -50,14 +50,14 @@ public class JavaScriptParseSpecTest
jsonMapper.setInjectableValues( jsonMapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
); );
JavaScriptParseSpec spec = new JavaScriptParseSpec( JavaScriptParseSpec spec = new JavaScriptParseSpec(
new TimestampSpec("abc", "iso", null), new TimestampSpec("abc", "iso", null),
new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null),
"abc", "abc",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
final JavaScriptParseSpec serde = jsonMapper.readValue( final JavaScriptParseSpec serde = jsonMapper.readValue(
jsonMapper.writeValueAsString(spec), jsonMapper.writeValueAsString(spec),
@ -73,7 +73,7 @@ public class JavaScriptParseSpecTest
@Test @Test
public void testMakeParser() public void testMakeParser()
{ {
final JavaScriptConfig config = JavaScriptConfig.getDefault(); final JavaScriptConfig config = JavaScriptConfig.getEnabledInstance();
JavaScriptParseSpec spec = new JavaScriptParseSpec( JavaScriptParseSpec spec = new JavaScriptParseSpec(
new TimestampSpec("abc", "iso", null), new TimestampSpec("abc", "iso", null),
new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null),
@ -89,7 +89,7 @@ public class JavaScriptParseSpecTest
@Test @Test
public void testMakeParserNotAllowed() public void testMakeParserNotAllowed()
{ {
final JavaScriptConfig config = new JavaScriptConfig(true); final JavaScriptConfig config = new JavaScriptConfig(false);
JavaScriptParseSpec spec = new JavaScriptParseSpec( JavaScriptParseSpec spec = new JavaScriptParseSpec(
new TimestampSpec("abc", "iso", null), new TimestampSpec("abc", "iso", null),
new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("abc")), null, null),

View File

@ -25,13 +25,39 @@ import org.junit.Test;
public class JavaScriptConfigTest public class JavaScriptConfigTest
{ {
private static ObjectMapper mapper = new ObjectMapper();
@Test @Test
public void testSerde() throws Exception public void testSerde() throws Exception
{ {
final JavaScriptConfig config = new JavaScriptConfig(true); String json = "{\"enabled\":true}";
final ObjectMapper mapper = new ObjectMapper();
final JavaScriptConfig config2 = mapper.readValue(mapper.writeValueAsBytes(config), JavaScriptConfig.class); JavaScriptConfig config = mapper.readValue(
Assert.assertTrue(config2.isDisabled()); mapper.writeValueAsString(
Assert.assertEquals(config, config2); mapper.readValue(
json,
JavaScriptConfig.class
)
), JavaScriptConfig.class
);
Assert.assertTrue(config.isEnabled());
}
@Test
public void testSerdeWithDefaults() throws Exception
{
String json = "{}";
JavaScriptConfig config = mapper.readValue(
mapper.writeValueAsString(
mapper.readValue(
json,
JavaScriptConfig.class
)
), JavaScriptConfig.class
);
Assert.assertFalse(config.isEnabled());
} }
} }

View File

@ -126,7 +126,7 @@ public class FilterPartitionBenchmark
private BenchmarkSchemaInfo schemaInfo; private BenchmarkSchemaInfo schemaInfo;
private static String JS_FN = "function(str) { return 'super-' + str; }"; private static String JS_FN = "function(str) { return 'super-' + str; }";
private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getDefault()); private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getEnabledInstance());
static { static {
JSON_MAPPER = new DefaultObjectMapper(); JSON_MAPPER = new DefaultObjectMapper();

View File

@ -126,7 +126,7 @@ public class FilteredAggregatorBenchmark
private TimeseriesQuery query; private TimeseriesQuery query;
private static String JS_FN = "function(str) { return 'super-' + str; }"; private static String JS_FN = "function(str) { return 'super-' + str; }";
private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getDefault()); private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getEnabledInstance());
static { static {
JSON_MAPPER = new DefaultObjectMapper(); JSON_MAPPER = new DefaultObjectMapper();
@ -167,7 +167,7 @@ public class FilteredAggregatorBenchmark
filter = new OrDimFilter( filter = new OrDimFilter(
Arrays.asList( Arrays.asList(
new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC),
new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getEnabledInstance()),
new RegexDimFilter("dimSequential", "X", null), new RegexDimFilter("dimSequential", "X", null),
new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null),
new InDimFilter("dimSequential", Arrays.asList("X"), null) new InDimFilter("dimSequential", Arrays.asList("X"), null)

View File

@ -171,7 +171,7 @@ public class IncrementalIndexReadBenchmark
DimFilter filter = new OrDimFilter( DimFilter filter = new OrDimFilter(
Arrays.asList( Arrays.asList(
new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC),
new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getEnabledInstance()),
new RegexDimFilter("dimSequential", "X", null), new RegexDimFilter("dimSequential", "X", null),
new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null),
new InDimFilter("dimSequential", Arrays.asList("X"), null) new InDimFilter("dimSequential", Arrays.asList("X"), null)

View File

@ -384,9 +384,8 @@ the following properties.
|Property|Description|Default| |Property|Description|Default|
|--------|-----------|-------| |--------|-----------|-------|
|`druid.javascript.disabled`|Set to "true" to disable JavaScript functionality. This affects the JavaScript parser, filter, extractionFn, aggregator, post-aggregator, router strategy, and worker selection strategy.|false| |`druid.javascript.enabled`|Set to "true" to enable JavaScript functionality. This affects the JavaScript parser, filter, extractionFn, aggregator, post-aggregator, router strategy, and worker selection strategy.|false|
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>

View File

@ -257,8 +257,7 @@ Example: a function that sends batch_index_task to workers 10.0.0.1 and 10.0.0.2
``` ```
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
#### Autoscaler #### Autoscaler

View File

@ -22,6 +22,14 @@ without needing to write and deploy Druid extensions.
Druid uses the Mozilla Rhino engine at optimization level 9 to compile and execute JavaScript. Druid uses the Mozilla Rhino engine at optimization level 9 to compile and execute JavaScript.
## Security
Druid does not execute JavaScript functions in a sandbox, so they have full access to the machine. So Javascript
functions allow users to execute arbutrary code inside druid process. So, by default, Javascript is disabled.
However, on dev/staging environments or secured production environments you can enable those by setting
the [configuration property](../configuration/index.html)
`druid.javascript.enabled = true`.
## Global variables ## Global variables
Avoid using global variables. Druid may share the global scope between multiple threads, which can lead to Avoid using global variables. Druid may share the global scope between multiple threads, which can lead to
@ -36,13 +44,6 @@ You may need to pay special attention to garbage collection when making heavy us
garbage collection of the compiled classes themselves. Be sure to use a garbage collector configuration that supports garbage collection of the compiled classes themselves. Be sure to use a garbage collector configuration that supports
timely collection of unused classes (this is generally easier on JDK8 with the Metaspace than it is on JDK7). timely collection of unused classes (this is generally easier on JDK8 with the Metaspace than it is on JDK7).
## Security
Druid does not execute JavaScript functions in a sandbox, so they have full access to the machine. If you are running
a cluster where users that can submit queries should not be allowed to execute arbitrary code, we recommend disabling
JavaScript functionality by setting the [configuration property](../configuration/index.html)
`druid.javascript.disabled = true`.
## JavaScript vs. Native Extensions ## JavaScript vs. Native Extensions
Generally we recommend using JavaScript when security is not an issue, and when speed of development is more important Generally we recommend using JavaScript when security is not an issue, and when speed of development is more important

View File

@ -117,8 +117,7 @@ Allows defining arbitrary routing rules using a JavaScript function. The functio
``` ```
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
HTTP Endpoints HTTP Endpoints

View File

@ -147,8 +147,7 @@ Note with the JavaScript parser that data must be fully parsed and returned as a
This means any flattening or parsing multi-dimensional values must be done here. This means any flattening or parsing multi-dimensional values must be done here.
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
### Multi-value dimensions ### Multi-value dimensions

View File

@ -162,8 +162,7 @@ JavaScript functions are expected to return floating-point values.
``` ```
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
## Approximate Aggregations ## Approximate Aggregations

View File

@ -308,8 +308,7 @@ Example for the `__time` dimension:
``` ```
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
### Lookup extraction function ### Lookup extraction function

View File

@ -89,8 +89,7 @@ The following matches any dimension values for the dimension `name` between `'ba
The JavaScript filter supports the use of extraction functions, see [Filtering with Extraction Functions](#filtering-with-extraction-functions) for details. The JavaScript filter supports the use of extraction functions, see [Filtering with Extraction Functions](#filtering-with-extraction-functions) for details.
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
### Extraction filter ### Extraction filter

View File

@ -99,8 +99,7 @@ Example JavaScript aggregator:
``` ```
<div class="note info"> <div class="note info">
Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines JavaScript-based functionality is disabled by default. Please refer to the Druid <a href="../development/javascript.html">JavaScript programming guide</a> for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
about using Druid's JavaScript functionality.
</div> </div>
### HyperUnique Cardinality post-aggregator ### HyperUnique Cardinality post-aggregator

View File

@ -57,7 +57,7 @@ public class JavaScriptWorkerSelectStrategy implements WorkerSelectStrategy
{ {
Preconditions.checkNotNull(fn, "function must not be null"); Preconditions.checkNotNull(fn, "function must not be null");
if (config.isDisabled()) { if (!config.isEnabled()) {
throw new ISE("JavaScript is disabled"); throw new ISE("JavaScript is disabled");
} }

View File

@ -69,7 +69,7 @@ public class JavaScriptWorkerSelectStrategyTest
+ "}\n" + "}\n"
+ "return null;\n" + "return null;\n"
+ "}", + "}",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
@Test @Test
@ -79,7 +79,7 @@ public class JavaScriptWorkerSelectStrategyTest
mapper.setInjectableValues( mapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
); );
@ -99,7 +99,7 @@ public class JavaScriptWorkerSelectStrategyTest
mapper.setInjectableValues( mapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
new JavaScriptConfig(true) new JavaScriptConfig(false)
) )
); );

View File

@ -85,10 +85,10 @@ public class JavaScriptAggregatorFactory extends AggregatorFactory
this.fnCombine = fnCombine; this.fnCombine = fnCombine;
this.config = config; this.config = config;
if (config.isDisabled()) { if (config.isEnabled()) {
this.compiledScript = null;
} else {
this.compiledScript = compileScript(fnAggregate, fnReset, fnCombine); this.compiledScript = compileScript(fnAggregate, fnReset, fnCombine);
} else {
this.compiledScript = null;
} }
} }

View File

@ -97,7 +97,7 @@ public class JavaScriptPostAggregator implements PostAggregator
Preconditions.checkNotNull(name, "Must have a valid, non-null post-aggregator name"); Preconditions.checkNotNull(name, "Must have a valid, non-null post-aggregator name");
Preconditions.checkNotNull(fieldNames, "Must have a valid, non-null fieldNames"); Preconditions.checkNotNull(fieldNames, "Must have a valid, non-null fieldNames");
Preconditions.checkNotNull(function, "Must have a valid, non-null function"); Preconditions.checkNotNull(function, "Must have a valid, non-null function");
Preconditions.checkState(!config.isDisabled(), "JavaScript is disabled"); Preconditions.checkState(config.isEnabled(), "JavaScript is disabled.");
this.name = name; this.name = name;
this.fieldNames = fieldNames; this.fieldNames = fieldNames;

View File

@ -80,10 +80,10 @@ public class JavaScriptExtractionFn implements ExtractionFn
this.function = function; this.function = function;
this.injective = injective; this.injective = injective;
if (config.isDisabled()) { if (config.isEnabled()) {
this.fn = null;
} else {
this.fn = compile(function); this.fn = compile(function);
} else {
this.fn = null;
} }
} }

View File

@ -60,10 +60,10 @@ public class JavaScriptDimFilter implements DimFilter
this.extractionFn = extractionFn; this.extractionFn = extractionFn;
this.config = config; this.config = config;
if (config.isDisabled()) { if (config.isEnabled()) {
this.predicateFactory = null;
} else {
this.predicateFactory = new JavaScriptPredicateFactory(function, extractionFn); this.predicateFactory = new JavaScriptPredicateFactory(function, extractionFn);
} else {
this.predicateFactory = null;
} }
} }
@ -111,7 +111,7 @@ public class JavaScriptDimFilter implements DimFilter
@Override @Override
public Filter toFilter() public Filter toFilter()
{ {
if (config.isDisabled()) { if (!config.isEnabled()) {
throw new ISE("JavaScript is disabled"); throw new ISE("JavaScript is disabled");
} }

View File

@ -139,7 +139,7 @@ public class QueryRunnerTestHelper
"function aggregate(current, a, b) { if ((Array.isArray(a) && a.indexOf('a') > -1) || a === 'a') { return current + b; } else { return current; } }", "function aggregate(current, a, b) { if ((Array.isArray(a) && a.indexOf('a') > -1) || a === 'a') { return current + b; } else { return current; } }",
JS_RESET_0, JS_RESET_0,
JS_COMBINE_A_PLUS_B, JS_COMBINE_A_PLUS_B,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
public static final JavaScriptAggregatorFactory jsCountIfTimeGreaterThan = new JavaScriptAggregatorFactory( public static final JavaScriptAggregatorFactory jsCountIfTimeGreaterThan = new JavaScriptAggregatorFactory(
"ntimestamps", "ntimestamps",
@ -149,7 +149,7 @@ public class QueryRunnerTestHelper
") { return current + 1; } else { return current; } }", ") { return current + 1; } else { return current; } }",
JS_RESET_0, JS_RESET_0,
JS_COMBINE_A_PLUS_B, JS_COMBINE_A_PLUS_B,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
public static final JavaScriptAggregatorFactory jsPlacementishCount = new JavaScriptAggregatorFactory( public static final JavaScriptAggregatorFactory jsPlacementishCount = new JavaScriptAggregatorFactory(
"pishcount", "pishcount",
@ -157,7 +157,7 @@ public class QueryRunnerTestHelper
"function aggregate(current, a) { if (Array.isArray(a)) { return current + a.length; } else if (typeof a === 'string') { return current + 1; } else { return current; } }", "function aggregate(current, a) { if (Array.isArray(a)) { return current + a.length; } else if (typeof a === 'string') { return current + 1; } else { return current; } }",
JS_RESET_0, JS_RESET_0,
JS_COMBINE_A_PLUS_B, JS_COMBINE_A_PLUS_B,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
public static final HyperUniquesAggregatorFactory qualityUniques = new HyperUniquesAggregatorFactory( public static final HyperUniquesAggregatorFactory qualityUniques = new HyperUniquesAggregatorFactory(
"uniques", "uniques",

View File

@ -307,7 +307,7 @@ public class FilteredAggregatorTest
String jsFn = "function(x) { return(x === 'a') }"; String jsFn = "function(x) { return(x === 'a') }";
factory = new FilteredAggregatorFactory( factory = new FilteredAggregatorFactory(
new DoubleSumAggregatorFactory("billy", "value"), new DoubleSumAggregatorFactory("billy", "value"),
new JavaScriptDimFilter("dim", jsFn, null, JavaScriptConfig.getDefault()) new JavaScriptDimFilter("dim", jsFn, null, JavaScriptConfig.getEnabledInstance())
); );
selector = new TestFloatColumnSelector(values); selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector); validateFilteredAggs(factory, values, selector);
@ -321,7 +321,7 @@ public class FilteredAggregatorTest
FilteredAggregatorFactory factory; FilteredAggregatorFactory factory;
String extractionJsFn = "function(str) { return str + 'AARDVARK'; }"; String extractionJsFn = "function(str) { return str + 'AARDVARK'; }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
factory = new FilteredAggregatorFactory( factory = new FilteredAggregatorFactory(
new DoubleSumAggregatorFactory("billy", "value"), new DoubleSumAggregatorFactory("billy", "value"),
@ -363,7 +363,7 @@ public class FilteredAggregatorTest
String jsFn = "function(x) { return(x === 'aAARDVARK') }"; String jsFn = "function(x) { return(x === 'aAARDVARK') }";
factory = new FilteredAggregatorFactory( factory = new FilteredAggregatorFactory(
new DoubleSumAggregatorFactory("billy", "value"), new DoubleSumAggregatorFactory("billy", "value"),
new JavaScriptDimFilter("dim", jsFn, extractionFn, JavaScriptConfig.getDefault()) new JavaScriptDimFilter("dim", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance())
); );
selector = new TestFloatColumnSelector(values); selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector); validateFilteredAggs(factory, values, selector);

View File

@ -276,7 +276,7 @@ public class JavaScriptAggregatorTest
scriptDoubleSum.get("fnAggregate"), scriptDoubleSum.get("fnAggregate"),
scriptDoubleSum.get("fnReset"), scriptDoubleSum.get("fnReset"),
scriptDoubleSum.get("fnCombine"), scriptDoubleSum.get("fnCombine"),
new JavaScriptConfig(true) new JavaScriptConfig(false)
); );
expectedException.expect(IllegalStateException.class); expectedException.expect(IllegalStateException.class);
@ -294,7 +294,7 @@ public class JavaScriptAggregatorTest
scriptDoubleSum.get("fnAggregate"), scriptDoubleSum.get("fnAggregate"),
scriptDoubleSum.get("fnReset"), scriptDoubleSum.get("fnReset"),
scriptDoubleSum.get("fnCombine"), scriptDoubleSum.get("fnCombine"),
new JavaScriptConfig(true) new JavaScriptConfig(false)
); );
expectedException.expect(IllegalStateException.class); expectedException.expect(IllegalStateException.class);

View File

@ -340,7 +340,7 @@ public class CardinalityAggregatorTest
String superJsFn = "function(str) { return 'super-' + str; }"; String superJsFn = "function(str) { return 'super-' + str; }";
ExtractionFn superFn = new JavaScriptExtractionFn(superJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn superFn = new JavaScriptExtractionFn(superJsFn, false, JavaScriptConfig.getEnabledInstance());
dim1WithExtraction = new TestDimensionSelector(values1, superFn); dim1WithExtraction = new TestDimensionSelector(values1, superFn);
dim2WithExtraction = new TestDimensionSelector(values2, superFn); dim2WithExtraction = new TestDimensionSelector(values2, superFn);
selectorListWithExtraction = Lists.newArrayList( selectorListWithExtraction = Lists.newArrayList(
@ -361,7 +361,7 @@ public class CardinalityAggregatorTest
); );
String helloJsFn = "function(str) { return 'hello' }"; String helloJsFn = "function(str) { return 'hello' }";
ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
dim1ConstantVal = new TestDimensionSelector(values1, helloFn); dim1ConstantVal = new TestDimensionSelector(values1, helloFn);
dim2ConstantVal = new TestDimensionSelector(values2, helloFn); dim2ConstantVal = new TestDimensionSelector(values2, helloFn);
selectorListConstantVal = Lists.newArrayList( selectorListConstantVal = Lists.newArrayList(

View File

@ -49,7 +49,7 @@ public class JavaScriptPostAggregatorTest
"absPercent", "absPercent",
Lists.newArrayList("delta", "total"), Lists.newArrayList("delta", "total"),
absPercentFunction, absPercentFunction,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
Assert.assertEquals(10.0, javaScriptPostAggregator.compute(metricValues)); Assert.assertEquals(10.0, javaScriptPostAggregator.compute(metricValues));
@ -65,7 +65,7 @@ public class JavaScriptPostAggregatorTest
"absPercent", "absPercent",
Lists.newArrayList("delta", "total"), Lists.newArrayList("delta", "total"),
absPercentFunction, absPercentFunction,
new JavaScriptConfig(true) new JavaScriptConfig(false)
); );
} }
} }

View File

@ -50,7 +50,7 @@ public class CascadeExtractionFnTest
private final JavaScriptExtractionFn javascriptExtractionFn = new JavaScriptExtractionFn( private final JavaScriptExtractionFn javascriptExtractionFn = new JavaScriptExtractionFn(
function, function,
true, true,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
private final SubstringDimExtractionFn substringDimExtractionFn = new SubstringDimExtractionFn(0, 7); private final SubstringDimExtractionFn substringDimExtractionFn = new SubstringDimExtractionFn(0, 7);
private final String regexDimExtractionFnJson = "{ \"type\" : \"regex\", \"expr\" : \"/([^/]+)/\" , " + private final String regexDimExtractionFnJson = "{ \"type\" : \"regex\", \"expr\" : \"/([^/]+)/\" , " +
@ -172,7 +172,7 @@ public class CascadeExtractionFnTest
objectMapper.setInjectableValues( objectMapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
); );
final String json = "{\"type\" : \"cascade\", \"extractionFns\": [" final String json = "{\"type\" : \"cascade\", \"extractionFns\": ["

View File

@ -53,7 +53,7 @@ public class JavaScriptExtractionFnTest
public void testJavascriptSubstring() public void testJavascriptSubstring()
{ {
String function = "function(str) { return str.substring(0,3); }"; String function = "function(str) { return str.substring(0,3); }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getEnabledInstance());
for (String str : testStrings) { for (String str : testStrings) {
String res = extractionFn.apply(str); String res = extractionFn.apply(str);
@ -65,7 +65,7 @@ public class JavaScriptExtractionFnTest
public void testJavascriptNotAllowed() public void testJavascriptNotAllowed()
{ {
String function = "function(str) { return str.substring(0,3); }"; String function = "function(str) { return str.substring(0,3); }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, new JavaScriptConfig(true)); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, new JavaScriptConfig(false));
expectedException.expect(IllegalStateException.class); expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("JavaScript is disabled"); expectedException.expectMessage("JavaScript is disabled");
@ -78,28 +78,28 @@ public class JavaScriptExtractionFnTest
{ {
String utcHour = "function(t) {\nreturn 'Second ' + Math.floor((t % 60000) / 1000);\n}"; String utcHour = "function(t) {\nreturn 'Second ' + Math.floor((t % 60000) / 1000);\n}";
final long millis = new DateTime("2015-01-02T13:00:59.999Z").getMillis(); final long millis = new DateTime("2015-01-02T13:00:59.999Z").getMillis();
Assert.assertEquals("Second 59" , new JavaScriptExtractionFn(utcHour, false, JavaScriptConfig.getDefault()).apply(millis)); Assert.assertEquals("Second 59" , new JavaScriptExtractionFn(utcHour, false, JavaScriptConfig.getEnabledInstance()).apply(millis));
} }
@Test @Test
public void testLongs() throws Exception public void testLongs() throws Exception
{ {
String typeOf = "function(x) {\nreturn typeof x\n}"; String typeOf = "function(x) {\nreturn typeof x\n}";
Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false, JavaScriptConfig.getDefault()).apply(1234L)); Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false, JavaScriptConfig.getEnabledInstance()).apply(1234L));
} }
@Test @Test
public void testFloats() throws Exception public void testFloats() throws Exception
{ {
String typeOf = "function(x) {\nreturn typeof x\n}"; String typeOf = "function(x) {\nreturn typeof x\n}";
Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false, JavaScriptConfig.getDefault()).apply(1234.0)); Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false, JavaScriptConfig.getEnabledInstance()).apply(1234.0));
} }
@Test @Test
public void testCastingAndNull() public void testCastingAndNull()
{ {
String function = "function(x) {\n x = Number(x);\n if(isNaN(x)) return null;\n return Math.floor(x / 5) * 5;\n}"; String function = "function(x) {\n x = Number(x);\n if(isNaN(x)) return null;\n return Math.floor(x / 5) * 5;\n}";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getEnabledInstance());
Iterator<String> it = Iterators.forArray("0", "5", "5", "10", null); Iterator<String> it = Iterators.forArray("0", "5", "5", "10", null);
@ -114,7 +114,7 @@ public class JavaScriptExtractionFnTest
public void testJavascriptRegex() public void testJavascriptRegex()
{ {
String function = "function(str) { return str.replace(/[aeiou]/g, ''); }"; String function = "function(str) { return str.replace(/[aeiou]/g, ''); }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getEnabledInstance());
Iterator it = Iterators.forArray("Qt", "Clgry", "Tky", "Stckhlm", "Vncvr", "Prtr", "Wllngtn", "Ontr"); Iterator it = Iterators.forArray("Qt", "Clgry", "Tky", "Stckhlm", "Vncvr", "Prtr", "Wllngtn", "Ontr");
for (String str : testStrings) { for (String str : testStrings) {
@ -127,7 +127,7 @@ public class JavaScriptExtractionFnTest
public void testJavascriptIsNull() public void testJavascriptIsNull()
{ {
String function = "function(x) { if (x == null) { return 'yes'; } else { return 'no' } }"; String function = "function(x) { if (x == null) { return 'yes'; } else { return 'no' } }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getEnabledInstance());
Assert.assertEquals("yes", extractionFn.apply((String) null)); Assert.assertEquals("yes", extractionFn.apply((String) null));
Assert.assertEquals("yes", extractionFn.apply((Object) null)); Assert.assertEquals("yes", extractionFn.apply((Object) null));
@ -332,7 +332,7 @@ public class JavaScriptExtractionFnTest
+ "" + ""
+ "}"; + "}";
ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(function, false, JavaScriptConfig.getEnabledInstance());
Iterator<String> inputs = Iterators.forArray("introducing", "exploratory", "analytics", "on", "large", "datasets"); Iterator<String> inputs = Iterators.forArray("introducing", "exploratory", "analytics", "on", "large", "datasets");
Iterator<String> it = Iterators.forArray("introduc", "exploratori", "analyt", "on", "larg", "dataset"); Iterator<String> it = Iterators.forArray("introduc", "exploratori", "analyt", "on", "larg", "dataset");
@ -350,7 +350,7 @@ public class JavaScriptExtractionFnTest
objectMapper.setInjectableValues( objectMapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
); );
@ -372,7 +372,7 @@ public class JavaScriptExtractionFnTest
@Test @Test
public void testInjective() public void testInjective()
{ {
Assert.assertEquals(ExtractionFn.ExtractionType.MANY_TO_ONE, new JavaScriptExtractionFn("function(str) { return str; }", false, JavaScriptConfig.getDefault()).getExtractionType()); Assert.assertEquals(ExtractionFn.ExtractionType.MANY_TO_ONE, new JavaScriptExtractionFn("function(str) { return str; }", false, JavaScriptConfig.getEnabledInstance()).getExtractionType());
Assert.assertEquals(ExtractionFn.ExtractionType.ONE_TO_ONE, new JavaScriptExtractionFn("function(str) { return str; }", true, JavaScriptConfig.getDefault()).getExtractionType()); Assert.assertEquals(ExtractionFn.ExtractionType.ONE_TO_ONE, new JavaScriptExtractionFn("function(str) { return str; }", true, JavaScriptConfig.getEnabledInstance()).getExtractionType());
} }
} }

View File

@ -60,7 +60,7 @@ public class GetDimensionRangeSetTest
); );
private final DimFilter other1 = new RegexDimFilter("someDim", "pattern", null); private final DimFilter other1 = new RegexDimFilter("someDim", "pattern", null);
private final DimFilter other2 = new JavaScriptDimFilter("someOtherDim", "function(x) { return x }", null, private final DimFilter other2 = new JavaScriptDimFilter("someOtherDim", "function(x) { return x }", null,
JavaScriptConfig.getDefault()); JavaScriptConfig.getEnabledInstance());
private final DimFilter other3 = new SearchQueryDimFilter("dim", new ContainsSearchQuerySpec("a", true), null); private final DimFilter other3 = new SearchQueryDimFilter("dim", new ContainsSearchQuerySpec("a", true), null);
private final DimFilter interval1 = new IntervalDimFilter( private final DimFilter interval1 = new IntervalDimFilter(

View File

@ -41,27 +41,27 @@ public class JavaScriptDimFilterTest
@Test @Test
public void testGetCacheKey() public void testGetCacheKey()
{ {
JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getEnabledInstance());
Assert.assertFalse(Arrays.equals(javaScriptDimFilter.getCacheKey(), javaScriptDimFilter2.getCacheKey())); Assert.assertFalse(Arrays.equals(javaScriptDimFilter.getCacheKey(), javaScriptDimFilter2.getCacheKey()));
RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null); RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getEnabledInstance());
Assert.assertFalse(Arrays.equals(javaScriptDimFilter.getCacheKey(), javaScriptDimFilter3.getCacheKey())); Assert.assertFalse(Arrays.equals(javaScriptDimFilter.getCacheKey(), javaScriptDimFilter3.getCacheKey()));
} }
@Test @Test
public void testEquals() public void testEquals()
{ {
JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getEnabledInstance());
Assert.assertNotEquals(javaScriptDimFilter, javaScriptDimFilter2); Assert.assertNotEquals(javaScriptDimFilter, javaScriptDimFilter2);
Assert.assertEquals(javaScriptDimFilter2, javaScriptDimFilter3); Assert.assertEquals(javaScriptDimFilter2, javaScriptDimFilter3);
RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null); RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
JavaScriptDimFilter javaScriptDimFilter4 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter4 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter5 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter5 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getEnabledInstance());
Assert.assertNotEquals(javaScriptDimFilter, javaScriptDimFilter3); Assert.assertNotEquals(javaScriptDimFilter, javaScriptDimFilter3);
Assert.assertEquals(javaScriptDimFilter4, javaScriptDimFilter5); Assert.assertEquals(javaScriptDimFilter4, javaScriptDimFilter5);
} }
@ -69,15 +69,15 @@ public class JavaScriptDimFilterTest
@Test @Test
public void testHashcode() public void testHashcode()
{ {
JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter2 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter3 = new JavaScriptDimFilter("di", FN2, null, JavaScriptConfig.getEnabledInstance());
Assert.assertNotEquals(javaScriptDimFilter.hashCode(), javaScriptDimFilter2.hashCode()); Assert.assertNotEquals(javaScriptDimFilter.hashCode(), javaScriptDimFilter2.hashCode());
Assert.assertEquals(javaScriptDimFilter2.hashCode(), javaScriptDimFilter3.hashCode()); Assert.assertEquals(javaScriptDimFilter2.hashCode(), javaScriptDimFilter3.hashCode());
RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null); RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
JavaScriptDimFilter javaScriptDimFilter4 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter4 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getEnabledInstance());
JavaScriptDimFilter javaScriptDimFilter5 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getDefault()); JavaScriptDimFilter javaScriptDimFilter5 = new JavaScriptDimFilter("dim", FN1, regexFn, JavaScriptConfig.getEnabledInstance());
Assert.assertNotEquals(javaScriptDimFilter.hashCode(), javaScriptDimFilter3.hashCode()); Assert.assertNotEquals(javaScriptDimFilter.hashCode(), javaScriptDimFilter3.hashCode());
Assert.assertEquals(javaScriptDimFilter4.hashCode(), javaScriptDimFilter5.hashCode()); Assert.assertEquals(javaScriptDimFilter4.hashCode(), javaScriptDimFilter5.hashCode());
} }
@ -89,7 +89,7 @@ public class JavaScriptDimFilterTest
"dim", "dim",
"function(x) { return true; }", "function(x) { return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
final Filter filter = javaScriptDimFilter.toFilter(); final Filter filter = javaScriptDimFilter.toFilter();
Assert.assertThat(filter, CoreMatchers.instanceOf(JavaScriptFilter.class)); Assert.assertThat(filter, CoreMatchers.instanceOf(JavaScriptFilter.class));
@ -98,7 +98,7 @@ public class JavaScriptDimFilterTest
@Test @Test
public void testToFilterNotAllowed() public void testToFilterNotAllowed()
{ {
JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, new JavaScriptConfig(true)); JavaScriptDimFilter javaScriptDimFilter = new JavaScriptDimFilter("dim", FN1, null, new JavaScriptConfig(false));
expectedException.expect(IllegalStateException.class); expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("JavaScript is disabled"); expectedException.expectMessage("JavaScript is disabled");

View File

@ -3457,10 +3457,10 @@ public class GroupByQueryRunnerTest
public void testDimFilterHavingSpecWithExtractionFns() public void testDimFilterHavingSpecWithExtractionFns()
{ {
String extractionJsFn = "function(str) { return 'super-' + str; }"; String extractionJsFn = "function(str) { return 'super-' + str; }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
String extractionJsFn2 = "function(num) { return num + 10; }"; String extractionJsFn2 = "function(num) { return num + 10; }";
ExtractionFn extractionFn2 = new JavaScriptExtractionFn(extractionJsFn2, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn2 = new JavaScriptExtractionFn(extractionJsFn2, false, JavaScriptConfig.getEnabledInstance());
List<Row> expectedResults = Arrays.asList( List<Row> expectedResults = Arrays.asList(
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "business", "rows", 2L, "idx", 217L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "business", "rows", 2L, "idx", 217L),
@ -3793,7 +3793,7 @@ public class GroupByQueryRunnerTest
"quality", "quality",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -3858,7 +3858,7 @@ public class GroupByQueryRunnerTest
"quality", "quality",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -3932,7 +3932,7 @@ public class GroupByQueryRunnerTest
"quality", "quality",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -4334,7 +4334,7 @@ public class GroupByQueryRunnerTest
"quality", "quality",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -4600,7 +4600,7 @@ public class GroupByQueryRunnerTest
"quality", "quality",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -4863,7 +4863,7 @@ public class GroupByQueryRunnerTest
"market", "market",
"function(dim){ return true; }", "function(dim){ return true; }",
null, null,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
)) ))
.setAggregatorSpecs( .setAggregatorSpecs(
Arrays.asList( Arrays.asList(
@ -4875,7 +4875,7 @@ public class GroupByQueryRunnerTest
"function(current, index, dim){return current + index + dim.length;}", "function(current, index, dim){return current + index + dim.length;}",
"function(){return 0;}", "function(){return 0;}",
"function(a,b){return a + b;}", "function(a,b){return a + b;}",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
) )
) )
@ -5257,7 +5257,7 @@ public class GroupByQueryRunnerTest
"function(current, index, dim){return current + index + dim.length;}", "function(current, index, dim){return current + index + dim.length;}",
"function(){return 0;}", "function(){return 0;}",
"function(a,b){return a + b;}", "function(a,b){return a + b;}",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
) )
) )
@ -5320,7 +5320,7 @@ public class GroupByQueryRunnerTest
"function(current, index, rows){return current + index + rows;}", "function(current, index, rows){return current + index + rows;}",
"function(){return 0;}", "function(){return 0;}",
"function(a,b){return a + b;}", "function(a,b){return a + b;}",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
) )
) )
@ -6691,7 +6691,7 @@ public class GroupByQueryRunnerTest
String extractionJsFn = "function(str) { return 'super-' + str; }"; String extractionJsFn = "function(str) { return 'super-' + str; }";
String jsFn = "function(x) { return(x === 'super-mezzanine') }"; String jsFn = "function(x) { return(x === 'super-mezzanine') }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
List<DimFilter> superFilterList = new ArrayList<>(); List<DimFilter> superFilterList = new ArrayList<>();
superFilterList.add(new SelectorDimFilter("quality", "super-mezzanine", extractionFn)); superFilterList.add(new SelectorDimFilter("quality", "super-mezzanine", extractionFn));
@ -6716,7 +6716,7 @@ public class GroupByQueryRunnerTest
new ContainsSearchQuerySpec("super-mezzanine", true), new ContainsSearchQuerySpec("super-mezzanine", true),
extractionFn extractionFn
)); ));
superFilterList.add(new JavaScriptDimFilter("quality", jsFn, extractionFn, JavaScriptConfig.getDefault())); superFilterList.add(new JavaScriptDimFilter("quality", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance()));
DimFilter superFilter = new AndDimFilter(superFilterList); DimFilter superFilter = new AndDimFilter(superFilterList);
GroupByQuery.Builder builder = GroupByQuery GroupByQuery.Builder builder = GroupByQuery
@ -6775,7 +6775,7 @@ public class GroupByQueryRunnerTest
new ContainsSearchQuerySpec("EMPTY", true), new ContainsSearchQuerySpec("EMPTY", true),
extractionFn extractionFn
)); ));
superFilterList.add(new JavaScriptDimFilter("null_column", jsFn, extractionFn, JavaScriptConfig.getDefault())); superFilterList.add(new JavaScriptDimFilter("null_column", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance()));
DimFilter superFilter = new AndDimFilter(superFilterList); DimFilter superFilter = new AndDimFilter(superFilterList);
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource) GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource)
@ -6806,7 +6806,7 @@ public class GroupByQueryRunnerTest
public void testGroupByCardinalityAggWithExtractionFn() public void testGroupByCardinalityAggWithExtractionFn()
{ {
String helloJsFn = "function(str) { return 'hello' }"; String helloJsFn = "function(str) { return 'hello' }";
ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
GroupByQuery query = GroupByQuery GroupByQuery query = GroupByQuery
.builder() .builder()
@ -7011,7 +7011,7 @@ public class GroupByQueryRunnerTest
} }
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
GroupByQuery query = GroupByQuery GroupByQuery query = GroupByQuery
.builder() .builder()
@ -7103,7 +7103,7 @@ public class GroupByQueryRunnerTest
public void testGroupByLongTimeColumnWithExFn() public void testGroupByLongTimeColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
GroupByQuery query = GroupByQuery GroupByQuery query = GroupByQuery
.builder() .builder()
@ -7276,7 +7276,7 @@ public class GroupByQueryRunnerTest
} }
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
GroupByQuery query = GroupByQuery GroupByQuery query = GroupByQuery
.builder() .builder()

View File

@ -665,7 +665,7 @@ public class SearchQueryRunnerTest
public void testSearchOnLongColumnWithExFn() public void testSearchOnLongColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
SearchQuery searchQuery = Druids.newSearchQueryBuilder() SearchQuery searchQuery = Druids.newSearchQueryBuilder()
.dimensions( .dimensions(
@ -711,7 +711,7 @@ public class SearchQueryRunnerTest
public void testSearchOnFloatColumnWithExFn() public void testSearchOnFloatColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
SearchQuery searchQuery = Druids.newSearchQueryBuilder() SearchQuery searchQuery = Druids.newSearchQueryBuilder()
.dimensions( .dimensions(

View File

@ -724,7 +724,7 @@ public class SelectQueryRunnerTest
public void testFullOnSelectWithLongAndFloatWithExFn() public void testFullOnSelectWithLongAndFloatWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
List<DimensionSpec> dimSpecs = Arrays.<DimensionSpec>asList( List<DimensionSpec> dimSpecs = Arrays.<DimensionSpec>asList(
new ExtractionDimensionSpec(QueryRunnerTestHelper.indexMetric, "floatIndex", jsExtractionFn), new ExtractionDimensionSpec(QueryRunnerTestHelper.indexMetric, "floatIndex", jsExtractionFn),

View File

@ -1705,7 +1705,7 @@ public class TopNQueryRunnerTest
new ExtractionDimensionSpec( new ExtractionDimensionSpec(
QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension,
QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension,
new JavaScriptExtractionFn("function(f) { return \"POTATO\"; }", false, JavaScriptConfig.getDefault()) new JavaScriptExtractionFn("function(f) { return \"POTATO\"; }", false, JavaScriptConfig.getEnabledInstance())
) )
) )
.metric("rows") .metric("rows")
@ -2923,7 +2923,7 @@ public class TopNQueryRunnerTest
public void testTopNQueryCardinalityAggregatorWithExtractionFn() public void testTopNQueryCardinalityAggregatorWithExtractionFn()
{ {
String helloJsFn = "function(str) { return 'hello' }"; String helloJsFn = "function(str) { return 'hello' }";
ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
DimensionSpec dimSpec = new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, DimensionSpec dimSpec = new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension,
QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension,
@ -3747,7 +3747,7 @@ public class TopNQueryRunnerTest
public void testFullOnTopNFloatColumnWithExFn() public void testFullOnTopNFloatColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder() TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource) .dataSource(QueryRunnerTestHelper.dataSource)
@ -3966,7 +3966,7 @@ public class TopNQueryRunnerTest
public void testFullOnTopNLongColumnWithExFn() public void testFullOnTopNLongColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder() TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource) .dataSource(QueryRunnerTestHelper.dataSource)
@ -4329,7 +4329,7 @@ public class TopNQueryRunnerTest
public void testFullOnTopNLongTimeColumnWithExFn() public void testFullOnTopNLongTimeColumnWithExFn()
{ {
String jsFn = "function(str) { return 'super-' + str; }"; String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder() TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource) .dataSource(QueryRunnerTestHelper.dataSource)
@ -4404,7 +4404,7 @@ public class TopNQueryRunnerTest
public void testFullOnTopNDimExtractionAllNulls() public void testFullOnTopNDimExtractionAllNulls()
{ {
String jsFn = "function(str) { return null; }"; String jsFn = "function(str) { return null; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getDefault()); ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder() TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource) .dataSource(QueryRunnerTestHelper.dataSource)

View File

@ -413,10 +413,10 @@ public class BoundFilterTest extends BaseFilterTest
public void testMatchWithExtractionFn() public void testMatchWithExtractionFn()
{ {
String extractionJsFn = "function(str) { return 'super-' + str; }"; String extractionJsFn = "function(str) { return 'super-' + str; }";
ExtractionFn superFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn superFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
String nullJsFn = "function(str) { return null; }"; String nullJsFn = "function(str) { return null; }";
ExtractionFn makeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn makeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getEnabledInstance());
assertFilterMatches( assertFilterMatches(
new BoundDimFilter("dim0", "", "", false, false, false, makeNullFn, StringComparators.LEXICOGRAPHIC), new BoundDimFilter("dim0", "", "", false, false, false, makeNullFn, StringComparators.LEXICOGRAPHIC),

View File

@ -165,7 +165,7 @@ public class FilterPartitionTest extends BaseFilterTest
} }
private static String JS_FN = "function(str) { return 'super-' + str; }"; private static String JS_FN = "function(str) { return 'super-' + str; }";
private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getDefault()); private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getEnabledInstance());
private static final String TIMESTAMP_COLUMN = "timestamp"; private static final String TIMESTAMP_COLUMN = "timestamp";

View File

@ -192,13 +192,13 @@ public class FloatFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 3 || x === 5) }"; String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "5") ImmutableList.<String>of("3", "5")
); );
String jsFn2 = "function(x) { return(x === 3.0 || x === 5.0) }"; String jsFn2 = "function(x) { return(x === 3.0 || x === 5.0) }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(FLOAT_COLUMN, jsFn2, null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(FLOAT_COLUMN, jsFn2, null, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "5") ImmutableList.<String>of("3", "5")
); );
@ -321,7 +321,7 @@ public class FloatFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }"; String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, exfn, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, exfn, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "4") ImmutableList.<String>of("3", "4")
); );

View File

@ -210,10 +210,10 @@ public class InFilterTest extends BaseFilterTest
public void testMatchWithExtractionFn() public void testMatchWithExtractionFn()
{ {
String extractionJsFn = "function(str) { return 'super-' + str; }"; String extractionJsFn = "function(str) { return 'super-' + str; }";
ExtractionFn superFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn superFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
String nullJsFn = "function(str) { if (str === null) { return 'YES'; } else { return 'NO';} }"; String nullJsFn = "function(str) { if (str === null) { return 'YES'; } else { return 'NO';} }";
ExtractionFn yesNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn yesNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getEnabledInstance());
assertFilterMatches( assertFilterMatches(
toInFilterWithFn("dim2", superFn, "super-null", "super-a", "super-b"), toInFilterWithFn("dim2", superFn, "super-null", "super-a", "super-b"),

View File

@ -185,7 +185,7 @@ public class JavaScriptFilterTest extends BaseFilterTest
dimension, dimension,
function, function,
extractionFn, extractionFn,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
} }
} }

View File

@ -166,7 +166,7 @@ public class LongFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 3 || x === 5) }"; String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(LONG_COLUMN, jsFn, null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(LONG_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "5") ImmutableList.<String>of("3", "5")
); );
@ -274,7 +274,7 @@ public class LongFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }"; String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(LONG_COLUMN, jsFn, exfn, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(LONG_COLUMN, jsFn, exfn, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "4") ImmutableList.<String>of("3", "4")
); );

View File

@ -140,7 +140,7 @@ public class RegexFilterTest extends BaseFilterTest
public void testRegexWithExtractionFn() public void testRegexWithExtractionFn()
{ {
String nullJsFn = "function(str) { if (str === null) { return 'NOT_NULL_ANYMORE'; } else { return str;} }"; String nullJsFn = "function(str) { if (str === null) { return 'NOT_NULL_ANYMORE'; } else { return str;} }";
ExtractionFn changeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn changeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getEnabledInstance());
assertFilterMatches(new RegexDimFilter("dim1", ".*ANYMORE", changeNullFn), ImmutableList.of("0")); assertFilterMatches(new RegexDimFilter("dim1", ".*ANYMORE", changeNullFn), ImmutableList.of("0"));
assertFilterMatches(new RegexDimFilter("dim1", "ab.*", changeNullFn), ImmutableList.<String>of("4", "5")); assertFilterMatches(new RegexDimFilter("dim1", "ab.*", changeNullFn), ImmutableList.<String>of("4", "5"));

View File

@ -149,7 +149,7 @@ public class SearchQueryFilterTest extends BaseFilterTest
public void testSearchQueryWithExtractionFn() public void testSearchQueryWithExtractionFn()
{ {
String nullJsFn = "function(str) { if (str === null) { return 'NOT_NULL_ANYMORE'; } else { return str;} }"; String nullJsFn = "function(str) { if (str === null) { return 'NOT_NULL_ANYMORE'; } else { return str;} }";
ExtractionFn changeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getDefault()); ExtractionFn changeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getEnabledInstance());
assertFilterMatches(new SearchQueryDimFilter("dim1", specForValue("ANYMORE"), changeNullFn), ImmutableList.of("0")); assertFilterMatches(new SearchQueryDimFilter("dim1", specForValue("ANYMORE"), changeNullFn), ImmutableList.of("0"));
assertFilterMatches(new SearchQueryDimFilter("dim1", specForValue("ab"), changeNullFn), ImmutableList.<String>of("4", "5")); assertFilterMatches(new SearchQueryDimFilter("dim1", specForValue("ab"), changeNullFn), ImmutableList.<String>of("4", "5"));

View File

@ -143,7 +143,7 @@ public class TimeFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 3 || x === 5) }"; String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("3", "5") ImmutableList.<String>of("3", "5")
); );
@ -207,7 +207,7 @@ public class TimeFilteringTest extends BaseFilterTest
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }"; String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatches( assertFilterMatches(
new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, exfn, JavaScriptConfig.getDefault()), new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, exfn, JavaScriptConfig.getEnabledInstance()),
ImmutableList.<String>of("2", "3") ImmutableList.<String>of("2", "3")
); );
@ -271,7 +271,7 @@ public class TimeFilteringTest extends BaseFilterTest
// increment timestamp by 2 hours // increment timestamp by 2 hours
String timeBoosterJsFn = "function(x) { return(x + 7200000) }"; String timeBoosterJsFn = "function(x) { return(x + 7200000) }";
ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getDefault()); ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
assertFilterMatches( assertFilterMatches(
new IntervalDimFilter( new IntervalDimFilter(
Column.TIME_COLUMN_NAME, Column.TIME_COLUMN_NAME,
@ -330,7 +330,7 @@ public class TimeFilteringTest extends BaseFilterTest
// increment timestamp by 2 hours // increment timestamp by 2 hours
String timeBoosterJsFn = "function(x) { return(Number(x) + 7200000) }"; String timeBoosterJsFn = "function(x) { return(Number(x) + 7200000) }";
ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getDefault()); ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
assertFilterMatches( assertFilterMatches(
new IntervalDimFilter( new IntervalDimFilter(
"dim0", "dim0",

View File

@ -191,7 +191,7 @@ public class IncrementalIndexStorageAdapterTest
"function(current, s, b) { return current + (s == null ? 0 : s.length) + (b == null ? 0 : b.length); }", "function(current, s, b) { return current + (s == null ? 0 : s.length) + (b == null ? 0 : b.length); }",
"function() { return 0; }", "function() { return 0; }",
"function(a,b) { return a + b; }", "function(a,b) { return a + b; }",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
) )
.build(), .build(),

View File

@ -54,7 +54,7 @@ public class JavaScriptTieredBrokerSelectorStrategy implements TieredBrokerSelec
{ {
Preconditions.checkNotNull(fn, "function must not be null"); Preconditions.checkNotNull(fn, "function must not be null");
if (config.isDisabled()) { if (!config.isEnabled()) {
throw new ISE("JavaScript is disabled"); throw new ISE("JavaScript is disabled");
} }

View File

@ -38,16 +38,16 @@ public class JavaScriptModuleTest
public void testInjectionDefault() throws Exception public void testInjectionDefault() throws Exception
{ {
JavaScriptConfig config = makeInjectorWithProperties(new Properties()).getInstance(JavaScriptConfig.class); JavaScriptConfig config = makeInjectorWithProperties(new Properties()).getInstance(JavaScriptConfig.class);
Assert.assertFalse(config.isDisabled()); Assert.assertFalse(config.isEnabled());
} }
@Test @Test
public void testInjectionDisabled() throws Exception public void testInjectionEnabled() throws Exception
{ {
final Properties props = new Properties(); final Properties props = new Properties();
props.setProperty("druid.javascript.disabled", "true"); props.setProperty("druid.javascript.enabled", "true");
JavaScriptConfig config = makeInjectorWithProperties(props).getInstance(JavaScriptConfig.class); JavaScriptConfig config = makeInjectorWithProperties(props).getInstance(JavaScriptConfig.class);
Assert.assertTrue(config.isDisabled()); Assert.assertTrue(config.isEnabled());
} }
private Injector makeInjectorWithProperties(final Properties props) private Injector makeInjectorWithProperties(final Properties props)

View File

@ -47,7 +47,7 @@ public class JavaScriptTieredBrokerSelectorStrategyTest
private final TieredBrokerSelectorStrategy STRATEGY = new JavaScriptTieredBrokerSelectorStrategy( private final TieredBrokerSelectorStrategy STRATEGY = new JavaScriptTieredBrokerSelectorStrategy(
"function (config, query) { if (query.getAggregatorSpecs && query.getDimensionSpec && query.getDimensionSpec().getDimension() == 'bigdim' && query.getAggregatorSpecs().size() >= 3) { var size = config.getTierToBrokerMap().values().size(); if (size > 0) { return config.getTierToBrokerMap().values().toArray()[size-1] } else { return config.getDefaultBrokerServiceName() } } else { return null } }", "function (config, query) { if (query.getAggregatorSpecs && query.getDimensionSpec && query.getDimensionSpec().getDimension() == 'bigdim' && query.getAggregatorSpecs().size() >= 3) { var size = config.getTierToBrokerMap().values().size(); if (size > 0) { return config.getTierToBrokerMap().values().toArray()[size-1] } else { return config.getDefaultBrokerServiceName() } } else { return null } }",
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
); );
@Test @Test
@ -57,7 +57,7 @@ public class JavaScriptTieredBrokerSelectorStrategyTest
mapper.setInjectableValues( mapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
JavaScriptConfig.getDefault() JavaScriptConfig.getEnabledInstance()
) )
); );
@ -77,7 +77,7 @@ public class JavaScriptTieredBrokerSelectorStrategyTest
mapper.setInjectableValues( mapper.setInjectableValues(
new InjectableValues.Std().addValue( new InjectableValues.Std().addValue(
JavaScriptConfig.class, JavaScriptConfig.class,
new JavaScriptConfig(true) new JavaScriptConfig(false)
) )
); );

View File

@ -37,10 +37,10 @@ public class Filtration
{ {
private static final Interval ETERNITY = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT); private static final Interval ETERNITY = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT);
private static final DimFilter MATCH_NOTHING = new JavaScriptDimFilter( private static final DimFilter MATCH_NOTHING = new JavaScriptDimFilter(
"dummy", "function(x){return false;}", null, JavaScriptConfig.getDefault() "dummy", "function(x){return false;}", null, JavaScriptConfig.getEnabledInstance()
); );
private static final DimFilter MATCH_EVERYTHING = new JavaScriptDimFilter( private static final DimFilter MATCH_EVERYTHING = new JavaScriptDimFilter(
"dummy", "function(x){return true;}", null, JavaScriptConfig.getDefault() "dummy", "function(x){return true;}", null, JavaScriptConfig.getEnabledInstance()
); );
// 1) If "dimFilter" is null, it should be ignored and not affect filtration. // 1) If "dimFilter" is null, it should be ignored and not affect filtration.