Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@
*/
String[] flows() default {};

/**
* Parameter paths that trigger a schema refresh in Studio when their value changes.
* Uses the same dot-notation as {@code @Updatable#parameters()}, relative to the component root.
* Example: {@code watch = {"configuration.dataSet.connection.url"}}
*
* @return the parameter paths to watch. Default to none (no dynamic refresh).
*/
String[] watch() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class ComponentSchemaEnricher implements ComponentMetadataEnricher {

public static final String FIXED_SCHEMA_FLOWS_META_PREFIX = "tcomp::ui::schema::flows::fixed";

public static final String FIXED_SCHEMA_WATCH_META_PREFIX = "tcomp::ui::schema::fixed::watch";

private static final Set<Class<? extends Annotation>> SUPPORTED_ANNOTATIONS =
new HashSet<>(Arrays.asList(PartitionMapper.class, Emitter.class, Processor.class, DriverRunner.class));

Expand Down Expand Up @@ -84,6 +86,9 @@ public Map<String, String> onComponent(final Type type, final Annotation[] annot
} else {
metadata.put(FIXED_SCHEMA_FLOWS_META_PREFIX, Branches.DEFAULT_BRANCH);
}
if (fixedSchema.watch().length > 0) {
metadata.put(FIXED_SCHEMA_WATCH_META_PREFIX, String.join(",", fixedSchema.watch()));
}

return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,38 @@ void fixedSchemaMetadataNotPresent() {
assertEquals(emptyMap(), enricher.onComponent(MyProcessor.class, MyProcessor.class.getAnnotations()));
}

@Test
void fixedSchemaWatchSinglePath() {
assertEquals(new HashMap<String, String>() {

{
put("tcomp::ui::schema::fixed", "discover");
put("tcomp::ui::schema::flows::fixed", "__default__");
put("tcomp::ui::schema::fixed::watch", "configuration.dataSet.connection.url");
}
}, enricher.onComponent(EmitterWithWatch.class, EmitterWithWatch.class.getAnnotations()));
}

@Test
void fixedSchemaWatchMultiplePaths() {
assertEquals(new HashMap<String, String>() {

{
put("tcomp::ui::schema::fixed", "discover");
put("tcomp::ui::schema::flows::fixed", "__default__");
put("tcomp::ui::schema::fixed::watch", "configuration.dataSet.url,configuration.dataSet.table");
}
}, enricher.onComponent(EmitterWithMultiWatch.class, EmitterWithMultiWatch.class.getAnnotations()));
}

@Test
void fixedSchemaWatchEmptyDoesNotEmitKey() {
final java.util.Map<String, String> result =
enricher.onComponent(MyEmitter.class, MyEmitter.class.getAnnotations());
org.junit.jupiter.api.Assertions.assertFalse(result.containsKey("tcomp::ui::schema::fixed::watch"),
"watch key must be absent when watch() is empty");
}

@Test
void dbMappingMetadataPresent() {
assertEquals(new HashMap<String, String>() {
Expand Down Expand Up @@ -103,4 +135,16 @@ private static class MyProcessor {
private static class MyEmitter {

}

@Emitter
@FixedSchema(value = "discover", watch = { "configuration.dataSet.connection.url" })
private static class EmitterWithWatch {

}

@Emitter
@FixedSchema(value = "discover", watch = { "configuration.dataSet.url", "configuration.dataSet.table" })
private static class EmitterWithMultiWatch {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ In some cases, the schema will always use the same scheme.
Having a fixed schema will prevent Studio to display the Guess schema button and the reject UI part.
The annotation's value should point to a `@DiscoverSchema` or `@DiscoverSchemaExtended` action.

The `@FixedSchema` annotation accepts the following attributes:

[cols="1,1,3",options="header"]
|===
| Attribute | Default | Description
| `value` | `""` | Name of the `@DiscoverSchema` / `@DiscoverSchemaExtended` action that returns the fixed schema.
| `flows` | `{}` (main flow) | The connector flows to which the fixed schema applies. For Input components this is always the main flow. For Output components you can list `main`, `reject`, or any custom flow name. Studio's main flow key is `__default__`.
| `watch` | `{}` (none) | Parameter paths (dot-notation, relative to the component root) whose value change triggers an automatic schema refresh in Studio. Uses the same path syntax as `@Updatable#parameters()`. Example: `watch = {"configuration.dataSet.connection.url"}`.
|===

Example with an emitter:

[source,java]
Expand Down
Loading