Skip to content

Commit 9fee2bc

Browse files
yangzhgHappenLee
authored andcommitted
Support plan vectorized functiuon in FE (apache#24)
* implememt vectorized avg in fe * implememt vectorized avg sum count min max in fe * implememt vectorized avg sum count min max in fe * implememt vectorized avg sum count min max in fe
1 parent d16e883 commit 9fee2bc

6 files changed

Lines changed: 256 additions & 36 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.doris.common.Config;
2828
import org.apache.doris.common.TreeNode;
2929
import org.apache.doris.common.io.Writable;
30+
import org.apache.doris.qe.ConnectContext;
3031
import org.apache.doris.thrift.TExpr;
3132
import org.apache.doris.thrift.TExprNode;
3233
import org.apache.doris.thrift.TExprOpcode;
@@ -1559,7 +1560,8 @@ protected Function getBuiltinFunction(
15591560
Analyzer analyzer, String name, Type[] argTypes, Function.CompareMode mode)
15601561
throws AnalysisException {
15611562
FunctionName fnName = new FunctionName(name);
1562-
Function searchDesc = new Function(fnName, argTypes, Type.INVALID, false);
1563+
Function searchDesc = new Function(fnName, argTypes, Type.INVALID, false,
1564+
ConnectContext.get().getSessionVariable().enableVectorizedEngine());
15631565
Function f = Catalog.getCurrentCatalog().getFunction(searchDesc, mode);
15641566
if (f != null && fnName.getFunction().equalsIgnoreCase("rand")) {
15651567
if (this.children.size() == 1

‎fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateFunction.java‎

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* TODO: Create separate AnalyticFunction class
4747
*/
4848
public class AggregateFunction extends Function {
49-
49+
5050
private static final Logger LOG = LogManager.getLogger(AggregateFunction.class);
5151
// Set if different from retType_, null otherwise.
5252
private Type intermediateType;
@@ -91,16 +91,30 @@ protected AggregateFunction() {
9191
}
9292

9393
public AggregateFunction(FunctionName fnName, ArrayList<Type> argTypes, Type retType,
94-
boolean hasVarArgs) {
95-
super(fnName, argTypes, retType, hasVarArgs);
94+
boolean hasVarArgs) {
95+
this(fnName, argTypes, retType, hasVarArgs, false);
96+
}
97+
98+
public AggregateFunction(FunctionName fnName, ArrayList<Type> argTypes, Type retType,
99+
boolean hasVarArgs, boolean vectorized) {
100+
super(fnName, argTypes, retType, hasVarArgs, vectorized);
101+
}
102+
103+
public AggregateFunction(FunctionName fnName, List<Type> argTypes,
104+
Type retType, Type intermediateType,
105+
HdfsURI location, String updateFnSymbol, String initFnSymbol,
106+
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
107+
String removeFnSymbol, String finalizeFnSymbol) {
108+
this(fnName, argTypes, retType, intermediateType, location, updateFnSymbol, initFnSymbol, serializeFnSymbol,
109+
mergeFnSymbol, getValueFnSymbol, removeFnSymbol, finalizeFnSymbol, false);
96110
}
97111

98112
public AggregateFunction(FunctionName fnName, List<Type> argTypes,
99-
Type retType, Type intermediateType,
100-
HdfsURI location, String updateFnSymbol, String initFnSymbol,
101-
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
102-
String removeFnSymbol, String finalizeFnSymbol) {
103-
super(fnName, argTypes, retType, false);
113+
Type retType, Type intermediateType,
114+
HdfsURI location, String updateFnSymbol, String initFnSymbol,
115+
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
116+
String removeFnSymbol, String finalizeFnSymbol, boolean vectorized) {
117+
super(fnName, argTypes, retType, false, vectorized);
104118
setLocation(location);
105119
this.intermediateType = (intermediateType.equals(retType)) ? null : intermediateType;
106120
this.updateFnSymbol = updateFnSymbol;
@@ -121,7 +135,16 @@ public AggregateFunction(FunctionName fnName, List<Type> argTypes,
121135
HdfsURI location, String updateFnSymbol, String initFnSymbol,
122136
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
123137
String removeFnSymbol, String finalizeFnSymbol) {
124-
super(fnName, argTypes, retType, hasVarArgs);
138+
this(fnName, argTypes, retType, intermediateType, location, updateFnSymbol, initFnSymbol, serializeFnSymbol,
139+
mergeFnSymbol, getValueFnSymbol, removeFnSymbol, finalizeFnSymbol, false);
140+
}
141+
142+
public AggregateFunction(FunctionName fnName, List<Type> argTypes,
143+
Type retType, Type intermediateType, boolean hasVarArgs,
144+
HdfsURI location, String updateFnSymbol, String initFnSymbol,
145+
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
146+
String removeFnSymbol, String finalizeFnSymbol, boolean vectorized) {
147+
super(fnName, argTypes, retType, hasVarArgs, vectorized);
125148
setLocation(location);
126149
this.intermediateType = (intermediateType.equals(retType)) ? null : intermediateType;
127150
this.updateFnSymbol = updateFnSymbol;
@@ -136,27 +159,47 @@ public AggregateFunction(FunctionName fnName, List<Type> argTypes,
136159
isAggregateFn = true;
137160
returnsNonNullOnEmpty = false;
138161
}
139-
140162
public static AggregateFunction createBuiltin(String name,
141-
List<Type> argTypes, Type retType, Type intermediateType,
142-
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
143-
String serializeFnSymbol, String finalizeFnSymbol, boolean ignoresDistinct,
144-
boolean isAnalyticFn, boolean returnsNonNullOnEmpty) {
163+
List<Type> argTypes, Type retType, Type intermediateType,
164+
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
165+
String serializeFnSymbol, String finalizeFnSymbol, boolean ignoresDistinct,
166+
boolean isAnalyticFn, boolean returnsNonNullOnEmpty) {
167+
return createBuiltin(name, argTypes, retType, intermediateType,
168+
initFnSymbol, updateFnSymbol, mergeFnSymbol,
169+
serializeFnSymbol, finalizeFnSymbol, ignoresDistinct, isAnalyticFn, returnsNonNullOnEmpty, false);
170+
}
171+
public static AggregateFunction createBuiltin(String name,
172+
List<Type> argTypes, Type retType, Type intermediateType,
173+
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
174+
String serializeFnSymbol, String finalizeFnSymbol, boolean ignoresDistinct,
175+
boolean isAnalyticFn, boolean returnsNonNullOnEmpty, boolean vectorized) {
145176
return createBuiltin(name, argTypes, retType, intermediateType, initFnSymbol,
146-
updateFnSymbol, mergeFnSymbol, serializeFnSymbol, null, null, finalizeFnSymbol,
147-
ignoresDistinct, isAnalyticFn, returnsNonNullOnEmpty);
177+
updateFnSymbol, mergeFnSymbol, serializeFnSymbol, null, null, finalizeFnSymbol,
178+
ignoresDistinct, isAnalyticFn, returnsNonNullOnEmpty, vectorized);
148179
}
149180

150181
public static AggregateFunction createBuiltin(String name,
151-
List<Type> argTypes, Type retType, Type intermediateType,
152-
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
153-
String serializeFnSymbol, String getValueFnSymbol, String removeFnSymbol,
154-
String finalizeFnSymbol, boolean ignoresDistinct, boolean isAnalyticFn,
155-
boolean returnsNonNullOnEmpty) {
182+
List<Type> argTypes, Type retType, Type intermediateType,
183+
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
184+
String serializeFnSymbol, String getValueFnSymbol, String removeFnSymbol,
185+
String finalizeFnSymbol, boolean ignoresDistinct, boolean isAnalyticFn,
186+
boolean returnsNonNullOnEmpty) {
187+
return createBuiltin(name, argTypes, retType, intermediateType,
188+
initFnSymbol, updateFnSymbol, mergeFnSymbol,
189+
serializeFnSymbol, getValueFnSymbol, removeFnSymbol,
190+
finalizeFnSymbol, ignoresDistinct, isAnalyticFn, returnsNonNullOnEmpty, false);
191+
}
192+
193+
public static AggregateFunction createBuiltin(String name,
194+
List<Type> argTypes, Type retType, Type intermediateType,
195+
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
196+
String serializeFnSymbol, String getValueFnSymbol, String removeFnSymbol,
197+
String finalizeFnSymbol, boolean ignoresDistinct, boolean isAnalyticFn,
198+
boolean returnsNonNullOnEmpty, boolean vectorized) {
156199
return createBuiltin(name, argTypes, retType, intermediateType, false,
157200
initFnSymbol, updateFnSymbol, mergeFnSymbol,
158201
serializeFnSymbol, getValueFnSymbol, removeFnSymbol,
159-
finalizeFnSymbol, ignoresDistinct, isAnalyticFn,returnsNonNullOnEmpty);
202+
finalizeFnSymbol, ignoresDistinct, isAnalyticFn, returnsNonNullOnEmpty, vectorized);
160203
}
161204

162205
public static AggregateFunction createBuiltin(String name,
@@ -165,10 +208,21 @@ public static AggregateFunction createBuiltin(String name,
165208
String serializeFnSymbol, String getValueFnSymbol, String removeFnSymbol,
166209
String finalizeFnSymbol, boolean ignoresDistinct, boolean isAnalyticFn,
167210
boolean returnsNonNullOnEmpty) {
211+
return createBuiltin(name, argTypes, retType, intermediateType, hasVarArgs, initFnSymbol, updateFnSymbol,
212+
mergeFnSymbol, serializeFnSymbol, getValueFnSymbol, removeFnSymbol, finalizeFnSymbol, ignoresDistinct,
213+
isAnalyticFn, returnsNonNullOnEmpty, false);
214+
}
215+
216+
public static AggregateFunction createBuiltin(String name,
217+
List<Type> argTypes, Type retType, Type intermediateType, boolean hasVarArgs,
218+
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
219+
String serializeFnSymbol, String getValueFnSymbol, String removeFnSymbol,
220+
String finalizeFnSymbol, boolean ignoresDistinct, boolean isAnalyticFn,
221+
boolean returnsNonNullOnEmpty, boolean vectorized) {
168222
AggregateFunction fn = new AggregateFunction(new FunctionName(name),
169223
argTypes, retType, intermediateType, hasVarArgs, null, updateFnSymbol, initFnSymbol,
170224
serializeFnSymbol, mergeFnSymbol, getValueFnSymbol, removeFnSymbol,
171-
finalizeFnSymbol);
225+
finalizeFnSymbol, vectorized);
172226
fn.setBinaryType(TFunctionBinaryType.BUILTIN);
173227
fn.ignoresDistinct = ignoresDistinct;
174228
fn.isAnalyticFn = isAnalyticFn;

‎fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.doris.analysis.FunctionName;
2323
import org.apache.doris.analysis.HdfsURI;
24+
import org.apache.doris.common.FeMetaVersion;
2425
import org.apache.doris.common.io.Text;
2526
import org.apache.doris.common.io.Writable;
2627
import org.apache.doris.thrift.TFunction;
@@ -104,6 +105,8 @@ public enum CompareMode {
104105
private HdfsURI location;
105106
private TFunctionBinaryType binaryType;
106107

108+
private boolean vectorized;
109+
107110
// library's checksum to make sure all backends use one library to serve user's request
108111
protected String checksum = "";
109112

@@ -115,11 +118,22 @@ public Function(FunctionName name, Type[] argTypes, Type retType, boolean varArg
115118
this(0, name, argTypes, retType, varArgs);
116119
}
117120

121+
public Function(FunctionName name, Type[] argTypes, Type retType, boolean varArgs, boolean vectorized) {
122+
this(0, name, argTypes, retType, varArgs, vectorized);
123+
}
118124
public Function(FunctionName name, List<Type> args, Type retType, boolean varArgs) {
119125
this(0, name, args, retType, varArgs);
120126
}
121127

128+
public Function(FunctionName name, List<Type> args, Type retType, boolean varArgs, boolean vectorized) {
129+
this(0, name, args, retType, varArgs, vectorized);
130+
}
131+
122132
public Function(long id, FunctionName name, Type[] argTypes, Type retType, boolean hasVarArgs) {
133+
this(id, name, argTypes, retType, hasVarArgs, false);
134+
}
135+
136+
public Function(long id, FunctionName name, Type[] argTypes, Type retType, boolean hasVarArgs, boolean vectorized) {
123137
this.id = id;
124138
this.name = name;
125139
this.hasVarArgs = hasVarArgs;
@@ -129,17 +143,20 @@ public Function(long id, FunctionName name, Type[] argTypes, Type retType, boole
129143
this.argTypes = argTypes;
130144
}
131145
this.retType = retType;
146+
this.vectorized = vectorized;
132147
}
133148

134-
public Function(long id, FunctionName name, List<Type> argTypes, Type retType, boolean hasVarArgs) {
135-
this(id, name, (Type[]) null, retType, hasVarArgs);
149+
public Function(long id, FunctionName name, List<Type> argTypes, Type retType, boolean hasVarArgs, boolean vectorized) {
150+
this(id, name, (Type[]) null, retType, hasVarArgs, vectorized);
136151
if (argTypes.size() > 0) {
137152
this.argTypes = argTypes.toArray(new Type[argTypes.size()]);
138153
} else {
139154
this.argTypes = new Type[0];
140155
}
141156
}
142-
157+
public Function(long id, FunctionName name, List<Type> argTypes, Type retType, boolean hasVarArgs) {
158+
this(id, name, argTypes, retType, hasVarArgs, false);
159+
}
143160
public FunctionName getFunctionName() {
144161
return name;
145162
}
@@ -438,6 +455,7 @@ public TFunction toThrift() {
438455
if (!checksum.isEmpty()) {
439456
fn.setChecksum(checksum);
440457
}
458+
fn.setVectorized(vectorized);
441459
return fn;
442460
}
443461

@@ -615,6 +633,7 @@ protected void writeFields(DataOutput output) throws IOException {
615633
}
616634
writeOptionString(output, libUrl);
617635
writeOptionString(output, checksum);
636+
output.writeBoolean(vectorized);
618637
}
619638

620639
@Override
@@ -643,6 +662,9 @@ public void readFields(DataInput input) throws IOException {
643662
if (hasChecksum) {
644663
checksum = Text.readString(input);
645664
}
665+
if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_98) {
666+
vectorized = input.readBoolean();
667+
}
646668
}
647669

648670
public static Function read(DataInput input) throws IOException {
@@ -701,4 +723,8 @@ public List<Comparable> getInfo(boolean isVerbose) {
701723
}
702724
return row;
703725
}
726+
727+
public boolean isVectorized() {
728+
return vectorized;
729+
}
704730
}

0 commit comments

Comments
 (0)