Membaca dari kueri
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Gunakan konektor BigQueryIO untuk membaca dari hasil kueri.
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to use the BigQueryIO connector to read data from a query result within a Dataflow pipeline.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Java code example executes a SQL query against a BigQuery public dataset to retrieve and process repository commit counts.\u003c/p\u003e\n"],["\u003cp\u003eThe code snippet utilizes the \u003ccode\u003eManaged.read(Managed.BIGQUERY)\u003c/code\u003e function to read the query results and then transforms the output rows.\u003c/p\u003e\n"],["\u003cp\u003eApplication Default Credentials are required to authenticate to Dataflow when using the provided code sample.\u003c/p\u003e\n"],["\u003cp\u003eThe full documentation can be found in the \u003ccode\u003eRead from BigQuery to Dataflow\u003c/code\u003e resource.\u003c/p\u003e\n"]]],[],null,["Use the BigQueryIO connector to read from a query result.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Read from BigQuery to Dataflow](/dataflow/docs/guides/read-from-bigquery)\n\nCode sample \n\nJava\n\n\nTo authenticate to Dataflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.common.collect.ImmutableMap;\n import org.apache.beam.sdk.Pipeline;\n import org.apache.beam.sdk.managed.Managed;\n import org.apache.beam.sdk.options.PipelineOptions;\n import org.apache.beam.sdk.options.PipelineOptionsFactory;\n import org.apache.beam.sdk.transforms.MapElements;\n import org.apache.beam.sdk.values.Row;\n import org.apache.beam.sdk.values.TypeDescriptors;\n\n public class BigQueryReadFromQuery {\n public static void main(String[] args) {\n // The SQL query to run inside BigQuery.\n final String queryString =\n \"SELECT repo_name as repo, COUNT(*) as count \"\n + \"FROM `bigquery-public-data.github_repos.sample_commits` \"\n + \"GROUP BY repo_name\";\n\n // Parse the pipeline options passed into the application.\n // For more information, see https://beam.apache.org/documentation/programming-guide/#configuring-pipeline-options\n PipelineOptions options = PipelineOptionsFactory.fromArgs(args)\n .withValidation().create();\n\n ImmutableMap\u003cString, Object\u003e config = ImmutableMap.\u003cString, Object\u003ebuilder()\n .put(\"query\", queryString)\n .build();\n\n // Create a pipeline and apply transforms.\n Pipeline pipeline = Pipeline.create(options);\n pipeline\n .apply(Managed.read(Managed.BIGQUERY).withConfig(config)).getSinglePCollection()\n .apply(MapElements\n .into(TypeDescriptors.strings())\n // Access individual fields in the row.\n .via((Row row) -\u003e {\n String output = String.format(\"Repo: %s, commits: %d%n\",\n row.getString(\"repo\"),\n row.getInt64(\"count\"));\n System.out.println(output);\n return output;\n }));\n pipeline.run().waitUntilFinish();\n }\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=dataflow)."]]