Package net.snowflake.client.core
Class SFStatement
- java.lang.Object
-
- net.snowflake.client.core.SFBaseStatement
-
- net.snowflake.client.core.SFStatement
-
public class SFStatement extends SFBaseStatement
Snowflake statement
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.snowflake.client.core.SFBaseStatement
SFBaseStatement.CallingMethod
-
-
Field Summary
-
Fields inherited from class net.snowflake.client.core.SFBaseStatement
MAX_STATEMENT_PARAMETERS, queryTimeout, statementParametersMap
-
-
Constructor Summary
Constructors Constructor Description SFStatement(SFSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SFBaseResultSet
asyncExecute(String sql, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData)
Execute sql asynchronously.void
cancel()
Aborts the statement.void
cancel(CancellationReason cancellationReason)
Aborts the statement.void
close()
Closes the statement.SFPreparedStatementMetaData
describe(String sql)
Describe a statementSFBaseResultSet
execute(String sql, boolean asyncExec, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData)
Execute sqlSFBaseResultSet
execute(String sql, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData)
Executes the given SQL string.Object
executeHelper(String sql, String mediaType, Map<String,ParameterBindingDTO> bindValues, boolean describeOnly, boolean internal, boolean asyncExec, ExecTimeTelemetryData execTimeData)
A helper method to build URL and submit the SQL to snowflake for execString[]
getChildQueryIds(String queryID)
Return an array of child query ID for the given query ID.long
getConservativeMemoryLimit()
int
getConservativePrefetchThreads()
boolean
getMoreResults()
boolean
getMoreResults(int current)
Sets the result set to the next one, if available.SFBaseResultSet
getResultSet()
Retrieves the current result as a ResultSet, if any.SFBaseSession
getSFBaseSession()
Returns the SFBaseSession associated with this SFBaseStatement.boolean
hasChildren()
If this is a multi-statement, i.e., has child results.-
Methods inherited from class net.snowflake.client.core.SFBaseStatement
addProperty, executeSetProperty, getStatementParameters, isFileTransfer
-
-
-
-
Constructor Detail
-
SFStatement
public SFStatement(SFSession session)
-
-
Method Detail
-
describe
public SFPreparedStatementMetaData describe(String sql) throws SFException, SQLException
Describe a statement- Specified by:
describe
in classSFBaseStatement
- Parameters:
sql
- statement- Returns:
- metadata of statement including result set metadata and binding information
- Throws:
SQLException
- if connection is already closedSFException
- if result set is null
-
executeHelper
public Object executeHelper(String sql, String mediaType, Map<String,ParameterBindingDTO> bindValues, boolean describeOnly, boolean internal, boolean asyncExec, ExecTimeTelemetryData execTimeData) throws SnowflakeSQLException, SFException
A helper method to build URL and submit the SQL to snowflake for exec- Parameters:
sql
- sql statementmediaType
- media typebindValues
- map of binding valuesdescribeOnly
- whether only show the result set metadatainternal
- run internal query not showing up in history- Returns:
- raw json response
- Throws:
SFException
- if query is canceledSnowflakeSQLException
- if query is already running
-
getConservativePrefetchThreads
public int getConservativePrefetchThreads()
- Specified by:
getConservativePrefetchThreads
in classSFBaseStatement
- Returns:
- conservative prefetch threads before fetching results
-
getConservativeMemoryLimit
public long getConservativeMemoryLimit()
- Specified by:
getConservativeMemoryLimit
in classSFBaseStatement
- Returns:
- conservative memory limit before fetching results
-
getChildQueryIds
public String[] getChildQueryIds(String queryID) throws SQLException
Return an array of child query ID for the given query ID.If the given query ID is for a multiple statements query, it returns an array of its child statements, otherwise, it returns an array to include the given query ID.
- Specified by:
getChildQueryIds
in classSFBaseStatement
- Parameters:
queryID
- The given query ID- Returns:
- An array of child query IDs
- Throws:
SQLException
- If the query is running or the corresponding query is FAILED.
-
execute
public SFBaseResultSet execute(String sql, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData) throws SQLException, SFException
Description copied from class:SFBaseStatement
Executes the given SQL string.- Specified by:
execute
in classSFBaseStatement
- Parameters:
sql
- The SQL string to execute, synchronously.parametersBinding
- parameters to bindcaller
- the JDBC interface method that called this method, if anyexecTimeData
- OOB telemetry object to record timings- Returns:
- whether there is result set or not
- Throws:
SQLException
- if failed to execute sqlSFException
- exception raised from Snowflake components
-
execute
public SFBaseResultSet execute(String sql, boolean asyncExec, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData) throws SQLException, SFException
Execute sql- Parameters:
sql
- sql statement.parametersBinding
- parameters to bindcaller
- the JDBC interface method that called this method, if any- Returns:
- whether there is result set or not
- Throws:
SQLException
- if failed to execute sqlSFException
- exception raised from Snowflake componentsSQLException
- if SQL error occurs
-
close
public void close()
Description copied from class:SFBaseStatement
Closes the statement. Open result sets are closed, connections are terminated, state is cleared, etc.- Specified by:
close
in classSFBaseStatement
-
cancel
public void cancel() throws SFException, SQLException
Description copied from class:SFBaseStatement
Aborts the statement.- Specified by:
cancel
in classSFBaseStatement
- Throws:
SFException
- if the statement is already closed.SQLException
- if there are server-side errors from trying to abort.
-
cancel
public void cancel(CancellationReason cancellationReason) throws SFException, SQLException
Description copied from class:SFBaseStatement
Aborts the statement.- Overrides:
cancel
in classSFBaseStatement
- Parameters:
cancellationReason
- reason for the cancellation- Throws:
SFException
- if the statement is already closed.SQLException
- if there are server-side errors from trying to abort.
-
getSFBaseSession
public SFBaseSession getSFBaseSession()
Description copied from class:SFBaseStatement
Returns the SFBaseSession associated with this SFBaseStatement.- Specified by:
getSFBaseSession
in classSFBaseStatement
-
getMoreResults
public boolean getMoreResults() throws SQLException
- Throws:
SQLException
-
getMoreResults
public boolean getMoreResults(int current) throws SQLException
Description copied from class:SFBaseStatement
Sets the result set to the next one, if available.- Specified by:
getMoreResults
in classSFBaseStatement
- Parameters:
current
- What to do with the current result. One of Statement.CLOSE_CURRENT_RESULT, Statement.CLOSE_ALL_RESULTS, or Statement.KEEP_CURRENT_RESULT- Returns:
- true if there is a next result and it's a result set false if there are no more results, or there is a next result and it's an update count
- Throws:
SQLException
- if something fails while getting the next result
-
getResultSet
public SFBaseResultSet getResultSet()
Description copied from class:SFBaseStatement
Retrieves the current result as a ResultSet, if any. This is invoked by SnowflakeStatement and should return an SFBaseResultSet, which is then wrapped in a SnowflakeResultSet.- Specified by:
getResultSet
in classSFBaseStatement
-
hasChildren
public boolean hasChildren()
Description copied from class:SFBaseStatement
If this is a multi-statement, i.e., has child results.- Specified by:
hasChildren
in classSFBaseStatement
-
asyncExecute
public SFBaseResultSet asyncExecute(String sql, Map<String,ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData) throws SQLException, SFException
Description copied from class:SFBaseStatement
Execute sql asynchronously. Note that at a minimum, this does not have to be supported; if executeAsyncQuery() is called from SnowflakeStatement and the SFConnectionHandler's supportsAsyncQuery() returns false, an exception is thrown. If this is un-implemented, then supportsAsyncQuery() should return false.- Specified by:
asyncExecute
in classSFBaseStatement
- Parameters:
sql
- sql statement.parametersBinding
- parameters to bindcaller
- the JDBC interface method that called this method, if any- Returns:
- whether there is result set or not
- Throws:
SQLException
- if failed to execute sqlSFException
- exception raised from Snowflake components
-
-