-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIR-31838 getting account_id from the server and not sending it as a …
…parameter for system engine
- Loading branch information
alexradzin
committed
Apr 8, 2024
1 parent
f967503
commit c9a933d
Showing
12 changed files
with
218 additions
and
88 deletions.
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.