Skip to content

Commit 10d960f

Browse files
SK-2302 add multi table insert support
1 parent 04d886d commit 10d960f

File tree

73 files changed

+1943
-645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1943
-645
lines changed

common/src/main/java/com/skyflow/errors/ErrorMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public enum ErrorMessage {
1010
ConnectionIdAlreadyInConfigList("%s0 Validation error. ConnectionId is present in an existing config. Specify a connectionId in config."),
1111
ConnectionIdNotInConfigList("%s0 Validation error. ConnectionId is missing from the config. Specify the connectionIds from configs."),
1212
EmptyCredentials("%s0 Validation error. Invalid credentials. Credentials must not be empty."),
13-
13+
TableSpecifiedInRequestAndRecordObject("%s0 Validation error. Table name cannot be specified at both the request and record levels. Please specify the table name in only one place."),
14+
UpsertAtRecordLevel("%s0 Validation error. Upsert specify "),
15+
UpsertTableRequestAtRecordLevel("%s0 Validation error. Table name should be present at each record level when upsert is present at record level."),
16+
UpsertTableRequestAtRequestLevel("%S0 Validation error. Upsert should be present at each record level when table name is present at record level."),
17+
TableNotSpecifiedInRequestAndRecordObject("%s0 Validation error. Table name is missing. Table name should be specified at one place either at the request level or record level. Please specify the table name at one place."),
1418
// Vault config
1519
InvalidVaultId("%s0 Initialization failed. Invalid vault ID. Specify a valid vault ID."),
1620
EmptyVaultId("%s0 Initialization failed. Invalid vault ID. Vault ID must not be empty."),

common/src/main/java/com/skyflow/logs/ErrorLogs.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ public enum ErrorLogs {
143143

144144
UNEXPECTED_ERROR_DURING_BATCH_PROCESSING("Unexpected error occurred during batch processing. Error: %s1"),
145145

146-
PROCESSING_ERROR_RESPONSE("Processing error response.");
147-
146+
PROCESSING_ERROR_RESPONSE("Processing error response."),
147+
TABLE_SPECIFIED_AT_BOTH_PLACE("Invalid %s1 request. Table name cannot be specified at both the request and record levels. Please specify the table name at only one place."),
148+
TABLE_NOT_SPECIFIED_AT_BOTH_PLACE("Invalid %s1 request. Table name is missing. Table name should be specified at one place either at the request level or record level. Please specify the table name at one place."),
149+
UPSERT_TABLE_REQUEST_AT_RECORD_LEVEL("Invalid %s1 request. Table name should be present at each record level when upsert is present at record level."),
150+
UPSERT_TABLE_REQUEST_AT_REQUEST_LEVEL("Invalid %s1 request. Upsert should be present at each record level when table name is present at record level.");
148151
private final String log;
149152

150153
ErrorLogs(String log) {

common/src/main/java/com/skyflow/vault/data/BaseInsertRequest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@ public String getTable() {
1414
return this.builder.table;
1515
}
1616

17-
public ArrayList<HashMap<String, Object>> getValues() {
18-
return this.builder.values;
19-
}
20-
2117
static class BaseInsertRequestBuilder {
2218
protected String table;
23-
protected ArrayList<HashMap<String, Object>> values;
2419
protected String upsert;
25-
2620
protected BaseInsertRequestBuilder() {
2721
}
2822

@@ -31,11 +25,6 @@ public BaseInsertRequestBuilder table(String table) {
3125
return this;
3226
}
3327

34-
public BaseInsertRequestBuilder values(ArrayList<HashMap<String, Object>> values) {
35-
this.values = values;
36-
return this;
37-
}
38-
3928
}
4029
}
4130

v2/src/main/java/com/skyflow/vault/data/InsertRequest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public String getUpsert() {
3434
public Boolean getReturnTokens() {
3535
return this.builder.returnTokens;
3636
}
37-
37+
public ArrayList<HashMap<String, Object>> getValues() {
38+
return this.builder.values;
39+
}
40+
3841
public ArrayList<HashMap<String, Object>> getTokens() {
3942
return this.builder.tokens;
4043
}
@@ -43,6 +46,7 @@ public static final class InsertRequestBuilder extends BaseInsertRequestBuilder
4346
private Boolean homogeneous;
4447
private Boolean continueOnError;
4548
private TokenMode tokenMode;
49+
private ArrayList<HashMap<String, Object>> values;
4650

4751
private ArrayList<HashMap<String, Object>> tokens;
4852
private Boolean returnTokens;
@@ -60,9 +64,8 @@ public InsertRequestBuilder table(String table) {
6064
return this;
6165
}
6266

63-
@Override
6467
public InsertRequestBuilder values(ArrayList<HashMap<String, Object>> values) {
65-
super.values(values);
68+
this.values = values;
6669
return this;
6770
}
6871

v3/src/main/java/com/skyflow/VaultClient.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import com.skyflow.utils.logger.LogUtil;
2121
import com.skyflow.utils.validations.Validations;
2222
import com.skyflow.vault.data.DetokenizeRequest;
23+
import com.skyflow.vault.data.InsertRecord;
24+
2325
import io.github.cdimascio.dotenv.Dotenv;
2426
import io.github.cdimascio.dotenv.DotenvException;
2527
import okhttp3.OkHttpClient;
2628
import okhttp3.Request;
2729

2830
import java.util.ArrayList;
29-
import java.util.HashMap;
3031
import java.util.List;
3132

3233

@@ -132,17 +133,41 @@ protected void updateExecutorInHTTP() {
132133
apiClientBuilder.httpClient(httpClient);
133134
}
134135

135-
protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) throws SkyflowException {
136-
List<HashMap<String, Object>> values = request.getValues();
136+
protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) {
137+
ArrayList<InsertRecord> values = request.getRecords();
137138
List<InsertRecordData> insertRecordDataList = new ArrayList<>();
138-
for (HashMap<String, Object> value : values) {
139-
InsertRecordData data = InsertRecordData.builder().data(value).build();
140-
insertRecordDataList.add(data);
139+
for (InsertRecord value : values) {
140+
InsertRecordData.Builder data = InsertRecordData.builder();
141+
data.data(value.getData());
142+
if (value.getTable() != null && !value.getTable().isEmpty()){
143+
data.tableName(value.getTable());
144+
}
145+
if (value.getUpsert() != null && !value.getUpsert().isEmpty()){
146+
if (value.getUpsertType() != null) {
147+
EnumUpdateType updateType = null;
148+
if (request.getUpsertType() == UpdateType.REPLACE) {
149+
updateType = EnumUpdateType.REPLACE;
150+
} else if (request.getUpsertType() == UpdateType.UPDATE) {
151+
updateType = EnumUpdateType.UPDATE;
152+
}
153+
Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).updateType(updateType).build();
154+
data.upsert(upsert);
155+
} else {
156+
Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).build();
157+
data.upsert(upsert);
158+
}
159+
}
160+
insertRecordDataList.add(data.build());
141161
}
162+
142163
InsertRequest.Builder builder = InsertRequest.builder()
143164
.vaultId(config.getVaultId())
144-
.records(insertRecordDataList)
145-
.tableName(request.getTable());
165+
.records(insertRecordDataList);
166+
167+
if (request.getTable() != null && !request.getTable().isEmpty()){
168+
builder.tableName(request.getTable());
169+
}
170+
146171
if (request.getUpsert() != null && !request.getUpsert().isEmpty()) {
147172
if (request.getUpsertType() != null) {
148173
EnumUpdateType updateType = null;

v3/src/main/java/com/skyflow/generated/rest/ApiClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55

66
import com.skyflow.generated.rest.core.ClientOptions;
77
import com.skyflow.generated.rest.core.Suppliers;
8+
import com.skyflow.generated.rest.resources.records.RecordsClient;
89
import com.skyflow.generated.rest.resources.recordservice.RecordserviceClient;
9-
1010
import java.util.function.Supplier;
1111

1212
public class ApiClient {
1313
protected final ClientOptions clientOptions;
1414

15+
protected final Supplier<RecordsClient> recordsClient;
16+
1517
protected final Supplier<RecordserviceClient> recordserviceClient;
1618

1719
public ApiClient(ClientOptions clientOptions) {
1820
this.clientOptions = clientOptions;
21+
this.recordsClient = Suppliers.memoize(() -> new RecordsClient(clientOptions));
1922
this.recordserviceClient = Suppliers.memoize(() -> new RecordserviceClient(clientOptions));
2023
}
2124

25+
public RecordsClient records() {
26+
return this.recordsClient.get();
27+
}
28+
2229
public RecordserviceClient recordservice() {
2330
return this.recordserviceClient.get();
2431
}

v3/src/main/java/com/skyflow/generated/rest/AsyncApiClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55

66
import com.skyflow.generated.rest.core.ClientOptions;
77
import com.skyflow.generated.rest.core.Suppliers;
8+
import com.skyflow.generated.rest.resources.records.AsyncRecordsClient;
89
import com.skyflow.generated.rest.resources.recordservice.AsyncRecordserviceClient;
9-
1010
import java.util.function.Supplier;
1111

1212
public class AsyncApiClient {
1313
protected final ClientOptions clientOptions;
1414

15+
protected final Supplier<AsyncRecordsClient> recordsClient;
16+
1517
protected final Supplier<AsyncRecordserviceClient> recordserviceClient;
1618

1719
public AsyncApiClient(ClientOptions clientOptions) {
1820
this.clientOptions = clientOptions;
21+
this.recordsClient = Suppliers.memoize(() -> new AsyncRecordsClient(clientOptions));
1922
this.recordserviceClient = Suppliers.memoize(() -> new AsyncRecordserviceClient(clientOptions));
2023
}
2124

25+
public AsyncRecordsClient records() {
26+
return this.recordsClient.get();
27+
}
28+
2229
public AsyncRecordserviceClient recordservice() {
2330
return this.recordserviceClient.get();
2431
}

v3/src/main/java/com/skyflow/generated/rest/core/ApiClientApiException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
*/
44
package com.skyflow.generated.rest.core;
55

6-
import okhttp3.Response;
7-
86
import java.util.ArrayList;
97
import java.util.HashMap;
108
import java.util.List;
119
import java.util.Map;
10+
import okhttp3.Response;
1211

1312
/**
1413
* This exception type will be thrown for any non-2XX API responses.
@@ -66,7 +65,7 @@ public Map<String, List<String>> headers() {
6665
return this.headers;
6766
}
6867

69-
@Override
68+
@java.lang.Override
7069
public String toString() {
7170
return "ApiClientApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: " + body
7271
+ "}";

v3/src/main/java/com/skyflow/generated/rest/core/ApiClientHttpResponse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
*/
44
package com.skyflow.generated.rest.core;
55

6-
import okhttp3.Response;
7-
86
import java.util.ArrayList;
97
import java.util.HashMap;
108
import java.util.List;
119
import java.util.Map;
10+
import okhttp3.Response;
1211

1312
public final class ApiClientHttpResponse<T> {
1413

v3/src/main/java/com/skyflow/generated/rest/core/ClientOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
*/
44
package com.skyflow.generated.rest.core;
55

6-
import okhttp3.OkHttpClient;
7-
86
import java.util.HashMap;
97
import java.util.Map;
108
import java.util.Optional;
119
import java.util.concurrent.TimeUnit;
1210
import java.util.function.Supplier;
11+
import okhttp3.OkHttpClient;
1312

1413
public final class ClientOptions {
1514
private final Environment environment;
@@ -35,7 +34,7 @@ private ClientOptions(
3534
{
3635
put("X-Fern-Language", "JAVA");
3736
put("X-Fern-SDK-Name", "com.skyflow.fern:api-sdk");
38-
put("X-Fern-SDK-Version", "0.0.275");
37+
put("X-Fern-SDK-Version", "0.0.352");
3938
}
4039
});
4140
this.headerSuppliers = headerSuppliers;

0 commit comments

Comments
 (0)