setColumnarTuple!
Syntax
setColumnarTuple!(X, [on=true])
Details
Marks a tuple as a columnar tuple in place, or clears the columnar tuple flag.
A columnar tuple is still an ANY tuple composed of scalars or vectors, but DolphinDB interprets it using columnar rules similar to those of array vectors: each element in the tuple corresponds to one row value of a table column; if an element is a vector, that row stores an array. A regular tuple is interpreted by tuple rules, where each row is a complete ANY element when the tuple is used as a table column.
For example, when ungroup is applied to a
table column containing vector elements, a regular tuple column is not flattened.
After it is converted to a columnar tuple, ungroup flattens the
vector elements in each row.
Parameters
X is a tuple composed of vectors or scalars of the same data type.
on (optional) is a Boolean value indicating whether to mark X as a columnar tuple. The default value is true.
-
If on = true, converts a regular tuple to a columnar tuple.
-
If on = false, clears the columnar tuple flag and converts it to a regular tuple.
Returns
Returns the modified X.
-
If on = true, returns a columnar tuple.
-
If on = false, returns a regular tuple.
Examples
Convert a regular tuple to a columnar tuple.
tp = [[1,2,3], [4,5,6], [7,8]]
isColumnarTuple(tp)
// output: false
tp.setColumnarTuple!()
isColumnarTuple(tp)
// output: true
When a regular tuple is used as a table column, each row is an ANY element.
ungroup does not flatten the vector elements in it.
t = table([1,2] as id, ([10,11], 12) as v)
ungroup(t)
| id | v |
|---|---|
| 1 | [10,11] |
| 2 | 12 |
After the regular tuple is converted to a columnar tuple,
ungroup flattens column v by array-vector rules.
t = table([1,2] as id, ([10,11], 12).setColumnarTuple!() as v)
ungroup(t)
| id | v |
|---|---|
| 1 | 10 |
| 1 | 11 |
| 2 | 12 |
Clear the columnar tuple flag.
v = ([10,11], 12).setColumnarTuple!()
isColumnarTuple(v)
// output: true
v.setColumnarTuple!(false)
isColumnarTuple(v)
// output: false
