forked from qlik-oss/enigma-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhypercube-stacked.go
83 lines (73 loc) · 2.03 KB
/
hypercube-stacked.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/qlik-oss/enigma-go"
)
const script = `
TempTable:
Load
RecNo() as ID,
RecNo()+1 as ID2,
Rand() as Value
AutoGenerate 100
`
func main() {
// Open the session and create a session document:
ctx := context.Background()
global, _ := enigma.Dialer{}.Dial(ctx, "ws://localhost:9076/app/engineData", nil)
doc, _ := global.CreateSessionApp(ctx)
doc.SetScript(ctx, script)
doc.DoReload(ctx, 0, false, false)
// Create a generic object with a hypercube stacked definition containing two dimensions and one measure
object, _ := doc.CreateObject(ctx, &enigma.GenericObjectProperties{
Info: &enigma.NxInfo{
Type: "my-stacked-hypercube",
},
HyperCubeDef: &enigma.HyperCubeDef{
Dimensions: []*enigma.NxDimension{{
Def: &enigma.NxInlineDimensionDef{
FieldDefs: []string{"ID"},
},
}, {
Def: &enigma.NxInlineDimensionDef{
FieldDefs: []string{"ID2"},
},
}},
Measures: []*enigma.NxMeasure{{
Def: &enigma.NxInlineMeasureDef{
Def: "Sum(Value)",
},
}},
Mode: "EQ_DATA_MODE_PIVOT_STACK",
AlwaysFullyExpanded: true,
},
})
// Get hypercube stacked data
data, _ := object.GetHyperCubeStackData(ctx, "/qHyperCubeDef", []*enigma.NxPage{{
Top: 0,
Left: 0,
Height: 5,
Width: 2,
}}, 10000)
HyperCubeDataPagesAsJSON, _ := json.MarshalIndent(data, "", " ")
fmt.Println(fmt.Sprintf("Hypercube data pages: %s", HyperCubeDataPagesAsJSON))
// Select second value in the first column of the data matrix
object.SelectPivotCells(ctx, "/qHyperCubeDef", []*enigma.NxSelectionCell{{
Type: "D",
Row: 1,
Col: 0,
}}, false, false)
// Get stacked data
data, _ = object.GetHyperCubeStackData(ctx, "/qHyperCubeDef", []*enigma.NxPage{{
Top: 0,
Left: 0,
Height: 5,
Width: 2,
}}, 10000)
HyperCubeDataPagesAsJSON, _ = json.MarshalIndent(data, "", " ")
fmt.Println(fmt.Sprintf("Hypercube data pages after selection: %s", HyperCubeDataPagesAsJSON))
// Close the session
global.DisconnectFromServer()
}