Execute In-Memory SQL Storage Operations
Problem statement
Execute a finite ordered batch against an in-memory database service. The five input arrays have equal length. Return one result per operation.
CREATE_DBcreates a database.CREATE_TABLEcreates a table in an existing database.INSERTstoresvalues[i]at a new integer row ID.READreturns the current value for an existing row.UPDATEreplaces the value of an existing row.DELETEremoves an existing row.
A successful write returns OK. A missing parent, missing row, or duplicate create/insert returns ERROR and changes no state. Fields unused by an operation may contain the empty value for their type.
Function
executeStorageOperations(operations: String[], databases: String[], tables: String[], ids: int[], values: String[]) → String[]Examples
Example 1
operations = ["CREATE_DB","CREATE_TABLE","INSERT","READ","UPDATE","READ","DELETE","READ"]databases = ["sales","sales","sales","sales","sales","sales","sales","sales"]tables = ["","orders","orders","orders","orders","orders","orders","orders"]ids = [0,0,7,7,7,7,7,7]values = ["","","new","","paid","","",""]return = ["OK","OK","OK","new","OK","paid","OK","ERROR"]The update changes the stored row and deletion removes it.
Example 2
operations = ["CREATE_TABLE","CREATE_DB","CREATE_DB","CREATE_TABLE","INSERT","INSERT"]databases = ["x","x","x","x","x","x"]tables = ["t","","","t","t","t"]ids = [0,0,0,0,1,1]values = ["","","","","a","b"]return = ["ERROR","OK","ERROR","OK","OK","ERROR"]Parents must exist and duplicate creates or inserts fail.
Example 3
operations = []databases = []tables = []ids = []values = []return = []An empty batch has no results.
Constraints
0 <= operations.length <= 100000and all five arrays have that length.- Every operation is one of the six documented uppercase strings.
- Database and table names used by their operations are nonempty and at most 100 characters.
- Row IDs are nonnegative, and stored values have at most 1000 characters.