FastPrepExecute In-Memory SQL Storage Operations

Execute In-Memory SQL Storage Operations

Fivetran logoFivetran● MediumFULLTIMEPHONE SCREEN
Learn

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_DB creates a database.
  • CREATE_TABLE creates a table in an existing database.
  • INSERT stores values[i] at a new integer row ID.
  • READ returns the current value for an existing row.
  • UPDATE replaces the value of an existing row.
  • DELETE removes 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 <= 100000 and 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.

More Fivetran problems

See Fivetran hiring insights
public String[] executeStorageOperations(String[] operations, String[] databases, String[] tables, int[] ids, String[] values) {
    // Write your solution here.
}
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","","",""]
expected["OK", "OK", "OK", "new", "OK", "paid", "OK", "ERROR"]
Checking account…