0

I ran a query abc and got the result table m in Datalab.

Is there any way I can create a new table in Bigquery and write the content of table m to it in Datalab?

%%bq query --name abc
select *
from `test`

m=abc.execute().result()
Houhouhia
  • 35
  • 6

1 Answers1

0

Yes you can, Datalab supports a number of BigQuery magic commands, among them is create, which allows for the creation of datasets and tables.

See the documentation here: http://googledatalab.github.io/pydatalab/datalab.magics.html

And specifically this section, which details all the available BigQuery commands:

positional arguments:
  {sample,create,delete,dryrun,udf,execute,pipeline,table,schema,datasets,tables,extract,load}
                        commands
    sample              Display a sample of the results of a BigQuery SQL
                        query. The cell can optionally contain arguments for
                        expanding variables in the query, if -q/--query was
                        used, or it can contain SQL for a query.
    create              Create a dataset or table.
    delete              Delete a dataset or table.
    dryrun              Execute a dry run of a BigQuery query and display
                        approximate usage statistics
    udf                 Create a named Javascript BigQuery UDF
    execute             Execute a BigQuery SQL query and optionally send the
                        results to a named table. The cell can optionally
                        contain arguments for expanding variables in the
                        query.
    pipeline            Define a deployable pipeline based on a BigQuery
                        query. The cell can optionally contain arguments for
                        expanding variables in the query.
    table               View a BigQuery table.
    schema              View a BigQuery table or view schema.
    datasets            List the datasets in a BigQuery project.
    tables              List the tables in a BigQuery project or dataset.
    extract             Extract BigQuery query results or table to GCS.
    load                Load data from GCS into a BigQuery table.
Ben P
  • 3,267
  • 4
  • 26
  • 53
  • The type of m is google.datalab.bigquery._query_results_table.QueryResultsTable. How can I use it together with create? @ben – Houhouhia Aug 19 '19 at 10:45
  • Take a look at these docs: https://googledatalab.github.io/pydatalab/datalab.bigquery.html#datalab.bigquery.Query - you can set the table destination and write rules in arguments to `.query`. – Ben P Aug 19 '19 at 10:52