Translate

Saturday 9 March 2024

How do you define variables in data weave scripts?101

 How do you define variables in data weave scripts?


DataWeave allows you to define two main types of variables:

  1. Global Variables: These are declared in the header section of your script using the var directive. They can be accessed and used throughout the entire script's body.

Here's the syntax:



%dw 2.0
var <variableName> = <expression>
---
<body of your script>

For example:



%dw 2.0
var greeting = "Hello"
---
{
  message: greeting ++ " World!"
}

  1. Local Variables: These are declared within the body of your script using the using keyword. Local variables are only accessible within the specific expression or code block where they are defined.

Here's the syntax:



using (<variableName> = <expression>) {
  <your code using the variable>
}

For example:



%dw 2.0
---
{
  using (fullName = payload.firstName ++ " " ++ payload.lastName) {
    greet: "Welcome " ++ fullName
  }
}

Here are some additional points to remember about DataWeave variables:

  • They cannot be reassigned a value after they are initialized.

  • Their scope is limited to the script where they are defined.

  • DataWeave also offers predefined variables like now() to access the current timestamp.

For further details and examples, you can refer to the official DataWeave documentation on variables: https://docs.mulesoft.com/dataweave/latest/dataweave-variables


Q: A clock is set right at 8 a.m. The clock gains 10 minutes in 24 hours. What will be the real/true time when the clock indicates 1 p.m. on the following day?

 


Q: A clock is set right at 8 a.m. The clock gains 10 minutes in 24 hours. What will be the real/true time when the clock indicates 1 p.m. on the following day?

  • A) 48 min. past 12

  • B) 46 min. past 12

  • C) 45 min. past 12

  • D) 47 min. past 12

Answer: A) 48 min. past 12

Explanation:

Here's how to solve this type of clock problem:

  1. Time Elapsed: From 8 a.m. on one day to 1 p.m. on the following day, 29 hours pass.

  2. Clock Gain: The clock gains 10 minutes every 24 hours. This can be expressed as a proportion: 10 minutes / 24 hours

  3. Calculate Gain Over 29 Hours: Set up a proportion to find how much the clock has gained in the 29 hours:
    (10 minutes / 24 hours) = (x minutes / 29 hours) Solving for 'x', we get x ≈ 12.08 minutes

  4. True Time: Since the clock gains time, it shows a later time than the real time. To find the true time:

  • Time on clock - Time gained = True Time

  • 1:00 PM - 12.08 minutes ≈ 12:48 PM

Therefore, the true time when the clock indicates 1 p.m. will be approximately 48 minutes past 12 noon.


Hindi

प्रश्न: एक घड़ी सुबह 8 बजे दाईं ओर सेट की जाती है, घड़ी 24 घंटे में 10 मिनट आगे बढ़ जाती है। जब घड़ी अगले दिन दोपहर 1 बजे का संकेत देगी तो वास्तविक/सही समय क्या होगा?

  • ए) 48 मिनट. 12 बज चुके हैं

  • बी) 46 मिनट। 12 बज चुके हैं

  • सी) 45 मिनट. 12 बज चुके हैं

  • डी) 47 मिनट. 12 बज चुके हैं

उत्तर: ए) 48 मिनट। 12 बज चुके हैं

स्पष्टीकरण:

इस प्रकार की घड़ी की समस्या को हल करने का तरीका यहां बताया गया है:

  1. बीता हुआ समय: एक दिन सुबह 8 बजे से अगले दिन दोपहर 1 बजे तक, 29 घंटे बीत जाते हैं।

  2. घड़ी का बढ़ना: घड़ी हर 24 घंटे में 10 मिनट बढ़ जाती है। इसे अनुपात के रूप में व्यक्त किया जा सकता है: 10 मिनट/24 घंटे

  3. 29 घंटे से अधिक लाभ की गणना करें: 29 घंटे में घड़ी ने कितना लाभ प्राप्त किया है यह जानने के लिए एक अनुपात स्थापित करें: (10 मिनट / 24 घंटे) = (x मिनट / 29 घंटे) 'x' को हल करने पर, हमें x ≈ 12.08 मिनट मिलते हैं

  4. सही समय: चूँकि घड़ी समय बढ़ाती है, यह वास्तविक समय की तुलना में बाद का समय दिखाती है। सही समय जानने के लिए:

  • घड़ी पर समय - प्राप्त समय = सही समय

  • 1:00 अपराह्न - 12.08 मिनट ≈ 12:48 अपराह्न

