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-1947501: Create AST API in JDBC #2112

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public abstract SFBaseResultSet execute(
throws SQLException, SFException;

/**
* Executes the given SQL string.
* Executes the given SQL string, with dataframe AST parameter.
*
* @param sql The SQL string to execute, synchronously.
* @param dataframeAst ...
* @param dataframeAst encoded string representation of the dataframe AST
* @param parametersBinding parameters to bind
* @param caller the JDBC interface method that called this method, if any
* @param execTimeData OOB telemetry object to record timings
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/net/snowflake/client/core/SFStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void sanityCheckQuery(String sql) throws SQLException {
* Execute SQL query with an option for describe only
*
* @param sql sql statement
* @param dataframeAst ...
* @param dataframeAst encoded string representation of the dataframe AST
* @param describeOnly true if describe only
* @return query result set
* @throws SQLException if connection is already closed
Expand All @@ -130,23 +130,25 @@ private SFBaseResultSet executeQuery(
CallingMethod caller,
ExecTimeTelemetryData execTimeData)
throws SQLException, SFException {
sanityCheckQuery(sql);
if (dataframeAst == null) {
sanityCheckQuery(sql);

String trimmedSql = sql.trim();

// 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.");
}

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

// 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.");
return executeFileTransfer(sql);
}

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

return executeFileTransfer(sql);
}

// NOTE: It is intentional two describeOnly parameters are specified.
Expand Down Expand Up @@ -191,6 +193,7 @@ public SFPreparedStatementMetaData describe(String sql) throws SFException, SQLE
* <p>
*
* @param sql sql statement
* @param dataframeAst encoded string representation of the dataframe AST
* @param parameterBindings binding information
* @param describeOnly true if just showing result set metadata
* @param internal true if internal command not showing up in the history
Expand Down Expand Up @@ -321,6 +324,7 @@ public Void call() throws SQLException {
* A helper method to build URL and submit the SQL to snowflake for exec
*
* @param sql sql statement
* @param dataframeAst encoded string representation of the dataframe AST
* @param mediaType media type
* @param bindValues map of binding values
* @param describeOnly whether only show the result set metadata
Expand Down Expand Up @@ -767,7 +771,7 @@ private void cancelHelper(String sql, String mediaType, CancellationReason cance
* Execute sql
*
* @param sql sql statement.
* @param dataframeAst ...
* @param dataframeAst encoded string representation of the dataframe AST
* @param asyncExec is async exec
* @param parametersBinding parameters to bind
* @param caller the JDBC interface method that called this method, if any
Expand All @@ -787,7 +791,10 @@ public SFBaseResultSet execute(
throws SQLException, SFException {
TelemetryService.getInstance().updateContext(session.getSnowflakeConnectionString());

// todo: if (dataframeAst == null)
if (dataframeAst != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of return early, just use if statement to skip all sql functions, then we can benefit from feature changes related to non-sql part.

return executeQuery(sql, dataframeAst, parametersBinding, false, asyncExec, caller, execTimeData);
}

sanityCheckQuery(sql);

session.injectedDelay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ public ResultSet executeAsyncQuery(String sql) throws SQLException {
return rs;
}

// todo: add doc
/**
* Execute SQL query asynchronously
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asynchronously ?

*
* @param dataframeAst encoded string representation of the dataframe AST
* @return ResultSet
* @throws SQLException if @link{#executeQueryInternal(String, Map)} throws an exception
*/
public ResultSet executeDataframeAst(String dataframeAst) throws SQLException {
ExecTimeTelemetryData execTimeData =
new ExecTimeTelemetryData("ResultSet Statement.executeQuery(String)", this.batchID);
Expand Down Expand Up @@ -284,6 +290,7 @@ private void setQueryIdWhenValidOrNull(String queryId) {
* Internal method for executing a query with bindings accepted.
*
* @param sql sql statement
* @param dataframeAst encoded string representation of the dataframe AST
* @param asyncExec execute query asynchronously
* @param parameterBindings parameters bindings
* @return query result set
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/MockConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ public SFBaseResultSet execute(
return new MockJsonResultSet(mockedResponse, sfSession);
}

@Override
public SFBaseResultSet execute(
String sql,
String dataframeAst,
Map<String, ParameterBindingDTO> parametersBinding,
CallingMethod caller,
ExecTimeTelemetryData execTimeData)
throws SQLException, SFException {
return new MockJsonResultSet(mockedResponse, sfSession);
}

@Override
public SFBaseResultSet asyncExecute(
String sql,
Expand Down
Loading