Skip to content

Commit

Permalink
Merge pull request #14 from metabolicdata/feature/add_atlan_metadata
Browse files Browse the repository at this point in the history
feature/add_atlan_metadata
  • Loading branch information
browniecode93 authored Aug 28, 2023
2 parents b3d0c6c + 611d883 commit a5e697b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,35 @@ class AtlanService(token: String, baseUrl: String) extends Logging {
guid match{
case "" => ""
case _ => {
val last_synced = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
val mode = mapping.environment.mode
val body =
s"""
|{
| "Data Quality": {
| "last_synced_at" : "${last_synced}",
| "engine_type":"${mode.toString}"
| }
|}
|""".stripMargin
val body: String = generateMetadaBody(mapping)
logger.info(s"Atlan Metadata Json Body ${body}")
HttpRequestHandler.sendHttpPostRequest(s"https://factorial.atlan.com/api/meta/entity/guid/$guid/businessmetadata/displayName?isOverwrite=false", body, token)
}
}
}

def generateMetadaBody(mapping: Config): String = {
val last_synced = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
val mode = mapping.environment.mode
val sql = mapping.mappings.head match {
case sqlmapping: SQLMapping => {
sqlmapping.sqlContents
}
case _ => ""
}
val body =
s"""
|{
| "Data Quality": {
| "last_synced_at" : "${last_synced}",
| "engine_type":"${mode.toString}",
| "sql_mapping":"$sql"
| }
|}
|""".stripMargin
body
}

def setDescription(mapping: Config): String = {
val outputTable = getOutputTableName(mapping)
val dbName = mapping.environment.dbName
Expand All @@ -62,12 +74,6 @@ class AtlanService(token: String, baseUrl: String) extends Logging {
}

def generateDescriptionBodyJson(mapping: Config, outputTable: String, qualifiedName: String): String = {
val sql = mapping.mappings.head match {
case sqlmapping: SQLMapping => {
sqlmapping.sqlContents
}
case _ => ""
}
s"""
|{
| "entities": [
Expand All @@ -76,7 +82,7 @@ class AtlanService(token: String, baseUrl: String) extends Logging {
| "attributes": {
| "name": "$outputTable",
| "qualifiedName": "$qualifiedName",
| "description": "$sql"
| "description": ""
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class MetabolicApp(sparkBuilder: SparkSession.Builder) extends Logging {
val atlan = new AtlanService(token, mapping.environment.atlanBaseUrl.getOrElse(""))
atlan.setLineage(mapping)
atlan.setMetadata(mapping)
atlan.setDescription(mapping)
}
case _ => ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import org.apache.spark.sql.SaveMode
import org.scalatest.BeforeAndAfterAll
import org.scalatest.funsuite.AnyFunSuite

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

class AtlanServiceTest extends AnyFunSuite
with DataFrameSuiteBase
with SharedSparkContext
Expand Down Expand Up @@ -113,7 +116,7 @@ class AtlanServiceTest extends AnyFunSuite
assert(response.trim.equalsIgnoreCase(""))
}

test("Test description body") {
ignore("Test metadata body") {
val testingConfig = Config(
"",
List(io.FileSource("raw/stripe/fake_employee/version=3/", "employees", IOFormat.PARQUET), io.FileSource("clean/fake_employee_s/version=123/", "employeesss", IOFormat.PARQUET), io.FileSource("raw/hubspot/owners/", "owners", IOFormat.PARQUET), io.FileSource("clean/hubspot_owners/", "clean_owners", IOFormat.PARQUET)),
Expand All @@ -123,21 +126,16 @@ class AtlanServiceTest extends AnyFunSuite
Environment("", EngineMode.Batch, "", false, "test", "", Option(""),Option(""), false, false, Seq("raw", "clean", "gold", "bronze"), Seq("raw_stripe", "raw_hubspot"))
)
val calculatedJson = new AtlanService("foo", "foo")
.generateDescriptionBodyJson(testingConfig, "gold_stripe_f_fake_employee_t", "foo/test/gold_stripe_f_fake_employee_t")
.generateMetadaBody(testingConfig)

val expectedJson =
"""
s"""
|{
| "entities": [
| {
| "typeName": "Table",
| "attributes": {
| "name": "gold_stripe_f_fake_employee_t",
| "qualifiedName": "foo/test/gold_stripe_f_fake_employee_t",
| "description": "select * from employees where age < 40"
| }
| }
| ]
| "Data Quality": {
| "last_synced_at" : ${LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))},
| "engine_type":"batch",
| "sql_mapping":"select * from employees where age < 40"
| }
|}
|""".stripMargin
assert(expectedJson.trim.equalsIgnoreCase(calculatedJson.trim))
Expand Down

0 comments on commit a5e697b

Please sign in to comment.