Class DefaultKeyValueTable

  • All Implemented Interfaces:
    KeyValueTable

    public class DefaultKeyValueTable
    extends Object
    implements KeyValueTable
    Default implementation of KeyValueTable.

    This implementation requires that the backing Snowflake table has the following structure:

    • column key of type STRING
    • column value of type Variant
    • column updated_at of type TIMESTAMP_NTZ
    • Field Detail

      • EXPRESSION_LIMIT

        public static final int EXPRESSION_LIMIT
        Maximum limit of inserted/updated records.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultKeyValueTable

        public DefaultKeyValueTable​(Session session,
                                    String tableName)
        Creates a new DefaultKeyValueTable, backed by the provided Snowflake table.
        Parameters:
        session - Snowpark session object
        tableName - name of the Snowflake table
    • Method Detail

      • fetch

        public Variant fetch​(String key)
        Description copied from interface: KeyValueTable
        Fetches the value stored under the provided key.
        Specified by:
        fetch in interface KeyValueTable
        Parameters:
        key - key associated with the value
        Returns:
        value stored under the provided key
      • update

        public void update​(String key,
                           Variant value)
        Updates the value stored under the provided key.

        If no value is currently stored under the provided key - it will be inserted into this table.

        Specified by:
        update in interface KeyValueTable
        Parameters:
        key - key associated with the value
        value - value
        Throws:
        RuntimeException - when the number of affected rows is different from 1
      • getAllWhere

        public List<Variant> getAllWhere​(Column filter)
        Description copied from interface: KeyValueTable
        Returns all values from this table where the record matches the provided filter.
        Specified by:
        getAllWhere in interface KeyValueTable
        Parameters:
        filter - filter for the table records
        Returns:
        values from records which match the provided filter
      • updateMany

        public void updateMany​(List<String> ids,
                               String fieldName,
                               Variant fieldValue)
        Description copied from interface: KeyValueTable
        Updates the provided field of the Variant value stored under the provided keys.

        If no value is currently stored under the provided key - it will be ignored.

        Specified by:
        updateMany in interface KeyValueTable
        Parameters:
        ids - keys associated with the values
        fieldName - name of the updated value field
        fieldValue - new value for the updated field
      • updateAll

        public void updateAll​(List<KeyValue> keyValues)
        Description copied from interface: KeyValueTable
        Updates the key-value pairs.

        If no value is currently stored under the provided key - it will be inserted into this table.

        Specified by:
        updateAll in interface KeyValueTable
        Parameters:
        keyValues - list of key-value pairs
      • delete

        public void delete​(String key)
        Description copied from interface: KeyValueTable
        Deletes the value stored under the provided key from this table.
        Specified by:
        delete in interface KeyValueTable
        Parameters:
        key - key associated with the value