ルーティンを取得する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
指定されたルーティン ID のルーティン リソースを取得します。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to retrieve metadata for a specified routine using the BigQuery API in Go, Java, Node.js, and Python.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample provides instructions on how to set up authentication via Application Default Credentials and references relevant BigQuery API documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe Go sample retrieves and prints the routine's type, language, and arguments, while the Python version also displays similar metadata in its output.\u003c/p\u003e\n"],["\u003cp\u003eThe Java sample demonstrates retrieving a routine by its ID, while the Node.js sample focuses on getting an existing routine from a specific dataset.\u003c/p\u003e\n"]]],[],null,["# Get a routine resource for a given routine ID.\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Go API\nreference documentation](https://godoc.org/cloud.google.com/go/bigquery).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/bigquery\"\n )\n\n // getRoutine demonstrates getting a routine's metadata via the API.\n func getRoutine(w io.Writer, projectID, datasetID, routineID string) error {\n \t// projectID := \"my-project-id\"\n \t// datasetID := \"mydatasetid\"\n \t// routineID := \"myroutineid\"\n \tctx := context.Background()\n\n \tclient, err := bigquery.NewClient(ctx, projectID)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigquery.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \tmeta, err := client.Dataset(datasetID).Routine(routineID).Metadata(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"couldn't retrieve routine metadata: %w\", err)\n \t}\n \t// Print information about the routine.\n \tfmt.Fprintf(w, \"Routine %s:\\n\", routineID)\n \tfmt.Fprintf(w, \"\\tType %s:\\n\", meta.Type)\n \tfmt.Fprintf(w, \"\\tLanguage %s:\\n\", meta.Language)\n \tfmt.Fprintln(w, \"\\tArguments:\")\n \tfor _, v := range meta.Arguments {\n \t\tfmt.Fprintf(w, \"\\t\\tName: %s\\tType: %v\", v.Name, v.DataType)\n \t}\n \treturn nil\n }\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Java API\nreference documentation](/java/docs/reference/google-cloud-bigquery/latest/overview).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryOptions.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Routine.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.RoutineId.html;\n\n // Sample to get a routine\n public class GetRoutine {\n\n public static void main(String[] args) {\n // TODO(developer): Replace these variables before running the sample.\n String datasetName = \"MY_DATASET_NAME\";\n String routineName = \"MY_ROUTINE_NAME\";\n getRoutine(datasetName, routineName);\n }\n\n public static void getRoutine(String datasetName, String routineName) {\n try {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html bigquery = https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryOptions.html.getDefaultInstance().getService();\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.RoutineId.html routineId = https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.RoutineId.html.of(datasetName, routineName);\n https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Routine.html routine = bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html#com_google_cloud_bigquery_BigQuery_getRoutine_com_google_cloud_bigquery_RoutineId_com_google_cloud_bigquery_BigQuery_RoutineOption____(routineId);\n System.out.println(\"Routine retrieved successfully\" + routine.getDescription());\n } catch (https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html e) {\n System.out.println(\"Routine not retrieved. \\n\" + e.toString());\n }\n }\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Node.js API\nreference documentation](https://googleapis.dev/nodejs/bigquery/latest/index.html).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n // Import the Google Cloud client library and create a client\n const {BigQuery} = require('https://cloud.google.com/nodejs/docs/reference/bigquery/latest/overview.html');\n const bigquery = new https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery.html();\n\n async function getRoutine() {\n // Gets an existing routine named \"my_routine\" in \"my_dataset\".\n\n /**\n * TODO(developer): Uncomment the following lines before running the sample.\n */\n // const datasetId = 'my_dataset';\n // const routineId = 'my_routine';\n\n const dataset = bigquery.dataset(datasetId);\n\n // Create routine reference and make API call\n const [routine] = await dataset.routine(routineId).get();\n\n console.log(\n `Routine ${routine.metadata.routineReference.routineId} retrieved.`,\n );\n }\n getRoutine();\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Python API\nreference documentation](/python/docs/reference/bigquery/latest).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n\n from google.cloud import https://cloud.google.com/python/docs/reference/bigquery/latest/\n\n # Construct a BigQuery client object.\n client = https://cloud.google.com/python/docs/reference/bigquery/latest/.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html()\n\n # TODO(developer): Set the fully-qualified ID for the routine.\n # routine_id = \"my-project.my_dataset.my_routine\"\n\n routine = client.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html#google_cloud_bigquery_client_Client_get_routine(routine_id) # Make an API request.\n\n print(\"Routine '{}':\".format(routine.reference))\n print(\"\\tType: '{}'\".format(routine.type_))\n print(\"\\tLanguage: '{}'\".format(routine.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.routine.Routine.html#google_cloud_bigquery_routine_Routine_language))\n print(\"\\tArguments:\")\n\n for argument in routine.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.routine.Routine.html#google_cloud_bigquery_routine_Routine_arguments:\n print(\"\\t\\tName: '{}'\".format(argument.name))\n print(\"\\t\\tType: '{}'\".format(argument.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.routine.RoutineArgument.html#google_cloud_bigquery_routine_RoutineArgument_data_type))\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigquery)."]]