Skip to content

Commit

Permalink
Add custom unmarshalling for Terms in indexsearchresponse
Browse files Browse the repository at this point in the history
Signed-off-by: Karanjot Singh <[email protected]>
  • Loading branch information
0xquark committed May 14, 2024
1 parent e90dca7 commit 39a5fe4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion atlan/model/assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ type Asset struct {
// Names of terms that have been linked to this asset.
MeaningNames *[]string `json:"meaningNames,omitempty"`
// Details of terms that have been linked to this asset.
Meanings *[]Meaning `json:"meanings,omitempty"`
Meanings *[]AtlasGlossaryTerm `json:"meanings,omitempty"`
// Unique identifiers (GUIDs) for any background tasks that are yet to operate on this asset.
PendingTasks *[]string `json:"pendingTasks,omitempty"`

Expand Down
22 changes: 22 additions & 0 deletions atlan/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,17 @@ type SearchAssets struct {
QualifiedName *string `json:"qualifiedName,omitempty"`
Name *string `json:"name,omitempty"`
SearchAttributes *SearchAttributes `json:"Attributes,omitempty"`
SearchMeanings []Meanings `json:"meanings,omitempty"` // If meanings as json is already defined in Asset struct then defining the meanings here would result in an empty response.
NotNull *bool `json:"notNull,omitempty"`
}

type Meanings struct {
Guid string `json:"termGuid,omitempty"`
RelationGuid string `json:"relationGuid,omitempty"`
DisplayText string `json:"displayText,omitempty"`
Confidence int `json:"confidence,omitempty"`
}

type SearchAttributes struct {
QualifiedName *string `json:"qualifiedName,omitempty"`
Name *string `json:"name,omitempty"`
Expand All @@ -494,6 +502,7 @@ func (sa *SearchAssets) UnmarshalJSON(data []byte) error {
QualifiedName *string `json:"qualifiedName,omitempty"`
Name *string `json:"name,omitempty"`
SearchAttributes *SearchAttributes `json:"attributes,omitempty"`
SearchMeanings []Meanings `json:"meanings,omitempty"`
NotNull *bool `json:"notNull,omitempty"`
}

Expand All @@ -503,11 +512,22 @@ func (sa *SearchAssets) UnmarshalJSON(data []byte) error {
return err
}

// Directly handling the SearchMeanings if present (This is done because Meanings in IndexSearchResponse conflicits with meanings of type AtlasGlossaryTerm defined in /assets/asset.go .
type SearchMeaningsData struct {
SearchMeanings []Meanings `json:"meanings,omitempty"`
}

var meaningsData SearchMeaningsData
if err := json.Unmarshal(data, &meaningsData); err != nil {
return err
}

// Copy fields from auxiliary struct to the main struct
sa.Asset = aux.Asset
sa.Table = aux.Table
sa.Column = aux.Column
sa.NotNull = aux.NotNull
sa.SearchMeanings = meaningsData.SearchMeanings

// Check if any search attributes are present
if aux.SearchAttributes != nil {
Expand All @@ -522,5 +542,7 @@ func (sa *SearchAssets) UnmarshalJSON(data []byte) error {
sa.CertificateStatus = aux.SearchAttributes.CertificateStatus
}

if len(aux.SearchMeanings) > 0 {
}
return nil
}
53 changes: 45 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,45 @@ func main() {

ctx := client.NewContext()

ctx.SetLogger(true, "info")
ctx.SetLogger(true, "debug")

qualifiedName := "default/snowflake/1714501359/RAW/WIDEWORLDIMPORTERS_SALESFORCE/WAITLIST_WORK_TYPE_HISTORY"
// Fetch columns of table from Atlan using Qualified Name
assetQualifiedName := "default/snowflake/1715371897/RAW/WIDEWORLDIMPORTERS_SALESFORCE/FIVETRAN_API_CALL"

TableResponse, _ := client.NewFluentSearch().
PageSizes(50).
columnSearchResponse, _ := client.NewFluentSearch().
PageSizes(1000).
ActiveAssets().
Where(ctx.Table.TYPENAME.Eq("Table")).
Where(ctx.Table.QUALIFIED_NAME.Eq(qualifiedName)).
IncludeOnResults("userDescription", "ownerUsers", "ownerGroups", "certificateStatus").
Where(ctx.Column.TYPENAME.Eq("Column")).
Where(ctx.Column.TABLE_QUALIFIED_NAME.Eq(assetQualifiedName)).
IncludeOnResults("userDescription", "dataType", "isPrimary").
Execute()

fmt.Println(*TableResponse[0].Entities[0].UserDescription)
//fmt.Println(*columnSearchResponse[0].Entities[0].Name)
//fmt.Println(*columnSearchResponse[0].Entities[0].DataType)

for _, entity := range columnSearchResponse[0].Entities {
fmt.Println(entity)
}

qualifiedname := "default/snowflake/1715371897/RAW/WIDEWORLDIMPORTERS_SALESFORCE/FIVETRAN_API_CALL"

response, atlanErr := client.NewFluentSearch().
PageSizes(10).
ActiveAssets().
Where(ctx.Table.QUALIFIED_NAME.Eq(qualifiedname)).
IncludeOnResults("userDescription", "ownerUsers", "ownerGroups", "certificateStatus", "tags").
Execute()

if atlanErr != nil {
fmt.Println(atlanErr)
}

fmt.Println(response[0].Entities[0].SearchMeanings[0].Guid)

/*
*/
/*
// Fetch columns of table from Atlan using Qualified Name
qualifiedname := "default/snowflake/1714501359/RAW/WIDEWORLDIMPORTERS_SALESFORCE/WAITLIST_WORK_TYPE_HISTORY/ID"
Expand Down Expand Up @@ -52,6 +78,17 @@ func main() {
//client.GetAll()

/*
g := &client.AtlasGlossary{}
g.Creator("go-sdk-test1", atlan.AtlanIconAirplaneInFlight)
response, err := client.Save(g)
if err != nil {
fmt.Println(err)
}
for _, entity := range response.MutatedEntities.CREATE {
fmt.Println(entity.DisplayText)
}
dc := &client.DataContract{}
dc.Creator("DataContractLatestCertified")
response, err := client.Save()
Expand Down

0 comments on commit 39a5fe4

Please sign in to comment.