Skip to content

Commit

Permalink
fix condition
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-kioo committed Aug 14, 2024
1 parent 87d8497 commit 35b6298
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/main/java/org/embulk/input/DatabricksInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ public interface DatabricksPluginTask extends PluginTask {
@Config("user_agent")
@ConfigDefault("{}")
public UserAgentEntry getUserAgentEntry();
}

public interface UserAgentEntry extends Task {
@Config("product_name")
@ConfigDefault("\"unknown\"")
public String getProductName();
public interface UserAgentEntry extends Task {
String defaultProductName = "unknown";
String defaultProductVersion = "0.0.0";

@Config("product_version")
@ConfigDefault("\"0.0.0\"")
public String getProductVersion();
}
@Config("product_name")
@ConfigDefault("\"unknown\"")
public String getProductName();

@Config("product_version")
@ConfigDefault("\"0.0.0\"")
public String getProductVersion();
}

@Override
Expand Down Expand Up @@ -90,12 +93,13 @@ protected JdbcInputConnection newConnection(PluginTask task) throws SQLException
props.put("ConnSchema", t.getSchemaName().get());
}
props.putAll(t.getOptions());
// overwrite UserAgentEntry property if the same property is set in options
if (t.getUserAgentEntry() != null) {
String product_name = t.getUserAgentEntry().getProductName();
String product_version = t.getUserAgentEntry().getProductVersion();

props.put("UserAgentEntry", product_name + "/" + product_version);
String productName = t.getUserAgentEntry().getProductName();
String productVersion = t.getUserAgentEntry().getProductVersion();
boolean isSetUserAgentEntryInOptions = props.containsKey("UserAgentEntry");
// overwrite UserAgentEntry property if the same property is set in options
if (isSetUserAgentEntry(isSetUserAgentEntryInOptions, productName, productVersion)) {
props.put("UserAgentEntry", productName + "/" + productVersion);
}

logConnectionProperties(url, props);
Expand Down Expand Up @@ -132,4 +136,9 @@ protected Schema setupTask(JdbcInputConnection con, PluginTask task) throws SQLE
}
return super.setupTask(con, task);
}

private boolean isSetUserAgentEntry(boolean isSetUserAgentEntryInOptions, String productName, String productVersion) {
boolean isDefaultUserAgent = (productName.equals(UserAgentEntry.defaultProductName) || productVersion.equals(UserAgentEntry.defaultProductVersion));
return !(isSetUserAgentEntryInOptions && isDefaultUserAgent);
}
}

0 comments on commit 35b6298

Please sign in to comment.