-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from scalar-dev/feature/new-model
Implement new facet data model
- Loading branch information
Showing
70 changed files
with
1,779 additions
and
1,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,5 @@ jobs: | |
poetry install | ||
poetry run pytest -s . | ||
docker-compose logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,28 @@ | ||
package datahub | ||
|
||
import ( | ||
"metadata/core" | ||
"strings" | ||
"time" | ||
|
||
"entgo.io/ent/dialect/sql" | ||
) | ||
|
||
func (h *AspectHandler) HandleDataHubExecutionRequestInput(aspect DataHubExecutionRequestInput) { | ||
urn := core.ProvURN{ | ||
Type: "activity", | ||
Universe: "default", | ||
Namespace: h.namespace, | ||
Source: "datahub", | ||
Name: strings.ReplaceAll(strings.TrimPrefix(h.entityUrn, "urn:li:"), ":", "/"), | ||
} | ||
func (h *AspectHandler) HandleDataHubExecutionRequestInput(aspect DataHubExecutionRequestInput) error { | ||
name := strings.TrimPrefix(h.entityUrn, "urn:li:dataHubExecutionRequest:") | ||
|
||
ingestSourceId := h.client.DatahubIngestSource.Create(). | ||
SetDatahubUrn(h.entityUrn). | ||
SetUrn(urn.ToString()). | ||
SetNamespace(urn.Namespace). | ||
err := h.client.DatahubIngest.Create(). | ||
SetNamespace(h.namespace). | ||
SetType("DataHubExecutionRequestInput"). | ||
SetKey(name). | ||
SetUpdatedAt(time.Now()). | ||
OnConflict(sql.ConflictColumns("namespace", "datahub_urn")). | ||
SetData(aspect.Args). | ||
OnConflict(sql.ConflictColumns("namespace", "type", "key")). | ||
UpdateUpdatedAt(). | ||
IDX(h.context) | ||
|
||
ingestSource := h.client.DatahubIngestSource.GetX(h.context, ingestSourceId) | ||
Exec(h.context) | ||
|
||
if ingestSource.DatasetSourceID == nil { | ||
datasetSource := h.client.DatasetSource.Create().SetUrn(urn.ToString()).SetData(aspect.Args).SaveX(h.context) | ||
h.client.DatahubIngestSource.Update().SetDatasetSourceID(datasetSource.ID).ExecX(h.context) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,51 @@ | ||
package datahub | ||
|
||
import ( | ||
"errors" | ||
"metadata/core" | ||
"metadata/core/facet" | ||
"metadata/ent" | ||
"metadata/ent/datahubingest" | ||
) | ||
|
||
func (h *AspectHandler) HandleDatasetProperties(aspect DatasetProperties) error { | ||
// Convert the datahub URN to a trawler URN | ||
urn, err := parseDatahubUrn(h.namespace, h.entityUrn) | ||
|
||
if err != nil { | ||
h.log.Error("failed to parse urn") | ||
h.log.Error("failed to parse urn", "urn", urn) | ||
return err | ||
} | ||
|
||
// Create the dataset | ||
datasetId, err := ingestDataset(h.client, h.context, urn, h.entityUrn, h.runId, aspect.Name) | ||
executionRequest, err := h.client.DatahubIngest.Query().Where(datahubingest.TypeEQ("DataHubExecutionRequestInput"), datahubingest.NamespaceEQ(h.namespace), datahubingest.KeyEQ(h.runId)).Only(h.context) | ||
|
||
if err != nil { | ||
h.log.Error("error ingesting dataset", "err", err) | ||
if err != nil && !errors.Is(err, &ent.NotFoundError{}) { | ||
return err | ||
} | ||
|
||
h.log.Debug("dataset with id", "datasetId", datasetId) | ||
updater := core.CreateUpdater(h.context, h.client, h.log) | ||
updater.ApplyUpdate( | ||
core.EntityUpdate{ | ||
URN: urn.ToString(), | ||
DataPlatform: urn.Platform, | ||
Type: "https://www.trawler.dev/schema#Dataset", | ||
Namespace: h.namespace, | ||
Facets: []core.FacetUpdate{ | ||
{ | ||
Type: core.DCTitle, | ||
Data: aspect.Name, | ||
}, | ||
{ | ||
Type: "http://www.w3.org/ns/dcat#keyword", | ||
Data: aspect.Tags, | ||
}, | ||
{ | ||
Type: core.DatahubExecutionRequest, | ||
Data: facet.DatahubExecutionRequest{Args: executionRequest.Data.(map[string]interface{})}, | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.