-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdictionary_column.go
120 lines (109 loc) · 2.66 KB
/
dictionary_column.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package olapsql
import (
"fmt"
"github.com/ahmetb/go-linq/v3"
"github.com/awatercolorpen/olap-sql/api/types"
"sort"
)
type columnStruct struct {
FieldProperty types.FieldProperty
Metric *types.Metric
Dimension *types.Dimension
}
func (c *columnStruct) GetTable() string {
if c.FieldProperty == types.FieldPropertyMetric {
return c.Metric.Table
}
if c.FieldProperty == types.FieldPropertyDimension {
return c.Dimension.Table
}
return ""
}
func (c *columnStruct) GetName() string {
if c.FieldProperty == types.FieldPropertyMetric {
return c.Metric.Name
}
if c.FieldProperty == types.FieldPropertyDimension {
return c.Dimension.Name
}
return ""
}
func (c *columnStruct) GetValueType() types.ValueType {
if c.FieldProperty == types.FieldPropertyMetric {
return c.Metric.ValueType
}
if c.FieldProperty == types.FieldPropertyDimension {
return c.Dimension.ValueType
}
return ""
}
func (c *columnStruct) GetExpression() string {
if c.FieldProperty == types.FieldPropertyMetric {
expression, _ := c.Metric.Expression()
return expression
}
if c.FieldProperty == types.FieldPropertyDimension {
expression, _ := c.Dimension.Expression()
return expression
}
return ""
}
func (c *columnStruct) IsAs() bool {
if c.FieldProperty == types.FieldPropertyMetric {
return c.Metric.Type == types.MetricTypeAs
}
if c.FieldProperty == types.FieldPropertyDimension {
return c.Dimension.Type == types.DimensionTypeMulti || c.Dimension.Type == types.DimensionTypeCase
}
return false
}
func (c *columnStruct) GetAsTables() []string {
var out []string
if c.FieldProperty == types.FieldPropertyMetric {
out = append(out, c.Metric.Children[0].Table)
}
if c.FieldProperty == types.FieldPropertyDimension {
for _, v := range c.Dimension.Dependency {
out = append(out, v.Table)
}
}
linq.From(out).Distinct().ToSlice(&out)
return out
}
func (c *columnStruct) GetTables() []string {
if c.IsAs() {
return c.GetAsTables()
}
return []string{c.GetTable()}
}
func (c *columnStruct) GetTargetFieldName(target string) string {
if c.FieldProperty == types.FieldPropertyMetric {
for _, v := range c.Metric.Children {
if v.Table == target {
return v.Name
}
}
}
if c.FieldProperty == types.FieldPropertyDimension {
for _, v := range c.Dimension.Dependency {
if v.Table == target {
return v.Name
}
}
}
return ""
}
func isSameColumnTables(t1, t2 []string) error {
if len(t1) != len(t2) {
return fmt.Errorf("table is not same t1=%v, t2=%v", t1, t2)
}
sort.Strings(t1)
sort.Strings(t2)
// TODO linq
for i := 0; i < len(t1); i++ {
if t1[i] != t2[i] {
return fmt.Errorf("table is not same t1=%v, t2=%v", t1, t2)
}
}
return nil
}