Skip to content

Commit af9b6ba

Browse files
Merge pull request #247 from skyflowapi/beta-release/25.9.4
SK-2306 Beta release/25.9.4
2 parents 04d886d + be6033d commit af9b6ba

File tree

87 files changed

+3151
-839
lines changed

Some content is hidden

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

87 files changed

+3151
-839
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ 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+
UpsertTableRequestAtRecordLevel("%s0 Validation error. Table name should be present at each record level when upsert is present at record level."),
15+
UpsertTableRequestAtRequestLevel("%s0 Validation error. Upsert should be present at each record level when table name is present at record level."),
16+
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."),
1417
// Vault config
1518
InvalidVaultId("%s0 Initialization failed. Invalid vault ID. Specify a valid vault ID."),
1619
EmptyVaultId("%s0 Initialization failed. Invalid vault ID. Vault ID must not be empty."),
@@ -60,6 +63,10 @@ public enum ErrorMessage {
6063
TableKeyError("%s0 Validation error. 'table' key is missing from the payload. Specify a 'table' key."),
6164
EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."),
6265
ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."),
66+
EmptyRecords("%s0 Validation error. 'records' can't be empty. Specify records."),
67+
EmptyKeyInRecords("%s0 Validation error. Invalid key in data in records. Specify a valid key."),
68+
EmptyValueInRecords("%s0 Validation error. Invalid value in records. Specify a valid value."),
69+
RecordsKeyError("%s0 Validation error. 'records' key is missing from the payload. Specify a 'records' key."),
6370
EmptyValues("%s0 Validation error. 'values' can't be empty. Specify values."),
6471
EmptyKeyInValues("%s0 Validation error. Invalid key in values. Specify a valid key."),
6572
EmptyValueInValues("%s0 Validation error. Invalid value in values. Specify a valid value."),
@@ -164,6 +171,7 @@ public enum ErrorMessage {
164171
NullRedactionInTokenGroup("%s0 Validation error. Redaction in TokenGroupRedactions is null or empty. Specify a valid redaction."),
165172

166173
NullTokenGroupNameInTokenGroup("%s0 Validation error. TokenGroupName in TokenGroupRedactions is null or empty. Specify a valid tokenGroupName."),
174+
InvalidRecord("%s0 Validation error. InsertRecord object in the list is invalid. Specify a valid InsertRecord object."),
167175
;
168176
;
169177
private final String message;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public enum ErrorLogs {
5151
EMPTY_TABLE_NAME("Invalid %s1 request. Table name can not be empty."),
5252
VALUES_IS_REQUIRED("Invalid %s1 request. Values are required."),
5353
EMPTY_VALUES("Invalid %s1 request. Values can not be empty."),
54+
RECORDS_IS_REQUIRED("Invalid %s1 request. Records are required."),
55+
EMPTY_RECORDS("Invalid %s1 request. Records can not be empty."),
56+
INVALID_RECORD("Invalid %s1 request. Invalid record. Specify a valid record."),
5457
RECORD_SIZE_EXCEED("Maximum number of records exceeded. The limit is 10000."),
5558
TOKENS_SIZE_EXCEED("Maximum number of tokens exceeded. The limit is 10000."),
5659
EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."),
@@ -143,8 +146,11 @@ public enum ErrorLogs {
143146

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

146-
PROCESSING_ERROR_RESPONSE("Processing error response.");
147-
149+
PROCESSING_ERROR_RESPONSE("Processing error response."),
150+
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."),
151+
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."),
152+
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."),
153+
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.");
148154
private final String log;
149155

150156
ErrorLogs(String log) {

common/src/main/java/com/skyflow/serviceaccount/util/BearerToken.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static V1GetAuthTokenResponse generateBearerTokenFromCredentials(
5959
FileReader reader = new FileReader(String.valueOf(credentialsFile));
6060
JsonObject serviceAccountCredentials = JsonParser.parseReader(reader).getAsJsonObject();
6161
return getBearerTokenFromCredentials(serviceAccountCredentials, context, roles);
62-
} catch (JsonSyntaxException e) {
62+
} catch (JsonSyntaxException | IllegalStateException e) {
6363
LogUtil.printErrorLog(ErrorLogs.INVALID_CREDENTIALS_FILE_FORMAT.getLog());
6464
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseUtils.parameterizedString(
6565
ErrorMessage.FileInvalidJson.getMessage(), credentialsFile.getPath()));
@@ -81,7 +81,7 @@ private static V1GetAuthTokenResponse generateBearerTokenFromCredentialString(
8181
}
8282
JsonObject serviceAccountCredentials = JsonParser.parseString(credentials).getAsJsonObject();
8383
return getBearerTokenFromCredentials(serviceAccountCredentials, context, roles);
84-
} catch (JsonSyntaxException e) {
84+
} catch (JsonSyntaxException | IllegalStateException e) {
8585
LogUtil.printErrorLog(ErrorLogs.INVALID_CREDENTIALS_STRING_FORMAT.getLog());
8686
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
8787
ErrorMessage.CredentialsStringInvalidJson.getMessage());

common/src/main/java/com/skyflow/serviceaccount/util/SignedDataTokens.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static List<SignedDataTokenResponse> generateSignedTokenFromCredentialsF
5656
FileReader reader = new FileReader(String.valueOf(credentialsFile));
5757
JsonObject serviceAccountCredentials = JsonParser.parseReader(reader).getAsJsonObject();
5858
responseToken = generateSignedTokensFromCredentials(serviceAccountCredentials, dataTokens, timeToLive, context);
59-
} catch (JsonSyntaxException e) {
59+
} catch (JsonSyntaxException | IllegalStateException e) {
6060
LogUtil.printErrorLog(ErrorLogs.INVALID_CREDENTIALS_FILE_FORMAT.getLog());
6161
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseUtils.parameterizedString(
6262
ErrorMessage.FileInvalidJson.getMessage(), credentialsFile.getPath()));
@@ -80,7 +80,7 @@ private static List<SignedDataTokenResponse> generateSignedTokensFromCredentials
8080
}
8181
JsonObject serviceAccountCredentials = JsonParser.parseString(credentials).getAsJsonObject();
8282
responseToken = generateSignedTokensFromCredentials(serviceAccountCredentials, dataTokens, timeToLive, context);
83-
} catch (JsonSyntaxException e) {
83+
} catch (JsonSyntaxException | IllegalStateException e) {
8484
LogUtil.printErrorLog(ErrorLogs.INVALID_CREDENTIALS_STRING_FORMAT.getLog());
8585
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
8686
ErrorMessage.CredentialsStringInvalidJson.getMessage());

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

samples/src/main/java/com/example/vault/BulkInsertAsync.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import com.skyflow.config.VaultConfig;
66
import com.skyflow.enums.Env;
77
import com.skyflow.enums.LogLevel;
8+
import com.skyflow.enums.UpdateType;
9+
import com.skyflow.vault.data.InsertRecord;
810
import com.skyflow.vault.data.InsertRequest;
911
import com.skyflow.vault.data.InsertResponse;
1012

1113
import java.util.ArrayList;
1214
import java.util.HashMap;
15+
import java.util.List;
1316
import java.util.concurrent.CompletableFuture;
1417
import java.util.concurrent.CompletionException;
1518

@@ -44,24 +47,38 @@ public static void main(String[] args) {
4447
.build();
4548

4649
// Step 4: Prepare first record for insertion
47-
HashMap<String, Object> record1 = new HashMap<>();
48-
record1.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
49-
record1.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
50+
HashMap<String, Object> recordData1 = new HashMap<>();
51+
recordData1.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
52+
recordData1.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
53+
54+
InsertRecord insertRecord1 = InsertRecord
55+
.builder()
56+
.data(recordData1)
57+
.build();
5058

5159
// Step 5: Prepare second record for insertion
52-
HashMap<String, Object> record2 = new HashMap<>();
53-
record2.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
54-
record2.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
60+
HashMap<String, Object> recordData2 = new HashMap<>();
61+
recordData2.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
62+
recordData2.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
63+
64+
InsertRecord insertRecord2 = InsertRecord
65+
.builder()
66+
.data(recordData2)
67+
.build();
5568

56-
// Step 6: Combine records into a single list
57-
ArrayList<HashMap<String, Object>> values = new ArrayList<>();
58-
values.add(record1);
59-
values.add(record2);
69+
// Step 6: Combine records into a Insert record list
70+
ArrayList<InsertRecord> insertRecords = new ArrayList<>();
71+
insertRecords.add(insertRecord1);
72+
insertRecords.add(insertRecord2);
6073

61-
// Step 7: Build the insert request with table name and values
74+
List<String> upsertColumns = new ArrayList<>();
75+
upsertColumns.add("<YOUR_COLUMN_NAME_1>");
76+
// Step 7: Build the insert request with table name and insertRecords
6277
InsertRequest request = InsertRequest.builder()
6378
.table("<YOUR_TABLE_NAME>")
64-
.values(values)
79+
.upsert(upsertColumns)
80+
.upsertType(UpdateType.REPLACE)
81+
.records(insertRecords)
6582
.build();
6683

6784
// Step 8: Execute the async bulk insert operation and handle response using callbacks

samples/src/main/java/com/example/vault/BulkInsertSync.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import com.skyflow.config.VaultConfig;
66
import com.skyflow.enums.Env;
77
import com.skyflow.enums.LogLevel;
8+
import com.skyflow.enums.UpdateType;
89
import com.skyflow.errors.SkyflowException;
910
import com.skyflow.vault.data.InsertRequest;
1011
import com.skyflow.vault.data.InsertResponse;
1112

1213
import java.util.ArrayList;
1314
import java.util.HashMap;
15+
import java.util.List;
1416

1517
/**
1618
* This sample demonstrates how to perform a synchronous bulk insert operation using the Skyflow Java SDK.
@@ -43,24 +45,39 @@ public static void main(String[] args) {
4345
.build();
4446

4547
// Step 4: Prepare first record for insertion
46-
HashMap<String, Object> record1 = new HashMap<>();
47-
record1.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
48-
record1.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
48+
HashMap<String, Object> recordData1 = new HashMap<>();
49+
recordData1.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
50+
recordData1.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
51+
52+
InsertRecord insertRecord1 = InsertRecord
53+
.builder()
54+
.data(recordData1)
55+
.build();
4956

5057
// Step 5: Prepare second record for insertion
51-
HashMap<String, Object> record2 = new HashMap<>();
52-
record2.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
53-
record2.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
58+
HashMap<String, Object> recordData2 = new HashMap<>();
59+
recordData2.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
60+
recordData2.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
61+
62+
InsertRecord insertRecord2 = InsertRecord
63+
.builder()
64+
.data(recordData2)
65+
.build();
66+
67+
// Step 6: Combine records into a Insert record list
68+
ArrayList<InsertRecord> insertRecords = new ArrayList<>();
69+
insertRecords.add(insertRecord1);
70+
insertRecords.add(insertRecord2);
5471

55-
// Step 6: Combine records into a single list
56-
ArrayList<HashMap<String, Object>> values = new ArrayList<>();
57-
values.add(record1);
58-
values.add(record2);
72+
List<String> upsertColumns = new ArrayList<>();
73+
upsertColumns.add("<YOUR_COLUMN_NAME_1>");
5974

60-
// Step 7: Build the insert request with table name and values
75+
// Step 7: Build the insert request with table name and insertRecords
6176
InsertRequest request = InsertRequest.builder()
6277
.table("<YOUR_TABLE_NAME>")
63-
.values(values)
78+
.upsert(upsertColumns)
79+
.upsertType(UpdateType.REPLACE)
80+
.records(insertRecords)
6481
.build();
6582

6683
// Step 8: Execute the bulk insert operation and print the response
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.example.vault;
2+
3+
import com.skyflow.Skyflow;
4+
import com.skyflow.config.Credentials;
5+
import com.skyflow.config.VaultConfig;
6+
import com.skyflow.enums.Env;
7+
import com.skyflow.enums.LogLevel;
8+
import com.skyflow.enums.UpdateType;
9+
import com.skyflow.vault.data.InsertRecord;
10+
import com.skyflow.vault.data.InsertRequest;
11+
import com.skyflow.vault.data.InsertResponse;
12+
13+
import java.util.ArrayList;
14+
import java.util.HashMap;
15+
import java.util.List;
16+
import java.util.concurrent.CompletableFuture;
17+
import java.util.concurrent.CompletionException;
18+
19+
/**
20+
* This sample demonstrates how to perform an asynchronous bulk insert operation using the Skyflow Java SDK.
21+
* The process involves:
22+
* 1. Setting up credentials and vault configuration
23+
* 2. Creating multiple records to be inserted
24+
* 3. Building and executing an async bulk insert request
25+
* 4. Handling the insert response or errors using CompletableFuture
26+
*/
27+
public class BulkMultiTableInsertAsync {
28+
29+
public static void main(String[] args) {
30+
try {
31+
// Step 1: Initialize credentials with the path to your service account key file
32+
String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
33+
Credentials credentials = new Credentials();
34+
credentials.setPath(filePath);
35+
36+
// Step 2: Configure the vault with required parameters
37+
VaultConfig vaultConfig = new VaultConfig();
38+
vaultConfig.setVaultId("<YOUR_VAULT_ID>");
39+
vaultConfig.setClusterId("<YOUR_CLUSTER_ID>");
40+
vaultConfig.setEnv(Env.PROD);
41+
vaultConfig.setCredentials(credentials);
42+
43+
// Step 3: Create Skyflow client instance with error logging
44+
Skyflow skyflowClient = Skyflow.builder()
45+
.setLogLevel(LogLevel.ERROR)
46+
.addVaultConfig(vaultConfig)
47+
.build();
48+
49+
// Step 4: Prepare first record for insertion
50+
HashMap<String, Object> recordData1 = new HashMap<>();
51+
rerecordData1cord1.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
52+
recordData1.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
53+
54+
List<String> upsertColumns = new ArrayList<>();
55+
upsertColumns.add("<YOUR_COLUMN_NAME_1>");
56+
57+
InsertRecord insertRecord1 = InsertRecord
58+
.builder()
59+
.data(recordData1)
60+
.table("<YOUR_TABLE_NAME>")
61+
.upsert(upsertColumns)
62+
.upsertType(UpsertType.UPDATE)
63+
.build();
64+
65+
// Step 5: Prepare second record for insertion
66+
HashMap<String, Object> recordData2 = new HashMap<>();
67+
recordData2.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");
68+
recordData2.put("<YOUR_COLUMN_NAME_2>", "<YOUR_VALUE_1>");
69+
70+
InsertRecord insertRecord2 = InsertRecord
71+
.builder()
72+
.data(recordData2)
73+
.table("<YOUR_TABLE_NAME>")
74+
.build();
75+
76+
// Step 6: Combine records into a Insert record list
77+
ArrayList<InsertRecord> insertRecords = new ArrayList<>();
78+
insertRecords.add(insertRecord1);
79+
insertRecords.add(insertRecord2);
80+
81+
// Step 7: Build the insert request with table name and values
82+
InsertRequest request = InsertRequest.builder()
83+
.records(insertRecords)
84+
.build();
85+
86+
// Step 8: Execute the async bulk insert operation and handle response using callbacks
87+
CompletableFuture<InsertResponse> future = skyflowClient.vault().bulkInsertAsync(request);
88+
// Add success and error callbacks
89+
future.thenAccept(response -> {
90+
System.out.println("Async bulk insert resolved with response:\t" + response);
91+
}).exceptionally(throwable -> {
92+
System.err.println("Async bulk insert rejected with error:\t" + throwable.getMessage());
93+
throw new CompletionException(throwable);
94+
});
95+
} catch (Exception e) {
96+
// Step 9: Handle any synchronous errors that occur during setup
97+
System.err.println("Error in Skyflow operations:\t" + e.getMessage());
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)