Skip to content

Commit

Permalink
int32 alias (#227)
Browse files Browse the repository at this point in the history
* Bump

* Changelog

* Changelog
  • Loading branch information
AsafMah authored Mar 4, 2024
1 parent b584ce2 commit 57720f8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ 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]
## [0.15.1] - 2024-03-04

### Changed

- Changed binary files data format compression to false
- Binary data formats are no longer compressed, as it is inefficient.

### Fixed

- Type aliases for int32 now work correctly when converting.



## [0.15.0] - 2023-12-04

Expand Down
23 changes: 14 additions & 9 deletions kusto/data/table/from_kusto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type SomeJSON struct {
ID int
}

type IntAlias int32

func TestFieldsConvert(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -416,24 +418,27 @@ func TestFieldsConvert(t *testing.T) {
desc: "valid Int",
columns: Columns{
{Type: types.Int, Name: "int"},
{Type: types.Int, Name: "IntAlias"},
{Type: types.Int, Name: "ptrint"},
{Type: types.Int, Name: "kInt"},
{Type: types.Int, Name: "PtrkInt"},
},
k: value.Int{Value: 1, Valid: true},
ptrStruct: &struct {
Int int32 `kusto:"int"`
PtrInt *int32 `kusto:"ptrint"`
KInt value.Int `kusto:"kInt"`
PtrkInt *value.Int
Int int32 `kusto:"int"`
IntAlias IntAlias
PtrInt *int32 `kusto:"ptrint"`
KInt value.Int `kusto:"kInt"`
PtrkInt *value.Int
}{},
err: false,
want: &struct {
Int int32 `kusto:"int"`
PtrInt *int32 `kusto:"ptrint"`
KInt value.Int `kusto:"kInt"`
PtrkInt *value.Int
}{1, int32Ptr(1), value.Int{Value: 1, Valid: true}, &value.Int{Value: 1, Valid: true}},
Int int32 `kusto:"int"`
IntAlias IntAlias
PtrInt *int32 `kusto:"ptrint"`
KInt value.Int `kusto:"kInt"`
PtrkInt *value.Int
}{1, 1, int32Ptr(1), value.Int{Value: 1, Valid: true}, &value.Int{Value: 1, Valid: true}},
},
{
desc: "non-valid Int",
Expand Down
45 changes: 30 additions & 15 deletions kusto/data/value/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,42 @@ func (in *Int) Unmarshal(i interface{}) error {
return nil
}

var (
int32PtrType = reflect.TypeOf((*int32)(nil))
int32Type = int32PtrType.Elem()
kustoIntPtrType = reflect.TypeOf((*Int)(nil))
kustoIntType = kustoIntPtrType.Elem()
)

// Convert Int into reflect value.
func (in Int) Convert(v reflect.Value) error {
t := v.Type()
switch {
case t.Kind() == reflect.Int32:
if in.Valid {
v.Set(reflect.ValueOf(in.Value))
}
return nil
case t.ConvertibleTo(reflect.TypeOf(new(int32))):
switch t {
case int32Type:
if in.Valid {
i := &in.Value
v.Set(reflect.ValueOf(i))
v.SetInt(int64(in.Value))
}
return nil
case t.ConvertibleTo(reflect.TypeOf(Int{})):
case kustoIntType:
v.Set(reflect.ValueOf(in))
return nil
case t.ConvertibleTo(reflect.TypeOf(&Int{})):
case kustoIntPtrType:
v.Set(reflect.ValueOf(&in))
return nil
default:
switch {
case int32Type.ConvertibleTo(t):
if in.Valid {
v.Set(reflect.ValueOf(in.Value).Convert(t))
}
case int32PtrType.ConvertibleTo(t):
if in.Valid {
v.Set(reflect.ValueOf(&in.Value).Convert(t))
}
case kustoIntType.ConvertibleTo(t):
v.Set(reflect.ValueOf(in).Convert(t))
case kustoIntPtrType.ConvertibleTo(t):
v.Set(reflect.ValueOf(&in).Convert(t))
default:
return fmt.Errorf("Column was type Kusto.Int, receiver had base Kind %s ", t.Kind())
}
}
return fmt.Errorf("Column was type Kusto.Int, receiver had base Kind %s ", t.Kind())
return nil
}
2 changes: 1 addition & 1 deletion kusto/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
package version

// Kusto is the version of this client package that is communicated to the server.
const Kusto = "0.15.0"
const Kusto = "0.15.1"

0 comments on commit 57720f8

Please sign in to comment.