Skip to content

Commit ab373e2

Browse files
feeblefakieinv-jishnuypeckstadt
authored
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]>
1 parent 0847ac6 commit ab373e2

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.scalar.db.dataloader.core.dataexport;
2+
3+
import com.scalar.db.api.Scan;
4+
import com.scalar.db.dataloader.core.FileFormat;
5+
import com.scalar.db.dataloader.core.ScanRange;
6+
import com.scalar.db.io.Key;
7+
import java.util.Collections;
8+
import java.util.List;
9+
import lombok.Builder;
10+
import lombok.Data;
11+
12+
/** Options for a ScalarDB export data operation */
13+
@SuppressWarnings("SameNameButDifferent")
14+
@Builder(builderMethodName = "hiddenBuilder")
15+
@Data
16+
public class ExportOptions {
17+
18+
private final String namespace;
19+
private final String tableName;
20+
private final Key scanPartitionKey;
21+
private final FileFormat outputFileFormat;
22+
private final ScanRange scanRange;
23+
private final int limit;
24+
private final int maxThreadCount;
25+
private final boolean prettyPrintJson;
26+
27+
@Builder.Default private final int dataChunkSize = 200;
28+
@Builder.Default private final String delimiter = ";";
29+
@Builder.Default private final boolean excludeHeaderRow = false;
30+
@Builder.Default private final boolean includeTransactionMetadata = false;
31+
@Builder.Default private List<String> projectionColumns = Collections.emptyList();
32+
private List<Scan.Ordering> sortOrders;
33+
34+
public static ExportOptionsBuilder builder(
35+
String namespace, String tableName, Key scanPartitionKey, FileFormat outputFileFormat) {
36+
return hiddenBuilder()
37+
.namespace(namespace)
38+
.tableName(tableName)
39+
.scanPartitionKey(scanPartitionKey)
40+
.outputFileFormat(outputFileFormat);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.scalar.db.dataloader.core.dataexport;
2+
3+
import java.util.concurrent.atomic.LongAdder;
4+
5+
/**
6+
* Represents the report of exported data from a table
7+
*
8+
* @author Jishnu J
9+
*/
10+
public class ExportReport {
11+
12+
/**
13+
* The field is used to get the total number of rows exported from the table and written to the
14+
* exported file. LongAdder is used because it is thread-safe and optimized for high contention
15+
* scenarios where multiple threads are incrementing the counter.
16+
*/
17+
private final LongAdder exportedRowCount = new LongAdder();
18+
19+
public long getExportedRowCount() {
20+
return exportedRowCount.sum();
21+
}
22+
23+
public void increaseExportedRowCount() {
24+
this.exportedRowCount.increment();
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.scalar.db.dataloader.core.dataexport;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class ExportReportTest {
7+
8+
@Test
9+
void getExportedRowCount_afterInitialisation_ShouldBeZero() {
10+
ExportReport exportReport = new ExportReport();
11+
Assertions.assertEquals(0, exportReport.getExportedRowCount());
12+
}
13+
14+
@Test
15+
void getExportedRowCount_afterIncrementingTwice_ShouldBeTwo() {
16+
ExportReport exportReport = new ExportReport();
17+
exportReport.increaseExportedRowCount();
18+
exportReport.increaseExportedRowCount();
19+
Assertions.assertEquals(2, exportReport.getExportedRowCount());
20+
}
21+
}

gradle/spotbugs-exclude.xml

+5
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@
3434
<Bug pattern="ODR_OPEN_DATABASE_RESOURCE"/>
3535
</Or>
3636
</Match>
37+
<!-- Ignore mutable object exposure warnings(caused by Lombok) for all classes in dataloader.core -->
38+
<Match>
39+
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/>
40+
<Package name="~com.scalar.db.dataloader.core.*"/>
41+
</Match>
3742
</FindBugsFilter>

0 commit comments

Comments
 (0)