Postgres/MySQL/MSSQL: Fix so that numeric/non-string values are returned from query variables (#35411)

Fixes a problem with query variables where SQL query returning for example only 
numeric values didn't populate the query variables with values.

Fixes #35391
This commit is contained in:
Marcus Efraimsson
2021-06-09 14:18:54 +02:00
committed by GitHub
parent dc7a641978
commit bf7301e485
6 changed files with 148 additions and 185 deletions

View File

@ -338,8 +338,8 @@ describe('PostgreSQLDatasource', () => {
});
});
describe('When performing metricFindQuery', () => {
it('should return list of all column values', async () => {
describe('When performing metricFindQuery that returns multiple string fields', () => {
it('should return list of all string field values', async () => {
const query = 'select * from atable';
const response = {
results: {
@ -487,6 +487,43 @@ describe('PostgreSQLDatasource', () => {
});
});
describe('When performing metricFindQuery without key, value columns', () => {
it('should return list of all field values as text', async () => {
const query = 'select id, values from atable';
const response = {
results: {
tempvar: {
refId: 'tempvar',
frames: [
dataFrameToJSON(
new MutableDataFrame({
fields: [
{ name: 'id', values: [1, 2, 3] },
{ name: 'values', values: ['test1', 'test2', 'test3'] },
],
meta: {
executedQueryString: 'select id, values from atable',
},
})
),
],
},
},
};
const { ds } = setupTestContext(response);
const results = await ds.metricFindQuery(query, {});
expect(results).toEqual([
{ text: 1 },
{ text: 2 },
{ text: 3 },
{ text: 'test1' },
{ text: 'test2' },
{ text: 'test3' },
]);
});
});
describe('When performing metricFindQuery with key, value columns and with duplicate keys', () => {
it('should return list of unique keys', async () => {
const query = 'select * from atable';