-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Register missing processors (#35121)
Add registration (and tests) for missing processors in the serialization chain. Fix #35119 (cherry picked from commit f87a534)
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/ProcessorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.sql.expression; | ||
|
||
import org.elasticsearch.common.io.stream.NamedWriteable; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.Processors; | ||
import org.elasticsearch.xpack.sql.expression.gen.processor.Processor; | ||
import org.elasticsearch.xpack.sql.tree.NodeSubclassTests; | ||
import org.junit.BeforeClass; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
|
||
import static java.util.stream.Collectors.toCollection; | ||
|
||
|
||
public class ProcessorTests extends ESTestCase { | ||
|
||
private static List<Class<? extends Processor>> processors; | ||
|
||
@BeforeClass | ||
public static void init() throws Exception { | ||
processors = NodeSubclassTests.subclassesOf(Processor.class); | ||
} | ||
|
||
|
||
public void testProcessorRegistration() throws Exception { | ||
LinkedHashSet<String> registered = Processors.getNamedWriteables().stream() | ||
.map(e -> e.name) | ||
.collect(toCollection(LinkedHashSet::new)); | ||
|
||
// discover available processors | ||
int missing = processors.size() - registered.size(); | ||
|
||
|
||
if (missing > 0) { | ||
List<String> notRegistered = new ArrayList<>(); | ||
for (Class<? extends Processor> proc : processors) { | ||
String procName = proc.getName(); | ||
assertTrue(procName + " does NOT implement NamedWriteable", NamedWriteable.class.isAssignableFrom(proc)); | ||
Field name = null; | ||
String value = null; | ||
try { | ||
name = proc.getField("NAME"); | ||
} catch (Exception ex) { | ||
fail(procName + " does NOT provide a NAME field\n" + ex); | ||
} | ||
try { | ||
value = name.get(proc).toString(); | ||
} catch (Exception ex) { | ||
fail(procName + " does NOT provide a static NAME field\n" + ex); | ||
} | ||
if (!registered.contains(value)) { | ||
notRegistered.add(procName); | ||
} | ||
} | ||
|
||
fail(missing + " processor(s) not registered : " + notRegistered); | ||
} else { | ||
assertEquals("Detection failed: discovered more registered processors than classes", 0, missing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters