Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment convertir des champs en décimaux et effectuer des transformations dessus lorsque vous préparez des données dans l'espace de travail Wrangler de Cloud Data Fusion Studio.
Ouvrez un objet, tel qu'une table, à partir d'une base de données ou d'un fichier Cloud Storage.
Pour une base de données ou une connexion BigQuery, si la table comporte une colonne décimale, Wrangler la convertit en type BigDecimal. Lorsque vous créez le pipeline à partir de Wrangler, la colonne est ensuite convertie en type de données decimal.
Si votre ensemble de données contient des données non décimales que vous souhaitez convertir en décimales, utilisez la directive set-column:
DECIMAL_COLUMN: colonne décimale à transformer. Une fois la directive exécutée, le type de données de la colonne passe à BigDecimal, et le schéma contient également le type de données approprié.
INPUT_COLUMN: colonne convertie, qui peut être l'un des types suivants: STRING, INTEGER, LONG, FLOAT ou DOUBLE.
Si votre ensemble de données inclut des valeurs à échelle variable, telles que 1,05, 2,698 et 5,8745512, définissez l'échelle avec une directive Wrangler et modifiez le schéma dans le pipeline pour définir l'échelle de la colonne décimale.
Pour définir l'échelle dans Wrangler, utilisez une directive semblable à la suivante:
L'exemple suivant convertit une colonne appelée cost d'une chaîne en décimal, définit une échelle de 9 et affiche les résultats dans une nouvelle colonne appelée output-column:
Les colonnes décimales de Wrangler utilisent la classe Java BigDecimal.
Une fois les colonnes converties au type de données BigDecimal, transformez-les à l'aide des méthodes de Class BigDecimal.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]