Hello, I'm making a `SourceAsset` that connects to...
# ask-community
a
Hello, I'm making a
SourceAsset
that connects to my BigQuery database. I see online that there is a lib that I can use to connect. But can I run query on my BigQuery tables with this library as well?
t
Hi! The link you posted is a guide on using BigQuery as an I/O Manager, a Dagster concept. You can also run your own queries using the more high-level BigQuery resource. Here are some docs on it: https://docs.dagster.io/integrations/bigquery/reference#executing-custom-sql-commands-with-the-bigquery-resource
a
Hi! Thank you so much for your reply!
So can I use
bigquery_pandas_io_manager
to query as well? Because according to the doc, only
bigquery_resource
covers the custom query.
I get this error when I query through my table with the method provided from the doc
Copy code
dagster._core.errors.DagsterInvariantViolationError: Object <google.cloud.bigquery.table.RowIterator object at 0x7fdda86779dC> is not picklable. You are currently using the fs_io_manager and the multi_or_in_process_executor. You will need to use a different io manager to continue using this output. For example, you can use the mem_io_manager with the in_process_executor.
For more information on io managers, visit <https://docs.dagster.io/concepts/io-management/io-managers> 
For more information on executors, vist <https://docs.dagster.io/deployment/executors#overview>
t
Hi! ā€¢ Yeah, you'll have to use the
bigquery_resource
to execute a raw query against BQ ā€¢ Looks like it's because it gave back a
RowIterator
object. I'm assuming that's a Python generator fn and not actual data, so you might want to either turn it into a dataframe with to_dataframe.
šŸ™ 1
a
Hello! Thank you so much it worked!! šŸ™šŸ¼šŸ”„
I defined the
Definitions
in my _`__init__.py`_ file. For example if I want multiple pipelines to use this same BigQuery resource, how would I be able to use it globally among different pipelines, in different folders?
t
Hmm, are the pipelines in the same
Definitions
object?
a
Yes I think so
if they are not in the same Definitions object, then it doesn't work I assume?
t
Yessirrrr
a
One more question, so my pipelines are in different folders, for example like:
Copy code
-My_project
 -Pipeline1 Folder
 -Pipeline2 Folder
 -Pipeline3 Folder
 -__init__.py
Do I put the Definition object in the
init
file like this to use globally?
Or do I need to put it somewhere under a folder?
t
Yeah, put the
Definitions
object in the
__init__
.py and load all your pipelines into that
Definitions
object. For example, if they're assets, you can import the whole module and use
load_assets_from_module
,
a
Okk! Got it thank you!