-
Notifications
You must be signed in to change notification settings - Fork 2
/
column_handler.go
139 lines (127 loc) · 4.12 KB
/
column_handler.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
package column_handler
import (
"database/sql"
"fmt"
"github.com/apache/arrow/go/v12/arrow"
"github.com/apache/arrow/go/v12/arrow/array"
)
type ColumnHandler interface {
GetVariable() interface{}
GetField() arrow.Field
AppendValues(builder *array.RecordBuilder, rows int64)
SetVariable(row int64)
}
func GetColumnHandler(index int, column *sql.ColumnType, batchSize int64) (ColumnHandler, error) {
nullable, ok := column.Nullable()
if !ok {
panic("SQL driver doesn't support nullable property")
}
switch column.DatabaseTypeName() {
case "UNSIGNED TINYINT":
if nullable {
return NewNullUint8ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint8ColumnHandler(column.Name(), index, batchSize), nil
}
case "UNSIGNED SMALLINT":
if nullable {
return NewNullUint16ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint16ColumnHandler(column.Name(), index, batchSize), nil
}
case "UNSIGNED MEDIUMINT":
if nullable {
return NewNullUint32ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint32ColumnHandler(column.Name(), index, batchSize), nil
}
case "UNSIGNED INT":
if nullable {
return NewNullUint32ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint32ColumnHandler(column.Name(), index, batchSize), nil
}
case "UNSIGNED BIGINT":
if nullable {
return NewNullUint64ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint64ColumnHandler(column.Name(), index, batchSize), nil
}
case "TINYINT":
if nullable {
return NewNullBooleanColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewBooleanColumnHandler(column.Name(), index, batchSize), nil
}
case "SMALLINT":
if nullable {
return NewNullInt16ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewInt16ColumnHandler(column.Name(), index, batchSize), nil
}
case "MEDIUMINT":
if nullable {
return NewNullInt32ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewInt32ColumnHandler(column.Name(), index, batchSize), nil
}
case "INT":
if nullable {
return NewNullInt32ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewInt32ColumnHandler(column.Name(), index, batchSize), nil
}
case "BIGINT":
if nullable {
return NewNullInt64ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewInt64ColumnHandler(column.Name(), index, batchSize), nil
}
case "FLOAT":
if nullable {
return NewNullFloat32ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewFloat32ColumnHandler(column.Name(), index, batchSize), nil
}
case "DOUBLE":
if nullable {
return NewNullFloat64ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewFloat64ColumnHandler(column.Name(), index, batchSize), nil
}
case "DATE", "TIME", "DATETIME", "TIMESTAMP":
// TODO: choose a better data type
if nullable {
return NewNullStringColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewStringColumnHandler(column.Name(), index, batchSize), nil
}
case "YEAR":
// TODO: choose a better data type
if nullable {
return NewNullUint16ColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewUint16ColumnHandler(column.Name(), index, batchSize), nil
}
case "DECIMAL":
if nullable {
return NewNullStringColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewStringColumnHandler(column.Name(), index, batchSize), nil
}
case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "JSON":
if nullable {
return NewNullStringColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewStringColumnHandler(column.Name(), index, batchSize), nil
}
case "BIT", "BINARY", "VARBINARY", "TINYBLOB", "MEDIUMBLOB", "BLOB", "LONGBLOB":
if nullable {
return NewNullBinaryColumnHandler(column.Name(), index, batchSize), nil
} else {
return NewBinaryColumnHandler(column.Name(), index, batchSize), nil
}
default:
return nil, fmt.Errorf("unsupported data type '%s'", column.DatabaseTypeName())
}
}