@@ -26,7 +26,7 @@ import (
26
26
"github.com/pilosa/pilosa/internal"
27
27
)
28
28
29
- // Action Mapping types
29
+ // Action types.
30
30
const (
31
31
InputMapping = "mapping"
32
32
InputValueToRow = "value-to-row"
@@ -101,19 +101,19 @@ func (i *InputDefinition) LoadDefinition(pb *internal.InputDefinition) error {
101
101
i .frames = append (i .frames , inputFrame )
102
102
}
103
103
104
- countRowID := make (map [string ]uint64 )
104
+ accountRowID := make (map [string ]uint64 )
105
105
for _ , field := range pb .Fields {
106
106
var actions []Action
107
107
for _ , action := range field .InputDefinitionActions {
108
108
if err := i .ValidateAction (action ); err != nil {
109
109
return err
110
110
}
111
111
if action .ValueDestination == InputSingleRowBool && action .Frame != "" {
112
- val , ok := countRowID [action .Frame ]
112
+ val , ok := accountRowID [action .Frame ]
113
113
if ok && val == action .RowID {
114
114
return fmt .Errorf ("duplicate rowID with other field: %v" , action .RowID )
115
115
}
116
- countRowID [action .Frame ] = action .RowID
116
+ accountRowID [action .Frame ] = action .RowID
117
117
}
118
118
actions = append (actions , Action {
119
119
Frame : action .Frame ,
@@ -152,40 +152,18 @@ func (i *InputDefinition) saveMeta() error {
152
152
if err := os .MkdirAll (i .path , 0777 ); err != nil {
153
153
return err
154
154
}
155
- // Marshal metadata.
155
+
156
156
var frames []* internal.Frame
157
157
for _ , fr := range i .frames {
158
- frameMeta := & internal.FrameMeta {
159
- RowLabel : fr .Options .RowLabel ,
160
- InverseEnabled : fr .Options .InverseEnabled ,
161
- CacheType : fr .Options .CacheType ,
162
- CacheSize : fr .Options .CacheSize ,
163
- TimeQuantum : string (fr .Options .TimeQuantum ),
164
- }
165
- frame := & internal.Frame {Name : fr .Name , Meta : frameMeta }
166
- frames = append (frames , frame )
158
+ frames = append (frames , fr .Encode ())
167
159
}
168
160
169
161
var fields []* internal.InputDefinitionField
170
162
for _ , field := range i .fields {
171
- var actions []* internal.InputDefinitionAction
172
- for _ , action := range field .Actions {
173
- actionMeta := & internal.InputDefinitionAction {
174
- Frame : action .Frame ,
175
- ValueDestination : action .ValueDestination ,
176
- ValueMap : action .ValueMap ,
177
- RowID : convert (action .RowID ),
178
- }
179
- actions = append (actions , actionMeta )
180
- }
181
-
182
- fieldMeta := & internal.InputDefinitionField {
183
- Name : field .Name ,
184
- PrimaryKey : field .PrimaryKey ,
185
- InputDefinitionActions : actions ,
186
- }
187
- fields = append (fields , fieldMeta )
163
+ fields = append (fields , field .Encode ())
188
164
}
165
+
166
+ // Marshal input definition.
189
167
buf , err := proto .Marshal (& internal.InputDefinition {
190
168
Name : i .name ,
191
169
Frames : frames ,
@@ -211,17 +189,16 @@ type InputDefinitionField struct {
211
189
}
212
190
213
191
// Encode converts InputDefinitionField into its internal representation.
214
- func (o * InputDefinitionField ) Encode () (* internal.InputDefinitionField , error ) {
215
- field := internal.InputDefinitionField {Name : o .Name , PrimaryKey : o .PrimaryKey }
216
-
192
+ func (o * InputDefinitionField ) Encode () * internal.InputDefinitionField {
193
+ var actions []* internal.InputDefinitionAction
217
194
for _ , action := range o .Actions {
218
- actionEncode , err := action .Encode ()
219
- if err != nil {
220
- return nil , err
221
- }
222
- field .InputDefinitionActions = append (field .InputDefinitionActions , actionEncode )
195
+ actions = append (actions , action .Encode ())
196
+ }
197
+ return & internal.InputDefinitionField {
198
+ Name : o .Name ,
199
+ PrimaryKey : o .PrimaryKey ,
200
+ InputDefinitionActions : actions ,
223
201
}
224
- return & field , nil
225
202
}
226
203
227
204
// Action describes the mapping method for the field in the InputDefinition.
@@ -233,16 +210,19 @@ type Action struct {
233
210
}
234
211
235
212
// Encode converts Action into its internal representation.
236
- func (o * Action ) Encode () (* internal.InputDefinitionAction , error ) {
237
- if o .RowID == nil && o .ValueDestination == "single-row-boolean" {
238
- return nil , errors .New ("rowID required for single-row-boolean" )
239
- }
213
+ func (o * Action ) Encode () * internal.InputDefinitionAction {
214
+ // TODO: this check needs to happen somewhere other than Encode()
215
+ /*
216
+ if o.RowID == nil && o.ValueDestination == InputSingleRowBool {
217
+ return nil, errors.New("rowID required for single-row-boolean")
218
+ }
219
+ */
240
220
return & internal.InputDefinitionAction {
241
221
Frame : o .Frame ,
242
222
ValueDestination : o .ValueDestination ,
243
223
ValueMap : o .ValueMap ,
244
224
RowID : convert (o .RowID ),
245
- }, nil
225
+ }
246
226
}
247
227
248
228
// convert pointer to uint64
@@ -259,27 +239,31 @@ type InputFrame struct {
259
239
Options FrameOptions `json:"options,omitempty"`
260
240
}
261
241
242
+ // Encode converts InputFrame into its internal representation.
243
+ func (f * InputFrame ) Encode () * internal.Frame {
244
+ return & internal.Frame {
245
+ Name : f .Name ,
246
+ Meta : f .Options .Encode (),
247
+ }
248
+
249
+ }
250
+
262
251
// InputDefinitionInfo represents the json message format needed to create an InputDefinition.
263
252
type InputDefinitionInfo struct {
264
253
Frames []InputFrame `json:"frames"`
265
254
Fields []InputDefinitionField `json:"fields"`
266
255
}
267
256
268
257
// Encode converts InputDefinitionInfo into its internal representation.
269
- func (i * InputDefinitionInfo ) Encode () ( * internal.InputDefinition , error ) {
258
+ func (i * InputDefinitionInfo ) Encode () * internal.InputDefinition {
270
259
var def internal.InputDefinition
271
260
for _ , f := range i .Frames {
272
- def .Frames = append (def .Frames , & internal. Frame { Name : f . Name , Meta : f . Options . Encode ()} )
261
+ def .Frames = append (def .Frames , f . Encode ())
273
262
}
274
263
for _ , f := range i .Fields {
275
- fEncode , err := f .Encode ()
276
- if err != nil {
277
- return nil , err
278
- }
279
- def .Fields = append (def .Fields , fEncode )
264
+ def .Fields = append (def .Fields , f .Encode ())
280
265
}
281
-
282
- return & def , nil
266
+ return & def
283
267
}
284
268
285
269
// AddFrame manually add frame to input definition.
0 commit comments