इसलिए, जब घड़ी दोपहर 1 बजे का संकेत देती है तो वास्तविक समय दोपहर 12 बजकर लगभग 48 मिनट होगा।


Telugu


ప్ర: గడియారం ఉదయం 8 గంటలకు సరిగ్గా సెట్ చేయబడింది, గడియారం 24 గంటల్లో 10 నిమిషాలు పెరుగుతుంది. గడియారం మరుసటి రోజు మధ్యాహ్నం 1 గంటను సూచించినప్పుడు నిజమైన/నిజమైన సమయం ఎంత?

  • ఎ) 48 నిమి. గత 12

  • బి) 46 నిమి. గత 12

  • సి) 45 నిమి. గత 12

  • డి) 47 నిమి. గత 12

సమాధానం: ఎ) 48 నిమి. గత 12

వివరణ:

ఈ రకమైన గడియార సమస్యను ఎలా పరిష్కరించాలో ఇక్కడ ఉంది:

  1. గడిచిన సమయం: ఒక రోజు ఉదయం 8 నుండి మరుసటి రోజు మధ్యాహ్నం 1 గంటల వరకు, 29 గంటలు గడిచిపోతాయి.

  2. గడియారం లాభం: గడియారం ప్రతి 24 గంటలకు 10 నిమిషాలు పెరుగుతుంది. దీనిని నిష్పత్తిలో వ్యక్తీకరించవచ్చు: 10 నిమిషాలు / 24 గంటలు

  3. 29 గంటల కంటే ఎక్కువ లాభాలను లెక్కించండి: 29 గంటల్లో గడియారం ఎంత సంపాదించిందో తెలుసుకోవడానికి ఒక నిష్పత్తిని సెటప్ చేయండి: (10 నిమిషాలు / 24 గంటలు) = (x నిమిషాలు / 29 గంటలు) 'x' కోసం పరిష్కరిస్తే, మనకు x ≈ 12.08 నిమిషాలు లభిస్తాయి

  4. నిజమైన సమయం: గడియారం సమయాన్ని పొందుతుంది కాబట్టి, ఇది నిజ సమయం కంటే తరువాతి సమయాన్ని చూపుతుంది. నిజమైన సమయాన్ని కనుగొనడానికి:

  • గడియారంలో సమయం - సంపాదించిన సమయం = నిజమైన సమయం

  • 1:00 PM - 12.08 నిమిషాలు ≈ 12:48 PM

కాబట్టి, గడియారం మధ్యాహ్నం 1 గంటను సూచించే నిజమైన సమయం మధ్యాహ్నం 12 గంటల తర్వాత దాదాపు 48 నిమిషాలు అవుతుంది.


Tamil


கே: ஒரு கடிகாரம் காலை 8 மணிக்கு சரியாக அமைக்கப்பட்டுள்ளது, கடிகாரம் 24 மணி நேரத்தில் 10 நிமிடங்களைப் பெறுகிறது. கடிகாரம் அடுத்த நாள் மதியம் 1 மணியைக் குறிக்கும் போது உண்மையான/உண்மையான நேரம் என்னவாக இருக்கும்?

  • A) 48 நிமிடம் கடந்த 12

  • B) 46 நிமிடம் கடந்த 12

  • C) 45 நிமிடம் கடந்த 12

  • D) 47 நிமிடம் கடந்த 12

பதில்: A) 48 நிமிடம். கடந்த 12

விளக்கம்:

இந்த வகையான கடிகார சிக்கலை எவ்வாறு தீர்ப்பது என்பது இங்கே:

  1. கழிந்த நேரம்: ஒரு நாள் காலை 8 மணி முதல் மறுநாள் மதியம் 1 மணி வரை, 29 மணி நேரம் கழிகிறது.

  2. கடிகார ஆதாயம்: கடிகாரம் ஒவ்வொரு 24 மணி நேரத்திற்கும் 10 நிமிடங்கள் பெறுகிறது. இதை ஒரு விகிதாச்சாரமாக வெளிப்படுத்தலாம்: 10 நிமிடங்கள் / 24 மணிநேரம்

  3. 29 மணிநேரத்திற்கு மேல் ஆதாயத்தைக் கணக்கிடுங்கள்: 29 மணிநேரத்தில் கடிகாரம் எவ்வளவு லாபம் ஈட்டியுள்ளது என்பதைக் கண்டறிய ஒரு விகிதத்தை அமைக்கவும்: (10 நிமிடங்கள் / 24 மணிநேரம்) = (x நிமிடங்கள் / 29 மணிநேரம்) 'x' க்கு தீர்வு காணும்போது, ​​நமக்கு x ≈ 12.08 நிமிடங்கள் கிடைக்கும்

  4. உண்மையான நேரம்: கடிகாரம் நேரத்தைப் பெறுவதால், அது உண்மையான நேரத்தை விட பிந்தைய நேரத்தைக் காட்டுகிறது. உண்மையான நேரத்தைக் கண்டறிய:

  • கடிகாரத்தில் நேரம் - கிடைத்த நேரம் = உண்மையான நேரம்

  • பிற்பகல் 1:00 - 12.08 நிமிடங்கள் ≈ 12:48 பிற்பகல்

எனவே, கடிகாரம் மதியம் 1 மணியைக் குறிக்கும் உண்மையான நேரம் மதியம் 12 மணிக்கு மேல் சுமார் 48 நிமிடங்கள் இருக்கும்.


Spanish


Pregunta: Un reloj está ajustado a las 8 am. El reloj gana 10 minutos en 24 horas. ¿Cuál será la hora real/verdadera cuando el reloj indique la 1 pm del día siguiente?

  • A) 48 min. pasadas las 12

  • B) 46 min. pasadas las 12

  • C) 45min. pasadas las 12

  • D) 47 min. pasadas las 12

Respuesta: A) 48 min. pasadas las 12

Explicación:

A continuación se explica cómo resolver este tipo de problema de reloj:

  1. Tiempo Transcurrido: Desde las 8 am de un día hasta las 13 pm del día siguiente, pasan 29 horas.

  2. Ganancia de reloj: El reloj gana 10 minutos cada 24 horas. Esto se puede expresar como una proporción: 10 minutos / 24 horas

  3. Calcule la ganancia durante 29 horas: establezca una proporción para encontrar cuánto ha ganado el reloj en las 29 horas: (10 minutos/24 horas) = ​​(x minutos/29 horas) Resolviendo para 'x', obtenemos x ≈ 12,08 minutos

  4. Hora Verdadera: Dado que el reloj gana tiempo, muestra una hora posterior a la hora real. Para encontrar la hora verdadera:

  • Tiempo en el reloj - Tiempo ganado = Tiempo verdadero

  • 13:00 - 12,08 minutos ≈ 12:48

Por lo tanto, la hora real cuando el reloj marca la 1:00 p.m. será aproximadamente 48 minutos después de las 12:00 del mediodía.


French


Q : Une horloge est réglée à 8 heures du matin. L'horloge gagne 10 minutes en 24 heures. Quelle sera l'heure réelle lorsque l'horloge indiquera 13 heures le lendemain ?

  • A) 48 minutes. 12 passés

  • B) 46 minutes. 12 passés

  • C) 45 minutes. 12 passés

  • D) 47 minutes. 12 passés

Réponse : A) 48 min. 12 passés

Explication:

Voici comment résoudre ce type de problème d'horloge :

  1. Temps écoulé : De 8h00 un jour à 13h00 le lendemain, 29 heures s'écoulent.

  2. Gain d'horloge : L'horloge gagne 10 minutes toutes les 24 heures. Cela peut être exprimé en proportion : 10 minutes / 24 heures

  3. Calculer le gain sur 29 heures : définissez une proportion pour déterminer combien l'horloge a gagné au cours des 29 heures : (10 minutes / 24 heures) = (x minutes / 29 heures) En résolvant « x », nous obtenons x ≈ 12,08 minutes

  4. Heure vraie : étant donné que l'horloge gagne du temps, elle affiche une heure ultérieure à l'heure réelle. Pour connaître l'heure réelle :

  • Heure sur l'horloge - Temps gagné = Temps réel

  • 13h00 - 12,08 minutes ≈ 12h48

Par conséquent, l’heure réelle lorsque l’horloge indique 13 heures sera d’environ 48 minutes après midi.