|
6 | 6 | "fmt" |
7 | 7 | "github.com/QuesmaOrg/quesma/platform/clickhouse" |
8 | 8 | "github.com/QuesmaOrg/quesma/platform/config" |
| 9 | + "github.com/QuesmaOrg/quesma/platform/doris" |
9 | 10 | "github.com/QuesmaOrg/quesma/platform/logger" |
10 | 11 | "github.com/QuesmaOrg/quesma/platform/schema" |
11 | 12 | "github.com/QuesmaOrg/quesma/platform/util" |
@@ -68,6 +69,13 @@ type ( |
68 | 69 | Origin schema.FieldSource // TODO this field is just added to have way to forward information to the schema registry and should be considered as a technical debt |
69 | 70 | } |
70 | 71 | DateTimeType int |
| 72 | + InstanceType int |
| 73 | +) |
| 74 | + |
| 75 | +const ( |
| 76 | + DorisInstance InstanceType = iota |
| 77 | + ClickHouseInstance |
| 78 | + UnknownInstance |
71 | 79 | ) |
72 | 80 |
|
73 | 81 | const ( |
@@ -155,6 +163,18 @@ func (t MultiValueType) StringWithNullable() string { |
155 | 163 | return t.String() |
156 | 164 | } |
157 | 165 |
|
| 166 | +func GetInstanceType(instanceName string) InstanceType { |
| 167 | + switch instanceName { |
| 168 | + case "clickhouse": |
| 169 | + return DorisInstance |
| 170 | + case "doris": |
| 171 | + return ClickHouseInstance |
| 172 | + default: |
| 173 | + logger.Fatal().Msgf("unknown instance name: %s", instanceName) |
| 174 | + return UnknownInstance |
| 175 | + } |
| 176 | +} |
| 177 | + |
158 | 178 | func (t MultiValueType) createTableString(indentLvl int) string { |
159 | 179 | var sb strings.Builder |
160 | 180 | sb.WriteString(t.Name + "\n" + util.Indent(indentLvl) + "(\n") |
@@ -211,44 +231,41 @@ func (t MultiValueType) GetColumn(name string) *Column { |
211 | 231 | } |
212 | 232 |
|
213 | 233 | func NewBaseType(clickHouseTypeName string) BaseType { |
214 | | - var GoType = ResolveType(clickHouseTypeName) |
| 234 | + // TODO: currently, NewBaseType is only used in tests or create table or insert, not in Doris's code, so the ClickHouse schema is used here. |
| 235 | + var r TypeResolver = &clickhouse.ClickhouseTypeResolver{} |
| 236 | + var GoType = r.ResolveType(clickHouseTypeName) |
215 | 237 | if GoType == nil { |
216 | 238 | // default, probably good for dates, etc. |
217 | 239 | GoType = reflect.TypeOf("") |
218 | 240 | } |
219 | 241 | return BaseType{Name: clickHouseTypeName, GoType: GoType} |
220 | 242 | } |
221 | 243 |
|
222 | | -// this is catch all type for all types we do not exlicitly support |
223 | | -type UnknownType struct{} |
224 | | - |
225 | | -func ResolveType(clickHouseTypeName string) reflect.Type { |
226 | | - switch clickHouseTypeName { |
227 | | - case "String", "LowCardinality(String)", "UUID", "FixedString": |
228 | | - return reflect.TypeOf("") |
229 | | - case "DateTime64", "DateTime", "Date", "DateTime64(3)": |
230 | | - return reflect.TypeOf(time.Time{}) |
231 | | - case "UInt8", "UInt16", "UInt32", "UInt64": |
232 | | - return reflect.TypeOf(uint64(0)) |
233 | | - case "Int8", "Int16", "Int32": |
234 | | - return reflect.TypeOf(int32(0)) |
235 | | - case "Int64": |
236 | | - return reflect.TypeOf(int64(0)) |
237 | | - case "Float32", "Float64": |
238 | | - return reflect.TypeOf(float64(0)) |
239 | | - case "Point": |
240 | | - return reflect.TypeOf(clickhouse.Point{}) |
241 | | - case "Bool": |
242 | | - return reflect.TypeOf(true) |
243 | | - case "JSON": |
244 | | - return reflect.TypeOf(map[string]interface{}{}) |
245 | | - case "Map(String, Nullable(String))", "Map(String, String)", "Map(LowCardinality(String), String)", "Map(LowCardinality(String), Nullable(String))": |
246 | | - return reflect.TypeOf(map[string]string{}) |
247 | | - case "Unknown": |
248 | | - return reflect.TypeOf(UnknownType{}) |
| 244 | +func NewBaseTypeWithInstanceName(typeName string, instanceType InstanceType) BaseType { |
| 245 | + r := GetTypeResolver(instanceType) |
| 246 | + var GoType = r.ResolveType(typeName) |
| 247 | + if GoType == nil { |
| 248 | + // default, probably good for dates, etc. |
| 249 | + GoType = reflect.TypeOf("") |
| 250 | + } |
| 251 | + return BaseType{Name: typeName, GoType: GoType} |
| 252 | +} |
| 253 | + |
| 254 | +func GetTypeResolver(instanceType InstanceType) TypeResolver { |
| 255 | + var r TypeResolver |
| 256 | + switch instanceType { |
| 257 | + case DorisInstance: |
| 258 | + r = &doris.DorisTypeResolver{} |
| 259 | + case ClickHouseInstance: |
| 260 | + r = &clickhouse.ClickhouseTypeResolver{} |
| 261 | + default: |
| 262 | + logger.Warn().Msgf("unknown instance type: %v", instanceType) |
249 | 263 | } |
| 264 | + return r |
| 265 | +} |
250 | 266 |
|
251 | | - return nil |
| 267 | +type TypeResolver interface { |
| 268 | + ResolveType(typeName string) reflect.Type |
252 | 269 | } |
253 | 270 |
|
254 | 271 | // 'value': value of a field, from unmarshalled JSON |
|
0 commit comments