Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina spiega come convertire i campi in decimali ed eseguire su di essi trasformazioni quando prepari i dati nello spazio di lavoro Wrangler di Studio di Cloud Data Fusion.
Apri un oggetto, ad esempio una tabella, da un database o da un file Cloud Storage.
Per un database o una connessione BigQuery, se la tabella contiene una colonna decimale, Wrangler la converte in un tipo BigDecimal. Quando crei la pipeline da Wrangler, la colonna viene convertita nel tipo di dati decimal.
Se il set di dati contiene dati non decimali che vuoi convertire in decimali, utilizza la direttiva set-column:
DECIMAL_COLUMN: la colonna decimale da trasformare. Dopo l'esecuzione della direttiva, il tipo di dati della colonna diventa BigDecimal e lo schema contiene anche il tipo di dati appropriato.
INPUT_COLUMN: la colonna che viene convertita,
che può essere uno dei seguenti tipi: STRING, INTEGER,
LONG, FLOAT o DOUBLE.
Se il set di dati include valori con scale diverse, ad esempio 1,05, 2,698,
5,8745512, imposta la scala con una direttiva Wrangler e modifica
lo schema nella pipeline per impostare la scala per la colonna decimale.
Per impostare la scala in Wrangler, utilizza un'istruzione simile alla seguente:
Il seguente esempio converte una colonna denominata cost da una stringa a un valore decimale, imposta una scala di 9 e restituisce i risultati in una nuova colonna denominata output-column:
Le colonne decimali in Wrangler utilizzano la classe BigDecimal di Java.
Dopo aver convertito le colonne nel tipo di dati BigDecimal, trasformale con i metodi di Class BigDecimal.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]