Class QueryStatus


  • public final class QueryStatus
    extends Object
    Represents detailed status information for a query execution.

    This class provides comprehensive metadata about a query's execution, including timing information, warehouse details, and error information if applicable. Use this class to monitor query progress and diagnose execution issues.

    Usage Example

    
     String queryId = statement.unwrap(SnowflakeStatement.class).getQueryID();
     QueryStatus status = connection.unwrap(SnowflakeConnection.class)
         .getQueryStatus(queryId);
    
     System.out.println("Query Status: " + status.getStatus());
     System.out.println("Duration: " + status.getTotalDuration() + "ms");
     if (status.getErrorCode() != 0) {
         System.err.println("Error: " + status.getErrorMessage());
     }
     
    • Constructor Detail

      • QueryStatus

        public QueryStatus​(long endTime,
                           int errorCode,
                           String errorMessage,
                           String id,
                           String name,
                           long sessionId,
                           String sqlText,
                           long startTime,
                           String state,
                           int totalDuration,
                           String warehouseExternalSize,
                           int warehouseId,
                           String warehouseName,
                           String warehouseServerType)
        Constructs a QueryStatus object with detailed query execution information.
        Parameters:
        endTime - the end time of the query in milliseconds since epoch
        errorCode - the error code if query failed, 0 otherwise
        errorMessage - the error message if query failed, empty otherwise
        id - the unique query ID
        name - the query status name
        sessionId - the session ID that executed the query
        sqlText - the SQL text of the query
        startTime - the start time of the query in milliseconds since epoch
        state - the internal state of the query
        totalDuration - the total duration of query execution in milliseconds
        warehouseExternalSize - the external size of the warehouse (e.g., "X-Small")
        warehouseId - the warehouse ID
        warehouseName - the warehouse name
        warehouseServerType - the warehouse server type
    • Method Detail

      • empty

        public static QueryStatus empty()
        Creates an empty QueryStatus instance with default values.
        Returns:
        an empty QueryStatus object
      • isEmpty

        public boolean isEmpty()
        Checks if this query status is empty (no data).
        Returns:
        true if the status name is empty
      • isStillRunning

        public boolean isStillRunning()
        Checks if the query is still running.
        Returns:
        true if the query is in a running state
      • isSuccess

        public boolean isSuccess()
        Checks if the query completed successfully.
        Returns:
        true if the query status is SUCCESS
      • isAnError

        public boolean isAnError()
        Checks if the query encountered an error.
        Returns:
        true if the query is in an error state
      • getEndTime

        public long getEndTime()
        Gets the end time of query execution.
        Returns:
        the end time in milliseconds since epoch
      • getErrorCode

        public int getErrorCode()
        Gets the error code if the query failed.
        Returns:
        the error code, or 0 if no error occurred
      • getErrorMessage

        public String getErrorMessage()
        Gets the error message if the query failed.
        Returns:
        the error message, or empty string if no error occurred
      • getId

        public String getId()
        Gets the unique query ID.
        Returns:
        the query ID
      • getName

        public String getName()
        Gets the query status name.
        Returns:
        the status name (e.g., "RUNNING", "SUCCESS")
      • getSessionId

        public long getSessionId()
        Gets the session ID that executed the query.
        Returns:
        the session ID
      • getSqlText

        public String getSqlText()
        Gets the SQL text of the query.
        Returns:
        the SQL query text
      • getStartTime

        public long getStartTime()
        Gets the start time of query execution.
        Returns:
        the start time in milliseconds since epoch
      • getState

        public String getState()
        Gets the internal state of the query.
        Returns:
        the internal query state
      • getTotalDuration

        public int getTotalDuration()
        Gets the total duration of query execution.
        Returns:
        the total duration in milliseconds
      • getWarehouseExternalSize

        public String getWarehouseExternalSize()
        Gets the external size of the warehouse that executed the query.
        Returns:
        the warehouse size (e.g., "X-Small", "Small", "Medium")
      • getWarehouseId

        public int getWarehouseId()
        Gets the warehouse ID that executed the query.
        Returns:
        the warehouse ID
      • getWarehouseName

        public String getWarehouseName()
        Gets the warehouse name that executed the query.
        Returns:
        the warehouse name
      • getWarehouseServerType

        public String getWarehouseServerType()
        Gets the warehouse server type that executed the query.
        Returns:
        the warehouse server type
      • getDescription

        public String getDescription()
        Gets the status description.
        Returns:
        the status name
      • getStatus

        public QueryStatus.Status getStatus()
        Gets the query status enum value.
        Returns:
        the Status enum representing the current state