Skip to content

Commit

Permalink
finish implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulalgorithm committed Jul 24, 2024
1 parent eac3ee7 commit d1e76fb
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 567 deletions.
10 changes: 10 additions & 0 deletions metaphor/dbt/cloud/discovery_api/graphql_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
GetJobRunMacrosJob,
GetJobRunMacrosJobMacros,
)
from .get_job_run_metrics import (
GetJobRunMetrics,
GetJobRunMetricsJob,
GetJobRunMetricsJobMetrics,
GetJobRunMetricsJobMetricsFilters,
)
from .get_job_run_models import (
GetJobRunModels,
GetJobRunModelsJob,
Expand Down Expand Up @@ -125,6 +131,10 @@
"GetJobRunMacros",
"GetJobRunMacrosJob",
"GetJobRunMacrosJobMacros",
"GetJobRunMetrics",
"GetJobRunMetricsJob",
"GetJobRunMetricsJobMetrics",
"GetJobRunMetricsJobMetricsFilters",
"GetJobRunModels",
"GetJobRunModelsJob",
"GetJobRunModelsJobModels",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from io import IOBase

from pydantic import BaseModel as PydanticBaseModel, ConfigDict
from pydantic import BaseModel as PydanticBaseModel
from pydantic import ConfigDict


class UnsetType:
Expand Down
46 changes: 45 additions & 1 deletion metaphor/dbt/cloud/discovery_api/graphql_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .get_environment_model_file_path import GetEnvironmentModelFilePath
from .get_environment_snapshot_file_path import GetEnvironmentSnapshotFilePath
from .get_job_run_macros import GetJobRunMacros
from .get_job_run_metrics import GetJobRunMetrics
from .get_job_run_models import GetJobRunModels
from .get_job_run_snapshots import GetJobRunSnapshots
from .get_job_run_sources import GetJobRunSources
Expand Down Expand Up @@ -207,6 +208,50 @@ def get_job_run_sources(
data = self.get_data(response)
return GetJobRunSources.model_validate(data)

def get_job_run_metrics(
self,
job_id: Any,
run_id: Union[Optional[Any], UnsetType] = UNSET,
**kwargs: Any
) -> GetJobRunMetrics:
query = gql(
"""
query GetJobRunMetrics($jobId: BigInt!, $runId: BigInt) {
job(id: $jobId, runId: $runId) {
metrics {
packageName
label
description
dependsOn
uniqueId
timeGrains
timestamp
dimensions
filters {
field
operator
value
}
tags
type
sql
expression
calculation_method
}
}
}
"""
)
variables: Dict[str, object] = {"jobId": job_id, "runId": run_id}
response = self.execute(
query=query,
operation_name="GetJobRunMetrics",
variables=variables,
**kwargs
)
data = self.get_data(response)
return GetJobRunMetrics.model_validate(data)

def get_job_run_tests(
self, job_id: Any, run_id: Any, **kwargs: Any
) -> GetJobRunTests:
Expand All @@ -220,7 +265,6 @@ def get_job_run_tests(
compiledCode
dependsOn
name
runId
uniqueId
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by ariadne-codegen
# Source: queries.graphql

from typing import List, Optional

from pydantic import Field

from .base_model import BaseModel


class GetJobRunMetrics(BaseModel):
job: Optional["GetJobRunMetricsJob"]


class GetJobRunMetricsJob(BaseModel):
metrics: List["GetJobRunMetricsJobMetrics"]


class GetJobRunMetricsJobMetrics(BaseModel):
package_name: Optional[str] = Field(alias="packageName")
label: Optional[str]
description: Optional[str]
depends_on: List[str] = Field(alias="dependsOn")
unique_id: str = Field(alias="uniqueId")
time_grains: Optional[List[str]] = Field(alias="timeGrains")
timestamp: Optional[str]
dimensions: List[str]
filters: List["GetJobRunMetricsJobMetricsFilters"]
tags: Optional[List[str]]
type: Optional[str]
sql: Optional[str]
expression: Optional[str]
calculation_method: Optional[str]


class GetJobRunMetricsJobMetricsFilters(BaseModel):
field: Optional[str]
operator: Optional[str]
value: Optional[str]


GetJobRunMetrics.model_rebuild()
GetJobRunMetricsJob.model_rebuild()
GetJobRunMetricsJobMetrics.model_rebuild()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by ariadne-codegen
# Source: queries.graphql

from typing import Any, List, Optional
from typing import List, Optional

from pydantic import Field

Expand All @@ -22,7 +22,6 @@ class GetJobRunTestsJobTests(BaseModel):
compiled_code: Optional[str] = Field(alias="compiledCode")
depends_on: List[str] = Field(alias="dependsOn")
name: Optional[str]
run_id: Any = Field(alias="runId")
unique_id: str = Field(alias="uniqueId")


Expand Down
167 changes: 25 additions & 142 deletions metaphor/dbt/cloud/discovery_api/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -108,148 +108,31 @@ query GetJobRunSources($jobId: BigInt!, $runId: BigInt!) {
}
}
}
# metrics {
# accountId
# calculation_method
# dbtVersion
# dependsOn
# description
# dimensions
# environmentId
# environmentName
# expression
# filters {
# field
# operator
# value
# }
# jobId
# label
# meta
# model {
# access
# accountId
# alias
# args
# childrenL1
# columns {
# comment
# description
# index
# meta
# name
# tags
# type
# }
# comment
# compileCompletedAt
# compileStartedAt
# compiledCode
# compiledSql
# database
# dbtGroup
# dbtVersion
# dependsOn
# description
# environmentId
# error
# executeCompletedAt
# executeStartedAt
# executionTime
# invocationId
# jobId
# language
# materializedType
# meta
# name
# owner
# packageName
# packages
# projectId
# rawCode
# rawSql
# resourceType
# runElapsedTime
# runGeneratedAt
# runId
# runResults {
# args
# compileCompletedAt
# compileStartedAt
# error
# executeCompletedAt
# executeStartedAt
# executionTime
# invocationId
# runElapsedTime
# runGeneratedAt
# skip
# status
# threadId
# }
# schema
# skip
# stats {
# description
# id
# include
# label
# value
# }
# status
# tags
# tests {
# accountId
# columnName
# compileCompletedAt
# compileStartedAt
# compiledCode
# compiledSql
# dbtVersion
# dependsOn
# description
# environmentId
# error
# executeCompletedAt
# executeStartedAt
# executionTime
# fail
# invocationId
# jobId
# language
# meta
# name
# projectId
# rawCode
# rawSql
# resourceType
# runElapsedTime
# runGeneratedAt
# runId
# skip
# state
# status
# tags
# threadId
# uniqueId
# warn
# }
# threadId
# type
# uniqueId
# }
# name
# packageName
# projectId
# resourceType
# runId
# sql
# tags
# timeGrains
# timestamp
# type
# uniqueId
# }

query GetJobRunMetrics($jobId: BigInt!, $runId: BigInt) {
job(id: $jobId, runId: $runId) {
metrics {
packageName
label
description
dependsOn
uniqueId
timeGrains
timestamp
dimensions
filters {
field
operator
value
}
tags
type
sql
expression
calculation_method
}
}
}

query GetJobRunTests($jobId: BigInt!, $runId: BigInt!) {
job(id: $jobId, runId: $runId) {
Expand Down
Loading

0 comments on commit d1e76fb

Please sign in to comment.