This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Adapt doris schema type #1495
Merged
Merged
Adapt doris schema type #1495
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright Quesma, licensed under the Elastic License 2.0. | ||
| // SPDX-License-Identifier: Elastic-2.0 | ||
| package clickhouse | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "time" | ||
| ) | ||
|
|
||
| // this is catch all type for all types we do not exlicitly support | ||
| type UnknownType struct{} | ||
|
|
||
| type ClickhouseTypeResolver struct{} | ||
|
|
||
| func (r *ClickhouseTypeResolver) ResolveType(clickHouseTypeName string) reflect.Type { | ||
| switch clickHouseTypeName { | ||
| case "String", "LowCardinality(String)", "UUID", "FixedString": | ||
| return reflect.TypeOf("") | ||
| case "DateTime64", "DateTime", "Date", "DateTime64(3)": | ||
| return reflect.TypeOf(time.Time{}) | ||
| case "UInt8", "UInt16", "UInt32", "UInt64": | ||
| return reflect.TypeOf(uint64(0)) | ||
| case "Int8", "Int16", "Int32": | ||
| return reflect.TypeOf(int32(0)) | ||
| case "Int64": | ||
| return reflect.TypeOf(int64(0)) | ||
| case "Float32", "Float64": | ||
| return reflect.TypeOf(float64(0)) | ||
| case "Point": | ||
| return reflect.TypeOf(Point{}) | ||
| case "Bool": | ||
| return reflect.TypeOf(true) | ||
| case "JSON": | ||
| return reflect.TypeOf(map[string]interface{}{}) | ||
| case "Map(String, Nullable(String))", "Map(String, String)", "Map(LowCardinality(String), String)", "Map(LowCardinality(String), Nullable(String))": | ||
| return reflect.TypeOf(map[string]string{}) | ||
| case "Unknown": | ||
| return reflect.TypeOf(UnknownType{}) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "fmt" | ||
| "github.com/QuesmaOrg/quesma/platform/clickhouse" | ||
| "github.com/QuesmaOrg/quesma/platform/config" | ||
| "github.com/QuesmaOrg/quesma/platform/doris" | ||
| "github.com/QuesmaOrg/quesma/platform/logger" | ||
| "github.com/QuesmaOrg/quesma/platform/schema" | ||
| "github.com/QuesmaOrg/quesma/platform/util" | ||
|
|
@@ -211,44 +212,38 @@ func (t MultiValueType) GetColumn(name string) *Column { | |
| } | ||
|
|
||
| func NewBaseType(clickHouseTypeName string) BaseType { | ||
| var GoType = ResolveType(clickHouseTypeName) | ||
| // 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. | ||
| var r TypeResolver = &clickhouse.ClickhouseTypeResolver{} | ||
| var GoType = r.ResolveType(clickHouseTypeName) | ||
| if GoType == nil { | ||
| // default, probably good for dates, etc. | ||
| GoType = reflect.TypeOf("") | ||
| } | ||
| return BaseType{Name: clickHouseTypeName, GoType: GoType} | ||
| } | ||
|
|
||
| // this is catch all type for all types we do not exlicitly support | ||
| type UnknownType struct{} | ||
|
|
||
| func ResolveType(clickHouseTypeName string) reflect.Type { | ||
| switch clickHouseTypeName { | ||
| case "String", "LowCardinality(String)", "UUID", "FixedString": | ||
| return reflect.TypeOf("") | ||
| case "DateTime64", "DateTime", "Date", "DateTime64(3)": | ||
| return reflect.TypeOf(time.Time{}) | ||
| case "UInt8", "UInt16", "UInt32", "UInt64": | ||
| return reflect.TypeOf(uint64(0)) | ||
| case "Int8", "Int16", "Int32": | ||
| return reflect.TypeOf(int32(0)) | ||
| case "Int64": | ||
| return reflect.TypeOf(int64(0)) | ||
| case "Float32", "Float64": | ||
| return reflect.TypeOf(float64(0)) | ||
| case "Point": | ||
| return reflect.TypeOf(clickhouse.Point{}) | ||
| case "Bool": | ||
| return reflect.TypeOf(true) | ||
| case "JSON": | ||
| return reflect.TypeOf(map[string]interface{}{}) | ||
| case "Map(String, Nullable(String))", "Map(String, String)", "Map(LowCardinality(String), String)", "Map(LowCardinality(String), Nullable(String))": | ||
| return reflect.TypeOf(map[string]string{}) | ||
| case "Unknown": | ||
| return reflect.TypeOf(UnknownType{}) | ||
| func NewBaseTypeWithInstanceName(typeName string, instanceName string) BaseType { | ||
| r := GetTypeResolver(instanceName) | ||
| var GoType = r.ResolveType(typeName) | ||
| if GoType == nil { | ||
| // default, probably good for dates, etc. | ||
| GoType = reflect.TypeOf("") | ||
| } | ||
| return BaseType{Name: typeName, GoType: GoType} | ||
| } | ||
|
|
||
| func GetTypeResolver(instanceName string) TypeResolver { | ||
| var r TypeResolver | ||
| if instanceName == "doris" { | ||
|
||
| r = &doris.DorisTypeResolver{} | ||
| } else { | ||
| r = &clickhouse.ClickhouseTypeResolver{} | ||
| } | ||
| return r | ||
| } | ||
|
|
||
| return nil | ||
| type TypeResolver interface { | ||
| ResolveType(typeName string) reflect.Type | ||
| } | ||
|
|
||
| // 'value': value of a field, from unmarshalled JSON | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright Quesma, licensed under the Elastic License 2.0. | ||
| // SPDX-License-Identifier: Elastic-2.0 | ||
| package doris | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // this is catch all type for all types we do not exlicitly support | ||
| type UnknownType struct{} | ||
|
|
||
| type DorisTypeResolver struct{} | ||
|
|
||
| func (r *DorisTypeResolver) ResolveType(dorisTypeName string) reflect.Type { | ||
| dorisTypeName = strings.ToLower(dorisTypeName) | ||
| switch dorisTypeName { | ||
| case "char", "varchar", "string", "text": | ||
| return reflect.TypeOf("") | ||
| case "date", "datetime", "datev2", "datetimev2": | ||
| return reflect.TypeOf(time.Time{}) | ||
| case "tinyint", "smallint", "int": | ||
| return reflect.TypeOf(int32(0)) | ||
| case "bigint": | ||
| return reflect.TypeOf(int64(0)) | ||
| case "largeint": | ||
| return reflect.TypeOf("") // LargeInt is typically handled as string due to size | ||
| case "boolean": | ||
| return reflect.TypeOf(true) | ||
| case "float": | ||
| return reflect.TypeOf(float32(0)) | ||
| case "double": | ||
| return reflect.TypeOf(float64(0)) | ||
| case "decimal", "decimalv2": | ||
| return reflect.TypeOf("") // Decimals often handled as strings for precision | ||
| case "json": | ||
| return reflect.TypeOf(map[string]interface{}{}) | ||
| case "hll": | ||
| return reflect.TypeOf([]byte{}) // HLL is a binary type | ||
| case "bitmap": | ||
| return reflect.TypeOf([]byte{}) // Bitmap is also binary | ||
| case "array": | ||
| return reflect.TypeOf([]interface{}{}) | ||
| case "map": | ||
| return reflect.TypeOf(map[string]interface{}{}) | ||
| case "struct": | ||
| return reflect.TypeOf(map[string]interface{}{}) | ||
| case "Unknown": | ||
| return reflect.TypeOf(UnknownType{}) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use some const enum instead of string as
instanceName