Skip to content
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

SNOW-887071 : Added connection property to disable PUT/GET command #1523

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public abstract class SFBaseSession {
// Whether enable returning timestamp with timezone as data type
private boolean enableReturnTimestampWithTimeZone = true;

// Server side value
private boolean jdbcEnablePutGet = true;

// Connection string setting
private boolean enablePutGet = true;

private Map<String, Object> commonParameters;

protected SFBaseSession(SFConnectionHandler sfConnectionHandler) {
Expand Down Expand Up @@ -682,6 +688,22 @@ public void setQueryContextCacheSize(int queryContextCacheSize) {
this.queryContextCacheSize = queryContextCacheSize;
}

public boolean getJdbcEnablePutGet() {
return jdbcEnablePutGet;
}

public void setJdbcEnablePutGet(boolean jdbcEnablePutGet) {
this.jdbcEnablePutGet = jdbcEnablePutGet;
}

public boolean getEnablePutGet() {
sfc-gh-igarish marked this conversation as resolved.
Show resolved Hide resolved
return enablePutGet;
}

public boolean putEnablePutGet(boolean enablePutGet) {
return this.enablePutGet = enablePutGet;
}

public int getClientResultChunkSize() {
return clientResultChunkSize;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro
}
break;

case ENABLE_PUT_GET:
if (propertyValue != null) {
putEnablePutGet(getBooleanValue(propertyValue));
}
break;

default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public enum SFSessionProperty {

MAX_HTTP_RETRIES("maxHttpRetries", false, Integer.class),

ENABLE_PUT_GET("enablePutGet", false, Boolean.class),

PUT_GET_MAX_RETRIES("putGetMaxRetries", false, Integer.class);

// property key in string
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/snowflake/client/core/SFStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ private SFBaseResultSet executeQuery(

// snowflake specific client side commands
if (isFileTransfer(trimmedSql)) {
// Server side value or Connection string value is false then disable the PUT/GET command
if ((session != null && !(session.getJdbcEnablePutGet() && session.getEnablePutGet()))) {
// PUT/GET command disabled either on server side or in the client connection string
logger.debug("Executing file transfer locally is disabled: {}", sql);
throw new SnowflakeSQLException("File transfers have been disabled.");
}

// PUT/GET command
logger.debug("Executing file transfer locally: {}", sql);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class SessionUtil {
public static final String CLIENT_MEMORY_LIMIT_JVM = "net.snowflake.jdbc.clientMemoryLimit";
public static final String CLIENT_MEMORY_LIMIT = "CLIENT_MEMORY_LIMIT";
public static final String QUERY_CONTEXT_CACHE_SIZE = "QUERY_CONTEXT_CACHE_SIZE";
public static final String JDBC_ENABLE_PUT_GET = "JDBC_ENABLE_PUT_GET";
public static final String CLIENT_PREFETCH_THREADS_JVM =
"net.snowflake.jdbc.clientPrefetchThreads";
public static final String CLIENT_PREFETCH_THREADS = "CLIENT_PREFETCH_THREADS";
Expand Down Expand Up @@ -1547,6 +1548,10 @@ static void updateSfDriverParamValues(Map<String, Object> parameters, SFBaseSess
if (session != null) {
session.setQueryContextCacheSize((int) entry.getValue());
}
} else if (JDBC_ENABLE_PUT_GET.equalsIgnoreCase(entry.getKey())) {
if (session != null) {
session.setJdbcEnablePutGet(SFLoginInput.getBooleanValue(entry.getValue()));
}
} else {
if (session != null) {
session.setOtherParameter(entry.getKey(), entry.getValue());
Expand Down