-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require and support configuring JSON transform
Add commands "CREATE DATA MAPPING" and "LIST data_mappings". Disable JSON transform by default unless mappings are created.
- Loading branch information
1 parent
cc39697
commit 21b9da5
Showing
19 changed files
with
451 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package catalog | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/metadb-project/metadb/cmd/metadb/config" | ||
) | ||
|
||
func (c *Catalog) initJSON() error { | ||
q := "SELECT schema_name, table_name, column_name, path, map FROM metadb.transform_json" | ||
rows, err := c.dp.Query(context.TODO(), q) | ||
if err != nil { | ||
return fmt.Errorf("selecting json configuration: %w", err) | ||
} | ||
defer rows.Close() | ||
t := make(map[config.JSONPath]string) | ||
for rows.Next() { | ||
var schema, table, column, path, tmap string | ||
err := rows.Scan(&schema, &table, &column, &path, &tmap) | ||
if err != nil { | ||
return fmt.Errorf("reading json configuration: %w", err) | ||
} | ||
t[config.NewJSONPath(schema, table, column, path)] = tmap | ||
} | ||
if err := rows.Err(); err != nil { | ||
return fmt.Errorf("reading json configuration: %w", err) | ||
} | ||
c.jsonTransform = t | ||
return nil | ||
} | ||
|
||
func (c *Catalog) JSONPathLookup(path config.JSONPath) string { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
return c.jsonTransform[path] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type JSONPath struct { | ||
Schema string | ||
Table string | ||
Column string | ||
Path [16]string | ||
} | ||
|
||
func NewJSONPath(schema, table, column string, path string) JSONPath { | ||
k := JSONPath{ | ||
Schema: schema, | ||
Table: table, | ||
Column: column, | ||
} | ||
if path != "" { | ||
s := strings.Split(path, ".") | ||
for i := 1; i < len(s); i++ { | ||
k.Path[i-1] = s[i] | ||
} | ||
} | ||
return k | ||
} | ||
|
||
func (j JSONPath) Append(node string) JSONPath { | ||
k := JSONPath{ | ||
Schema: j.Schema, | ||
Table: j.Table, | ||
Column: j.Column, | ||
} | ||
for i := 0; i < len(j.Path); i++ { | ||
if j.Path[i] == "" { | ||
k.Path[i] = node | ||
return k | ||
} else { | ||
k.Path[i] = j.Path[i] | ||
} | ||
} | ||
panic(fmt.Sprintf("JSON path exceeds limit of %d nodes", len(j.Path))) | ||
} |
Oops, something went wrong.