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

Fix: Add Column Search Attributes #62

Merged
merged 1 commit into from
Nov 11, 2024
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
130 changes: 129 additions & 1 deletion atlan/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package model
import (
"encoding/json"
"regexp"
"time"

"github.com/atlanhq/atlan-go/atlan"
"github.com/atlanhq/atlan-go/atlan/model/structs"
Expand Down Expand Up @@ -552,12 +553,76 @@ type Meanings struct {
}

type SearchAttributes struct {
// Column Attributes
SubDataType *string `json:"subDataType,omitempty"`
RawDataTypeDefinition *string `json:"rawDataTypeDefinition,omitempty"`
Order *int `json:"order,omitempty"`
NestedColumnCount *int `json:"nestedColumnCount,omitempty"`
IsPartition *bool `json:"isPartition,omitempty"`
PartitionOrder *int `json:"partitionOrder,omitempty"`
IsClustered *bool `json:"isClustered,omitempty"`
IsPrimary *bool `json:"isPrimary,omitempty"`
IsForeign *bool `json:"isForeign,omitempty"`
IsIndexed *bool `json:"isIndexed,omitempty"`
IsSort *bool `json:"isSort,omitempty"`
IsDist *bool `json:"isDist,omitempty"`
IsPinned *bool `json:"isPinned,omitempty"`
PinnedBy *string `json:"pinnedBy,omitempty"`
PinnedAt *time.Time `json:"pinnedAt,omitempty"`
Precision *int `json:"precision,omitempty"`
DefaultValue *string `json:"defaultValue,omitempty"`
NumericScale *float64 `json:"numericScale,omitempty"`
Validations map[string]string `json:"validations,omitempty"`
ParentColumnQualifiedName *string `json:"parentColumnQualifiedName,omitempty"`
ParentColumnName *string `json:"parentColumnName,omitempty"`
ColumnDistinctValuesCount *int `json:"columnDistinctValuesCount,omitempty"`
ColumnDistinctValuesCountLong *int `json:"columnDistinctValuesCountLong,omitempty"`
ColumnHistogram *structs.Histogram `json:"columnHistogram,omitempty"`
ColumnMax *float64 `json:"columnMax,omitempty"`
ColumnMin *float64 `json:"columnMin,omitempty"`
ColumnMean *float64 `json:"columnMean,omitempty"`
ColumnSum *float64 `json:"columnSum,omitempty"`
ColumnMedian *float64 `json:"columnMedian,omitempty"`
ColumnStandardDeviation *float64 `json:"columnStandardDeviation,omitempty"`
ColumnUniqueValuesCount *int `json:"columnUniqueValuesCount,omitempty"`
ColumnUniqueValuesCountLong *int `json:"columnUniqueValuesCountLong,omitempty"`
ColumnAverage *float64 `json:"columnAverage,omitempty"`
ColumnAverageLength *float64 `json:"columnAverageLength,omitempty"`
ColumnDuplicateValuesCount *int `json:"columnDuplicateValuesCount,omitempty"`
ColumnDuplicateValuesCountLong *int `json:"columnDuplicateValuesCountLong,omitempty"`
ColumnMaximumStringLength *int `json:"columnMaximumStringLength,omitempty"`
ColumnMaxs *map[string]bool `json:"columnMaxs,omitempty"`
ColumnMinimumStringLength *int `json:"columnMinimumStringLength,omitempty"`
ColumnMins *map[string]bool `json:"columnMins,omitempty"`
ColumnMissingValuesCount *int `json:"columnMissingValuesCount,omitempty"`
ColumnMissingValuesCountLong *int `json:"columnMissingValuesCountLong,omitempty"`
ColumnMissingValuesPercentage *float64 `json:"columnMissingValuesPercentage,omitempty"`
ColumnUniquenessPercentage *float64 `json:"columnUniquenessPercentage,omitempty"`
ColumnVariance *float64 `json:"columnVariance,omitempty"`
ColumnTopValues []*structs.ColumnValueFrequencyMap `json:"columnTopValues,omitempty"`
ColumnDepthLevel *int `json:"columnDepthLevel,omitempty"`
SnowflakeDynamicTable *structs.SnowflakeDynamicTable `json:"snowflakeDynamicTable,omitempty"`
View *structs.View `json:"view,omitempty"`
NestedColumns []*structs.Column `json:"nestedColumns,omitempty"`
DataQualityMetricDimensions []*structs.Metric `json:"dataQualityMetricDimensions,omitempty"`
DbtModelColumns []*structs.DbtModelColumn `json:"dbtModelColumns,omitempty"`
Table *structs.Table `json:"table,omitempty"`
ColumnDbtModelColumns []*structs.DbtModelColumn `json:"columnDbtModelColumns,omitempty"`
MaterialisedView *structs.MaterialisedView `json:"materialisedView,omitempty"`
ParentColumn *structs.Column `json:"parentColumn,omitempty"`
Queries []*Query `json:"queries,omitempty"`
MetricTimestamps []*structs.Metric `json:"metricTimestamps,omitempty"`
ForeignKeyTo []*structs.Column `json:"foreignKeyTo,omitempty"`
ForeignKeyFrom *structs.Column `json:"foreignKeyFrom,omitempty"`
DbtMetrics []*structs.DbtMetric `json:"dbtMetrics,omitempty"`
TablePartition *structs.TablePartition `json:"tablePartition,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`

QualifiedName *string `json:"qualifiedName,omitempty"`
Name *string `json:"name,omitempty"`
UserDescription *string `json:"userDescription,omitempty"`
Description *string `json:"description,omitempty"`
DataType *string `json:"dataType,omitempty"`
IsPrimary *bool `json:"isPrimary,omitempty"`
IsNullable *bool `json:"isNullable,omitempty"`
OwnerGroups *[]string `json:"ownerGroups,omitempty"`
OwnerUsers *[]string `json:"ownerUsers,omitempty"`
Expand Down Expand Up @@ -621,6 +686,69 @@ func (sa *SearchAssets) UnmarshalJSON(data []byte) error {
sa.AnnouncementMessage = aux.SearchAttributes.AnnouncementMessage
sa.CertificateStatus = aux.SearchAttributes.CertificateStatus
sa.CertificateStatusMessage = aux.SearchAttributes.CertificateStatusMessage
// Column Attributes
sa.MaxLength = aux.SearchAttributes.MaxLength
sa.Precision = aux.SearchAttributes.Precision
sa.NumericScale = aux.SearchAttributes.NumericScale
sa.IsPartition = aux.SearchAttributes.IsPartition
sa.SubDataType = aux.SearchAttributes.SubDataType
sa.RawDataTypeDefinition = aux.SearchAttributes.RawDataTypeDefinition
sa.Order = aux.SearchAttributes.Order
sa.NestedColumnCount = aux.SearchAttributes.NestedColumnCount
sa.IsPartition = aux.SearchAttributes.IsPartition
sa.PartitionOrder = aux.SearchAttributes.PartitionOrder
sa.IsClustered = aux.SearchAttributes.IsClustered
sa.IsPrimary = aux.SearchAttributes.IsPrimary
sa.IsForeign = aux.SearchAttributes.IsForeign
sa.IsIndexed = aux.SearchAttributes.IsIndexed
sa.IsSort = aux.SearchAttributes.IsSort
sa.IsDist = aux.SearchAttributes.IsDist
sa.IsPinned = aux.SearchAttributes.IsPinned
sa.PinnedBy = aux.SearchAttributes.PinnedBy
sa.PinnedAt = aux.SearchAttributes.PinnedAt
sa.DefaultValue = aux.SearchAttributes.DefaultValue
sa.Validations = aux.SearchAttributes.Validations
sa.ParentColumnQualifiedName = aux.SearchAttributes.ParentColumnQualifiedName
sa.ParentColumnName = aux.SearchAttributes.ParentColumnName
sa.ColumnDistinctValuesCount = aux.SearchAttributes.ColumnDistinctValuesCount
sa.ColumnDistinctValuesCountLong = aux.SearchAttributes.ColumnDistinctValuesCountLong
sa.ColumnHistogram = aux.SearchAttributes.ColumnHistogram
sa.ColumnMax = aux.SearchAttributes.ColumnMax
sa.ColumnMin = aux.SearchAttributes.ColumnMin
sa.ColumnMean = aux.SearchAttributes.ColumnMean
sa.ColumnSum = aux.SearchAttributes.ColumnSum
sa.ColumnMedian = aux.SearchAttributes.ColumnMedian
sa.ColumnStandardDeviation = aux.SearchAttributes.ColumnStandardDeviation
sa.ColumnUniqueValuesCount = aux.SearchAttributes.ColumnUniqueValuesCount
sa.ColumnUniqueValuesCountLong = aux.SearchAttributes.ColumnUniqueValuesCountLong
sa.ColumnAverage = aux.SearchAttributes.ColumnAverage
sa.ColumnAverageLength = aux.SearchAttributes.ColumnAverageLength
sa.ColumnDuplicateValuesCount = aux.SearchAttributes.ColumnDuplicateValuesCount
sa.ColumnDuplicateValuesCountLong = aux.SearchAttributes.ColumnDuplicateValuesCountLong
sa.ColumnMaximumStringLength = aux.SearchAttributes.ColumnMaximumStringLength
sa.ColumnMaxs = aux.SearchAttributes.ColumnMaxs
sa.ColumnMinimumStringLength = aux.SearchAttributes.ColumnMinimumStringLength
sa.ColumnMins = aux.SearchAttributes.ColumnMins
sa.ColumnMissingValuesCount = aux.SearchAttributes.ColumnMissingValuesCount
sa.ColumnMissingValuesCountLong = aux.SearchAttributes.ColumnMissingValuesCountLong
sa.ColumnMissingValuesPercentage = aux.SearchAttributes.ColumnMissingValuesPercentage
sa.ColumnUniquenessPercentage = aux.SearchAttributes.ColumnUniquenessPercentage
sa.ColumnVariance = aux.SearchAttributes.ColumnVariance
sa.ColumnTopValues = aux.SearchAttributes.ColumnTopValues
sa.ColumnDepthLevel = aux.SearchAttributes.ColumnDepthLevel
sa.SnowflakeDynamicTable = aux.SearchAttributes.SnowflakeDynamicTable
sa.View = aux.SearchAttributes.View
sa.NestedColumns = aux.SearchAttributes.NestedColumns
sa.DataQualityMetricDimensions = aux.SearchAttributes.DataQualityMetricDimensions
sa.DbtModelColumns = aux.SearchAttributes.DbtModelColumns
sa.ColumnDbtModelColumns = aux.SearchAttributes.ColumnDbtModelColumns
sa.MaterialisedView = aux.SearchAttributes.MaterialisedView
sa.ParentColumn = aux.SearchAttributes.ParentColumn
sa.MetricTimestamps = aux.SearchAttributes.MetricTimestamps
sa.ForeignKeyTo = aux.SearchAttributes.ForeignKeyTo
sa.ForeignKeyFrom = aux.SearchAttributes.ForeignKeyFrom
sa.DbtMetrics = aux.SearchAttributes.DbtMetrics
sa.TablePartition = aux.SearchAttributes.TablePartition

// Populate `rawSearchAttributes` (necessary for setting `SearchAssets.CustomMetadataSets`)
// First, unmarshal the data into a `rawSearchAsset` map
Expand Down
85 changes: 56 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,74 @@ package main

import (
"fmt"
_ "github.com/atlanhq/atlan-go/atlan"
"github.com/atlanhq/atlan-go/atlan/assets"
_ "github.com/atlanhq/atlan-go/atlan/model/structs"
)

func main() {

ctx := assets.NewContext()
ctx.EnableLogging("debug")

//ctx, _ := assets.Context("tenet.atlan.com", "xyz")
assetQualifiedName := "default/snowflake/1728590954/ANALYTICS/WIDE_WORLD_IMPORTERS/STG_CUSTOMER_TRANSACTIONS"

ctx.SetLogger(true, "debug")
columnSearchResponse, _ := assets.NewFluentSearch().
PageSizes(100).
ActiveAssets().
Where(ctx.Column.TYPENAME.Eq("Column")).
Where(ctx.Column.NAME.Eq("PAYMENT_METHOD_ID")).
Where(ctx.Table.TABLE_QUALIFIED_NAME.Eq(assetQualifiedName)).
IncludeOnResults("maxLength", "precision", "numericScale").
Execute()

//t := &assets.Table{} // create a new Table instance
fmt.Println(*columnSearchResponse[0].Entities[0].MaxLength)
fmt.Println(*columnSearchResponse[0].Entities[0].Precision)
fmt.Println(*columnSearchResponse[0].Entities[0].NumericScale)

// Define the Atlan tag details
qualifiedName := "default/snowflake/1725896074/ANALYTICS/WIDE_WORLD_IMPORTERS/FCT_STOCK_ITEM_HOLDINGS"
//atlanTagNames := []string{"Daily", "Hourly"} // List of tags to add

err := assets.RemoveAtlanTag[*assets.Table](qualifiedName, "Confidential")
/*
// Set the propagation options
propagate := true
removePropagationOnDelete := true
restrictLineagePropagation := false
restrictPropagationThroughHierarchy := false


// Call the AddAtlanTags function
err := assets.UpdateAtlanTags[*assets.Table](
qualifiedName, // The qualified name of the asset
atlanTagNames, // The list of Atlan tags to add
propagate, // Whether to propagate the tags or not
removePropagationOnDelete, // Remove propagation on delete
restrictLineagePropagation, // Restrict lineage propagation
restrictPropagationThroughHierarchy, // Restrict propagation through hierarchy
)
ctx := assets.NewContext()

//ctx, _ := assets.Context("tenet.atlan.com", "xyz")

ctx.SetLogger(true, "debug")

generator.RunGenerator()


*/
if err != nil {
fmt.Printf("Failed to add Atlan tags: %v\n", err)
} else {
fmt.Println("Atlan tags added successfully.")
}
/*
//t := &assets.Table{} // create a new Table instance

// Define the Atlan tag details
qualifiedName := "default/snowflake/1725896074/ANALYTICS/WIDE_WORLD_IMPORTERS/FCT_STOCK_ITEM_HOLDINGS"
//atlanTagNames := []string{"Daily", "Hourly"} // List of tags to add

err := assets.RemoveAtlanTag[*assets.Table](qualifiedName, "Confidential")
/*
// Set the propagation options
propagate := true
removePropagationOnDelete := true
restrictLineagePropagation := false
restrictPropagationThroughHierarchy := false


// Call the AddAtlanTags function
err := assets.UpdateAtlanTags[*assets.Table](
qualifiedName, // The qualified name of the asset
atlanTagNames, // The list of Atlan tags to add
propagate, // Whether to propagate the tags or not
removePropagationOnDelete, // Remove propagation on delete
restrictLineagePropagation, // Restrict lineage propagation
restrictPropagationThroughHierarchy, // Restrict propagation through hierarchy
)

if err != nil {
fmt.Printf("Failed to add Atlan tags: %v\n", err)
} else {
fmt.Println("Atlan tags added successfully.")
}
*/
//schemaName := "WIDEWORLDIMPORTERS_PURCHASING"
//dataBaseName := "RAW"
//dataBaseQualifiedName := "default/snowflake/1723642516/RAW"
Expand Down Expand Up @@ -530,4 +556,5 @@ func main() {
*/
//fmt.Println("Retrieved Typedef:")
//fmt.Printf("DisplayName: %s\n", t.AtlanTagDefs[1].DisplayName)
//
}
Loading