hansva opened a new issue, #9560:
URL: https://github.com/apache/hop/issues/9560
### Apache Hop version?
2.20.0
### Java version?
21
### Operating system
Other
### What happened?
`ValueMetaAvroRecord` (type *Avro Record*, id 20) doesn't override
`convertData`. `ValueMetaBase.convertData` only knows Hop's built-in types, so
converting any value into an Avro Record field throws:
<field> Avro Record : I can't convert the specified value to data type :
20
This also happens for the two conversions that should just work:
- **Text holding a record as JSON:** `getString` /
`convertGenericRecordToString` write a record as `{ "schema" : …, "data" : …
}`, and `convertStringToGenericRecord` reads that back. `getGenericRecord`
already uses it when the field's own type is String. But a conversion from a
String field to an Avro Record field doesn't.
- **Avro Record to Avro Record.**
`convertDataFromString` ends by calling `convertData`, so reading an Avro
Record field from text fails the same way.
### How to reproduce
1. A pipeline with an Avro Record field, for example from *Avro File Input*.
2. Write it as text (e.g. *Select values* changing the type to String, or
*Text file output*), then turn it back: *Select values*, *Meta-data* tab,
change the type to Avro Record. Or read the text with *Text file input* and a
field of type Avro Record.
3. Run: the transform fails with the error above.
Any engine or transform that hands Avro Record values over as text and
converts them back runs into the same error.
### Expected
- A String value holding the JSON that `getString` writes converts to that
record. Empty or null text converts to null.
- An Avro Record value converts to the same record.
- Text that isn't a valid schema-plus-data JSON fails with an error that
says so.
- Other types still fail with a clear "can't convert to an Avro record"
error.
### Proposed fix
Override `convertData(IValueMeta, Object)` in `ValueMetaAvroRecord`:
- null → null;
- Avro Record → the record (`getGenericRecord`);
- String → `convertStringToGenericRecord`, with empty text → null;
- anything else → `HopValueException`.
### Tests
`ValueMetaAvroRecordTest`:
- A record written with `getString` and converted back from a String field
equals the original: same schema and same field values.
- Avro Record → Avro Record gives the same record.
- `convertDataFromString` with the JSON text gives the record.
- Null and empty text give null.
- Invalid JSON and a non-string type throw a `HopValueException`.
### Issue Priority
Priority: 2
### Issue Component
Component: API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]