diff --git a/pkg/database-types/constants.go b/pkg/database-types/constants.go index 0ba2cec..ceedb3f 100644 --- a/pkg/database-types/constants.go +++ b/pkg/database-types/constants.go @@ -34,6 +34,7 @@ const S3 = "s3" const Scheme = "scheme" const SecretAccessID = "secret_access_id" const SecurityConfig = "securityConfig" +const Trino = "Trino" const Type = "type" const Username = "username" const Value = "value" diff --git a/pkg/database-types/trino.go b/pkg/database-types/trino.go new file mode 100644 index 0000000..d51dabb --- /dev/null +++ b/pkg/database-types/trino.go @@ -0,0 +1,74 @@ +// Copyright 2022 IBM Corp. +// SPDX-License-Identifier: Apache-2.0 + +package databasetypes + +import ( + "fmt" + "reflect" + + "github.com/rs/zerolog" + + models "fybrik.io/openmetadata-connector/datacatalog-go-models" + "fybrik.io/openmetadata-connector/pkg/utils" +) + +type trino struct { + dataBase +} + +func NewTrino(logger *zerolog.Logger) *trino { + return &trino{dataBase: dataBase{name: Trino, logger: logger}} +} + +func (t *trino) TranslateFybrikConfigToOpenMetadataConfig(config map[string]interface{}, + connectionType string, credentials *string) map[string]interface{} { + return config +} + +func (t *trino) TranslateOpenMetadataConfigToFybrikConfig(tableName string, + config map[string]interface{}) (map[string]interface{}, string, error) { + return config, Trino, nil +} + +func (t *trino) TableFQN(serviceName string, createAssetRequest *models.CreateAssetRequest) (string, error) { + connectionProperties, ok := utils.InterfaceToMap(createAssetRequest.Details.GetConnection().AdditionalProperties["trino"], t.logger) + if !ok { + return EmptyString, fmt.Errorf(FailedToConvert, AdditionalProperties) + } + assetName := *createAssetRequest.DestinationAssetID + databaseSchema, found := connectionProperties[DatabaseSchema] + if found { + return fmt.Sprintf("%s.%s.%s.%s", serviceName, Default, databaseSchema.(string), assetName), nil + } + return fmt.Sprintf("%s.%s.%s", serviceName, Default, assetName), nil +} + +func (t *trino) EquivalentServiceConfigurations(requestConfig, serviceConfig map[string]interface{}) bool { + for property, value := range requestConfig { + if !reflect.DeepEqual(serviceConfig[property], value) { + return false + } + } + return true +} + +func (t *trino) DatabaseName(createAssetRequest *models.CreateAssetRequest) string { + return Default +} + +func (t *trino) DatabaseFQN(serviceName string, createAssetRequest *models.CreateAssetRequest) string { + return EmptyString +} + +func (t *trino) DatabaseSchemaName(createAssetRequest *models.CreateAssetRequest) string { + return EmptyString +} + +func (t *trino) DatabaseSchemaFQN(serviceName string, createAssetRequest *models.CreateAssetRequest) string { + return EmptyString +} + +func (t *trino) TableName(createAssetRequest *models.CreateAssetRequest) (string, error) { + return EmptyString, nil +} diff --git a/pkg/openmetadata-connector-core/connector_helper.go b/pkg/openmetadata-connector-core/connector_helper.go index 0d4cfd9..c52c72a 100644 --- a/pkg/openmetadata-connector-core/connector_helper.go +++ b/pkg/openmetadata-connector-core/connector_helper.go @@ -287,12 +287,14 @@ func NewOpenMetadataAPIService(conf map[string]interface{}, customization map[st MysqlLowercase: dbtypes.NewMysql(logger), S3: dbtypes.NewS3(vaultConf, logger), Generic: dbtypes.NewGeneric(logger), + TrinoLowercase: dbtypes.NewTrino(logger), } serviceTypeToConnectionType := map[string]string{ dbtypes.Datalake: S3, dbtypes.Mysql: MysqlLowercase, dbtypes.CustomDatabase: Generic, + dbtypes.Trino: TrinoLowercase, } s := &OpenMetadataAPIService{Endpoint: conf["openmetadata_endpoint"].(string), diff --git a/pkg/openmetadata-connector-core/constants.go b/pkg/openmetadata-connector-core/constants.go index adfbe93..ec10965 100644 --- a/pkg/openmetadata-connector-core/constants.go +++ b/pkg/openmetadata-connector-core/constants.go @@ -47,6 +47,7 @@ const TableProperties = "table-properties" const TagCategories = "tag-categories" const Tags = "tags" const TagsPath = "/tags" +const TrinoLowercase = "trino" const True = "true" const Type = "type" const TypeListLengthLimit = 100