-
Notifications
You must be signed in to change notification settings - Fork 34
[CASSANALYTICS-183] - Pass quoted identifiers to sidecar API calls for mixed-case keyspace/table restore #226
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
Open
bianca-stanciu29
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
bianca-stanciu29:CASSANALYTICS-183
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4578c9a
[CASSANALYTICS-183] - Mixed-case keyspace restore fails with Keyspace…
bianca-stanciu29 ea64e1c
Fixing the tests
bianca-stanciu29 e59fe5b
Fix checkstyle violation and add changelog entry
bianca-stanciu29 21e44dc
Merge branch 'trunk' into CASSANALYTICS-183
bianca-stanciu29 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
...nalytics-common/src/test/java/org/apache/cassandra/spark/data/QualifiedTableNameTest.java
This file contains hidden or 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,84 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.cassandra.spark.data; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class QualifiedTableNameTest | ||
| { | ||
| @Test | ||
| void testUnquotedIdentifiersReturnedAsIs() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("mykeyspace", "mytable", false); | ||
| assertThat(name.keyspace()).isEqualTo("mykeyspace"); | ||
| assertThat(name.table()).isEqualTo("mytable"); | ||
| assertThat(name.maybeQuotedKeyspace()).isEqualTo("mykeyspace"); | ||
| assertThat(name.maybeQuotedTable()).isEqualTo("mytable"); | ||
| } | ||
|
|
||
| @Test | ||
| void testQuotedIdentifiersWrappedInDoubleQuotes() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("MyKeyspace", "MyTable", true); | ||
| assertThat(name.maybeQuotedKeyspace()).isEqualTo("\"MyKeyspace\""); | ||
| assertThat(name.maybeQuotedTable()).isEqualTo("\"MyTable\""); | ||
| } | ||
|
|
||
| @Test | ||
| void testRawAccessorsUnaffectedByQuoteFlag() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("MyKeyspace", "MyTable", true); | ||
| assertThat(name.keyspace()).isEqualTo("MyKeyspace"); | ||
| assertThat(name.table()).isEqualTo("MyTable"); | ||
| } | ||
|
|
||
| @Test | ||
| void testToStringQuotesBothWhenFlagSet() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("MyKeyspace", "MyTable", true); | ||
| assertThat(name.toString()).isEqualTo("\"MyKeyspace\".\"MyTable\""); | ||
| } | ||
|
|
||
| @Test | ||
| void testToStringUnquotedWhenFlagNotSet() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("mykeyspace", "mytable", false); | ||
| assertThat(name.toString()).isEqualTo("mykeyspace.mytable"); | ||
| } | ||
|
|
||
| @Test | ||
| void testDefaultConstructorDoesNotQuote() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("MyKeyspace", "MyTable"); | ||
| assertThat(name.quoteIdentifiers()).isFalse(); | ||
| assertThat(name.maybeQuotedKeyspace()).isEqualTo("MyKeyspace"); | ||
| assertThat(name.maybeQuotedTable()).isEqualTo("MyTable"); | ||
| } | ||
|
|
||
| @Test | ||
| void testReservedWordIdentifiersQuoted() | ||
| { | ||
| QualifiedTableName name = new QualifiedTableName("keyspace", "table", true); | ||
| assertThat(name.maybeQuotedKeyspace()).isEqualTo("\"keyspace\""); | ||
| assertThat(name.maybeQuotedTable()).isEqualTo("\"table\""); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -289,11 +289,12 @@ protected String getCurrentKeyspaceSchema() throws Exception | |
| private TokenRangeReplicasResponse getTokenRangesAndReplicaSets() | ||
| { | ||
| CassandraContext context = getCassandraContext(); | ||
| String quotedKeyspace = maybeQuotedIdentifier(bridge(), conf.quoteIdentifiers, conf.keyspace); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: change name to maybeQuotedKeyspace? |
||
| try | ||
| { | ||
| long start = System.nanoTime(); | ||
| TokenRangeReplicasResponse response = context.getSidecarClient() | ||
| .tokenRangeReplicas(new ArrayList<>(context.getCluster()), conf.keyspace) | ||
| .tokenRangeReplicas(new ArrayList<>(context.getCluster()), quotedKeyspace) | ||
| .get(); | ||
| long elapsedTimeNanos = System.nanoTime() - start; | ||
| LOGGER.info("Retrieved token ranges for {} instances in {} milliseconds", | ||
|
|
@@ -303,8 +304,8 @@ private TokenRangeReplicasResponse getTokenRangesAndReplicaSets() | |
| } | ||
| catch (ExecutionException | InterruptedException exception) | ||
| { | ||
| LOGGER.error("Failed to get token ranges for keyspace {}", conf.keyspace, exception); | ||
| throw new SidecarApiCallException("Failed to get token ranges for keyspace" + conf.keyspace, exception); | ||
| LOGGER.error("Failed to get token ranges for keyspace {}", quotedKeyspace, exception); | ||
| throw new SidecarApiCallException("Failed to get token ranges for keyspace " + quotedKeyspace, exception); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
...g/apache/cassandra/spark/bulkwriter/cloudstorage/CloudStorageDataTransferApiImplTest.java
This file contains hidden or 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,120 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.cassandra.spark.bulkwriter.cloudstorage; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import o.a.c.sidecar.client.shaded.common.request.data.CreateRestoreJobRequestPayload; | ||
| import o.a.c.sidecar.client.shaded.common.request.data.UpdateRestoreJobRequestPayload; | ||
| import o.a.c.sidecar.client.shaded.common.response.data.RestoreJobSummaryResponsePayload; | ||
| import o.a.c.sidecar.client.shaded.client.SidecarClient; | ||
| import org.apache.cassandra.spark.bulkwriter.JobInfo; | ||
| import org.apache.cassandra.spark.data.QualifiedTableName; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| class CloudStorageDataTransferApiImplTest | ||
| { | ||
| private static final String QUOTED_KEYSPACE = "\"MyKeyspace\""; | ||
| private static final String QUOTED_TABLE = "\"MyTable\""; | ||
| private static final UUID JOB_ID = UUID.randomUUID(); | ||
|
|
||
| private SidecarClient sidecarClient; | ||
| private JobInfo jobInfo; | ||
| private CloudStorageDataTransferApiImpl api; | ||
|
|
||
| @BeforeEach | ||
| void setup() | ||
| { | ||
| sidecarClient = mock(SidecarClient.class); | ||
| jobInfo = mock(JobInfo.class); | ||
| when(jobInfo.qualifiedTableName()).thenReturn(new QualifiedTableName("MyKeyspace", "MyTable", true)); | ||
| when(jobInfo.getRestoreJobId()).thenReturn(JOB_ID); | ||
| when(jobInfo.getRestoreJobId(null)).thenReturn(JOB_ID); | ||
| api = new CloudStorageDataTransferApiImpl(jobInfo, sidecarClient, mock(StorageClient.class), null); | ||
| } | ||
|
|
||
| @Test | ||
| void testCreateRestoreJobUsesQuotedIdentifiers() throws Exception | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding quoted identifiers tests to the other modified APIs? |
||
| { | ||
| when(sidecarClient.createRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), any())) | ||
| .thenReturn(CompletableFuture.completedFuture(null)); | ||
|
|
||
| api.createRestoreJob(mock(CreateRestoreJobRequestPayload.class)); | ||
|
|
||
| verify(sidecarClient).createRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), any()); | ||
| } | ||
|
|
||
| @Test | ||
| void testRestoreJobSummaryUsesQuotedIdentifiers() throws Exception | ||
| { | ||
| RestoreJobSummaryResponsePayload response = mock(RestoreJobSummaryResponsePayload.class); | ||
| when(sidecarClient.restoreJobSummary(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID))) | ||
| .thenReturn(CompletableFuture.completedFuture(response)); | ||
|
|
||
| RestoreJobSummaryResponsePayload result = api.restoreJobSummary(); | ||
|
|
||
| assertThat(result).isSameAs(response); | ||
| verify(sidecarClient).restoreJobSummary(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID)); | ||
| } | ||
|
|
||
| @Test | ||
| void testUpdateRestoreJobUsesQuotedIdentifiers() throws Exception | ||
| { | ||
| when(sidecarClient.updateRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID), any())) | ||
| .thenReturn(CompletableFuture.completedFuture(null)); | ||
|
|
||
| api.updateRestoreJob(mock(UpdateRestoreJobRequestPayload.class)); | ||
|
|
||
| verify(sidecarClient).updateRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID), any()); | ||
| } | ||
|
|
||
| @Test | ||
| void testAbortRestoreJobUsesQuotedIdentifiers() throws Exception | ||
| { | ||
| when(sidecarClient.abortRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID))) | ||
| .thenReturn(CompletableFuture.completedFuture(null)); | ||
|
|
||
| api.abortRestoreJob(); | ||
|
|
||
| verify(sidecarClient).abortRestoreJob(eq(QUOTED_KEYSPACE), eq(QUOTED_TABLE), eq(JOB_ID)); | ||
| } | ||
|
|
||
| @Test | ||
| void testUnquotedIdentifiersPassedAsIsWhenFlagNotSet() throws Exception | ||
| { | ||
| when(jobInfo.qualifiedTableName()).thenReturn(new QualifiedTableName("mykeyspace", "mytable", false)); | ||
| when(sidecarClient.createRestoreJob(eq("mykeyspace"), eq("mytable"), any())) | ||
| .thenReturn(CompletableFuture.completedFuture(null)); | ||
|
|
||
| api.createRestoreJob(mock(CreateRestoreJobRequestPayload.class)); | ||
|
|
||
| verify(sidecarClient).createRestoreJob(eq("mykeyspace"), eq("mytable"), any()); | ||
| } | ||
| } | ||
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.
Wondering here if we really need wrappers with the "maybe*" prefix, or we can just use this as default for keyspace() and table(). What do you think @yifan-c / @frankgh ?