-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcallBack.go
456 lines (436 loc) · 11.4 KB
/
callBack.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
package griddb_go
import "C"
import (
"unsafe"
"time"
)
const (
RESULT_OK = 0
RESULT_FALSE = -1
)
const (
UTC_TIMESTAMP_MILI_MAX = 253402300799999
MILI_SECOND = 1000
)
const (
TYPE_OPTION_NULLABLE = 2
TYPE_OPTION_NOT_NULL = 4
)
const (
INDEX_FLAG_DEFAULT = -1
INDEX_FLAG_TREE = 1
INDEX_FLAG_HASH = 2
INDEX_FLAG_SPATIAL = 4
)
const (
FETCH_OPTION_LIMIT_MAX = 2147483647
FETCH_LIMIT = 0
FETCH_SIZE = 1
FETCH_PARTIAL_EXECUTION = 2
)
const (
CONTAINER_COLLECTION = iota
CONTAINER_TIME_SERIES
)
const (
ROW_SET_CONTAINER_ROWS = iota
ROW_SET_AGGREGATION_RESULT
ROW_SET_QUERY_ANALYSIS
)
const (
TYPE_STRING = iota
TYPE_BOOL
TYPE_BYTE
TYPE_SHORT
TYPE_INTEGER
TYPE_LONG
TYPE_FLOAT
TYPE_DOUBLE
TYPE_TIMESTAMP
TYPE_GEOMETRY
TYPE_BLOB
// TYPE_STRING_ARRAY
// TYPE_BOOL_ARRAY
// TYPE_BYTE_ARRAY
// TYPE_SHORT_ARRAY
// TYPE_INTEGER_ARRAY
// TYPE_LONG_ARRAY
// TYPE_FLOAT_ARRAY
// TYPE_DOUBLE_ARRAY
// TYPE_TIMESTAMP_ARRAY
TYPE_NULL = -1
)
const (
TIME_UNIT_YEAR = iota
TIME_UNIT_MONTH
TIME_UNIT_DAY
TIME_UNIT_HOUR
TIME_UNIT_MINUTE
TIME_UNIT_SECOND
TIME_UNIT_MILLISECOND
)
//export lenTimestampArray
func lenTimestampArray(dataInput uintptr) (lenArray int64, convertResult int32) {
tmpData := (*interface{})(unsafe.Pointer(dataInput))
data, g := (*tmpData).([]interface{})
if (g) {
lenArray = int64(len(data))
convertResult = RESULT_OK
} else {
convertResult = RESULT_FALSE
}
return
}
//export eachElementRowStoreMulPut
func eachElementRowStoreMulPut(dataInput uintptr, arrayElement [][]uintptr) (result int32){
data := *(*[][]interface{})(unsafe.Pointer(dataInput))
if (len(data) != len(arrayElement)) {
result = RESULT_FALSE
return
}
for i := range data {
if (data[i] == nil) {
result = RESULT_FALSE
return
}
if (len(data[i]) != len(arrayElement[i])) {
result = RESULT_FALSE
return
}
for j := range data[i] {
arrayElement[i][j] = (uintptr)(unsafe.Pointer(&(data[i][j])))
}
}
result = RESULT_OK
return
}
//export lenRow
func lenRow(dataInput uintptr) (lenResult int64) {
data := *(*[]interface{})(unsafe.Pointer(dataInput))
lenResult = int64(len(data))
return
}
//export eachElementRow
func eachElementRow(dataInput uintptr, arrayElement []uintptr) {
data := *(*[]interface{})(unsafe.Pointer(dataInput))
for i := range data {
arrayElement[i] = (uintptr)(unsafe.Pointer(&(data[i])))
}
return
}
//export GetInterfaceArrayLength
func GetInterfaceArrayLength(dataInput uintptr, colType int) (length int, convertResult int32) {
data := (*interface{})(unsafe.Pointer(dataInput))
convertResult = RESULT_OK
if (colType == TYPE_STRING || colType == TYPE_GEOMETRY) {
value, ok := (*data).(string)
if (ok) {
length = len(value)
} else {
convertResult = RESULT_FALSE
}
} else if (colType == TYPE_BLOB) {
value, ok := (*data).([]byte)
if (ok) {
length = len(value)
} else {
convertResult = RESULT_FALSE
}
// } else if (colType == TYPE_STRING_ARRAY) {
// value, ok := (*data).([]string)
// if (ok) {
// length = len(value)
// } else {
// convertResult = RESULT_FALSE
// }
} else {
value, ok := (*data).([]interface{})
if (ok) {
length = len(value)
} else {
convertResult = RESULT_FALSE
}
}
return
}
//export checkNil
func checkNil(dataInput uintptr) (isNil bool) {
data := (*interface{})(unsafe.Pointer(dataInput))
if ((*data) == nil) {
isNil = true
} else {
isNil = false
}
return
}
//export SetForBlobString
func SetForBlobString(dataInput uintptr, blob []byte) (convertResult int32) {
data := (*interface{})(unsafe.Pointer(dataInput))
convertResult = RESULT_OK
value, ok := (*data).([]byte)
if (ok) {
for i := 0; i < len(value); i++ {
blob[i] = value[i]
}
} else {
s, result := (*data).(string)
if (result) {
for i := 0; i < len(s); i++ {
blob[i] = s[i]
}
} else {
convertResult = RESULT_FALSE
}
}
return
}
//export GetNumericInterface
func GetNumericInterface(dataInput uintptr, colType int) (
mType int32,
asLong int64,
asDouble float64,
convertResult int32) {
data := (*interface{})(unsafe.Pointer(dataInput))
switch colType {
case TYPE_BOOL, TYPE_BYTE, TYPE_SHORT, TYPE_INTEGER, TYPE_LONG: {
convertResult = RESULT_OK
mType = TYPE_LONG
switch (*data).(type) {
case bool:
{
value, _ := (*data).(bool)
if (colType != TYPE_BOOL) {
convertResult = RESULT_FALSE
}
if asLong = 0; value {
asLong = 1
}
return
}
case int8:
{
asLong = (int64)((*data).(int8))
return
}
case int16:
{
asLong = (int64)((*data).(int16))
return
}
case int32:
{
asLong = (int64)((*data).(int32))
return
}
case int:
{
asLong = (int64)((*data).(int))
return
}
case int64:
{
asLong = (int64)((*data).(int64))
return
}
default:
convertResult = RESULT_FALSE
return
}
}
case TYPE_FLOAT, TYPE_DOUBLE: {
convertResult = RESULT_OK
mType = TYPE_DOUBLE
switch (*data).(type) {
case int8:
{
asDouble = (float64)((*data).(int8))
return
}
case int16:
{
asDouble = (float64)((*data).(int16))
return
}
case int32:
{
asDouble = (float64)((*data).(int32))
return
}
case int:
{
asDouble = (float64)((*data).(int))
return
}
case int64:
{
asDouble = (float64)((*data).(int64))
return
}
case float32:
{
asDouble = (float64)((*data).(float32))
return
}
case float64:
{
asDouble = (float64)((*data).(float64))
return
}
default:
convertResult = RESULT_FALSE
return
}
}
case TYPE_TIMESTAMP: {
convertResult = RESULT_OK
mType = TYPE_LONG
switch (*data).(type) {
// cast for numerical input
case int8:
{
value, _ := (*data).(int8)
asLong = (int64)(value) * MILI_SECOND
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case int16:
{
value, _ := (*data).(int16)
asLong = (int64)(value) * MILI_SECOND
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case int32:
{
value, _ := (*data).(int32)
asLong = (int64)(value) * MILI_SECOND
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case int:
{
value, _ := (*data).(int)
asLong = (int64)(value) * MILI_SECOND
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case int64:
{
value, _ := (*data).(int64)
asLong = (int64)(value) * MILI_SECOND
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case float32:
{
value, _ := (*data).(float32)
tmp := value * MILI_SECOND
if (tmp > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
} else {
asLong = (int64)(tmp)
}
return
}
case float64:
{
value, _ := (*data).(float64)
tmp := value * MILI_SECOND
if (tmp > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
} else {
asLong = (int64)(tmp)
}
return
}
case time.Time:
{
// cast for datetime input
value, _ := (*data).(time.Time)
asLong = value.Unix() // get second
tmpMili := int64(value.Nanosecond() / 1000000) // get mili second for timestamp
asLong = asLong * 1000 + tmpMili
if (asLong > UTC_TIMESTAMP_MILI_MAX) {
convertResult = RESULT_FALSE
}
return
}
case string:
{
// cast for string input
value, _ := (*data).(string)
mType = TYPE_STRING
asLong = int64(len(value))
return
}
default:
convertResult = RESULT_FALSE
return
}
}
default:
convertResult = RESULT_FALSE
return
}
return
}
//export lenColumnName
func lenColumnName(dataInput uintptr) (lenName int64, convertResult int32) {
data := *(*[]interface{})(unsafe.Pointer(dataInput))
convertResult = RESULT_OK
if (len(data) <= 0) {
convertResult = RESULT_FALSE
return
}
value, ok := (data[0]).(string)
if (ok) {
lenName = (int64)(len(value))
} else {
convertResult = RESULT_FALSE
}
return
}
//export getColumnInfo
func getColumnInfo(dataInput uintptr, colName []byte) (mType int64, option int64, convertResult int32) {
data := *(*[]interface{})(unsafe.Pointer(dataInput))
convertResult = RESULT_OK
if (len(data) != 2 && len(data) != 3) {
convertResult = RESULT_FALSE
return
}
value, ok := (data[0]).(string)
if (!ok) {
convertResult = RESULT_FALSE
return
}
for i := 0; i < len(value); i++ {
colName[i] = value[i]
}
mTypeTmp, ok2 := data[1].(int)
if (!ok2) {
convertResult = RESULT_FALSE
return
}
mType = int64(mTypeTmp)
if (len(data) == 3) {
optionTmp, ok3 := data[2].(int)
if (!ok3) {
convertResult = RESULT_FALSE
return
}
option = int64(optionTmp)
} else {
option = 0
}
return
}