Methods for working with Azure Cosmos DB user-defined functions
Methods for working with Azure Cosmos DB user-defined functions
get_udf(object,...)## S3 method for class 'cosmos_container'get_udf(object, funcname,...)list_udfs(object,...)create_udf(object,...)## S3 method for class 'cosmos_container'create_udf(object, funcname, body,...)replace_udf(object,...)## S3 method for class 'cosmos_container'replace_udf(object, funcname, body,...)## S3 method for class 'cosmos_udf'replace_udf(object, body,...)delete_udf(object,...)## S3 method for class 'cosmos_container'delete_udf(object, funcname, confirm =TRUE,...)## S3 method for class 'cosmos_udf'delete_udf(object,...)
Arguments
object: A Cosmos DB container object, as obtained by get_cosmos_container or create_cosmos_container, or for delete_udf.cosmos_udf, the function object.
...: Optional arguments passed to lower-level functions.
funcname: The name of the user-defined function.
body: For create_udf and replace_udf, the body of the function. This can be either a character string containing the source code, or the name of a source file.
confirm: For delete_udf, whether to ask for confirmation before deleting.
Returns
For get_udf and create_udf, an object of class cosmos_udf. For list_udfs, a list of such objects.
Details
These are methods for working with user-defined functions (UDFs) in Azure Cosmos DB using the core (SQL) API. In the Cosmos DB model, UDFs are written in JavaScript and associated with a container.
Examples
## Not run:endp <- cosmos_endpoint("https://myaccount.documents.azure.com:443/", key="mykey")db <- get_cosmos_database(endp,"mydatabase")# importing the Star Wars data from dplyrcont <- endp %>% get_cosmos_database(endp,"mydatabase")%>% create_cosmos_container(db,"mycontainer", partition_key="sex")create_udf(cont,"times2","function(x) { return 2*x; }")list_udfs(cont)# UDFs in queries are prefixed with the 'udf.' identifierquery_documents(cont,"select udf.times2(c.height) t2 from cont c")delete_udf(cont,"times2")## End(Not run)