Skip to content

Commit

Permalink
Backport to branch(3.13) : Export options and basic export report dto (
Browse files Browse the repository at this point in the history
…#2436)

Co-authored-by: inv-jishnu <[email protected]>
Co-authored-by: Peckstadt Yves <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 0847ac6 commit ab373e2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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);
}
}
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();
}
}
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());
}
}
5 changes: 5 additions & 0 deletions gradle/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
<Bug pattern="ODR_OPEN_DATABASE_RESOURCE"/>
</Or>
</Match>
<!-- Ignore mutable object exposure warnings(caused by Lombok) for all classes in dataloader.core -->
<Match>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/>
<Package name="~com.scalar.db.dataloader.core.*"/>
</Match>
</FindBugsFilter>

0 comments on commit ab373e2

Please sign in to comment.