diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportOptions.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportOptions.java new file mode 100644 index 0000000000..da515cf3c2 --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportOptions.java @@ -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 projectionColumns = Collections.emptyList(); + private List sortOrders; + + public static ExportOptionsBuilder builder( + String namespace, String tableName, Key scanPartitionKey, FileFormat outputFileFormat) { + return hiddenBuilder() + .namespace(namespace) + .tableName(tableName) + .scanPartitionKey(scanPartitionKey) + .outputFileFormat(outputFileFormat); + } +} diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportReport.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportReport.java new file mode 100644 index 0000000000..9907fe1891 --- /dev/null +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataexport/ExportReport.java @@ -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(); + } +} diff --git a/data-loader/core/src/test/java/com/scalar/db/dataloader/core/dataexport/ExportReportTest.java b/data-loader/core/src/test/java/com/scalar/db/dataloader/core/dataexport/ExportReportTest.java new file mode 100644 index 0000000000..e9820582c7 --- /dev/null +++ b/data-loader/core/src/test/java/com/scalar/db/dataloader/core/dataexport/ExportReportTest.java @@ -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()); + } +} diff --git a/gradle/spotbugs-exclude.xml b/gradle/spotbugs-exclude.xml index 05571f3fdb..1724740470 100644 --- a/gradle/spotbugs-exclude.xml +++ b/gradle/spotbugs-exclude.xml @@ -34,4 +34,9 @@ + + + + +