Skip to content

Commit

Permalink
feat: 优化函数转换拓展性
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Apr 26, 2024
1 parent 1c314d3 commit e03a708
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,30 @@ public Function<ReactorQLRecord, Publisher<?>> createMapper(Expression expressio
if (parameters.size() > maxParamSize || parameters.size() < minParamSize) {
throw new UnsupportedOperationException("函数[" + expression + "]参数数量错误");
}
@SuppressWarnings("all")
List<Function<ReactorQLRecord, Publisher<Object>>> mappers = (List) parameters
.stream()
.map(expr -> ValueMapFeature.createMapperNow(expr, metadata))
.collect(Collectors.toList());

List<Function<ReactorQLRecord, Publisher<Object>>> mappers = createParamMappers(metadata, parameters);
// fun(distinct col)
if (function.isDistinct()) {
return v -> Flux
.from(apply(v, mappers))
.distinct();
}

// fun(unique col)
if (function.isUnique()) {
return v -> CastUtils.uniqueFlux(Flux.from(apply(v, mappers)));
}

return v -> apply(v, mappers);
}

@SuppressWarnings("all")
protected List<Function<ReactorQLRecord, Publisher<Object>>> createParamMappers(ReactorQLMetadata metadata,
List<Expression> parameters) {
return (List) parameters
.stream()
.map(expr -> ValueMapFeature.createMapperNow(expr, metadata))
.collect(Collectors.toList());
}

public FunctionMapFeature defaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
return this;
Expand Down

0 comments on commit e03a708

Please sign in to comment.