Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion plugins/sinks/compass/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import (
//go:embed README.md
var summary string

const defaultConcurrency = 10
const (
defaultConcurrency = 10

dataFieldLabels = "labels"
dataFieldPartitionDetail = "partition_detail"
)

type Config struct {
Host string `mapstructure:"host" validate:"required"`
Expand Down Expand Up @@ -228,9 +233,31 @@ func (s *Sink) buildCompassData(anyData *anypb.Any) (map[string]interface{}, err
return nil, fmt.Errorf("unmarshalling to mapdata: %w", err)
}

replaceEmptyTableMapsWithNull(mapData)
return mapData, nil
}

func replaceEmptyTableMapsWithNull(data map[string]interface{}) {
for _, key := range []string{dataFieldLabels, dataFieldPartitionDetail} {
if isEmptyStringMap(data[key]) {
data[key] = nil
}
}
}

func isEmptyStringMap(v interface{}) bool {
if v == nil {
return false
}

m, ok := v.(map[string]interface{})
if !ok {
return false
}

return len(m) == 0
}

func (s *Sink) buildLineage(asset *v1beta2.Asset) (upstreams, downstreams []LineageRecord) {
lineage := asset.GetLineage()
if lineage == nil {
Expand Down
12 changes: 6 additions & 6 deletions plugins/sinks/compass/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func TestSink(t *testing.T) {
"profile": nil,
"update_time": nil,
"attributes": map[string]interface{}{},
"labels": map[string]string{},
"partition_detail": map[string]interface{}{},
"labels": nil,
"partition_detail": nil,
},
Labels: map[string]string{
"labelA": "valueLabelA",
Expand Down Expand Up @@ -312,8 +312,8 @@ func TestSink(t *testing.T) {
"preview_rows": nil,
"profile": nil,
"update_time": nil,
"labels": map[string]string{},
"partition_detail": map[string]interface{}{},
"labels": nil,
"partition_detail": nil,
},
},
},
Expand Down Expand Up @@ -363,8 +363,8 @@ func TestSink(t *testing.T) {
"preview_rows": nil,
"profile": nil,
"update_time": nil,
"labels": map[string]string{},
"partition_detail": map[string]interface{}{},
"labels": nil,
"partition_detail": nil,
},
},
},
Expand Down
Loading