Skip to content

Commit

Permalink
Added internalId for tables without PK (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Adalbert Makarovych <[email protected]>
  • Loading branch information
AdalbertMemSQL and Adalbert Makarovych authored Nov 6, 2024
1 parent 6214533 commit 229a6d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gradle jar
3. Run the Jar

```
java -jar build/libs/singlestore-fivetran-connector-0.0.2.jar
java -jar build/libs/singlestore-fivetran-connector-0.0.3.jar
```

## Steps for running Java tests
Expand Down Expand Up @@ -108,7 +108,7 @@ CREATE TABLE t(a INT PRIMARY KEY, b INT);
wget -O src/main/proto/common.proto https://raw.githubusercontent.com/fivetran/fivetran_sdk/production/common.proto
wget -O src/main/proto/connector_sdk.proto https://raw.githubusercontent.com/fivetran/fivetran_sdk/production/connector_sdk.proto
gradle jar
java -jar build/libs/singlestore-fivetran-connector-0.0.2.jar
java -jar build/libs/singlestore-fivetran-connector-0.0.3.jar
```

6. Update the `./tester/configuration.json` file with your credentials
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
mavenCentral()
}

version = '0.0.2'
version = '0.0.3'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public SchemaList getSchema() throws Exception {
}
}

// If table doesn't have PK - add an internal id instead
if (primaryKeyColumns.isEmpty()) {
Column.Builder internalId = Column.newBuilder()
.setName("InternalId")
.setType(DataType.BINARY)
.setPrimaryKey(true);
columns.add(internalId.build());
}

return SchemaList.newBuilder()
.addSchemas(
Schema.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.singlestore.fivetran.connector;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.ImmutableMap;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import fivetran_sdk.Column;
Expand All @@ -11,12 +17,6 @@
import fivetran_sdk.ValueType;
import java.sql.SQLException;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand All @@ -27,8 +27,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableMap;

public class SingleStoreConnectionTest extends IntegrationTestBase {

@Test
Expand Down Expand Up @@ -150,7 +148,7 @@ public void getSchema() throws Exception {
assertEquals("getSchema", table.getName());

List<Column> columns = table.getColumnsList();
assertEquals(44, columns.size());
assertEquals(45, columns.size());

List<String> columnNames = Arrays.asList(
"boolColumn",
Expand Down Expand Up @@ -196,7 +194,8 @@ public void getSchema() throws Exception {
"geographyColumn",
"geographypointColumn",
"vectorColumn",
"bsonColumn"
"bsonColumn",
"InternalId"
);

List<DecimalParams> decimalParameters = Arrays.asList(
Expand Down Expand Up @@ -255,6 +254,7 @@ public void getSchema() throws Exception {
DecimalParams.newBuilder().build(),
DecimalParams.newBuilder().build(),
DecimalParams.newBuilder().build(),
DecimalParams.newBuilder().build(),
DecimalParams.newBuilder().build()
);

Expand Down Expand Up @@ -302,6 +302,7 @@ public void getSchema() throws Exception {
DataType.STRING,
DataType.STRING,
DataType.BINARY,
DataType.BINARY,
DataType.BINARY
);

Expand All @@ -310,7 +311,7 @@ public void getSchema() throws Exception {
assertEquals(columnNames.get(i), column.getName());
assertEquals(decimalParameters.get(i), column.getDecimal());
assertEquals(types.get(i), column.getType());
assertFalse(column.getPrimaryKey());
assertEquals(column.getName().equals("InternalId"), column.getPrimaryKey());
}
}

Expand Down Expand Up @@ -868,7 +869,7 @@ public void observeVectorJson() throws Exception {
assertEquals("observeVectorJson", table.getName());

List<Column> columns = table.getColumnsList();
assertEquals(1, columns.size());
assertEquals(2, columns.size());

Column column = columns.get(0);
assertEquals("a", column.getName());
Expand Down

0 comments on commit 229a6d5

Please sign in to comment.