Class DefaultKeyValueTable
- java.lang.Object
-
- com.snowflake.connectors.common.table.DefaultKeyValueTable
-
- All Implemented Interfaces:
KeyValueTable
public class DefaultKeyValueTable extends Object implements KeyValueTable
Default implementation ofKeyValueTable
.This implementation requires that the backing Snowflake table has the following structure:
- column
key
of typeSTRING
- column
value
of typeVariant
- column
updated_at
of typeTIMESTAMP_NTZ
-
-
Field Summary
Fields Modifier and Type Field Description static int
EXPRESSION_LIMIT
Maximum limit of inserted/updated records.
-
Constructor Summary
Constructors Constructor Description DefaultKeyValueTable(Session session, String tableName)
Creates a newDefaultKeyValueTable
, backed by the provided Snowflake table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(String key)
Deletes the value stored under the provided key from this table.Variant
fetch(String key)
Fetches the value stored under the provided key.Map<String,Variant>
fetchAll()
Fetches all key-value pairs and returns them as a Map.List<Variant>
getAllWhere(Column filter)
Returns all values from this table where the record matches the provided filter.void
update(String key, Variant value)
Updates the value stored under the provided key.void
updateAll(List<KeyValue> keyValues)
Updates the key-value pairs.void
updateMany(List<String> ids, String fieldName, Variant fieldValue)
Updates the provided field of the Variant value stored under the provided keys.
-
-
-
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 newDefaultKeyValueTable
, backed by the provided Snowflake table.- Parameters:
session
- Snowpark session objecttableName
- 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 interfaceKeyValueTable
- Parameters:
key
- key associated with the value- Returns:
- value stored under the provided key
-
fetchAll
public Map<String,Variant> fetchAll()
Description copied from interface:KeyValueTable
Fetches all key-value pairs and returns them as a Map.- Specified by:
fetchAll
in interfaceKeyValueTable
- Returns:
- all key-value pairs
-
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 interfaceKeyValueTable
- Parameters:
key
- key associated with the valuevalue
- 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 interfaceKeyValueTable
- 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 interfaceKeyValueTable
- Parameters:
ids
- keys associated with the valuesfieldName
- name of the updated value fieldfieldValue
- 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 interfaceKeyValueTable
- 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 interfaceKeyValueTable
- Parameters:
key
- key associated with the value
-
-