Skip to content

Commit

Permalink
Merge pull request #70 from fschoell/feature/support_nullable_types
Browse files Browse the repository at this point in the history
add support for Nullable types in Clickhouse
  • Loading branch information
maoueh authored Nov 15, 2024
2 parents 3cdf12c + a419805 commit c596f46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist/
devel/data*
build/
*.spkg
/substreams-sink-sql
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

* Added support for `Nullable` types in Clickhouse.

## v4.2.2

* Fix major bug when receiving empty `MapOutput`
Expand Down
15 changes: 14 additions & 1 deletion db/dialect_clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,20 @@ func convertToType(value string, valueType reflect.Type) (any, error) {
newInt.SetString(value, 10)
return newInt, nil
}
return "", fmt.Errorf("unsupported pointer type %s", valueType)

elemType := valueType.Elem()
val, err := convertToType(value, elemType)
if err != nil {
return nil, fmt.Errorf("invalid pointer type: %w", err)
}

// We cannot just return &val here as this will return an *interface{} that the Clickhouse Go client won't be
// able to convert on inserting. Instead, we create a new variable using the type that valueType has been
// pointing to, assign the converted value from convertToType to that and then return a pointer to the new variable.
result := reflect.New(elemType).Elem()
result.Set(reflect.ValueOf(val))
return result.Addr().Interface(), nil

default:
return value, nil
}
Expand Down

0 comments on commit c596f46

Please sign in to comment.