@@ -67,7 +67,7 @@ public FunctionConverter(
67
67
signatures .addAll (additionalSignatures );
68
68
signatures .addAll (getSigs ());
69
69
this .typeFactory = typeFactory ;
70
- this .substraitFuncKeyToSqlOperatorMap = ArrayListMultimap .< String , SqlOperator > create ();
70
+ this .substraitFuncKeyToSqlOperatorMap = ArrayListMultimap .create ();
71
71
72
72
var alm = ArrayListMultimap .<String , F >create ();
73
73
for (var f : functions ) {
@@ -78,22 +78,19 @@ public FunctionConverter(
78
78
signatures .stream ()
79
79
.collect (
80
80
Multimaps .toMultimap (
81
- FunctionMappings .Sig ::name , f -> f , () -> ArrayListMultimap . create () ));
81
+ FunctionMappings .Sig ::name , Function . identity (), ArrayListMultimap :: create ));
82
82
var matcherMap = new IdentityHashMap <SqlOperator , FunctionFinder >();
83
83
for (String key : alm .keySet ()) {
84
84
var sigs = calciteOperators .get (key );
85
- if (sigs == null ) {
86
- logger .atInfo ().log ("Dropping function due to no binding: {}" , key );
87
- continue ;
85
+ if (sigs .isEmpty ()) {
86
+ logger .atInfo ().log ("No binding for function: {}" , key );
88
87
}
89
88
90
89
for (var sig : sigs ) {
91
90
var implList = alm .get (key );
92
- if (implList == null || implList .isEmpty ()) {
93
- continue ;
91
+ if (! implList .isEmpty ()) {
92
+ matcherMap . put ( sig . operator (), new FunctionFinder ( key , sig . operator (), implList )) ;
94
93
}
95
-
96
- matcherMap .put (sig .operator (), new FunctionFinder (key , sig .operator (), implList ));
97
94
}
98
95
}
99
96
@@ -110,14 +107,16 @@ public FunctionConverter(
110
107
111
108
public Optional <SqlOperator > getSqlOperatorFromSubstraitFunc (String key , Type outputType ) {
112
109
var resolver = getTypeBasedResolver ();
113
- if (!substraitFuncKeyToSqlOperatorMap .containsKey (key )) {
110
+ var operators = substraitFuncKeyToSqlOperatorMap .get (key );
111
+ if (operators .isEmpty ()) {
114
112
return Optional .empty ();
115
113
}
116
- var operators = substraitFuncKeyToSqlOperatorMap . get ( key );
114
+
117
115
// only one SqlOperator is possible
118
116
if (operators .size () == 1 ) {
119
117
return Optional .of (operators .iterator ().next ());
120
118
}
119
+
121
120
// at least 2 operators. Use output type to resolve SqlOperator.
122
121
String outputTypeStr = outputType .accept (ToTypeString .INSTANCE );
123
122
var resolvedOperators =
@@ -146,15 +145,15 @@ private Map<SqlOperator, FunctionMappings.TypeBasedResolver> getTypeBasedResolve
146
145
protected abstract ImmutableList <FunctionMappings .Sig > getSigs ();
147
146
148
147
protected class FunctionFinder {
149
- private final String name ;
148
+ private final String substraitName ;
150
149
private final SqlOperator operator ;
151
150
private final List <F > functions ;
152
151
private final Map <String , F > directMap ;
153
152
private final Optional <SingularArgumentMatcher <F >> singularInputType ;
154
153
private final Util .IntRange argRange ;
155
154
156
- public FunctionFinder (String name , SqlOperator operator , List <F > functions ) {
157
- this .name = name ;
155
+ public FunctionFinder (String substraitName , SqlOperator operator , List <F > functions ) {
156
+ this .substraitName = substraitName ;
158
157
this .operator = operator ;
159
158
this .functions = functions ;
160
159
this .argRange =
@@ -167,7 +166,7 @@ public FunctionFinder(String name, SqlOperator operator, List<F> functions) {
167
166
String key = func .key ();
168
167
directMap .put (key , func );
169
168
if (func .requiredArguments ().size () != func .args ().size ()) {
170
- directMap .put (F .constructKey (name , func .requiredArguments ()), func );
169
+ directMap .put (F .constructKey (substraitName , func .requiredArguments ()), func );
171
170
}
172
171
}
173
172
this .directMap = directMap .build ();
@@ -357,7 +356,7 @@ public Optional<T> attemptMatch(C call, Function<RexNode, Expression> topLevelCo
357
356
358
357
Optional <String > directMatchKey =
359
358
possibleKeys
360
- .map (argList -> name + ":" + argList )
359
+ .map (argList -> substraitName + ":" + argList )
361
360
.filter (directMap ::containsKey )
362
361
.findFirst ();
363
362
@@ -438,8 +437,8 @@ private Optional<T> matchCoerced(C call, Type outputType, List<Expression> expre
438
437
return Optional .of (generateBinding (call , matchFunction .get (), coercedArgs , outputType ));
439
438
}
440
439
441
- protected String getName () {
442
- return name ;
440
+ protected String getSubstraitName () {
441
+ return substraitName ;
443
442
}
444
443
445
444
public SqlOperator getOperator () {
0 commit comments