Skip to content
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

테이블 조회 페이징 적용 #43

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ subprojects {
}
}

tasks.named('test') {
tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
showExceptions = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ private ClusterTableGetArgs(String keyspace, String table, boolean withTableDesc
public static class ClusterTableListArgs {

private String keyspace;
private int limit = 50;
private int pageSize = 50;
private String nextPageState;

@Builder
private ClusterTableListArgs(String keyspace, int limit, String nextPageState) {
private ClusterTableListArgs(String keyspace, int pageSize, String nextPageState) {
this.keyspace = keyspace;
this.limit = limit;
this.pageSize = pageSize;
this.nextPageState = nextPageState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import com.datastax.oss.protocol.internal.util.Bytes;
import io.micrometer.common.util.StringUtils;
import kr.hakdang.cassdio.core.domain.cluster.BaseClusterCommander;
import kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace;
import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableArgs.ClusterTableListArgs;
import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.CassandraSystemTablesColumn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker;
import static kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace.SYSTEM_SCHEMA;
import static kr.hakdang.cassdio.core.domain.cluster.keyspace.table.CassandraSystemTable.SYSTEM_SCHEMA_TABLES;
import static kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME;

/**
* ClusterTableListCommander
Expand All @@ -30,16 +32,17 @@ public class ClusterTableListCommander extends BaseClusterCommander {

public ClusterTableListResult listTables(CqlSession session, ClusterTableListArgs args) {
SimpleStatement statement = QueryBuilder
.selectFrom(CassandraSystemKeyspace.SYSTEM_SCHEMA.getKeyspaceName(), CassandraSystemTable.SYSTEM_SCHEMA_TABLES.getTableName())
.selectFrom(SYSTEM_SCHEMA.getKeyspaceName(), SYSTEM_SCHEMA_TABLES.getTableName())
.all()
.whereColumn(CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker())
.limit(args.getLimit())
.whereColumn(TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker())
.build(args.getKeyspace())
.setPageSize(args.getPageSize())
.setPagingState(StringUtils.isBlank(args.getNextPageState()) ? null : Bytes.fromHexString(args.getNextPageState()));

ResultSet rs = session.execute(statement);

List<ClusterTable> tables = rs.all().stream()
List<ClusterTable> tables = StreamSupport.stream(rs.spliterator(), false)
.limit(rs.getAvailableWithoutFetching())
.map(ClusterTable::from)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ClusterTableGetCommanderTest extends IntegrationTest {
private ClusterTableGetCommander clusterTableGetCommander;

@Test
void getTable() {
void get_table_in_keyspace() {
// given
ClusterTableGetArgs args = ClusterTableGetArgs.builder()
.keyspace(keyspaceName)
Expand Down Expand Up @@ -71,7 +71,7 @@ void getTable() {
}

@Test
void not_exists_table() {
void when_get_not_exists_table_throw_not_exists_exception() {
// given
ClusterTableGetArgs args = ClusterTableGetArgs.builder()
.keyspace(keyspaceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class ClusterTableListCommanderTest extends IntegrationTest {
private ClusterTableListCommander clusterTableListCommander;

@Test
void listTables() {
void list_tables() {
// given
ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder()
.keyspace(keyspaceName)
.limit(50)
.pageSize(50)
.build();

// when
Expand All @@ -46,7 +46,7 @@ void listTables_with_limit() {
// given
ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder()
.keyspace(keyspaceName)
.limit(1)
.pageSize(1)
.build();

// when
Expand All @@ -57,6 +57,22 @@ void listTables_with_limit() {
assertThat(sut.getTables().getFirst().getTableName()).isEqualTo("test_table_1");
assertThat(sut.getTables().getFirst().getComment()).isEqualTo("test_table_one");
assertThat(sut.getTables().getFirst().getOptions()).containsEntry("bloom_filter_fp_chance", 0.01);
assertThat(sut.getNextPageState()).isNotBlank();
}

@Test
void when_empty_table_in_keyspace_result_empty() {
// given
ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder()
.keyspace("empty_table_keyspace")
.build();

// when
ClusterTableListResult sut = clusterTableListCommander.listTables(makeSession(), args);

// then
assertThat(sut.getTables()).isEmpty();
assertThat(sut.getNextPageState()).isNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ClusterTableOptionTest extends IntegrationTest {

@Test
void extra_table_options() {
void extract_table_option() {
// given
SimpleStatement statement = QueryBuilder
.selectFrom(CassandraSystemKeyspace.SYSTEM_SCHEMA.getKeyspaceName(), CassandraSystemTable.SYSTEM_SCHEMA_TABLES.getTableName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ItemListWithCursorResponse<ClusterTable, String> listTables(String cluste
try (CqlSession session = tempClusterConnector.makeSession(clusterId, keyspace)) {
ClusterTableListResult result = clusterTableListCommander.listTables(session, ClusterTableListArgs.builder()
.keyspace(keyspace)
.limit(cursorRequest.getSize())
.pageSize(cursorRequest.getSize())
.nextPageState(cursorRequest.getCursor())
.build());

Expand Down
Loading