-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DO NOT MERGE!] SNOW-1176557 Support max lob size to 128MB in client SDK #877
Open
sfc-gh-ggeng
wants to merge
3
commits into
master
Choose a base branch
from
ggeng_SNOW-1176557-max_lob_size
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
.../java/net/snowflake/ingest/streaming/example/SnowflakeStreamingIngestLargeLobExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2021 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
package net.snowflake.ingest.streaming.example; | ||
|
||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import net.snowflake.client.jdbc.internal.apache.tika.utils.StringUtils; | ||
import net.snowflake.ingest.streaming.InsertValidationResponse; | ||
import net.snowflake.ingest.streaming.OpenChannelRequest; | ||
import net.snowflake.ingest.streaming.SnowflakeStreamingIngestChannel; | ||
import net.snowflake.ingest.streaming.SnowflakeStreamingIngestClient; | ||
import net.snowflake.ingest.streaming.SnowflakeStreamingIngestClientFactory; | ||
|
||
/** | ||
* Example on how to use the Streaming Ingest client APIs. | ||
* | ||
* <p>Please read the README.md file for detailed steps | ||
*/ | ||
public class SnowflakeStreamingIngestLargeLobExample { | ||
// Please follow the example in profile_streaming.json.example to see the required properties, or | ||
// if you have already set up profile.json with Snowpipe before, all you need is to add the "role" | ||
// property. If the "role" is not specified, the default user role will be applied. | ||
private static String PROFILE_PATH = "profile.json"; | ||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
public static void main(String[] args) throws Exception { | ||
Properties props = new Properties(); | ||
Iterator<Map.Entry<String, JsonNode>> propIt = | ||
mapper.readTree(new String(Files.readAllBytes(Paths.get(PROFILE_PATH)))).fields(); | ||
while (propIt.hasNext()) { | ||
Map.Entry<String, JsonNode> prop = propIt.next(); | ||
props.put(prop.getKey(), prop.getValue().asText()); | ||
} | ||
|
||
// Create a streaming ingest client | ||
try (SnowflakeStreamingIngestClient client = | ||
SnowflakeStreamingIngestClientFactory.builder("MY_CLIENT").setProperties(props).build()) { | ||
|
||
// Create an open channel request on table MY_TABLE, note that the corresponding | ||
// db/schema/table needs to be present | ||
// Example: create or replace table MY_TABLE(c1 number); | ||
OpenChannelRequest request1 = | ||
OpenChannelRequest.builder("MY_CHANNEL") | ||
.setDBName("MY_DATABASE") | ||
.setSchemaName("MY_SCHEMA") | ||
.setTableName("MY_TABLE") | ||
.setOnErrorOption( | ||
OpenChannelRequest.OnErrorOption.CONTINUE) // Another ON_ERROR option is ABORT | ||
.build(); | ||
|
||
// Open a streaming ingest channel from the given client | ||
SnowflakeStreamingIngestChannel channel1 = client.openChannel(request1); | ||
|
||
// Insert rows into the channel (Using insertRows API) | ||
final int totalRowsInTable = 10; | ||
for (int val = 0; val < totalRowsInTable; val++) { | ||
Map<String, Object> row = new HashMap<>(); | ||
|
||
// large columns corresponds to the column name in table | ||
row.put("c1", StringUtils.repeat("a", 127 * 1024 * 1024) + val); | ||
row.put("c2", new byte[60 * 1024 * 1024]); | ||
row.put("c3", "{\"a\":\"" + StringUtils.repeat("a", 127 * 1024 * 1024) + "\"}"); | ||
row.put("c4", "{\"a\":\"" + StringUtils.repeat("a", 127 * 1024 * 1024) + "\"}"); | ||
|
||
// Insert the row with the current offset_token | ||
InsertValidationResponse response = channel1.insertRow(row, String.valueOf(val)); | ||
if (response.hasErrors()) { | ||
// Simply throw if there is an exception, or you can do whatever you want with the | ||
// erroneous row | ||
throw response.getInsertErrors().get(0).getException(); | ||
} | ||
} | ||
|
||
// If needed, you can check the offset_token registered in Snowflake to make sure everything | ||
// is committed | ||
final int expectedOffsetTokenInSnowflake = totalRowsInTable - 1; // 0 based offset_token | ||
final int maxRetries = 10; | ||
int retryCount = 0; | ||
|
||
do { | ||
String offsetTokenFromSnowflake = channel1.getLatestCommittedOffsetToken(); | ||
if (offsetTokenFromSnowflake != null | ||
&& offsetTokenFromSnowflake.equals(String.valueOf(expectedOffsetTokenInSnowflake))) { | ||
System.out.println("SUCCESSFULLY inserted " + totalRowsInTable + " rows"); | ||
break; | ||
} | ||
retryCount++; | ||
} while (retryCount < maxRetries); | ||
|
||
// Close the channel, the function internally will make sure everything is committed (or throw | ||
// an exception if there is any issue) | ||
channel1.close().get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sfc-gh-tzhang do you know why in the past we have the parameter here, but the customer can not set it? Is there any explicit reason or just missing implementation? Thanks!