Skip to content
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
18 changes: 16 additions & 2 deletions plugins/flytekit-bigquery/flytekitplugins/bigquery/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
from typing import Dict, Optional

from flyteidl.core.execution_pb2 import TaskExecution, TaskLog
from google.api_core.client_info import ClientInfo
from google.cloud import bigquery

from flytekit import FlyteContextManager, StructuredDataset, logger
from flytekit.core.type_engine import TypeEngine
from flytekit.extend.backend.base_connector import AsyncConnectorBase, ConnectorRegistry, Resource, ResourceMeta
from flytekit.extend.backend.base_connector import (
AsyncConnectorBase,
ConnectorRegistry,
Resource,
ResourceMeta,
)
from flytekit.extend.backend.utils import convert_to_flyte_phase
from flytekit.models.literals import LiteralMap
from flytekit.models.task import TaskTemplate
Expand Down Expand Up @@ -59,9 +65,17 @@ def create(
)

custom = task_template.custom

domain = custom.get("Domain")
sdk_version = task_template.metadata.runtime.version

user_agent = f"Flytekit/{sdk_version} (GPN:Union;{domain or ''})"
cinfo = ClientInfo(user_agent=user_agent)

project = custom["ProjectID"]
location = custom["Location"]
client = bigquery.Client(project=project, location=location)

client = bigquery.Client(project=project, location=location, client_info=cinfo)
query_job = client.query(task_template.sql.statement, job_config=job_config)

return BigQueryMetadata(job_id=str(query_job.job_id), location=location, project=project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]:
config = {
"Location": self.task_config.Location,
"ProjectID": self.task_config.ProjectID,
"Domain": settings.domain,
}
Comment thread
samhita-alla marked this conversation as resolved.
if self.task_config.QueryJobConfig is not None:
config.update(self.task_config.QueryJobConfig.to_api_repr()["query"])
Expand Down
2 changes: 1 addition & 1 deletion plugins/flytekit-bigquery/tests/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def my_wf(ds: str) -> StructuredDataset:
assert "@version" in task_spec.template.sql.statement
assert task_spec.template.sql.dialect == task_spec.template.sql.Dialect.ANSI
s = Struct()
s.update({"ProjectID": "Flyte", "Location": "Asia", "allowLargeResults": True})
s.update({"Domain": "dom", "ProjectID": "Flyte", "Location": "Asia", "allowLargeResults": True})
assert task_spec.template.custom == json_format.MessageToDict(s)
assert len(task_spec.template.interface.inputs) == 1
assert len(task_spec.template.interface.outputs) == 1
Expand Down
1 change: 1 addition & 0 deletions plugins/flytekit-bigquery/tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self):
task_config = {
"Location": "us-central1",
"ProjectID": "dummy_project",
"Domain": "dev",
}

int_type = types.LiteralType(types.SimpleType.INTEGER)
Expand Down
Loading