public class ToFlatTupleOperator extends Object
{
"bookstore_city": "paris",
"books_price": [
22,
13
],
"bookstore_id": 16,
"books_title": [
"war and piece",
"learning the punch"
]
}
If you simply run :
Tuple flat = toFlatTuple().on(input);
it produces a the following flat tuple:
{
"books_0_title": "war and piece",
"bookstore_city": "paris",
"books_1_price": "13",
"bookstore_id": "16",
"books_0_price": "22",
"books_1_title": "learning the punch"
}
Notice that arrays are flattened as well.
In some case you want to preserve arrays. Do as follows:
Tuple flat = toFlatTuple().preserveArrays().on(input);
it produces :
{
"bookstore_city": "paris",
"books_price": [
"22",
"13"
],
"bookstore_id": "16",
"books_title": [
"war and piece",
"learning the punch"
]
}
In the two last examples all the values were converted as strings. If you want to preserve the original types, use the preserveTypes() method.
Tuple flat = toFlatTuple().preserveTypes().on(input);
Constructor and Description |
---|
ToFlatTupleOperator()
Create a new ToFlatTupleOperator operator.
|
Modifier and Type | Method and Description |
---|---|
ToFlatTupleOperator |
nestedSeparator(String separator)
Set the string to be used to separate nested properties when creating the tuple keys.
|
Tuple |
on(Tuple input)
Make the operator work on an input Tuple.
|
ToFlatTupleOperator |
preserveArrays()
Preserve the arrays.
|
ToFlatTupleOperator |
preserveTypes() |
public ToFlatTupleOperator()
public Tuple on(Tuple input)
input
- the input Tuplepublic ToFlatTupleOperator preserveTypes()
public ToFlatTupleOperator nestedSeparator(String separator)
separator
- the separator you want.public ToFlatTupleOperator preserveArrays()
Copyright © 2023. All rights reserved.