Skip to content

Commit

Permalink
table param from Lua 7970
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavsteindler committed Jul 23, 2024
1 parent d9924c0 commit 57469c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pkg/actions/lua/lakefs/catalogexport/glue_exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ local function export_glue(glue, db, table_src_path, create_table_input, action_

local create_db = opts.create_nonexistant_db or false
if create_db then
glue.create_database(db) -- may fail if db doesn't exist
dbopts={error_on_already_exists=false}
glue.create_database(db, dbopts)
end

-- finallize create glue table input
Expand Down
37 changes: 24 additions & 13 deletions pkg/actions/lua/storage/aws/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,26 +230,37 @@ func createDatabase(c *GlueClient) lua.Function {
return func(l *lua.State) int {
client := c.client()
database := aws.String(lua.CheckString(l, 1))
var description *string

var createDBInput *glue.CreateDatabaseInput
errorOnAlreadyExists := true
if !l.IsNone(2) {
description = aws.String(lua.CheckString(l, 2))
lua.CheckType(l, 2, lua.TypeTable)
l.Field(2, "error_on_already_exists") // -2
l.Field(2, "create_db_input") // -1
errorOnAlreadyExists = l.ToBoolean(-2)
createDBInputJSON := lua.CheckString(l, -1)

err := json.Unmarshal([]byte(createDBInputJSON), &createDBInput)
if err != nil {
lua.Errorf(l, "%s", err.Error())
panic("unreachable")
}
}

// check if catalog ID provided
var catalogID *string
if !l.IsNone(3) {
catalogID = aws.String(lua.CheckString(l, 3))
if createDBInput == nil {
createDBInput = &glue.CreateDatabaseInput{}
}
if createDBInput.DatabaseInput == nil {
createDBInput.DatabaseInput = &types.DatabaseInput{}
}
createDBInput.DatabaseInput.Name = database

// AWS API call
_, err := client.CreateDatabase(c.ctx, &glue.CreateDatabaseInput{
DatabaseInput: &types.DatabaseInput{
Name: database,
Description: description,
},
CatalogId: catalogID,
})
_, err := client.CreateDatabase(c.ctx, createDBInput)
if err != nil {
if !errorOnAlreadyExists {
return 0
}
lua.Errorf(l, "%s", err.Error())
panic("unreachable")
}
Expand Down

0 comments on commit 57469c8

Please sign in to comment.