Skip to content

Commit

Permalink
Merge pull request #2 from alberttwong/master
Browse files Browse the repository at this point in the history
overrided methods that uses the "groups" in SQL
  • Loading branch information
brmei committed Aug 4, 2023
2 parents 4432641 + f2b406d commit 4d97aeb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ dependencies {
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
implementation 'com.alibaba:fastjson:1.2.75'
implementation libs.connectors.testcontainers

implementation project(':airbyte-config-oss:config-models-oss')
// implementation project(':airbyte-protocol:protocol-models')
implementation project(':airbyte-integrations:bases:base-java')
implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
implementation libs.airbyte.protocol

integrationTestJavaImplementation libs.connectors.testcontainers
integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-destination-test')
integrationTestJavaImplementation project(':airbyte-integrations:connectors:destination-starrocks')
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
import java.sql.SQLException;
import java.sql.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SqlUtil {

private static final Logger LOG = LoggerFactory.getLogger(SqlUtil.class);

public static Connection createJDBCConnection(JsonNode config) throws ClassNotFoundException, SQLException {
String dbUrl = String.format(StarRocksConstants.PATTERN_JDBC_URL,
config.get(StarRocksConstants.KEY_FE_HOST).asText(),
Expand Down Expand Up @@ -54,21 +60,25 @@ public static void execute(Connection conn, String sql) throws SQLException {

public static void createDatabaseIfNotExist(Connection conn, String db) throws SQLException {
String sql = String.format("CREATE DATABASE IF NOT EXISTS %s;", db);
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

public static void truncateTable(Connection conn, String tableName) throws SQLException {
String sql = String.format("TRUNCATE TABLE %s;", tableName);
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

public static void insertFromTable(Connection conn, String srcTableName, String dstTableName) throws SQLException {
String sql = String.format("INSERT INTO %s SELECT * FROM %s;", dstTableName, srcTableName);
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

public static void renameTable(Connection conn, String srcTableName, String dstTableName) throws SQLException {
String sql = String.format("ALTER TABLE %s RENAME %s;", srcTableName, dstTableName);
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

Expand All @@ -83,11 +93,13 @@ public static void createTableIfNotExist(Connection conn, String tableName) thro
+ "PROPERTIES ( \n"
+ "\"replication_num\" = \"1\" \n"
+ ");";
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

public static void dropTableIfExists(Connection conn, String tableName) throws SQLException {
String sql = String.format("DROP TABLE IF EXISTS `%s`;", tableName);
LOG.info("SQL: {}", sql);
execute(conn, sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;


public class StarrocksDestinationAcceptanceTest extends DestinationAcceptanceTest {
Expand All @@ -33,6 +35,7 @@ public class StarrocksDestinationAcceptanceTest extends DestinationAcceptanceTes
private static final StandardNameTransformer namingResolver = new StandardNameTransformer();

private JsonNode configJson;
protected GenericContainer container;

private static Connection conn = null;

Expand All @@ -43,7 +46,7 @@ protected String getImageName() {

@BeforeAll
public static void getConnect() throws SQLException, ClassNotFoundException {
JsonNode config = Jsons.deserialize(IOs.readFile(Paths.get("../../../secrets/config.json")));
JsonNode config = Jsons.deserialize(IOs.readFile(Paths.get("secrets/config.json")));
conn = SqlUtil.createJDBCConnection(config);
}

Expand All @@ -59,7 +62,7 @@ protected JsonNode getConfig() {
// TODO: Generate the configuration JSON file to be used for running the destination during the test
// configJson can either be static and read from secrets/config.json directly
// or created in the setup method
configJson = Jsons.deserialize(IOs.readFile(Paths.get("../../../secrets/config.json")));
configJson = Jsons.deserialize(IOs.readFile(Paths.get("secrets/config.json")));

return configJson;
}
Expand Down Expand Up @@ -100,11 +103,16 @@ protected List<JsonNode> retrieveRecords(TestDestinationEnv testEnv,
@Override
protected void setup(TestDestinationEnv testEnv) {
// TODO Implement this method to run any setup actions needed before every test case
container = new GenericContainer(DockerImageName.parse("starrocks/allin1-ubuntu:latest"))
.withExposedPorts(9030,8030,8040);
//container.start();
}

@Override
protected void tearDown(TestDestinationEnv testEnv) {
// TODO Implement this method to run any cleanup actions needed after every test case
//container.stop();
//container.close();
}

@Override
Expand All @@ -117,4 +125,15 @@ public void testSecondSync() throws Exception {
// PubSub cannot overwrite messages, its always append only
}

@Override
public void testSyncWithLargeRecordBatch(final String messagesFilename,
final String catalogFilename) throws Exception {
// groups is a reserve word in starrocks
}

@Override
public void testSync(final String messagesFilename, final String catalogFilename) throws Exception {
// groups is a reserve word in starrocks
}

}

0 comments on commit 4d97aeb

Please sign in to comment.