mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix Postgres query handling null values for smallint (#36648)
* Fix Postgres query handling null values for smallint * Fix converting to int16
This commit is contained in:
parent
c26bd6c52f
commit
5d01add7da
@ -200,5 +200,25 @@ func (t *postgresQueryResultTransformer) GetConverterList() []sqlutil.StringConv
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "handle INT2",
|
||||
InputScanKind: reflect.Interface,
|
||||
InputTypeName: "INT2",
|
||||
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
||||
Replacer: &sqlutil.StringFieldReplacer{
|
||||
OutputFieldType: data.FieldTypeNullableInt16,
|
||||
ReplaceFunc: func(in *string) (interface{}, error) {
|
||||
if in == nil {
|
||||
return nil, nil
|
||||
}
|
||||
i64, err := strconv.ParseInt(*in, 10, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := int16(i64)
|
||||
return &v, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func TestGenerateConnectionString(t *testing.T) {
|
||||
}
|
||||
|
||||
// To run this test, set runPostgresTests=true
|
||||
// Or from the commandline: GRAFANA_TEST_DB=postgres go test -v ./pkg/tsdb/postgres
|
||||
// Or from the commandline: GRAFANA_TEST_DB=postgres go test -tags=integration -v ./pkg/tsdb/postgres
|
||||
// The tests require a PostgreSQL db named grafanadstest and a user/password grafanatest/grafanatest!
|
||||
// Use the docker/blocks/postgres_tests/docker-compose.yaml to spin up a
|
||||
// preconfigured Postgres server suitable for running these tests.
|
||||
@ -214,7 +214,8 @@ func TestPostgres(t *testing.T) {
|
||||
c13_time time without time zone,
|
||||
c14_timetz time with time zone,
|
||||
time date,
|
||||
c15_interval interval
|
||||
c15_interval interval,
|
||||
c16_smallint smallint
|
||||
);
|
||||
`
|
||||
_, err := sess.Exec(sql)
|
||||
@ -226,7 +227,8 @@ func TestPostgres(t *testing.T) {
|
||||
4.5,6.7,1.1,1.2,
|
||||
'char10','varchar10','text',
|
||||
|
||||
now(),now(),now(),now(),now(),now(),'15m'::interval
|
||||
now(),now(),now(),now(),now(),now(),'15m'::interval,
|
||||
null
|
||||
);
|
||||
`
|
||||
_, err = sess.Exec(sql)
|
||||
@ -252,9 +254,9 @@ func TestPostgres(t *testing.T) {
|
||||
|
||||
frames, _ := queryResult.Dataframes.Decoded()
|
||||
require.Len(t, frames, 1)
|
||||
require.Len(t, frames[0].Fields, 17)
|
||||
require.Len(t, frames[0].Fields, 18)
|
||||
|
||||
require.Equal(t, int16(1), frames[0].Fields[0].At(0).(int16))
|
||||
require.Equal(t, int16(1), *frames[0].Fields[0].At(0).(*int16))
|
||||
require.Equal(t, int32(2), *frames[0].Fields[1].At(0).(*int32))
|
||||
require.Equal(t, int64(3), *frames[0].Fields[2].At(0).(*int64))
|
||||
|
||||
@ -280,6 +282,7 @@ func TestPostgres(t *testing.T) {
|
||||
_, ok = frames[0].Fields[15].At(0).(*time.Time)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "00:15:00", *frames[0].Fields[16].At(0).(*string))
|
||||
require.Nil(t, frames[0].Fields[17].At(0))
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user