fix segment table filter (#8034)

This commit is contained in:
Vadim Ogievetsky 2019-07-06 09:21:28 -07:00 committed by Fangjin Yang
parent 9c7c7c58ae
commit 2de6cc3b30
2 changed files with 22 additions and 3 deletions

View File

@ -16,7 +16,7 @@
* limitations under the License.
*/
import { alphanumericCompare, sortWithPrefixSuffix } from './general';
import { alphanumericCompare, sortWithPrefixSuffix, sqlQueryCustomTableFilter } from './general';
describe('general', () => {
describe('sortWithPrefixSuffix', () => {
@ -42,4 +42,22 @@ describe('general', () => {
).toEqual('gefcdhba');
});
});
describe('sqlQueryCustomTableFilter', () => {
it('works', () => {
expect(
sqlQueryCustomTableFilter({
id: 'datasource',
value: `hello`,
}),
).toMatchInlineSnapshot(`"LOWER(\\"datasource\\") LIKE LOWER('hello%')"`);
expect(
sqlQueryCustomTableFilter({
id: 'datasource',
value: `"hello"`,
}),
).toMatchInlineSnapshot(`"\\"datasource\\" = 'hello'"`);
});
});
});

View File

@ -113,9 +113,10 @@ export function sqlQueryCustomTableFilter(filter: Filter): string {
const needleAndMode: NeedleAndMode = getNeedleAndMode(filter.value);
const needle = needleAndMode.needle;
if (needleAndMode.mode === 'exact') {
return `${columnName} = '${needle.toUpperCase()}' OR ${columnName} = '${needle.toLowerCase()}'`;
return `${columnName} = '${needle}'`;
} else {
return `LOWER(${columnName}) LIKE LOWER('${needle}%')`;
}
return `${columnName} LIKE '${needle.toUpperCase()}%' OR ${columnName} LIKE '${needle.toLowerCase()}%'`;
}
// ----------------------------