mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-12-04 13:09:02 +08:00
[Core] [DataSet] Support ad hoc query custom functions (#686)
This commit is contained in:
commit
15b5bcd679
@ -108,7 +108,7 @@ public class SqlBuilder
|
||||
private List<String> applyGroupByColumns()
|
||||
{
|
||||
return configure.getGroups().stream()
|
||||
.map(v -> String.join(" ", String.format("`%s`", v.getColumn())))
|
||||
.map(v -> String.join(" ", String.format("%s", v.getColumn())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ public class AdhocColumn
|
||||
{
|
||||
private Long id;
|
||||
private String expression;
|
||||
private String function;
|
||||
private String alias;
|
||||
private String order;
|
||||
}
|
||||
|
@ -175,9 +175,12 @@ public class DataSetServiceImpl
|
||||
configure.getColumns()
|
||||
.forEach(column -> columnRepository.findById(column.getId())
|
||||
.ifPresent(entity -> {
|
||||
String columnName = entity.getName();
|
||||
AtomicReference<String> columnAlias = new AtomicReference<>(null);
|
||||
AtomicReference<String> expression = new AtomicReference<>(null);
|
||||
AtomicReference<String> columnName = new AtomicReference<>(entity.getName());
|
||||
if (StringUtils.isNotEmpty(column.getFunction())) {
|
||||
columnName.set(column.getFunction());
|
||||
}
|
||||
configure.getColumns().stream()
|
||||
.filter(it -> it.getId().equals(entity.getId()))
|
||||
.findFirst()
|
||||
@ -186,7 +189,7 @@ public class DataSetServiceImpl
|
||||
columnAlias.set(it.getAlias());
|
||||
});
|
||||
SqlColumn sqlColumn = SqlColumn.builder()
|
||||
.column(columnName)
|
||||
.column(columnName.get())
|
||||
.expression(expression.get())
|
||||
.alias(columnAlias.get())
|
||||
.build();
|
||||
@ -194,7 +197,7 @@ public class DataSetServiceImpl
|
||||
// Only dimensions are added to GROUP BY
|
||||
if (entity.getMode().equals(ColumnMode.DIMENSION)) {
|
||||
groupBy.add(SqlColumn.builder()
|
||||
.column(columnName)
|
||||
.column(columnName.get())
|
||||
.build());
|
||||
}
|
||||
// Add to Sort Sequence
|
||||
@ -300,14 +303,14 @@ public class DataSetServiceImpl
|
||||
{
|
||||
switch (type) {
|
||||
case NUMBER:
|
||||
return "bigint";
|
||||
return "Bigint";
|
||||
case NUMBER_SIGNED:
|
||||
return "UInt64";
|
||||
case BOOLEAN:
|
||||
return "boolean";
|
||||
return "Boolean";
|
||||
case STRING:
|
||||
default:
|
||||
return "varchar";
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,4 +75,5 @@ export default {
|
||||
columnExpressionAvg: 'Average',
|
||||
columnExpressionCount: 'Count',
|
||||
validatorSamplingTip: 'The order by key must contain a sampling key',
|
||||
customFunction: 'Custom Function'
|
||||
}
|
||||
|
@ -74,5 +74,6 @@ export default {
|
||||
columnExpressionSum: '总和',
|
||||
columnExpressionAvg: '平均值',
|
||||
columnExpressionCount: '计数',
|
||||
validatorSamplingTip: '排序键中必须包含抽样键'
|
||||
validatorSamplingTip: '排序键中必须包含抽样键',
|
||||
customFunction: '自定义函数'
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
@onOk="handlerCommit()"
|
||||
@cancel="handlerCancel()">
|
||||
<Form :model="formState"
|
||||
:label-width="80">
|
||||
:label-width="90">
|
||||
<FormItem v-if="columnType === 'METRIC'"
|
||||
:label="$t('common.expression')">
|
||||
<Select v-model="formState.expression">
|
||||
@ -34,6 +34,10 @@
|
||||
<Radio label="DESC">{{ $t('dataset.columnOrderDesc') }}</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
<FormItem v-if="columnType === 'DIMENSION'"
|
||||
:label="$t('dataset.customFunction')">
|
||||
<Input v-model="formState.function"/>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
@ -91,7 +95,8 @@ export default defineComponent({
|
||||
type: null,
|
||||
alias: null,
|
||||
expression: null,
|
||||
order: null
|
||||
order: null,
|
||||
function: null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user