ZihanLi58 commented on a change in pull request #3414:
URL: https://github.com/apache/gobblin/pull/3414#discussion_r734124528
##########
File path:
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/FlowSpecSearchObject.java
##########
@@ -51,4 +61,127 @@
public static FlowSpecSearchObject fromFlowId(FlowId flowId) {
return
FlowSpecSearchObject.builder().flowGroup(flowId.getFlowGroup()).flowName(flowId.getFlowName()).build();
}
+
+ /** This expects at least one parameter of `this` to be not null */
+ @Override
+ public String augmentBaseGetStatement(String baseStatement)
+ throws IOException {
+ List<String> conditions = new ArrayList<>();
+
+ if (this.getFlowSpecUri() != null) {
+ conditions.add("spec_uri = ?");
+ }
+
+ if (this.getFlowGroup() != null) {
+ conditions.add("flow_group = ?");
+ }
+
+ if (this.getFlowName() != null) {
+ conditions.add("flow_name = ?");
+ }
+
+ if (this.getTemplateURI() != null) {
+ conditions.add("template_uri = ?");
+ }
+
+ if (this.getUserToProxy() != null) {
+ conditions.add("user_to_proxy = ?");
+ }
+
+ if (this.getSourceIdentifier() != null) {
+ conditions.add("source_identifier = ?");
+ }
+
+ if (this.getDestinationIdentifier() != null) {
+ conditions.add("destination_identifier = ?");
+ }
+
+ if (this.getSchedule() != null) {
+ conditions.add("schedule = ?");
+ }
+
+ if (this.getModifiedTimestamp() != null) {
+ conditions.add("modified_time = ?");
+ }
+
+ if (this.getIsRunImmediately() != null) {
+ conditions.add("isRunImmediately = ?");
+ }
+
+ if (this.getOwningGroup() != null) {
+ conditions.add("owning_group = ?");
+ }
+
+ // If the propertyFilter is myKey=myValue, it looks for a config where key
is `myKey` and value contains string `myValue`.
+ // If the propertyFilter string does not have `=`, it considers the string
as a key and just looks for its existence.
+ // Multiple occurrences of `=` in propertyFilter are not supported and
ignored completely.
+ if (this.getPropertyFilter() != null) {
+ String propertyFilter = this.getPropertyFilter();
+ Splitter commaSplitter =
Splitter.on(",").trimResults().omitEmptyStrings();
+ for (String property : commaSplitter.splitToList(propertyFilter)) {
+ if (property.contains("=")) {
+ String[] keyValue = property.split("=");
+ if (keyValue.length != 2) {
+ log.error("Incorrect flow config search query");
+ continue;
+ }
+ conditions.add("spec_json->'$.configAsProperties.\"" + keyValue[0] +
"\"' like " + "'%" + keyValue[1] + "%'");
+ } else {
+ conditions.add("spec_json->'$.configAsProperties.\"" + property +
"\"' is not null");
+ }
+ }
+ }
+
+ if (conditions.size() == 0) {
+ throw new IOException("At least one condition is required to query flow
configs.");
+ }
+
+ return baseStatement + String.join(" AND ", conditions);
+ }
+
+ @Override
+ public void completePreparedStatement(PreparedStatement statement)
+ throws SQLException {
+ int i = 0;
+
+ if (this.getFlowSpecUri() != null) {
Review comment:
If it's possible to abstract these argument into same class and put them
into array instead of we need to maintain the order manually? Or we need to add
some comment to indicate that the order here should match the order in
augmentBaseGetStatement method, so that in the future if someone want to add
more parameter, we will not break the function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]