-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport to branch(3.13) : Export options and basic export report dto (…
…#2436) Co-authored-by: inv-jishnu <[email protected]> Co-authored-by: Peckstadt Yves <[email protected]>
- Loading branch information
1 parent
0847ac6
commit ab373e2
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportOptions.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,42 @@ | ||
package com.scalar.db.dataloader.core.dataexport; | ||
|
||
import com.scalar.db.api.Scan; | ||
import com.scalar.db.dataloader.core.FileFormat; | ||
import com.scalar.db.dataloader.core.ScanRange; | ||
import com.scalar.db.io.Key; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
/** Options for a ScalarDB export data operation */ | ||
@SuppressWarnings("SameNameButDifferent") | ||
@Builder(builderMethodName = "hiddenBuilder") | ||
@Data | ||
public class ExportOptions { | ||
|
||
private final String namespace; | ||
private final String tableName; | ||
private final Key scanPartitionKey; | ||
private final FileFormat outputFileFormat; | ||
private final ScanRange scanRange; | ||
private final int limit; | ||
private final int maxThreadCount; | ||
private final boolean prettyPrintJson; | ||
|
||
@Builder.Default private final int dataChunkSize = 200; | ||
@Builder.Default private final String delimiter = ";"; | ||
@Builder.Default private final boolean excludeHeaderRow = false; | ||
@Builder.Default private final boolean includeTransactionMetadata = false; | ||
@Builder.Default private List<String> projectionColumns = Collections.emptyList(); | ||
private List<Scan.Ordering> sortOrders; | ||
|
||
public static ExportOptionsBuilder builder( | ||
String namespace, String tableName, Key scanPartitionKey, FileFormat outputFileFormat) { | ||
return hiddenBuilder() | ||
.namespace(namespace) | ||
.tableName(tableName) | ||
.scanPartitionKey(scanPartitionKey) | ||
.outputFileFormat(outputFileFormat); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportReport.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,26 @@ | ||
package com.scalar.db.dataloader.core.dataexport; | ||
|
||
import java.util.concurrent.atomic.LongAdder; | ||
|
||
/** | ||
* Represents the report of exported data from a table | ||
* | ||
* @author Jishnu J | ||
*/ | ||
public class ExportReport { | ||
|
||
/** | ||
* The field is used to get the total number of rows exported from the table and written to the | ||
* exported file. LongAdder is used because it is thread-safe and optimized for high contention | ||
* scenarios where multiple threads are incrementing the counter. | ||
*/ | ||
private final LongAdder exportedRowCount = new LongAdder(); | ||
|
||
public long getExportedRowCount() { | ||
return exportedRowCount.sum(); | ||
} | ||
|
||
public void increaseExportedRowCount() { | ||
this.exportedRowCount.increment(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...-loader/core/src/test/java/com/scalar/db/dataloader/core/dataexport/ExportReportTest.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,21 @@ | ||
package com.scalar.db.dataloader.core.dataexport; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ExportReportTest { | ||
|
||
@Test | ||
void getExportedRowCount_afterInitialisation_ShouldBeZero() { | ||
ExportReport exportReport = new ExportReport(); | ||
Assertions.assertEquals(0, exportReport.getExportedRowCount()); | ||
} | ||
|
||
@Test | ||
void getExportedRowCount_afterIncrementingTwice_ShouldBeTwo() { | ||
ExportReport exportReport = new ExportReport(); | ||
exportReport.increaseExportedRowCount(); | ||
exportReport.increaseExportedRowCount(); | ||
Assertions.assertEquals(2, exportReport.getExportedRowCount()); | ||
} | ||
} |
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