Skip to content

Commit

Permalink
[Type removal] Remove _type deprecation from script and conditional p…
Browse files Browse the repository at this point in the history
…rocessor

Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed May 18, 2022
1 parent f021860 commit 71c0c58
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@
*/
public final class ScriptProcessor extends AbstractProcessor {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DynamicMap.class);
private static final Map<String, Function<Object, Object>> PARAMS_FUNCTIONS = org.opensearch.common.collect.Map.of("_type", value -> {
deprecationLogger.deprecate("script_processor", "[types removal] Looking up doc types [_type] in scripts is deprecated.");
return value;
});

public static final String TYPE = "script";

private final Script script;
Expand Down Expand Up @@ -111,7 +105,7 @@ public IngestDocument execute(IngestDocument document) {
} else {
ingestScript = precompiledIngestScript;
}
ingestScript.execute(new DynamicMap(document.getSourceAndMetadata(), PARAMS_FUNCTIONS));
ingestScript.execute(document.getSourceAndMetadata());
CollectionUtils.ensureNoSelfReferences(document.getSourceAndMetadata(), "ingest script");
return document;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,4 @@ private void assertIngestDocument(IngestDocument ingestDocument) {
int bytesTotal = ingestDocument.getFieldValue("bytes_in", Integer.class) + ingestDocument.getFieldValue("bytes_out", Integer.class);
assertThat(ingestDocument.getSourceAndMetadata().get("bytes_total"), is(bytesTotal));
}

public void testTypeDeprecation() throws Exception {
String scriptName = "script";
ScriptService scriptService = new ScriptService(
Settings.builder().build(),
Collections.singletonMap(
Script.DEFAULT_SCRIPT_LANG,
new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Collections.singletonMap(scriptName, ctx -> {
ctx.get("_type");
return null;
}), Collections.emptyMap())
),
new HashMap<>(ScriptModule.CORE_CONTEXTS)
);
Script script = new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptName, Collections.emptyMap());
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
ScriptProcessor processor = new ScriptProcessor(randomAlphaOfLength(10), null, script, null, scriptService);
processor.execute(ingestDocument);
assertWarnings("[types removal] Looking up doc types [_type] in scripts is deprecated.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@
*/
public class ConditionalProcessor extends AbstractProcessor implements WrappingProcessor {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DynamicMap.class);
private static final Map<String, Function<Object, Object>> FUNCTIONS = org.opensearch.common.collect.Map.of("_type", value -> {
deprecationLogger.deprecate(
"conditional-processor__type",
"[types removal] Looking up doc types [_type] in scripts is deprecated."
);
return value;
});

static final String TYPE = "conditional";

private final Script condition;
Expand Down Expand Up @@ -153,7 +144,7 @@ boolean evaluate(IngestDocument ingestDocument) {
IngestConditionalScript.Factory factory = scriptService.compile(condition, IngestConditionalScript.CONTEXT);
script = factory.newInstance(condition.getParams());
}
return script.execute(new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS)));
return script.execute(new UnmodifiableIngestData(ingestDocument.getSourceAndMetadata()));
}

public Processor getInnerProcessor() {
Expand Down
8 changes: 1 addition & 7 deletions server/src/main/java/org/opensearch/script/UpdateScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
*/
public abstract class UpdateScript {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DynamicMap.class);
private static final Map<String, Function<Object, Object>> PARAMS_FUNCTIONS = org.opensearch.common.collect.Map.of("_type", value -> {
deprecationLogger.deprecate("update-script", "[types removal] Looking up doc types [_type] in scripts is deprecated.");
return value;
});

public static final String[] PARAMETERS = {};

/** The context used to compile {@link UpdateScript} factories. */
Expand All @@ -63,7 +57,7 @@ public abstract class UpdateScript {

public UpdateScript(Map<String, Object> params, Map<String, Object> ctx) {
this.params = params;
this.ctx = new DynamicMap(ctx, PARAMS_FUNCTIONS);
this.ctx = ctx;
}

/** Return the parameters for this script. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,56 +163,6 @@ public void testActsOnImmutableData() throws Exception {
assertMutatingCtxThrows(ctx -> ((List<Object>) ctx.get("listField")).remove("bar"));
}

public void testTypeDeprecation() throws Exception {

ScriptService scriptService = new ScriptService(
Settings.builder().build(),
Collections.singletonMap(
Script.DEFAULT_SCRIPT_LANG,
new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Collections.singletonMap(scriptName, ctx -> {
ctx.get("_type");
return true;
}), Collections.emptyMap())
),
new HashMap<>(ScriptModule.CORE_CONTEXTS)
);

LongSupplier relativeTimeProvider = mock(LongSupplier.class);
when(relativeTimeProvider.getAsLong()).thenReturn(0L, TimeUnit.MILLISECONDS.toNanos(1), 0L, TimeUnit.MILLISECONDS.toNanos(2));
ConditionalProcessor processor = new ConditionalProcessor(
randomAlphaOfLength(10),
"description",
new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptName, Collections.emptyMap()),
scriptService,
new Processor() {
@Override
public IngestDocument execute(final IngestDocument ingestDocument) {
return ingestDocument;
}

@Override
public String getType() {
return null;
}

@Override
public String getTag() {
return null;
}

@Override
public String getDescription() {
return null;
}
},
relativeTimeProvider
);

IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
processor.execute(ingestDocument, (result, e) -> {});
assertWarnings("[types removal] Looking up doc types [_type] in scripts is deprecated.");
}

public void testPrecompiledError() {
ScriptService scriptService = MockScriptService.singleContext(
IngestConditionalScript.CONTEXT,
Expand Down

0 comments on commit 71c0c58

Please sign in to comment.