ConvertFieldType: Handle undefined values in joinWith (#106712)
fix: escalation fix - groupBy with joinWith
This commit is contained in:
@@ -423,6 +423,35 @@ describe('field convert types transformer', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('will support custom join separators for field type string, correctly handling undefined and null', () => {
|
||||
const options = {
|
||||
conversions: [{ targetField: 'mixed_values', destinationType: FieldType.string, joinWith: '&' }],
|
||||
};
|
||||
|
||||
const mixedValues = toDataFrame({
|
||||
fields: [
|
||||
{
|
||||
name: 'mixed_values',
|
||||
type: FieldType.string,
|
||||
values: [['a', 'b', 'c'], ['d', undefined, 'f'], undefined, 'regular string', null],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const stringified = convertFieldTypes(options, [mixedValues]);
|
||||
expect(
|
||||
stringified[0].fields.map(({ type, values }) => ({
|
||||
type,
|
||||
values,
|
||||
}))
|
||||
).toEqual([
|
||||
{
|
||||
type: FieldType.string,
|
||||
values: ['a&b&c', 'd&&f', undefined, '"regular string"', 'null'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('will convert time fields to strings', () => {
|
||||
const options = {
|
||||
conversions: [{ targetField: 'time', destinationType: FieldType.string, dateFormat: 'YYYY-MM' }],
|
||||
|
||||
@@ -218,7 +218,7 @@ export function fieldToStringField(
|
||||
if (joinWith?.length && Array.isArray(v)) {
|
||||
return v.join(joinWith);
|
||||
}
|
||||
return field.type === FieldType.other ? JSON.stringify(v) : `${v}`;
|
||||
return JSON.stringify(v);
|
||||
});
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user