-
Notifications
You must be signed in to change notification settings - Fork 9
Misc updates/fixes: labkey.domain.createAndLoad fix for strictFieldValidation, labkey.webdav.put description support, add labkey.query.import #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69ca2c6
Issue 43107 labkey.domain.createAndLoad - conditionalize strictFieldV…
cnathe a2174f0
Issue 43107 labkey.domain.createAndLoad - add support for strictField…
cnathe 4cb079d
Issue 42950: Inserting file description using R API
cnathe dabbc20
Issue 42546: Improve performance of Rlabkey import for large number o…
cnathe 027b746
Add labkey.setCurlOptions.Rd doc info related to setting alternate pa…
cnathe 45904c1
typo: remove -> remote
cnathe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| ## | ||
| # Copyright (c) 2013-2018 LabKey Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| ## | ||
|
|
||
| labkey.query.import <- function(baseUrl=NULL, folderPath, schemaName, queryName, toImport, options = NULL) | ||
| { | ||
| baseUrl=labkey.getBaseUrl(baseUrl) | ||
|
|
||
| ## check required parameters | ||
| if (missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(schemaName) || missing(queryName) || missing(toImport)) | ||
| stop (paste("A value must be specified for each of baseUrl, folderPath, schemaName, queryName, and toImport.")) | ||
| if (!missing(options) & !is.list(options)) | ||
| stop (paste("options must be a list data structure.")) | ||
|
|
||
| ## normalize the folder path | ||
| folderPath <- encodeFolderPath(folderPath) | ||
|
|
||
| ## write the dataframe to a tempfile to post to the server | ||
| tf <- tempfile(fileext=".tsv") | ||
| write.table(toImport, file=tf, sep="\t", quote=FALSE, row.names=FALSE) | ||
|
|
||
| ## build the options param list | ||
| if (is.null(options)) | ||
| options <- list() | ||
| options <- c(options, list(schemaName=schemaName, queryName=queryName, file=upload_file(tf))) | ||
|
|
||
| ## Execute via our standard POST function | ||
| url <- paste(baseUrl, "query", folderPath, "import.api", sep="") | ||
| rawdata <- labkey.post(url, options, encoding="multipart") | ||
| response <- fromJSON(rawdata, simplifyVector=FALSE, simplifyDataFrame=FALSE) | ||
|
|
||
| ## delete the temp file | ||
| file.remove(tf) | ||
|
|
||
| return(response) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| \name{labkey.query.import} | ||
| \alias{labkey.query.import} | ||
| \title{Bulk import an R data frame into a LabKey Server table using file import.} | ||
| \description{ | ||
| Bulk import an R data frame into a LabKey Server table using file import. | ||
| } | ||
| \usage{ | ||
| labkey.query.import(baseUrl, folderPath, | ||
| schemaName, queryName, toImport, options = NULL) | ||
| } | ||
| \arguments{ | ||
| \item{baseUrl}{a string specifying the \code{baseUrl}for the labkey server} | ||
| \item{folderPath}{a string specifying the \code{folderPath} } | ||
| \item{schemaName}{a string specifying the \code{schemaName} for the query} | ||
| \item{queryName}{a string specifying the \code{queryName}} | ||
| \item{toImport}{a data frame containing rows of data to be imported} | ||
| \item{options}{(optional) a list containing options specific to the import | ||
| action of the query} | ||
| } | ||
| \details{ | ||
| This command mimics the "Import bulk data" option that you see in the LabKey server UI | ||
| for a table/query. It takes the passed in \code{toImport} data frame and writes it to a | ||
| temp file to be posted to the import action for the given LabKey query. It is very similar | ||
| to the \code{labkey.importRows} command but will be much more performant. | ||
| \cr \cr | ||
| Multiple rows of data can be imported in bulk using the \code{toImport} data frame. | ||
| The names of the data in the data frame must be the column names from the | ||
| LabKey Server. | ||
| \cr \cr | ||
| LabKey data types support different import options. The list of valid options for each | ||
| query will vary, but some common examples include: | ||
| \itemize{ | ||
| \item{ \code{insertOption (string)} : Whether the import action should be done as an insert, creating new | ||
| rows for each provided row of the data frame, or a merge. When merging during import, any data you provide | ||
| for the rows representing records that already exist will replace the previous values. | ||
| Note that when updating an existing record, you only need to provide the columns you wish to update, | ||
| existing data for other columns will be left as is. Available options are "INSERT" and "MERGE". | ||
| Defaults to "INSERT".} | ||
| \item{ \code{auditBehavior (string)} : Set the level of auditing details for this import action. | ||
| Available options are "SUMMARY" and "DETAILED". SUMMARY - Audit log reflects that a change was made, | ||
| but does not mention the nature of the change. DETAILED - Provides full details on what change was made, | ||
| including values before and after the change. Defaults to the setting as specified by the LabKey query.} | ||
| \item{ \code{importLookupByAlternateKey (boolean)} : Allows lookup target rows to be resolved by values | ||
| rather than the target's primary key. This option will only be available for lookups that are | ||
| configured with unique column information. Defaults to FALSE.} | ||
| } | ||
| } | ||
|
|
||
| \value{ | ||
| A list is returned with the row count for the number of affected rows. If options are provided, | ||
| additional details may be included in the response object related to those options. | ||
| } | ||
| \author{Cory Nathe} | ||
| \seealso{ | ||
| \code{\link{labkey.insertRows}}, \code{\link{labkey.updateRows}}, \code{\link{labkey.importRows}} | ||
| } | ||
| \examples{ | ||
| \donttest{ | ||
|
|
||
| ## Note that users must have the necessary permissions in the database | ||
| ## to be able to modify data through the use of these functions | ||
| # library(Rlabkey) | ||
|
|
||
| df <- data.frame( | ||
| name=c("test1","test2","test3"), | ||
| customInt=c(1:3), | ||
| customString=c("aaa", "bbb", "ccc") | ||
| ) | ||
|
|
||
| importedInfo <- labkey.query.import( | ||
| "http://localhost:8080/labkey", | ||
| folderPath="/apisamples", schemaName="samples", queryName="SampleType1", | ||
| toImport=df, options=list(insertOption = "MERGE", auditBehavior = "DETAILED") | ||
| ) | ||
|
|
||
| importedInfo$rowCount | ||
|
|
||
| } | ||
| } | ||
| \keyword{IO} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@labkey-klum What do you think of this change? The new
labkey.query.importcall is much faster then thelabkey.insertRowsorlabkey.importRowscalls. Do you recall any specific reason why thelabkey.domain.createAndLoadwould need to use theinsertRowsor do you think it is fine to change it tolabkey.query.import?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, agreed that changing this to use the new
query.importfunction will improve the perf on this function.