feat: allow to set distinct for query measures (#5091)

This commit is contained in:
YANG QIA 2024-08-20 16:47:03 +08:00 committed by GitHub
parent 77b60ed16c
commit ba95bfafe2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 4 deletions

View File

@ -289,6 +289,12 @@ export const querySchema: ISchema = {
},
},
},
distinct: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-content': '{{t("Distinct")}}',
},
},
{
required: true,

View File

@ -94,5 +94,6 @@
"Aspect ratio": "Aspect ratio",
"Fixed height": "Fixed height",
"Show background": "Show background",
"Show padding": "Show padding"
"Show padding": "Show padding",
"Distinct": "Distinct"
}

View File

@ -95,5 +95,6 @@
"Aspect ratio": "宽高比",
"Fixed height": "固定高度",
"Show background": "显示背景",
"Show padding": "显示内边距"
"Show padding": "显示内边距",
"Distinct": "去重"
}

View File

@ -19,6 +19,7 @@ type MeasureProps = {
type?: string;
aggregation?: string;
alias?: string;
distinct?: boolean;
};
type DimensionProps = {
@ -117,7 +118,7 @@ export const parseBuilder = async (ctx: Context, next: Next) => {
let hasAgg = false;
measures.forEach((measure: MeasureProps & { field: string }) => {
const { field, aggregation, alias } = measure;
const { field, aggregation, alias, distinct } = measure;
const attribute = [];
const col = sequelize.col(field);
if (aggregation) {
@ -125,7 +126,7 @@ export const parseBuilder = async (ctx: Context, next: Next) => {
throw new Error(`Invalid aggregation function: ${aggregation}`);
}
hasAgg = true;
attribute.push(sequelize.fn(aggregation, col));
attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn('DISTINCT', col) : col));
} else {
attribute.push(col);
}