GBQQueryDataset¶
GBQQueryDataset loads data from a provided SQL query in Google BigQuery using pandas-gbq. It is read-only.
kedro_datasets.pandas.GBQQueryDataset ¶
GBQQueryDataset(
sql=None,
project=None,
credentials=None,
load_args=None,
fs_args=None,
filepath=None,
metadata=None,
)
Bases: AbstractDataset[None, DataFrame]
GBQQueryDataset loads data from a provided SQL query from Google
BigQuery. It uses pandas_gbq.read_gbq which itself uses pandas-gbq
internally to read from BigQuery table. Therefore it supports all allowed
pandas options on read_gbq.
Example usage for the YAML API:¶
vehicles:
type: pandas.GBQQueryDataset
sql: "select shuttle, shuttle_id from spaceflights.shuttles;"
project: my-project
credentials: gbq-creds
load_args:
reauth: True
Example usage for the Python API:¶
from kedro_datasets.pandas import GBQQueryDataset
sql = "SELECT * FROM dataset_1.table_a"
dataset = GBQQueryDataset(sql, project="my-project")
sql_data = dataset.load()
Parameters:
-
sql(str | None, default:None) –The sql query statement.
-
project(str | None, default:None) –Google BigQuery Account project ID. Optional when available from the environment. https://cloud.google.com/resource-manager/docs/creating-managing-projects
-
credentials(dict[str, Any] | Credentials | None, default:None) –Credentials for accessing Google APIs. Either a credential that bases on
google.auth.credentials.CredentialsOR a service account json as a dictionary OR a path to a service account key json file. https://googleapis.dev/python/google-auth/latest/ -
load_args(dict[str, Any] | None, default:None) –Pandas options for loading BigQuery table into DataFrame. Here you can find all available arguments: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_gbq.html All defaults are preserved.
-
fs_args(dict[str, Any] | None, default:None) –Extra arguments to pass into underlying filesystem class constructor (e.g.
{"project": "my-project"}forGCSFileSystem) used for reading the SQL query from filepath. -
filepath(str | PathLike | None, default:None) –A path to a file with a sql query statement. Can be a string or a PathLike object.
-
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.
Raises:
-
DatasetError–When
sqlandfilepathparameters are either both empty or both provided, as well as when thesave()method is invoked.
Source code in kedro_datasets/pandas/gbq_dataset.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
_describe ¶
_describe()
Source code in kedro_datasets/pandas/gbq_dataset.py
304 305 306 307 308 309 310 311 | |
load ¶
load()
Source code in kedro_datasets/pandas/gbq_dataset.py
313 314 315 316 317 318 319 320 321 322 323 324 325 | |
save ¶
save(data)
Source code in kedro_datasets/pandas/gbq_dataset.py
327 328 | |