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

Added an extension point for doltgres to lookup values in the dolt_ignore table #8847

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions go/libraries/doltcore/doltdb/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
"github.com/dolthub/dolt/go/store/prolly/tree"
"github.com/dolthub/dolt/go/store/types"
"github.com/dolthub/dolt/go/store/val"
)
Expand Down Expand Up @@ -57,6 +58,9 @@ type IgnorePatterns []IgnorePattern
// ConvertTupleToIgnoreBoolean is a function that converts a Tuple to a boolean for the ignore field. This is used to handle the Doltgres extended boolean type.
var ConvertTupleToIgnoreBoolean = convertTupleToIgnoreBoolean

// GetIgnoreTablePatternKey is a function that converts a Tuple to a string for the pattern field. This is used to handle the Doltgres extended string type.
var GetIgnoreTablePatternKey = getIgnoreTablePatternKey

func convertTupleToIgnoreBoolean(valueDesc val.TupleDesc, valueTuple val.Tuple) (bool, error) {
if !valueDesc.Equals(val.NewTupleDescriptor(val.Type{Enc: val.Int8Enc, Nullable: false})) {
return false, fmt.Errorf("dolt_ignore had unexpected value type, this should never happen")
Expand All @@ -68,6 +72,17 @@ func convertTupleToIgnoreBoolean(valueDesc val.TupleDesc, valueTuple val.Tuple)
return ignore, nil
}

func getIgnoreTablePatternKey(keyDesc val.TupleDesc, keyTuple val.Tuple, _ tree.NodeStore) (string, error) {
if !keyDesc.Equals(val.NewTupleDescriptor(val.Type{Enc: val.StringEnc, Nullable: false})) {
return "", fmt.Errorf("dolt_ignore had unexpected key type, this should never happen")
}
key, ok := keyDesc.GetString(0, keyTuple)
if !ok {
return "", fmt.Errorf("could not read pattern")
}
return key, nil
}

func GetIgnoredTablePatterns(ctx context.Context, roots Roots, schemas []string) (map[string]IgnorePatterns, error) {
ignorePatternsForSchemas := make(map[string]IgnorePatterns)
workingSet := roots.Working
Expand Down Expand Up @@ -98,10 +113,6 @@ func GetIgnoredTablePatterns(ctx context.Context, roots Roots, schemas []string)
}
keyDesc, valueDesc := ignoreTableSchema.GetMapDescriptors()

if !keyDesc.Equals(val.NewTupleDescriptor(val.Type{Enc: val.StringEnc})) {
return nil, fmt.Errorf("dolt_ignore had unexpected key type, this should never happen")
}

ignoreTableMap, err := durable.ProllyMapFromIndex(index).IterAll(ctx)
if err != nil {
return nil, err
Expand All @@ -115,10 +126,13 @@ func GetIgnoredTablePatterns(ctx context.Context, roots Roots, schemas []string)
return nil, err
}

pattern, ok := keyDesc.GetString(0, keyTuple)
if !ok {
return nil, fmt.Errorf("could not read pattern")
m := durable.MapFromIndex(index)

pattern, err := GetIgnoreTablePatternKey(keyDesc, keyTuple, m.NodeStore())
if err != nil {
return nil, err
}

ignore, err := ConvertTupleToIgnoreBoolean(valueDesc, valueTuple)
if err != nil {
return nil, err
Expand Down
Loading