Class ResultUtil


  • public class ResultUtil
    extends Object
    • Field Detail

      • DEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDS

        public static final int DEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDS
        See Also:
        Constant Field Values
    • Constructor Detail

      • ResultUtil

        public ResultUtil()
    • Method Detail

      • effectiveParamValue

        public static Object effectiveParamValue​(Map<String,​Object> parameters,
                                                 String paramName)
        Returns the effective parameter value, using the value explicitly provided in parameters, or the default if absent
        Parameters:
        parameters - keyed in parameter name and valued in parameter value
        paramName - Parameter to return the value of
        Returns:
        Effective value
      • specializedFormatter

        public static net.snowflake.common.core.SnowflakeDateTimeFormat specializedFormatter​(Map<String,​Object> parameters,
                                                                                             String id,
                                                                                             String param,
                                                                                             String defaultFormat)
        Helper function building a formatter for a specialized timestamp type. Note that it will be based on either the 'param' value if set, or the default format provided.
      • adjustTimestamp

        public static Timestamp adjustTimestamp​(Timestamp timestamp)
        Adjust timestamp for dates before 1582-10-05
        Parameters:
        timestamp - needs to be adjusted
        Returns:
        adjusted timestamp
      • msDiffJulianToGregorian

        public static long msDiffJulianToGregorian​(Date date)
        For dates before 1582-10-05, calculate the number of millis to adjust.
        Parameters:
        date - date before 1582-10-05
        Returns:
        millis needs to be adjusted
      • getSFTimestamp

        public static net.snowflake.common.core.SFTimestamp getSFTimestamp​(String timestampStr,
                                                                           int scale,
                                                                           int internalColumnType,
                                                                           long resultVersion,
                                                                           TimeZone sessionTZ,
                                                                           SFBaseSession session)
                                                                    throws SFException
        Convert a timestamp internal value (scaled number of seconds + fractional seconds) into a SFTimestamp.
        Parameters:
        timestampStr - timestamp object
        scale - timestamp scale
        internalColumnType - snowflake timestamp type
        resultVersion - For new result version, timestamp with timezone is formatted as the seconds since epoch with fractional part in the decimal followed by time zone index. E.g.: "123.456 1440". Here 123.456 is the * number of seconds since epoch and 1440 is the timezone index.
        sessionTZ - session timezone
        session - session object
        Returns:
        converted snowflake timestamp object
        Throws:
        SFException - if timestampStr is an invalid timestamp
      • getSFTime

        public static net.snowflake.common.core.SFTime getSFTime​(String obj,
                                                                 int scale,
                                                                 SFBaseSession session)
                                                          throws SFException
        Convert a time internal value (scaled number of seconds + fractional seconds) into an SFTime.

        Example: getSFTime("123.456", 5) returns an SFTime for 00:02:03.45600.

        Parameters:
        obj - time object
        scale - time scale
        session - session object
        Returns:
        snowflake time object
        Throws:
        SFException - if time is invalid
      • getSFTimeAsString

        public static String getSFTimeAsString​(net.snowflake.common.core.SFTime sft,
                                               int scale,
                                               net.snowflake.common.core.SnowflakeDateTimeFormat timeFormatter)
        Convert a time value into a string
        Parameters:
        sft - snowflake time object
        scale - time scale
        timeFormatter - time formatter
        Returns:
        time in string
      • getBooleanAsString

        public static String getBooleanAsString​(boolean bool)
        Convert a boolean to a string
        Parameters:
        bool - boolean
        Returns:
        boolean in string
      • getSFTimestampAsString

        public static String getSFTimestampAsString​(net.snowflake.common.core.SFTimestamp sfTS,
                                                    int columnType,
                                                    int scale,
                                                    net.snowflake.common.core.SnowflakeDateTimeFormat timestampNTZFormatter,
                                                    net.snowflake.common.core.SnowflakeDateTimeFormat timestampLTZFormatter,
                                                    net.snowflake.common.core.SnowflakeDateTimeFormat timestampTZFormatter,
                                                    SFBaseSession session)
                                             throws SFException
        Convert a SFTimestamp to a string value.
        Parameters:
        sfTS - snowflake timestamp object
        columnType - internal snowflake t
        scale - timestamp scale
        timestampNTZFormatter - snowflake timestamp ntz format
        timestampLTZFormatter - snowflake timestamp ltz format
        timestampTZFormatter - snowflake timestamp tz format
        session - session object
        Returns:
        timestamp in string in desired format
        Throws:
        SFException - timestamp format is missing
      • getDateAsString

        public static String getDateAsString​(Date date,
                                             net.snowflake.common.core.SnowflakeDateTimeFormat dateFormatter)
        Convert a date value into a string
        Parameters:
        date - date will be converted
        dateFormatter - date format
        Returns:
        date in string
      • adjustDate

        public static Date adjustDate​(Date date)
        Adjust date for before 1582-10-05
        Parameters:
        date - date before 1582-10-05
        Returns:
        adjusted date
      • getDate

        @Deprecated
        public static Date getDate​(String str,
                                   TimeZone tz,
                                   SFBaseSession session)
                            throws SFException
        Deprecated.
        Convert a date internal object to a Date object in specified timezone.
        Parameters:
        str - snowflake date object
        tz - timezone we want convert to
        session - snowflake session object
        Returns:
        java date object
        Throws:
        SFException - if date is invalid
      • getBoolean

        public static boolean getBoolean​(String str)
        Convert snowflake bool to java boolean
        Parameters:
        str - boolean type in string representation
        Returns:
        true if the value indicates true otherwise false
      • calculateUpdateCount

        public static long calculateUpdateCount​(SFBaseResultSet resultSet)
                                         throws SFException,
                                                SQLException
        Calculate number of rows updated given a result set Interpret result format based on result set's statement type
        Parameters:
        resultSet - result set to extract update count from
        Returns:
        the number of rows updated
        Throws:
        SFException - if failed to calculate update count
        SQLException - if failed to calculate update count
      • listSearchCaseInsensitive

        public static int listSearchCaseInsensitive​(List<String> source,
                                                    String target)
        Given a list of String, do a case insensitive search for target string Used by resultsetMetadata to search for target column name
        Parameters:
        source - source string list
        target - target string to match
        Returns:
        index in the source string list that matches the target string index starts from zero
      • getChildResults

        public static List<SFChildResult> getChildResults​(SFBaseSession session,
                                                          String requestId,
                                                          com.fasterxml.jackson.databind.JsonNode result)
                                                   throws SFException
        Return the list of child results provided in a result, if available; otherwise return an empty list
        Parameters:
        session - the current session
        requestId - the current request id
        result - result json
        Returns:
        list of child results
        Throws:
        SFException - if the number of child IDs does not match child statement types