title: BigQuery: Is there a way to get the schema of a SELECT statement without running it (dry_run)?
body: <p>As part of our data engineering testing efforts we would like to check the schema of our views and tables against our schema files (JSON) before we run them so as to be able to capture breakage in typing during integration tests before running the pipeline.</p>
  <p>Our current implementation checks for the typing after having created the table, which could result in issues if a table is created with the wrong schema:</p>
  <pre class="lang-py prettyprint-override"><code>sql = (
          f&quot;CREATE OR REPLACE VIEW `{project}`.{dataset_key}.{table_name} AS (\n&quot; +
         templating.render(path, render_context) + &quot;\n&quot; +
          &quot;)&quot;
      )
  
      BigQueryOperator(
          task_id=f&quot;view_{table_name}&quot;,
          sql=sql,
          use_legacy_sql=False,
          # maximum_billing_tier=10,
      ).execute(context=context)
  
      # asserting schema
      if schema_path is not None:
          bq_hook = BigQueryHook(location=&quot;northamerica-northeast1&quot;, use_legacy_sql=False)
          with open(schema_path, 'r') as f:
              schema = json.load(f)
          fields = bq_hook.get_records(
              f&quot;&quot;&quot;
          SELECT
              column_name AS name,
              type,
              CASE WHEN is_nullable = 'NO' THEN 'REQUIRED' ELSE 'NULLABLE' END AS mode,
          FROM
              `{project}.clinic_data_{clinic_id}`.INFORMATION_SCHEMA.COLUMNS
          WHERE table_name = '{table_name}'
          ORDER BY ordinal_position ASC
          &quot;&quot;&quot;)
          LOG.info('fields: %s', fields)
          LOG.info('schema: %s', schema)
          LOG.info('fields == schema: %s', fields == schema)
          assert fields == schema, &quot;Expected created view to match schema&quot;
  </code></pre>
  <p>Where the schema is a list of dictionaries in the format expected by BQ:</p>
  <pre class="lang-yaml prettyprint-override"><code>[
    {
      &quot;name&quot;: &quot;date_key&quot;,
      &quot;type&quot;: &quot;DATE&quot;,
      &quot;mode&quot;: &quot;REQUIRED&quot;
    },
    {
      &quot;name&quot;: &quot;year&quot;,
      &quot;type&quot;: &quot;INT64&quot;,
      &quot;mode&quot;: &quot;REQUIRED&quot;
    },
    # ...
  ]
  </code></pre>
  <p>We would like to transition to an approach where we can run the table SELECT in dry_run mode and obtain the resulting schema of the SELECT query so as to reduce chances of breakage at runtime and reduce our development feedback loop.
  Hence the question: Is there a way to get the schema of a SELECT statement without running it (dry_run)?</p>
  <p>We could not find a way to do this using the QueryJob parameters returned by a QueryJobConfig with dry_run=True, but we may have overlooked some things :)</p>
  <p>Any answer would be much appreciated!</p>