Skip to content

Commit

Permalink
STAR-1575 port cndb-1496 and 1145b3e61f4 from DSE
Browse files Browse the repository at this point in the history
* port cndb-1496

Enables overriding keypace with a prefixed keyspace.

* port 1145b3e61f4 from DSE

"Add KS override for schema altering statements (#19372)"

(cherry picked from commit 2eaf23d)
(cherry picked from commit 0ccdffa)
(cherry picked from commit a3962ad)
  • Loading branch information
jtgrabowski authored and djatnieks committed Sep 12, 2023
1 parent a0618be commit 6b0c581
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -645,6 +646,12 @@ private void setKeyspace(ClientState state) throws InvalidRequestException
statement.setKeyspace(state);
}

public void setKeyspace(Function<ModificationStatement.Parsed, String> convertKeyspace) throws InvalidRequestException
{
for (ModificationStatement.Parsed statement : parsedStatements)
statement.setKeyspace(convertKeyspace.apply(statement));
}

@Override
public BatchStatement prepare(ClientState state, UnaryOperator<String> keyspaceMapper)
{
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.apache.cassandra.cql3.statements.schema;

import java.util.Set;
import java.util.function.Function;

import com.google.common.collect.ImmutableSet;

Expand All @@ -41,7 +42,7 @@
public abstract class AlterSchemaStatement implements CQLStatement.SingleKeyspaceCqlStatement, SchemaTransformation
{
private final String rawCQLStatement;
protected final String keyspaceName; // name of the keyspace affected by the statement
protected String keyspaceName; // name of the keyspace affected by the statement

protected AlterSchemaStatement(String queryString, String keyspaceName)
{
Expand Down Expand Up @@ -72,6 +73,11 @@ public String keyspace()
return keyspaceName;
}

public void overrideKeyspace(Function<String, String> overrideKeyspace)
{
this.keyspaceName = overrideKeyspace.apply(keyspaceName);
}

public ResultMessage executeLocally(QueryState state, QueryOptions options)
{
return execute(state, true);
Expand Down

0 comments on commit 6b0c581

Please sign in to comment.