Reference documentation and code samples for the BigQuery API module Google::Cloud::Bigquery::External.
External
Creates a new DataSource (or subclass) object that
represents the external data source that can be queried from directly,
even though the data is not stored in BigQuery. Instead of loading or
streaming the data, this object references the external data source.
require"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newcsv_url="gs://bucket/path/to/data.csv"csv_table=bigquery.externalcsv_urldo|csv|csv.autodetect=truecsv.skip_leading_rows=1enddata=bigquery.query"SELECT * FROM my_ext_table",external:{my_ext_table:csv_table}# Iterate over the first page of resultsdata.eachdo|row|putsrow[:name]end# Retrieve the next page of resultsdata=data.nextifdata.next?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# BigQuery API - Module Google::Cloud::Bigquery::External (v1.56.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.56.0 (latest)](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External)\n- [1.55.0](/ruby/docs/reference/google-cloud-bigquery/1.55.0/Google-Cloud-Bigquery-External)\n- [1.54.0](/ruby/docs/reference/google-cloud-bigquery/1.54.0/Google-Cloud-Bigquery-External)\n- [1.53.0](/ruby/docs/reference/google-cloud-bigquery/1.53.0/Google-Cloud-Bigquery-External)\n- [1.52.1](/ruby/docs/reference/google-cloud-bigquery/1.52.1/Google-Cloud-Bigquery-External)\n- [1.51.1](/ruby/docs/reference/google-cloud-bigquery/1.51.1/Google-Cloud-Bigquery-External)\n- [1.50.0](/ruby/docs/reference/google-cloud-bigquery/1.50.0/Google-Cloud-Bigquery-External)\n- [1.49.1](/ruby/docs/reference/google-cloud-bigquery/1.49.1/Google-Cloud-Bigquery-External)\n- [1.48.1](/ruby/docs/reference/google-cloud-bigquery/1.48.1/Google-Cloud-Bigquery-External)\n- [1.47.0](/ruby/docs/reference/google-cloud-bigquery/1.47.0/Google-Cloud-Bigquery-External)\n- [1.46.1](/ruby/docs/reference/google-cloud-bigquery/1.46.1/Google-Cloud-Bigquery-External)\n- [1.45.0](/ruby/docs/reference/google-cloud-bigquery/1.45.0/Google-Cloud-Bigquery-External)\n- [1.44.2](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External)\n- [1.43.1](/ruby/docs/reference/google-cloud-bigquery/1.43.1/Google-Cloud-Bigquery-External)\n- [1.42.0](/ruby/docs/reference/google-cloud-bigquery/1.42.0/Google-Cloud-Bigquery-External)\n- [1.41.0](/ruby/docs/reference/google-cloud-bigquery/1.41.0/Google-Cloud-Bigquery-External)\n- [1.40.0](/ruby/docs/reference/google-cloud-bigquery/1.40.0/Google-Cloud-Bigquery-External)\n- [1.39.0](/ruby/docs/reference/google-cloud-bigquery/1.39.0/Google-Cloud-Bigquery-External)\n- [1.38.1](/ruby/docs/reference/google-cloud-bigquery/1.38.1/Google-Cloud-Bigquery-External) \nReference documentation and code samples for the BigQuery API module Google::Cloud::Bigquery::External.\n\nExternal\n--------\n\nCreates a new [DataSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-DataSource \"Google::Cloud::Bigquery::External::DataSource (class)\") (or subclass) object that\nrepresents the external data source that can be queried from directly,\neven though the data is not stored in BigQuery. Instead of loading or\nstreaming the data, this object references the external data source.\n\nSee [DataSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-DataSource \"Google::Cloud::Bigquery::External::DataSource (class)\"), [CsvSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-CsvSource \"Google::Cloud::Bigquery::External::CsvSource (class)\"),\n[JsonSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-JsonSource \"Google::Cloud::Bigquery::External::JsonSource (class)\"), [SheetsSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-SheetsSource \"Google::Cloud::Bigquery::External::SheetsSource (class)\"),\n[BigtableSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource \"Google::Cloud::Bigquery::External::BigtableSource (class)\")\n\nExamples\n--------\n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\ncsv_url = \"gs://bucket/path/to/data.csv\"\ncsv_table = bigquery.external csv_url do |csv|\n csv.autodetect = true\n csv.skip_leading_rows = 1\nend\n\ndata = bigquery.query \"SELECT * FROM my_ext_table\",\n external: { my_ext_table: csv_table }\n\n# Iterate over the first page of results\ndata.each do |row|\n puts row[:name]\nend\n# Retrieve the next page of results\ndata = data.next if data.next?\n```\n\nHive partitioning options: \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\ngcs_uri = \"gs://cloud-samples-data/bigquery/hive-partitioning-samples/autolayout/*\"\nsource_uri_prefix = \"gs://cloud-samples-data/bigquery/hive-partitioning-samples/autolayout/\"\nexternal_data = bigquery.external gcs_uri, format: :parquet do |ext|\n ext.hive_partitioning_mode = :auto\n ext.hive_partitioning_require_partition_filter = true\n ext.hive_partitioning_source_uri_prefix = source_uri_prefix\nend\n\nexternal_data.hive_partitioning? #=\u003e true\nexternal_data.hive_partitioning_mode #=\u003e \"AUTO\"\nexternal_data.hive_partitioning_require_partition_filter? #=\u003e true\nexternal_data.hive_partitioning_source_uri_prefix #=\u003e source_uri_prefix\n```"]]