Skip to content
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

Add Commit Hooks to write extra information within the same transaction #321

Open
osopardo1 opened this issue Apr 23, 2024 · 2 comments · May be fixed by #319
Open

Add Commit Hooks to write extra information within the same transaction #321

osopardo1 opened this issue Apr 23, 2024 · 2 comments · May be fixed by #319
Assignees
Labels
enhancement New feature or request

Comments

@osopardo1
Copy link
Member

osopardo1 commented Apr 23, 2024

Table Formats encapsulate write actions into an Optimistic Transaction. Various processes could try to commit the info to the Transaction Log, but only one would succeed, making the others retry the operation.

When the user wants to write any extra metadata about the process or to do any checks on the data, it has to wait until the transaction is successfully over, thus leading to delays and possible inconsistencies.

The idea is to add commit hooks that allow to run custom code before or after calling the Delta Lake txn.commit() method.

@osopardo1 osopardo1 added the enhancement New feature or request label Apr 23, 2024
@osopardo1
Copy link
Member Author

If you could provide any other necessary info regarding this enhancement would be great @Jiaweihu08 @cugni

@osopardo1 osopardo1 changed the title Add PreCommit hooks to commit extra information within the same transaction Add Commit Hooks to write extra information within the same transaction Apr 23, 2024
@osopardo1 osopardo1 linked a pull request Apr 25, 2024 that will close this issue
@osopardo1 osopardo1 linked a pull request Apr 25, 2024 that will close this issue
@osopardo1
Copy link
Member Author

osopardo1 commented Apr 25, 2024

More details about the implementation in #319

The idea is to have an interface such as:

/**
 * A hook that can be run before a commit
 */
trait QbeastPreCommitHook {

  /**
   * The name of the hook
   */
  val name: String

  type PreCommitHookResponse = Map[String, String]

  /**
   * Run the hook with the given actions
   *
   * @param actions
   *   the actions to run the hook with
   */
  def run(actions: Seq[Action]): PreCommitHookResponse
}

Users can extend that interface and add their code to run pre-commit checks or actions. Those actions need to return a Map[String, String] of information they want to write on the Commit Log about the execution of the hook.

Registering a PreCommitHook

In terms of usage from the DataFrame API, one user may call the hook as:

df.write
.format("qbeast")
.option("qbeast.preCommitHook.my_hook_1", "my.hook.class.path")
.option("qbeast.preCommitHook.my_hook_1.arg1", "first_argument")
.save(...)

In that way, we will identify each hook by its name on the options.

Output of a PreCommitHook

Each implementation of a PreCommitHook must return a Map[String, String] with any useful information to register in the Commit Log. Qbeast will add the prefix registered in the options to the result map keys, and it will save it on the tags variable in the CommitInfo.

"commitInfo" {
    "tags" { 
          "qbeast.preCommitHook.my_hook_1.write_id":"id",
          "qbeast.preCommitHook.my_hook_1.cpu_time":"30ms"
     }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants