Skip to content
Snippets Groups Projects
Unverified Commit 50dd7c02 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Use string/contains for new high cardinality string field filters (#29885)

parent 1101600c
Branches
Tags
No related merge requests found
......@@ -223,6 +223,7 @@ describe("scenarios > filters > sql filters > values source", () => {
SQLFilter.openTypePickerFromDefaultFilterType();
SQLFilter.chooseType("Field Filter");
FieldFilter.mapTo({ table: "Products", field: "Ean" });
FieldFilter.setWidgetType("String");
setFilterQuestionSource({ question: "SQL source", field: "EAN" });
saveQuestion("SQL filter");
......@@ -304,6 +305,7 @@ describe("scenarios > filters > sql filters > values source", () => {
SQLFilter.openTypePickerFromDefaultFilterType();
SQLFilter.chooseType("Field Filter");
FieldFilter.mapTo({ table: "Products", field: "Ean" });
FieldFilter.setWidgetType("String");
setFilterListSource({ values: ["1018947080336", "7663515285824"] });
saveQuestion("SQL filter");
......
......@@ -45,7 +45,16 @@ export function getDefaultParameterWidgetType(tag: TemplateTag, field: Field) {
options.some(option => option.type === widgetType)
) {
return widgetType;
} else {
return options[0].type;
}
const distinctCount = field.fingerprint?.global?.["distinct-count"];
if (
distinctCount != null &&
distinctCount > 20 &&
options.some(option => option.type === "string/contains")
) {
return "string/contains";
}
return options[0].type;
}
......@@ -4,7 +4,7 @@ import { TableId } from "./table";
export type FieldId = number;
export interface FieldFingerprint {
global: FieldGlobalFingerprint;
global?: FieldGlobalFingerprint;
type?: FieldTypeFingerprint;
}
......
......@@ -107,7 +107,25 @@ describe("TagEditorParam", () => {
});
describe("tag dimension", () => {
it("should default to string/= for a new string field filter", async () => {
it("should default to string/= for a new low cardinality string field filter", async () => {
const tag = createMockTemplateTag({
type: "dimension",
dimension: undefined,
"widget-type": undefined,
});
const { setTemplateTag } = setup({ tag });
userEvent.click(await screen.findByText("People"));
userEvent.click(await screen.findByText("Source"));
expect(setTemplateTag).toHaveBeenCalledWith({
...tag,
dimension: ["field", PEOPLE.SOURCE, null],
"widget-type": "string/=",
});
});
it("should default to string/contains for a new high cardinality string field filter", async () => {
const tag = createMockTemplateTag({
type: "dimension",
dimension: undefined,
......@@ -121,7 +139,7 @@ describe("TagEditorParam", () => {
expect(setTemplateTag).toHaveBeenCalledWith({
...tag,
dimension: ["field", PEOPLE.NAME, null],
"widget-type": "string/=",
"widget-type": "string/contains",
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment