I have a value (surv_amount) which is currently a string within the database. I need to convert it from a string to a big decimal in TMap. I have tried new BigDecimal(surv_amount) but get this error message:
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "schema_talendStats_DB" is null
Any idea how I would resolve this please?
Try this
Relational.ISNULL(row1.surv_amount)? new BigDecimal("0.0") : new BigDecimal(row1.surv_amount)
Related
I am reading data from Firestore. I was getting an error that said type 'Timestamp' is not a subtype of type 'String' in type cast, so I changed the createDate line below to use .toString() instead of doing as String. This solved the problem, but why did this work?
Notification.fromJson(Map<dynamic, dynamic>? json): //Transform JSON into Notification
createDate = (json?['createDate']).toString(), //This works
modifiedDate = json?['modifiedDate'] as String; //This gives the error: 'type 'Timestamp' is not a subtype of type 'String' in type cast'
The format of both of these fields is October 5, 2022 at 10:49 PM UTC-5.
Like it is said in error message, you are getting this error, because the value's type, which is coming from json is Timestamp, not String. It is better to make createDate and modifiedDate fields in Timestamp type instead of String, because it provides it's own methods, that make your work easier. Converting to String (and probably, you are parsing this String in somewhere) is redundant.
In Flutter every object class have toString() method, which is return a value with String type
(json?['createDate']).toString();
So if you write that code above, it will return a value with String type and then assign that value to createDate variable. It means you not assign json?['createDate'].
modifiedDate = json?['modifiedDate'] as String;
That line above will error because you assign that json to modifiedDate which is have different type. Cast (as) only work if the object/variable have same hierarchy, like
Child child = Child();
Parent parent = child as Parent();
json?['createDate'] is a Timestamp type object that just contains numbers describing a point in time. As you can see from the API documentation, it has a method called toString that knows how to convert that to formatted date string. Since a Timestamp it is not a subclass of String, Dart does not allow it to be cast to one. Perhaps you want to cast it to Timestamp instead, since that's what it is?
I have a SpecificRecord object from which I want to read a property from. Lets assume that I do not have access to the generated class of this SpecificRecord object (since these are dynamically chosen at runtime from a pool of classes via Reflection). Every generated class does have a common property "EXTRACT_DT_TM" (and a getter method for it) that I want to be able to read from this SpecificRecord object (Which is what I am having issues with).
So far I have tried:
public String map(SpecificRecord record) {
System.out.println("genericData to String = " +
GenericData.get().deepCopy(record.getSchema(), record).toString());
GenericRecord genericRecord = (GenericRecord)
GenericData.get().deepCopy(record.getSchema(), record);
System.out.println("genericRecord to String = " + genericRecord.toString());
Long extractionTime = (Long) genericRecord.get("EXTRACT_DT_TM");
But I get the following exception:
2021-08-22 01:14:43,280 WARN [main] org.apache.hadoop.mapred.YarnChild: Exception running child : java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to org.apache.avro.specific.SpecificRecord
at com.x.y.analytics.ods.z.ExtractionDatePartitionFn.map(ExtractionDatePartitionFn.java:49)
at com.x.y.analytics.ods.wolfe.ExtractionDatePartitionFn.map(ExtractionDatePartitionFn.java:22)
at org.apache.crunch.fn.ExtractKeyFn.map(ExtractKeyFn.java:64)
at org.apache.crunch.fn.ExtractKeyFn.map(ExtractKeyFn.java:29)
at org.apache.crunch.MapFn.process(MapFn.java:34)
Looking for any thoughts on how to read this value from the SpecificRecord.. In the above approach, I was trying to convert a SpecificRecord to a GenericRecord and then read the value from it..
For now since the position of the property is fixed across all generated classes, I was able to use the following. I would still like to know if anyone has a better answer that is not tied to the index.
Long extractionTime = (Long) record.get(2); // EXTRACT_DT_TM field
Need help with the below conversion in Talend:
"0.12900-" string to -0.12900 in float via Tmap expression.
I am not well versed with Java hence the difficulty.
You could try something like this :
row1.column.contains("-")?Float.parseFloat( "-"+ StringHandling.LEFT(row1.column,row1.column.length()-1)):Float.parseFloat(row1.column)
Float.parseFloat allows you to convert a string to a float type.
StringHandling.LEFT gets the first characters of a string, here the total length-1.
Ternary operator controls if your string contains "-", otherwise you just have to parse the "-" symbol
I have a jrxml file which has a field of BigDecimal value and when I try to execute the report. I get an error called " Cannot cast from BigDecimal to String in jasper". Im doing the report using ireport 5.6.0, and I get a weird error like this,
1. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getValue())); //$JR_EXPR_ID=18$
<----------------------------------------------------------------------->
2. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getOldValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------->
3. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getEstimatedValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------------->
3 errors
I tried to change the expression class. but nothing seems to work. I need the value to get the sum and also as a field.
You have a field e.g $F{ID} with field class=java.math.BigDecimal.As you want to use this field as a string as well as decimal;
You can create two variables variable1 with variable Class=java.math.BigDecimal with Variable Expression as $F{ID}
and create another variable variable2 with variable Class=java.lang.String with Variable Expression as $F{ID}.toPlainString()
When I removed tag "printWhenExpression" for that text field with error, the error did not show again.
I have an TextField with datatype Integer, so I am trying to getFieldValue() and write it to Integer field. So in runtime I have an error here:
TextField<Integer> priceField = new TextField<Integer>();
Integer newPriceFieldValue = priceField.getValue(); //here is an error in runtime
So I cant understand whats the problem - proceField.getValue() should be Integer, why string? Maybe I should another type of Field?
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Integer
at
ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:64)
at
ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:1)
If you are expecting only numbers to be used in this field NumberField may be the better choice.
NumberField field = new NumberField();
field.setPropertyEditorType(Integer.class);
It will ensure only numbers are entered, and save you some casting & error handling on the getValue() call.
getValue returns a String!
You want to assign this String to an Integer which causes an CastException (like it would in any Type oriented Programming language.
Try
Integer newPriceFieldValue = Integer.parseInt(priceField.getValue());
Regards,
Stefan