-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Table import
- Loading branch information
Showing
14 changed files
with
512 additions
and
49 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
10 changes: 10 additions & 0 deletions
10
cassdio-core/src/main/java/kr/hakdang/cassdio/common/utils/CsvHelper.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,10 @@ | ||
package kr.hakdang.cassdio.common.utils; | ||
|
||
/** | ||
* CsvHelper | ||
* | ||
* @author akageun | ||
* @since 2024-08-19 | ||
*/ | ||
public class CsvHelper { | ||
} |
69 changes: 69 additions & 0 deletions
69
...c/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterCsvProvider.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,69 @@ | ||
package kr.hakdang.cassdio.core.domain.cluster.keyspace.table; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVPrinter; | ||
import org.apache.commons.csv.CSVRecord; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* ClusterTableCsvProvider | ||
* | ||
* @author akageun | ||
* @since 2024-08-08 | ||
*/ | ||
@Slf4j | ||
@Service | ||
public class ClusterCsvProvider { | ||
|
||
public void importerCsvSampleDownload(Writer writer, List<String> headerList) { | ||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder() | ||
.setHeader(headerList.toArray(String[]::new)) | ||
.build(); | ||
|
||
try (final CSVPrinter printer = new CSVPrinter(writer, csvFormat)) { | ||
log.info("create complete importer csv sample"); | ||
|
||
printer.flush(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
public List<Map<String, Object>> importCsvReader(Reader reader, List<String> columnList) throws IOException { | ||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder() | ||
.setHeader(columnList.toArray(String[]::new)) | ||
.setSkipHeaderRecord(true) | ||
.setTrim(true) | ||
.build(); | ||
|
||
Iterable<CSVRecord> records = csvFormat.parse(reader); | ||
//Validation 방식에 대해 고민 필요 | ||
|
||
List<Map<String, Object>> values = new ArrayList<>(); | ||
|
||
for (CSVRecord record : records) { | ||
|
||
Map<String, Object> map = new HashMap<>(); | ||
|
||
for (String column : columnList) { | ||
map.put(column, StringUtils.defaultIfBlank(record.get(column), "")); | ||
} | ||
|
||
values.add(map); | ||
} | ||
|
||
return values; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...n/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableCsvProvider.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,36 @@ | ||
package kr.hakdang.cassdio.core.domain.cluster.keyspace.table; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVPrinter; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.List; | ||
|
||
/** | ||
* ClusterTableCsvProvider | ||
* | ||
* @author akageun | ||
* @since 2024-08-08 | ||
*/ | ||
@Slf4j | ||
@Service | ||
public class ClusterTableCsvProvider { | ||
|
||
public void importerCsvSampleDownload(Writer writer, List<String> sortedColumnList) { | ||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder() | ||
.setHeader(sortedColumnList.toArray(String[]::new)) | ||
.build(); | ||
|
||
try (final CSVPrinter printer = new CSVPrinter(writer, csvFormat)) { | ||
//printer.printRecord(author, title); | ||
log.info("create complete importer csv sample"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
...rc/main/java/kr/hakdang/cassdio/web/route/cluster/keyspace/table/ClusterTableRequest.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,28 @@ | ||
package kr.hakdang.cassdio.web.route.cluster.keyspace.table; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* ClusterTableRequest | ||
* | ||
* @author akageun | ||
* @since 2024-08-19 | ||
*/ | ||
public class ClusterTableRequest { | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public static class TableRowImportRequest { | ||
private int perCommitSize; | ||
private String batchTypeCode; | ||
|
||
@Builder | ||
public TableRowImportRequest(int perCommitSize, String batchTypeCode) { | ||
this.perCommitSize = perCommitSize; | ||
this.batchTypeCode = batchTypeCode; | ||
} | ||
} | ||
} |
Oops, something went wrong.