Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export options and basic export report dto #2397

Merged
merged 16 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lombok does not work well with Spotbugs. To avoid having to disable the bug patterns for all projects, the rules are only disabled for the com.scalar.db.dataloader.core.* package.

<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/>
<Package name="~com.scalar.db.dataloader.core.*"/>
</Match>
</FindBugsFilter>
Loading