Class SqlTools


  • public class SqlTools
    extends Object
    Set of basic SQL utilities.
    • Constructor Detail

      • SqlTools

        public SqlTools()
    • Method Detail

      • callProcedure

        public static ConnectorResponse callProcedure​(Session session,
                                                      String schema,
                                                      String procedureName,
                                                      String... arguments)
        Calls the specified application procedure with the provided arguments.

        The procedure called must return a Variant, which must be possible to map into a ConnectorResponse instance.

        Parameters:
        session - Snowpark session object
        schema - schema in which the procedure exists
        procedureName - procedure name
        arguments - procedure arguments
        Returns:
        standard connector response created from the Variant returned by the procedure
      • callProcedureRaw

        public static Variant callProcedureRaw​(Session session,
                                               String schema,
                                               String procedureName,
                                               String... arguments)
        Calls the specified application procedure with the provided arguments.

        The procedure called must return a Variant which will be returned.

        Parameters:
        session - Snowpark session object
        schema - schema in which the procedure exists
        procedureName - procedure name
        arguments - procedure arguments
        Returns:
        Variant representing response from a procedure.
      • callPublicProcedure

        public static ConnectorResponse callPublicProcedure​(Session session,
                                                            String procedureName,
                                                            String... arguments)
        Calls the specified application procedure, created in the PUBLIC schema, with the provided arguments.

        The procedure called must return a Variant, which must be possible to map into a ConnectorResponse instance.

        Parameters:
        session - Snowpark session object
        procedureName - procedure name
        arguments - procedure arguments
        Returns:
        standard connector response created from the Variant returned by the procedure
      • callPublicProcedureRaw

        public static Variant callPublicProcedureRaw​(Session session,
                                                     String procedureName,
                                                     String... arguments)
        Calls the specified application procedure, created in the PUBLIC schema, with the provided arguments.

        The procedure called must return a Variant which will be returned

        Parameters:
        session - Snowpark session object
        procedureName - procedure name
        arguments - procedure arguments
        Returns:
        Variant
      • asVarchar

        public static String asVarchar​(String string)
        Returns the provided String wrapped in single quotes, so it can be treated as a SQL varchar.

        If the provided String contains any single quote characters - they are escaped with a backslash character.

        Parameters:
        string - String value
        Returns:
        provided value escaped and wrapped in single quotes
      • arrayConstruct

        public static String arrayConstruct​(String... objects)
        Creates a String that wraps provided arguments in ARRAY_CONSTRUCT() function.
        Parameters:
        objects - String values that represent ARRAY_CONSTRUCT() function arguments.
        Returns:
        provided values wrapped in ARRAY_CONSTRUCT() function.
      • arrayConstruct

        public static String arrayConstruct​(List<String> objects)
        Creates a String that wraps provided arguments in ARRAY_CONSTRUCT() function.
        Parameters:
        objects - List of string values that represent ARRAY_CONSTRUCT() function arguments.
        Returns:
        provided values wrapped in ARRAY_CONSTRUCT() function.
      • varcharArgument

        @Deprecated(since="2.1.0",
                    forRemoval=true)
        public static String varcharArgument​(String argument)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Deprecated, use asVarchar(String) instead.
        Parameters:
        argument - String value
        Returns:
        provided value escaped and wrapped in single quotes
      • asVariant

        public static String asVariant​(Variant variant)
        Returns the provided Variant changed to a JSON String and wrapped in the PARSE_JSON function, so it can be used as a SQL Variant.
        Parameters:
        variant - Variant value
        Returns:
        provided value changed to a JSON String and wrapped in the PARSE_JSON function
      • variantArgument

        @Deprecated(since="2.1.0",
                    forRemoval=true)
        public static String variantArgument​(Variant variant)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Deprecated, use asVariant(Variant) instead.
        Parameters:
        variant - Variant value
        Returns:
        provided value changed to a JSON String and wrapped in the PARSE_JSON function
      • asCommaSeparatedSqlList

        public static String asCommaSeparatedSqlList​(Collection<String> strings)
        Quotes each string using quote and joins them into one separated by commas.
        Parameters:
        strings - values to be joined
        Returns:
        comma separated string
      • quoted

        public static String quoted​(String string)
        Wraps input text with double quotes, e.g. input test will create output "test".
        Parameters:
        string - string to be formatted
        Returns:
        input string wrapped in double quotes