Package net.snowflake.client.core
Class ResultUtil
- java.lang.Object
-
- net.snowflake.client.core.ResultUtil
-
public class ResultUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDSstatic intMILLIS_IN_ONE_DAY
-
Constructor Summary
Constructors Constructor Description ResultUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DateadjustDate(Date date)Adjust date for before 1582-10-05static TimestampadjustTimestamp(Timestamp timestamp)Adjust timestamp for dates before 1582-10-05static longcalculateUpdateCount(SFBaseResultSet resultSet)Calculate number of rows updated given a result set Interpret result format based on result set's statement typestatic ObjecteffectiveParamValue(Map<String,Object> parameters, String paramName)Returns the effective parameter value, using the value explicitly provided in parameters, or the default if absentstatic booleangetBoolean(String str)Convert snowflake bool to java booleanstatic StringgetBooleanAsString(boolean bool)Convert a boolean to a stringstatic List<SFChildResult>getChildResults(SFBaseSession session, String requestId, com.fasterxml.jackson.databind.JsonNode result)Return the list of child results provided in a result, if available; otherwise return an empty liststatic DategetDate(String str, TimeZone tz, SFBaseSession session)Deprecated.static StringgetDateAsString(Date date, net.snowflake.common.core.SnowflakeDateTimeFormat dateFormatter)Convert a date value into a stringstatic net.snowflake.common.core.SFTimegetSFTime(String obj, int scale, SFBaseSession session)Convert a time internal value (scaled number of seconds + fractional seconds) into an SFTime.static StringgetSFTimeAsString(net.snowflake.common.core.SFTime sft, int scale, net.snowflake.common.core.SnowflakeDateTimeFormat timeFormatter)Convert a time value into a stringstatic net.snowflake.common.core.SFTimestampgetSFTimestamp(String timestampStr, int scale, int internalColumnType, long resultVersion, TimeZone sessionTZ, SFBaseSession session)Convert a timestamp internal value (scaled number of seconds + fractional seconds) into a SFTimestamp.static StringgetSFTimestampAsString(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)Convert a SFTimestamp to a string value.static intlistSearchCaseInsensitive(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 namestatic longmsDiffJulianToGregorian(Date date)For dates before 1582-10-05, calculate the number of millis to adjust.static net.snowflake.common.core.SnowflakeDateTimeFormatspecializedFormatter(Map<String,Object> parameters, String id, String param, String defaultFormat)Helper function building a formatter for a specialized timestamp type.
-
-
-
Field Detail
-
MILLIS_IN_ONE_DAY
public static final int MILLIS_IN_ONE_DAY
- See Also:
- Constant Field Values
-
DEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDS
public static final int DEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDS
- See Also:
- Constant Field Values
-
-
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 valueparamName- 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 objectscale- timestamp scaleinternalColumnType- snowflake timestamp typeresultVersion- 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 timezonesession- 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 objectscale- time scalesession- 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 objectscale- time scaletimeFormatter- 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 objectcolumnType- internal snowflake tscale- timestamp scaletimestampNTZFormatter- snowflake timestamp ntz formattimestampLTZFormatter- snowflake timestamp ltz formattimestampTZFormatter- snowflake timestamp tz formatsession- 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 converteddateFormatter- 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 objecttz- timezone we want convert tosession- 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 countSQLException- 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 listtarget- 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 sessionrequestId- the current request idresult- result json- Returns:
- list of child results
- Throws:
SFException- if the number of child IDs does not match child statement types
-
-