XBRAPI: Cheat Sheet
This page can be used as a quick reference when utilizing XBRApi from within business rules and workspaces.
Use Case #1
Retrieve/Extract a DataTable from a .parquet file in the MetaFileSystem
DataTable dt = XBRApi.Etl.ExtractMetaFileSystemParquetAsDataTable(si, MetaFileSystemLocation.Shared, "ExampleFilePath/exampleFile.parquet")
Use Case #2
Retrieve/Extract a DataTable from a .csv file in the MetaFileSystem
DataTable dt = XBRApi.Etl.ExtractMetaFileSystemCsvAsDataTable(si, MetaFileSystemLocation.Shared, "ExampleFilePath/exampleFile.csv")
Use Case #3
Make an instance of or get the MetaFileSystemClient
var mfsClient = XBRApi.MetaFileSystem.GetMetaFileSystemClient(si, MetaFileSystemLocation.Shared);
Use Case #4
Create a new directory within the MetaFileSystem
mfsClient.MakeDirectoriesAsync("CBahr").Wait();
Use Case #5
Write/Create a file to the MetaFileSystem
string message = "Hello, World!";
mfsClient.WriteFileAsync("CBahr/hello_world.txt", message).Wait();
Use Case #6
Make an instance of or get the MetaFileSystemClient
var mfsClient = XBRApi.MetaFileSystem.GetMetaFileSystemClient(si, MetaFileSystemLocation.Shared);
Use Case #7
Remove/Delete a file from the MetaFileSystem
mfsClient.RemoveFileAsync("CBahr/hello_world.txt").Wait();
Use Case #8
Remove/Delete a directory or folder from the MetaFileSystem
mfsClient.RemoveDirectoryAsync("CBahr").Wait();
Use Case #9
Extract/retrieve a CSV file from the OneStream File System as a DataTable
DataTable dt = XBRApi.Etl.ExtractOneStreamFileSystemCsvAsDataTable(si, FileSystemLocation.ApplicationDatabase, filePath);
Use Case #10
Load/Save a DataTable to the OneStream database
XBRApi.Etl.LoadTableToOneStreamDatabase(si, Constants.AISDataSourcesDb, dt);
Use Case #11
Load/Save a Parquet file to the MetaFileSystem
XBRApi.Etl.LoadParquetToMetaFileSystem(si, MetaFileSystemLocation.Shared, "CBahr/E2Step3.parquet", dt);
Use Case #12
Load/Save a CSV file to the MetaFileSystem
XBRApi.Etl.LoadCsvToMetaFileSystem(si, MetaFileSystemLocation.Shared, "CBahr/E2Step4.csv", dt);
Use Case #13
Load/Save a CSV file to the OneStream File System
XBRApi.Etl.LoadCsvToOneStreamFileSystem(si, FileSystemLocation.ApplicationDatabase, "Documents/Users/ChrisBahr/E2Step5.csv", dt);
Use Case #14
Create an instance of a OneStream SQL Connection Data Definition
DataDefinition dataDefinition = XBRApi.Etl.CreateOneStreamSqlConnectionDataDefinition(si, Constants.AISDataSourcesDb, tableName);
Use Case #15
Create an instance of a OneStream File System Data Definition
DataDefinition dataDefinition = XBRApi.Etl.CreateOneStreamFileSystemDataDefinition(si, FileSystemLocation.ApplicationDatabase, filePath);
Use Case #16
Create an instance of a Create MetaFileSystem Data Definition
DataDefinition dataDefinition = XBRApi.Etl.CreateMetaFileSystemDataDefinition(si, "sql-server-shared", filePath);
Use Case #17
Create a file path by joining the parts of the path together. This would be used for the MetaFileSystem file paths
string filePath = MetaFilePathUtil.JoinPathParts(true, "Bootcamp", "ETL", "pb_sales_all.parquet");
Use Case #18
Create an instance of a OneStream File System Data Definition
var tabularEtlManager = XBRApi.Etl.GetTabularEtlManager(si);
var sourceDataDefinition = // Code to create a DataDefintion
var destinationDataDefinition = // Code to create a DataDefintion
tabularEtlManager.ExtractAndLoad(sourceDataDefinition, destinationDataDefinition);
Use Case #19
Create an instance of the RoutineClient
var routineClient = XBRApi.Routines.GetRoutineClient(si);
Additionally, I can optionally include a solution code if I would like to have Routine Instance and all related downstream objects (Run objects, Artifact objects, etc.) be tied to that particular solution.
var routineClient = XBRApi.Routines.GetRoutineClient(si, "AIRecs");
## Use Case #20
Get/retrieve a RoutineInstance by name
```csharp
RoutineInstance? routineInstance = routineClient.GetRoutineInstanceByNameAsync(routineInstanceName).Result;
Use Case #21: Create a Routine Instance
var routineInstance = routineClient.CreateRoutineInstanceAsync("InMemExecutionTestRoutine", // Routine Type Name
null, // Routine Name (null means the name will be automatically generated)
labels: new List < string >
{
"MyCustomLabel", "AnotherCustomLabel"
}, // User defined labels you can filter/categorize Routine Instances by
attributes: new JObject()
{
{
"RoutineAttribute", "RoutineAttributeValue"
},
{
"RoutineAttribute2", "RoutineAttributeValue2"
}
} // Arbitrary json attributes that will live at the routine instance level. These are accessible on the python side as well
).Result;
Use Case #22
Create a background execution Run. It returns an instance of Run.
var run = routineInstance.CreateRunAsync("concat", // The method name that you want to execute
null, // The user-defined Run name. (null means the name will be auto generated)
includeStatistics: false, includePreviews: false, invocationMethodType: InvocationMethodType.Direct, inputParams: new JObject(new JProperty("first", "Hello"), new JProperty("second", "World")), description: "My Description", storeArtifacts: true, // Whether or not to store the artifacts
executionType: "background", labels: new List < string >
{
"MyRunlevelCustomLabel", "AnotherCustomLabel"
}, // User defined labels you can filter/categorize Runs by
attributes: new JObject()
{
{
"RunAttribute", "RunAttributeValue"
},
{
"RunAttribute2", "RunAttributeValue2"
}
} // Arbitrary json attributes that will live at the Run level. These are accessible on the python side as well
).Result;
Use Case #23
Start an instance of Run and wait for it to successfully complete
ExecutionStatus executionStatus = run.StartAndWaitForSuccessfulCompletionAsync().Result;
Use Case #24
An an instance of an Artifact from a Run.
Artifact? artifact = run.GetArtifactAsync(artifactQualifiedKey).Result;
Use Case #25
Get the file paths for the Data from an Artifact
List<string> artifactFilePaths = artifact.GetDataFilePathsAsync().Result;
Use Case #26
Start an instance of Run and wait for it to successfully complete
ExecutionStatus executionStatus = run.StartAndWaitForSuccessfulCompletionAsync().Result;
Use Case #27
An an instance of an Artifact from a Run.
Artifact? artifact = run.GetArtifactAsync(artifactQualifiedKey).Result;
Use Case #28
Retrieve Tabular Artifact Data as a DataTable object.
// Retrieve Tabular (parquet-based) Artifact Data (using the Artifact Qualified Key "predictions")
var tabularArtifact = routineRun ? .GetArtifactAsync("predictions").Result;
// Pull out the tabular artifact as a DataTable
DataTable dtPredictions = tabularArtifact ? .GetDataAsObjectAsync < DataTable > ().Result;
Use Case #29
Query parquet data existing in the MetaFileSystem using the MetaDB using DuckDB SQL Syntax.
// Where Clause the Data
var sql = new StringBuilder();
sql.AppendLine("SELECT * FROM 'shared://Datasets/RetailDemo_300Targets.parquet' LIMIT 100;");
// Execute the metadb query
var dt = XBRApi.MetaDB.ExecuteSql(si, sql.ToString());