diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java index 052bf35d09d16..9c72735b566d5 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java @@ -421,22 +421,23 @@ public boolean guessSchemaThroughAction(final Schema schema) { ServiceMeta.ActionMeta actionRef; if (action == null || action.isEmpty()) { - // dataset name should be the same as DiscoverSchema action name so let's try to guess from the component + // Dataset name should match the DiscoverSchema or DiscoverSchemaExtended action name, so try to + // guess it from the component (preferring DiscoverSchemaExtended over DiscoverSchema). actionRef = findFirstComponentDataSetName() .flatMap(datasetName -> services .stream() .flatMap(s -> s.getActions().stream()) - .filter(a -> a.getFamily().equals(family) && a.getType().equals(SCHEMA_TYPE)) + .filter(a -> a.getFamily().equals(family) && a.getType().equals(SCHEMA_EXTENDED_TYPE)) .filter(a -> a.getAction().equals(datasetName)) .findFirst()) .orElse(null); if (actionRef == null) { - // let's try DiscoverSchemaExtended action name + // Then try the DiscoverSchema action name. actionRef = findFirstComponentDataSetName() .flatMap(datasetName -> services .stream() .flatMap(s -> s.getActions().stream()) - .filter(a -> a.getFamily().equals(family) && a.getType().equals(SCHEMA_EXTENDED_TYPE)) + .filter(a -> a.getFamily().equals(family) && a.getType().equals(SCHEMA_TYPE)) .filter(a -> a.getAction().equals(datasetName)) .findFirst()) .orElse(null); @@ -446,10 +447,18 @@ public boolean guessSchemaThroughAction(final Schema schema) { .stream() .flatMap(s -> s.getActions().stream()) .filter(a -> a.getFamily().equals(family) && a.getAction().equals(action) - && a.getType().equals(SCHEMA_TYPE)) + && (a.getType().equals(SCHEMA_EXTENDED_TYPE) || a.getType().equals(SCHEMA_TYPE))) + // When both DiscoverSchemaExtended and DiscoverSchema exist for the same action name, + // prefer the extended schema action by ordering it first. + .sorted((action1, action2) -> { + boolean action1IsExtended = action1.getType().equals(SCHEMA_EXTENDED_TYPE); + boolean action2IsExtended = action2.getType().equals(SCHEMA_EXTENDED_TYPE); + return Boolean.compare(!action1IsExtended, !action2IsExtended); + }) .findFirst() .orElseThrow(() -> new IllegalArgumentException( - "No action " + family + "#" + SCHEMA_TYPE + "#" + action)); + "No action " + family + "#(" + SCHEMA_TYPE + " or " + SCHEMA_EXTENDED_TYPE + ")#" + + action)); } if (actionRef == null) { return false; diff --git a/documentation/src/main/antora/modules/ROOT/pages/studio-schema.adoc b/documentation/src/main/antora/modules/ROOT/pages/studio-schema.adoc index 81574e7557d88..91b1409f54777 100644 --- a/documentation/src/main/antora/modules/ROOT/pages/studio-schema.adoc +++ b/documentation/src/main/antora/modules/ROOT/pages/studio-schema.adoc @@ -240,10 +240,9 @@ Example: ==== For inputs . Try to find an action in declared Service class -.. search an action of type `@DiscoverSchema` named like the input dataset. .. search an action of type `@DiscoverSchemaExtended` named like the input dataset. -.. search an action of type `@DiscoverSchema`. -. Execute a fake job with component to retrieve output schema. +.. search an action of type `@DiscoverSchema` named like the input dataset. +. If no matching action is found, execute a fake job with the component to retrieve the output schema. ==== For processors