Skip to content

Commit

Permalink
Merge branch 'master' into feat/data-loader/import-data-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ypeckstadt authored Dec 19, 2024
2 parents f3fc40d + 05251a2 commit f20772c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Execute Gradle 'integrationTestJdbc' task
run: ./gradlew integrationTestJdbc ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:mariadb://localhost:3306 ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}

- name: Upload Gradle test reports
if: always()
Expand Down Expand Up @@ -1496,7 +1496,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Execute Gradle 'integrationTestJdbc' task
run: ./gradlew integrationTestJdbc ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:mariadb://localhost:3306 ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}

- name: Upload Gradle test reports
if: always()
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ subprojects {
sqlserverDriverVersion = '11.2.3.jre8'
sqliteDriverVersion = '3.47.1.0'
yugabyteDriverVersion = '42.7.3-yb-2'
mariadDbDriverVersion = '3.5.1'
picocliVersion = '4.7.6'
commonsTextVersion = '1.12.0'
junitVersion = '5.11.3'
commonsTextVersion = '1.13.0'
junitVersion = '5.11.4'
commonsLangVersion = '3.17.0'
assertjVersion = '3.26.3'
mockitoVersion = '4.11.0'
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ dependencies {
implementation "com.microsoft.sqlserver:mssql-jdbc:${sqlserverDriverVersion}"
implementation "org.xerial:sqlite-jdbc:${sqliteDriverVersion}"
implementation "com.yugabyte:jdbc-yugabytedb:${yugabyteDriverVersion}"
implementation "org.mariadb.jdbc:mariadb-java-client:${mariadDbDriverVersion}"
implementation "org.apache.commons:commons-text:${commonsTextVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static RdbEngineStrategy create(JdbcConfig config) {
return new RdbEngineSqlite();
} else if (jdbcUrl.startsWith("jdbc:yugabytedb:")) {
return new RdbEngineYugabyte();
} else if (jdbcUrl.startsWith("jdbc:mariadb:")) {
return new RdbEngineMariaDB();
} else {
throw new IllegalArgumentException(
CoreError.JDBC_RDB_ENGINE_NOT_SUPPORTED.buildMessage(jdbcUrl));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.io.DataType;
import java.sql.Driver;
import java.sql.JDBCType;

class RdbEngineMariaDB extends RdbEngineMysql {
@Override
public Driver getDriver() {
return new org.mariadb.jdbc.Driver();
}

@Override
public DataType getDataTypeForScalarDb(
JDBCType type, String typeName, int columnSize, int digits, String columnDescription) {
if (type == JDBCType.BOOLEAN) {
// MariaDB JDBC driver maps TINYINT(1) type as a BOOLEAN JDBC type which differs from the
// MySQL driver which maps it to a BIT type.
return DataType.BOOLEAN;
} else {
return super.getDataTypeForScalarDb(type, typeName, columnSize, digits, columnDescription);
}
}
}
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 f20772c

Please sign in to comment.