Actualizar una rutina
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Actualiza un recurso de rutina existente
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples in Go, Java, Node.js, and Python demonstrating how to update an existing BigQuery routine.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample requires setting up Application Default Credentials for authentication and directs users to the respective language's BigQuery client library quickstart guide.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets showcase the use of BigQuery client libraries to fetch existing routine metadata and then update it, which may include altering the routine's body or other properties.\u003c/p\u003e\n"],["\u003cp\u003eDue to a limitation in the backend API, the Go and Python code samples explicitly note the need to provide all routine properties during an update, not just those being changed.\u003c/p\u003e\n"],["\u003cp\u003eThe page directs users to the Google Cloud sample browser to discover code samples for other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Update a routine\n\nUpdate an existing routine resource.\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\n \t\"cloud.google.com/go/bigquery\"\n )\n\n // updateRoutine demonstrates updating an existing BigQuery UDF using the routine API.\n func updateRoutine(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 \troutineRef := client.Dataset(datasetID).Routine(routineID)\n\n \t// fetch existing metadata\n \tmeta, err := routineRef.Metadata(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"couldn't retrieve metadata: %w\", err)\n \t}\n\n \t// Due to a limitation in the backend, supply all the properties for update.\n \tupdate := &bigquery.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/index.html#cloud_google_com_go_bigquery_RoutineMetadataToUpdate{\n \t\tType: meta.Type,\n \t\tLanguage: meta.Language,\n \t\tArguments: meta.Arguments,\n \t\tDescription: meta.Description,\n \t\tReturnType: meta.ReturnType,\n \t\tBody: \"x * 4\",\n \t}\n\n \tif _, err := routineRef.Update(ctx, update, meta.ETag); err != nil {\n \t\treturn fmt.Errorf(\"update failed: %w\", err)\n \t}\n\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 update routine\n public class UpdateRoutine {\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 updateRoutine(datasetName, routineName);\n }\n\n public static void updateRoutine(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.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.of(datasetName, routineName));\n routine.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Routine.html#com_google_cloud_bigquery_Routine_toBuilder__().setBody(\"x * 4\").build().update();\n System.out.println(\"Routine updated successfully\");\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 was not updated. \\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 updateRoutine() {\n // Updates a 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 updates = {\n description: 'New description',\n };\n\n const dataset = bigquery.dataset(datasetId);\n\n // Create routine reference\n let routine = dataset.routine(routineId);\n\n // Make API call\n [routine] = await routine.setMetadata(updates);\n\n console.log(`Routine description: ${routine.description}`);\n }\n updateRoutine();\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)\n\n routine.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.routine.Routine.html#google_cloud_bigquery_routine_Routine_body = \"x * 4\"\n\n routine = client.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html#google_cloud_bigquery_client_Client_update_routine(\n routine,\n [\n \"body\",\n # Due to a limitation of the API,\n # all fields are required, not just\n # those that have been updated.\n \"arguments\",\n \"language\",\n \"type_\",\n \"return_type\",\n ],\n ) # Make an API request.\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)."]]