EXPERIMENTAL - this feature is still in design stage and it is not reccomended that you implement this for your package at this stage. Utility for simplifying export of results to files from sql queries
Note that this utility is not strictly thread safe though seperate processes can export separate tables without issue. When exporting a the same table across multiple threads primary key checks may create issues.
Methods
Method new()
Create a class for exporting results from a study in a standard, consistend manner
Usage
ResultExportManager$new(
tableSpecification,
exportDir,
minCellCount = getOption("ohdsi.minCellCount", default = 5),
validateTypes = FALSE,
usePrimaryKeyCheck = FALSE,
databaseId = NULL
)Arguments
tableSpecificationTable specification data.frame
exportDirDirectory files are being exported to
minCellCountMinimum cell count - reccomended that you set with options("ohdsi.minCellCount" = count) in all R projects. Default is 5
validateTypesTest if row values strictly conform to types - optional, not currently reccomended outside of development
usePrimaryKeyCheckTest if primary key fields are violated at export step. - optional, not currently reccomended outside of development get table spec
databaseIddatabase identifier - required when exporting according to many specs
Method checkPrimaryKeys()
Checks to see if the rows conform to the valid primary keys If the same table has already been checked in the life of this object set "invalidateCache" to TRUE as the keys will be cached in a temporary file on disk.
Method exportDataFrame()
This method is intended for use where exporting a data.frame and not a query from a rdbms table For example, if you perform a transformation in R this method will check primary keys, min cell counts and data types before writing the file to according to the table spec
Method exportQuery()
Writes files in batch to stop overflowing system memory Checks primary keys on write Checks minimum cell count
Usage
ResultExportManager$exportQuery(
connection,
sql,
exportTableName,
transformFunction = NULL,
transformFunctionArgs = list(),
append = FALSE,
...
)Arguments
connectionDatabaseConnector connection instance
sqlOHDSI sql string to export tables
exportTableNameName of table to export (in snake_case format)
transformFunction(optional) transformation of the data set callback. must take two paramters - rows and pos
transformFunctionArgsarguments to be passed to the transformation function
appendLogical add results to existing file, if FALSE (default) creates a new file and removes primary key validation cache
...extra parameters passed to sql get manifest list
Method getManifestList()
Create a meta data set for each collection of result files with sha256 has for all files
Usage
ResultExportManager$getManifestList(
packageName = NULL,
packageVersion = NULL,
migrationsPath = NULL,
migrationRegexp = .defaultMigrationRegexp
)Arguments
packageNameif an R analysis package, specify the name
packageVersionif an analysis package, specify the version
migrationsPathpath to sql migrations (use top level folder (e.g. sql/sql_server/migrations)
migrationRegexp(optional) regular expression to search for sql files. It is not reccomended to change the default. Write manifest