Skip to content

Commit

Permalink
Query Editor Column List
Browse files Browse the repository at this point in the history
- apply sorting(with partition, clustering key)
  • Loading branch information
akageun committed Aug 8, 2024
1 parent 74d84c6 commit ac3a75b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.querybuilder.BuildableQuery;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
import com.datastax.oss.driver.api.querybuilder.select.Select;
import com.datastax.oss.driver.api.querybuilder.select.SelectFrom;
Expand All @@ -17,9 +18,11 @@
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker;
import static java.util.Collections.emptyList;
Expand All @@ -41,18 +44,24 @@ public CqlSessionSelectResults columnList(String clusterId, String keyspace, Str
public CqlSessionSelectResults columnList(String clusterId, String keyspace, String table, List<String> columnList) {
CqlSession session = cqlSessionFactory.get(clusterId);

SimpleStatement statement;

Select select = getColumnTable(session, keyspace)
.all()
.whereColumn(CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker())
.whereColumn(CassandraSystemTablesColumn.TABLES_TABLE_NAME.getColumnName()).isEqualTo(bindMarker());

// if (CollectionUtils.isNotEmpty(columnList)) {
// select.whereColumn("column_name").in(columnList.stream().map(info -> bindMarker()).toList());
// }
List<String> arr = new ArrayList<>();
arr.add(keyspace);
arr.add(table);

if (CollectionUtils.isNotEmpty(columnList)) {
select = select.whereColumn("column_name").in(columnList.stream()
.map(info -> bindMarker())
.collect(Collectors.toSet()));

arr.addAll(columnList);
}

statement = select.build(keyspace, table)
SimpleStatement statement = select.build(arr.toArray())
.setTimeout(Duration.ofSeconds(3));

ResultSet resultSet = session.execute(statement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package kr.hakdang.cassdio.web.route.cluster.query;

import kr.hakdang.cassdio.core.domain.cluster.CqlSessionSelectResults;
import kr.hakdang.cassdio.core.domain.cluster.keyspace.CassdioColumnDefinition;
import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.ClusterTableColumnCommander;
import kr.hakdang.cassdio.core.domain.cluster.query.ClusterQueryCommander;
import kr.hakdang.cassdio.core.domain.cluster.query.QueryDTO;
import kr.hakdang.cassdio.web.common.dto.response.ApiResponse;
Expand All @@ -11,6 +14,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -24,11 +28,14 @@
@RequestMapping("/api/cassandra/cluster")
public class ClusterQueryApi {
private final ClusterQueryCommander clusterQueryCommander;
private final ClusterTableColumnCommander clusterTableColumnCommander;

public ClusterQueryApi(
ClusterQueryCommander clusterQueryCommander
ClusterQueryCommander clusterQueryCommander,
ClusterTableColumnCommander clusterTableColumnCommander
) {
this.clusterQueryCommander = clusterQueryCommander;
this.clusterTableColumnCommander = clusterTableColumnCommander;
}

@PostMapping(value = {"/{clusterId}/query", "/{clusterId}/keyspace/{keyspace}/query"})
Expand All @@ -44,10 +51,26 @@ public ApiResponse<Map<String, Object>> clusterQueryCommand(
request.makeArgs(keyspace)
);

CassdioColumnDefinition columnDefinition = result.getRowHeader().getFirst();

List<String> columnListForParam = result.getRowHeader()
.stream()
.map(CassdioColumnDefinition::getColumnName)
.toList();

CqlSessionSelectResults columnListResult = clusterTableColumnCommander.columnList(
clusterId,
columnDefinition.getKeyspace(),
columnDefinition.getTable(),
columnListForParam
);

responseMap.put("wasApplied", result.isWasApplied());
responseMap.put("nextCursor", result.getNextCursor());
responseMap.put("rows", result.getRows());
responseMap.put("rowHeader", result.getRowHeader());
responseMap.put("columnList", columnListResult);

if (request.isTrace()) {
responseMap.put("queryTrace", result.getQueryTrace());
}
Expand Down
28 changes: 18 additions & 10 deletions cassdio-web/src/main/webapp/src/components/cluster/query-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,39 @@ const QueryResult = ({queryExecute, result, query, nextCursor, setShowQueryTrace
<thead>
<tr className={"table-dark"}>
{
result.rowHeader.map((info, infoIndex) => {
result.columnList.rows && result.columnList.rows.map((info, infoIndex) => {
return (
<th className={"text-center text-truncate"}
key={`resultHeader${infoIndex}`}
<th className={"text-center text-truncate"} key={`resultHeader${infoIndex}`}
scope="col">

<OverlayTrigger placement="bottom" overlay={
<Tooltip id="tooltip">
{info.columnName}<br/>
({info.type})
{info.column_name} ({info.type})
</Tooltip>
}>
<span style={{cursor: "pointer"}}>{info.columnName}</span>
<span style={{cursor: "pointer"}}>
{
info.kind === 'partition_key' &&
<i className="bi bi-p-square me-1"></i>
}
{
info.kind === 'clustering' &&
<i className="bi bi-c-square me-1"></i>
}
{info.column_name}
</span>
</OverlayTrigger>
</th>
)
})
}

</tr>
</thead>
<tbody className="table-group-divider" style={{maxHeight: "50vh"}}>
{
result.rows.length <= 0 ? <>
<tr>
<td className={"text-center"} colSpan={result.rowHeader.length}>
<td className={"text-center"} colSpan={result.columnList.rows.length}>
No Data
</td>
</tr>
Expand All @@ -87,11 +95,11 @@ const QueryResult = ({queryExecute, result, query, nextCursor, setShowQueryTrace
return (
<tr key={`resultBody${rowIndex}`}>
{
result.rowHeader.map((info, infoIndex) => {
result.columnList.rows.map((info, infoIndex) => {
return (
<td className={`text-center text-break text-truncate`}
key={`resultItem${infoIndex}`}>
<DataRowItem data={row[info.columnName]}/>
<DataRowItem data={row[info.column_name]}/>
</td>
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ClusterQueryPage = () => {
wasApplied: null,
rows: [],
rowHeader: [],
columnList: {},
queryTrace: {},
};

Expand Down Expand Up @@ -79,6 +80,7 @@ const ClusterQueryPage = () => {
wasApplied: data.result.wasApplied,
rows: rows,
rowHeader: data.result.rowHeader,
columnList : data.result.columnList,
queryTrace: data.result.queryTrace,
})
}).finally(() => {
Expand Down

0 comments on commit ac3a75b

Please sign in to comment.