Listar rotinas
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Lista todas as rotinas existentes em um conjunto de dados.
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to list all existing routines within a specified dataset using BigQuery's client libraries.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in Go, Java, Node.js, and Python, showcasing how to retrieve and iterate through a list of routines.\u003c/p\u003e\n"],["\u003cp\u003eEach code example outlines the necessary setup, including authentication via Application Default Credentials and links to relevant quickstart guides and API reference documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe core functionality across all languages involves using the BigQuery client to access a dataset and then iterating through the routines it contains.\u003c/p\u003e\n"],["\u003cp\u003eThe routines contained are obtained by using a given dataset ID.\u003c/p\u003e\n"]]],[],null,["# List routines\n\nLists all existing routines in a dataset.\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 \t\"google.golang.org/api/iterator\"\n )\n\n // listRoutines demonstrates listing the routines within a dataset.\n func listRoutines(w io.Writer, projectID, datasetID 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 \tit := client.Dataset(datasetID).https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/index.html#cloud_google_com_go_bigquery_Dataset_Routines(ctx)\n \tfor {\n \t\tr, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn fmt.Errorf(\"error during iteration: %w\", err)\n \t\t}\n \t\tfmt.Fprintf(w, \"Routine: %q\\n\", r.RoutineID)\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.api.gax.paging.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.paging.Page.html;\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\n // Sample to get list of routines\n public class ListRoutines {\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 listRoutines(datasetName);\n }\n\n public static void listRoutines(String datasetName) {\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 Page\u003cRoutine\u003e routines =\n bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html#com_google_cloud_bigquery_BigQuery_listRoutines_com_google_cloud_bigquery_DatasetId_com_google_cloud_bigquery_BigQuery_RoutineListOption____(datasetName, BigQuery.RoutineListOption.pageSize(100));\n if (routines == null) {\n System.out.println(\"Dataset does not contain any routines.\");\n return;\n }\n routines\n .iterateAll()\n .forEach(routine -\u003e System.out.printf(\"Success! Routine ID: %s\", routine.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.RoutineInfo.html#com_google_cloud_bigquery_RoutineInfo_getRoutineId__()));\n } catch (https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html e) {\n System.out.println(\"Routines not listed in dataset due to error: \\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 listRoutines() {\n // Lists routines in \"my_dataset\".\n\n /**\n * TODO(developer): Uncomment the following lines before running the sample.\n */\n // const datasetId = 'my_dataset';\n\n // List all routines in the dataset\n const [routines] = await bigquery.dataset(datasetId).https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html();\n\n console.log('Routines:');\n routines.forEach(routine =\u003e console.log(routine.id));\n }\n listRoutines();\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 dataset_id to the ID of the dataset that contains\n # the routines you are listing.\n # dataset_id = 'your-project.your_dataset'\n\n routines = client.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html#google_cloud_bigquery_client_Client_list_routines(dataset_id) # Make an API request.\n\n print(\"Routines contained in dataset {}:\".format(dataset_id))\n for routine in routines:\n print(routine.reference)\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)."]]