Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página, se explica cómo convertir campos en decimales y realizar
transformaciones en ellos cuando preparas datos en el espacio de trabajo de Wrangler de
Cloud Data Fusion Studio.
Abrir un objeto, como una tabla, desde una base de datos o un archivo de Cloud Storage
Para una base de datos o una conexión de BigQuery, si la tabla
tiene una columna decimal, Wrangler la convierte en un tipo BigDecimal. Cuando
creas la canalización desde Wrangler, la columna se convierte en
el tipo de datos decimal.
Si tu conjunto de datos contiene datos no decimales que deseas convertir a decimales, usa la directiva set-column:
DECIMAL_COLUMN: Es la columna decimal que se transformará. Después de que se ejecuta la directiva, el tipo de datos de la columna cambia a BigDecimal y el esquema también contiene el tipo de datos apropiado.
INPUT_COLUMN: Es la columna que se convierte, que puede ser uno de los siguientes tipos: STRING, INTEGER, LONG, FLOAT o DOUBLE.
Si tu conjunto de datos incluye valores con escalas variables, como 1.05, 2.698, 5.8745512, establece la escala con una directiva de Wrangler y edita el esquema en la canalización para establecer la escala de la columna decimal.
Para establecer la escala en Wrangler, usa una directiva similar a la siguiente:
En el siguiente ejemplo, se convierte una columna llamada cost de una cadena a un decimal, se establece una escala de 9 y se muestran los resultados en una columna nueva llamada output-column:
Las columnas decimales en Wrangler usan la clase BigDecimal de Java.
Después de que las columnas se conviertan al tipo de datos BigDecimal, transfórmalas con métodos de Class BigDecimal.
[[["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"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eWrangler in Cloud Data Fusion automatically converts decimal columns from databases or BigQuery into \u003ccode\u003eBigDecimal\u003c/code\u003e type, which then becomes the \u003ccode\u003edecimal\u003c/code\u003e data type when a pipeline is created.\u003c/p\u003e\n"],["\u003cp\u003eNon-decimal data can be converted to decimals in Wrangler using the \u003ccode\u003eset-column\u003c/code\u003e directive with the \u003ccode\u003enew("java.math.BigDecimal", INPUT_COLUMN)\u003c/code\u003e expression, allowing the transformation of data types like \u003ccode\u003eSTRING\u003c/code\u003e, \u003ccode\u003eINTEGER\u003c/code\u003e, \u003ccode\u003eLONG\u003c/code\u003e, \u003ccode\u003eFLOAT\u003c/code\u003e, or \u003ccode\u003eDOUBLE\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eset-column\u003c/code\u003e directive in Wrangler can be used to adjust the scale of decimal values with varying precision using the \u003ccode\u003e.setScale()\u003c/code\u003e method, ensuring consistent formatting.\u003c/p\u003e\n"],["\u003cp\u003eOnce columns are converted to \u003ccode\u003eBigDecimal\u003c/code\u003e, you can apply various transformations like absolute value, precision, scale, addition, subtraction, division, and type conversions using methods from the \u003ccode\u003eClass BigDecimal\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMultiple methods to transform decimal data are available in the \u003ccode\u003eClass BigDecimal\u003c/code\u003e using \u003ccode\u003eset-column\u003c/code\u003e directives, such as comparing values, determining the maximum or minimum of two columns, adjusting the decimal point, and calculating powers.\u003c/p\u003e\n"]]],[],null,["# Work with decimal data\n\nThis page explains how to convert fields into the decimals and perform\ntransformations on them when you prepare data in the Wrangler workspace of the\nCloud Data Fusion Studio.\n\nRead decimal data\n-----------------\n\n1. [Go to the Wrangler workspace in Cloud Data Fusion](/data-fusion/docs/concepts/wrangler-overview#navigate-to-wrangler).\n2. Open an object, such as a table, from a database or a Cloud Storage file.\n\n - For a database or a BigQuery connection, if the table has a decimal column, Wrangler converts it into a `BigDecimal` type. When you create the pipeline from Wrangler, the column is then converted to the `decimal` data type.\n - If your dataset contains non-decimal data that you want to convert to\n decimals, use the `set-column` directive:\n\n set-column : \u003cvar translate=\"no\"\u003eDECIMAL_COLUMN\u003c/var\u003e exp:{new(\"java.math.BigDecimal\", \u003cvar translate=\"no\"\u003eINPUT_COLUMN\u003c/var\u003e)}\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDECIMAL_COLUMN\u003c/var\u003e: the decimal column to be\n transformed. After the directive executes, the column's data type\n changes to `BigDecimal`, and the schema also contains the\n appropriate data type.\n\n - \u003cvar translate=\"no\"\u003eINPUT_COLUMN\u003c/var\u003e: the column that gets converted,\n which can be one of the following types: `STRING`, `INTEGER`,\n `LONG`, `FLOAT`, or `DOUBLE`.\n\n - If your dataset includes values with varying scale, such as 1.05, 2.698,\n 5.8745512, set the scale with a Wrangler directive and edit the\n schema in the pipeline to set the scale for the decimal column.\n\n To set the scale in the Wrangler, use a directive similar to the\n following: \n\n set-column : \u003cvar translate=\"no\"\u003eOUTPUT_COLUMN\u003c/var\u003e exp:{new(\"java.math.BigDecimal\", \u003cvar translate=\"no\"\u003eDECIMAL_COLUMN\u003c/var\u003e).setScale()}\n\n The following example converts a column called `cost` from a string to a\n decimal, sets a scale of 9, and outputs the results to a new column\n called `output-column`: \n\n set-column : output-column exp:{new(\"java.math.BigDecimal\", \"cost\").setScale(9)}\n\nTransform decimal data\n----------------------\n\nDecimal columns in Wrangler use the Java BigDecimal class.\nAfter the columns are converted to the BigDecimal data type, transform the\ncolumns with methods from [`Class BigDecimal`](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html).\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eOUTPUT_COLUMN\u003c/var\u003e: the column containing the output of the operation.\n- \u003cvar translate=\"no\"\u003eDECIMAL_COLUMN\u003c/var\u003e: the decimal column that's transformed.\n- \u003cvar translate=\"no\"\u003eDECIMAL_COLUMN_2\u003c/var\u003e: the second decimal column included in the operation, such as when you add the values from two decimal columns together.\n\nWhat's next\n-----------\n\n- Learn more about [Wrangler directives](/data-fusion/docs/concepts/wrangler-overview#apply_directives)."]]