-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIR-31838 getting account_id from the server and not sending it as a … #371
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/firebolt/jdbc/statement/rawstatement/NoOpStatementValidator.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,8 @@ | ||
package com.firebolt.jdbc.statement.rawstatement; | ||
|
||
public class NoOpStatementValidator implements StatementValidator { | ||
@Override | ||
public void validate(RawStatement statement) { | ||
// do nothing | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/firebolt/jdbc/statement/rawstatement/SetValidator.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,49 @@ | ||
package com.firebolt.jdbc.statement.rawstatement; | ||
|
||
import com.firebolt.jdbc.connection.FireboltConnection; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import static com.firebolt.jdbc.connection.settings.FireboltQueryParameterKey.ACCOUNT_ID; | ||
import static com.firebolt.jdbc.connection.settings.FireboltQueryParameterKey.DATABASE; | ||
import static com.firebolt.jdbc.connection.settings.FireboltQueryParameterKey.ENGINE; | ||
import static com.firebolt.jdbc.connection.settings.FireboltQueryParameterKey.OUTPUT_FORMAT; | ||
import static java.lang.String.CASE_INSENSITIVE_ORDER; | ||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
public class SetValidator implements StatementValidator { | ||
private static final Map<String, String> forbiddenParameters1 = caseInsensitiveNameSet(DATABASE, ENGINE, ACCOUNT_ID, OUTPUT_FORMAT); | ||
private static final Map<String, String> forbiddenParameters2 = caseInsensitiveNameSet(DATABASE, ENGINE, OUTPUT_FORMAT); | ||
private static final Map<String, String> useSupporting = caseInsensitiveNameSet(DATABASE, ENGINE); | ||
private static final String FORBIDDEN_PROPERTY_ERROR_PREFIX = "Could not set parameter. Set parameter '%s' is not allowed. "; | ||
private static final String FORBIDDEN_PROPERTY_ERROR_USE_SUFFIX = "Try again with 'USE %s' instead of SET."; | ||
private static final String FORBIDDEN_PROPERTY_ERROR_SET_SUFFIX = "Try again with a different parameter name."; | ||
private static final String USE_ERROR = FORBIDDEN_PROPERTY_ERROR_PREFIX + FORBIDDEN_PROPERTY_ERROR_USE_SUFFIX; | ||
private static final String SET_ERROR = FORBIDDEN_PROPERTY_ERROR_PREFIX + FORBIDDEN_PROPERTY_ERROR_SET_SUFFIX; | ||
|
||
private final Map<String, String> forbiddenParameters; | ||
|
||
public SetValidator(FireboltConnection connection) { | ||
forbiddenParameters = connection.getInfraVersion() < 2 ? forbiddenParameters1 : forbiddenParameters2; | ||
} | ||
|
||
@Override | ||
public void validate(RawStatement statement) { | ||
validateProperty(((SetParamRawStatement)statement).getAdditionalProperty().getKey()); | ||
} | ||
|
||
private void validateProperty(String name) { | ||
String standardName = forbiddenParameters.get(name); | ||
if (standardName != null) { | ||
throw new IllegalArgumentException(format(useSupporting.containsKey(name) ? USE_ERROR : SET_ERROR, standardName, standardName)); | ||
} | ||
} | ||
|
||
@SafeVarargs | ||
private static <T extends Enum<T>> Map<String, String> caseInsensitiveNameSet(Enum<T> ... elements) { | ||
return Arrays.stream(elements).map(Enum::name).collect(toMap(name -> name, name -> name, (one, two) -> two, () -> new TreeMap<>(CASE_INSENSITIVE_ORDER))); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/firebolt/jdbc/statement/rawstatement/StatementValidator.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,5 @@ | ||
package com.firebolt.jdbc.statement.rawstatement; | ||
|
||
public interface StatementValidator { | ||
void validate(RawStatement statement); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/firebolt/jdbc/statement/rawstatement/StatementValidatorFactory.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,13 @@ | ||
package com.firebolt.jdbc.statement.rawstatement; | ||
|
||
import com.firebolt.jdbc.connection.FireboltConnection; | ||
|
||
public abstract class StatementValidatorFactory { | ||
private StatementValidatorFactory() { | ||
// empty private constructor to ensure that this class will be used as factory only. | ||
} | ||
|
||
public static StatementValidator createValidator(RawStatement statement, FireboltConnection connection) { | ||
return statement instanceof SetParamRawStatement ? new SetValidator(connection) : new NoOpStatementValidator(); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea here is to use all parameters and not only
account_id
. Yes, currently (and maybe even further) we only receiveaccount_id
, but generally this assumes the ability to receive other parameters.So generally, we should take all received parameters (not only
account_id
) and add them when we connect to a system engine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if account_id is not provided in parameters, we should not provide it either instead of getting it manually and setting it as default.
For example, we can receive a URL like
https:/01hnj9r1xrx3a4t3kb1ec7qs2b.api.us-east-1.staging.firebolt.io
, where account_id is included in the endpoint itself, so there is no need to add a query parameter as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these are supported. Please take a look on lines 112-114 that iterate over all parameters. Concerning to the account ID it should work too. Indeed if account ID is not supplied in the engine URL parametersthe value
accountId
defined in line 11 will be as current account ID (account.getId()
) and therefore setting it into loginProperties in line 119 will not change the value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, as for parameter makes sense, didn't see that.
As for account_id, my point is that we need to forcefully unset it (even if it was provided by a user). As I understand from the code, account_id value can still exist in the url even if it wasn't provided in system engine url response. Let me know if I'm missing someting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is implemented in StatemtentClientImpl: lines 310-331
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense