278278import org .apache .calcite .sql .validate .SqlUserDefinedAggFunction ;
279279import org .apache .calcite .sql .validate .SqlUserDefinedFunction ;
280280import org .apache .calcite .tools .RelBuilder ;
281- import org .apache .commons .lang3 .tuple .Pair ;
282281import org .apache .logging .log4j .LogManager ;
283282import org .apache .logging .log4j .Logger ;
284283import org .opensearch .sql .calcite .CalcitePlanContext ;
@@ -357,42 +356,38 @@ default RexNode resolve(RexBuilder builder, RexNode... args) {
357356 * implementations are independent of any specific data storage, should be registered here
358357 * internally.
359358 */
360- private final ImmutableMap <BuiltinFunctionName , Pair <CalciteFuncSignature , FunctionImp >>
361- functionRegistry ;
359+ private final ImmutableMap <BuiltinFunctionName , FunctionImp > functionRegistry ;
362360
363361 /**
364362 * The external function registry. Functions whose implementations depend on a specific data
365363 * engine should be registered here. This reduces coupling between the core module and particular
366364 * storage backends.
367365 */
368- private final Map <BuiltinFunctionName , Pair <CalciteFuncSignature , FunctionImp >>
369- externalFunctionRegistry ;
366+ private final Map <BuiltinFunctionName , FunctionImp > externalFunctionRegistry ;
370367
371368 /**
372369 * The registry for built-in agg functions. Agg Functions defined by the PPL specification, whose
373370 * implementations are independent of any specific data storage, should be registered here
374371 * internally.
375372 */
376- private final ImmutableMap <BuiltinFunctionName , Pair <CalciteFuncSignature , AggHandler >>
377- aggFunctionRegistry ;
373+ private final ImmutableMap <BuiltinFunctionName , AggHandler > aggFunctionRegistry ;
378374
379375 /**
380376 * The external agg function registry. Agg Functions whose implementations depend on a specific
381377 * data engine should be registered here. This reduces coupling between the core module and
382378 * particular storage backends.
383379 */
384- private final Map <BuiltinFunctionName , Pair <CalciteFuncSignature , AggHandler >>
385- aggExternalFunctionRegistry ;
380+ private final Map <BuiltinFunctionName , AggHandler > aggExternalFunctionRegistry ;
386381
387382 private PPLFuncImpTable (Builder builder , AggBuilder aggBuilder ) {
388- final ImmutableMap .Builder <BuiltinFunctionName , Pair < CalciteFuncSignature , FunctionImp >>
389- mapBuilder = ImmutableMap .builder ();
383+ final ImmutableMap .Builder <BuiltinFunctionName , FunctionImp > mapBuilder =
384+ ImmutableMap .builder ();
390385 mapBuilder .putAll (builder .map );
391386 this .functionRegistry = ImmutableMap .copyOf (mapBuilder .build ());
392387 this .externalFunctionRegistry = new ConcurrentHashMap <>();
393388
394- final ImmutableMap .Builder <BuiltinFunctionName , Pair < CalciteFuncSignature , AggHandler >>
395- aggMapBuilder = ImmutableMap .builder ();
389+ final ImmutableMap .Builder <BuiltinFunctionName , AggHandler > aggMapBuilder =
390+ ImmutableMap .builder ();
396391 aggMapBuilder .putAll (aggBuilder .map );
397392 this .aggFunctionRegistry = ImmutableMap .copyOf (aggMapBuilder .build ());
398393 this .aggExternalFunctionRegistry = new ConcurrentHashMap <>();
@@ -405,14 +400,11 @@ private PPLFuncImpTable(Builder builder, AggBuilder aggBuilder) {
405400 * @param operator a SqlOperator representing an externally implemented function
406401 */
407402 public void registerExternalOperator (BuiltinFunctionName functionName , SqlOperator operator ) {
408- CalciteFuncSignature signature =
409- new CalciteFuncSignature (functionName .getName (), operator .getOperandTypeChecker ());
410403 if (externalFunctionRegistry .containsKey (functionName )) {
411404 logger .warn (
412405 String .format (Locale .ROOT , "Function %s is registered multiple times" , functionName ));
413406 }
414- externalFunctionRegistry .put (
415- functionName , Pair .of (signature , (builder , args ) -> builder .makeCall (operator , args )));
407+ externalFunctionRegistry .put (functionName , (builder , args ) -> builder .makeCall (operator , args ));
416408 }
417409
418410 /**
@@ -429,13 +421,11 @@ public void registerExternalAggOperator(
429421 String .format (
430422 Locale .ROOT , "Aggregate function %s is registered multiple times" , functionName ));
431423 }
432- CalciteFuncSignature signature =
433- new CalciteFuncSignature (functionName .getName (), aggFunction .getOperandTypeChecker ());
434424 AggHandler handler =
435425 (distinct , field , argList , ctx ) ->
436426 UserDefinedFunctionUtils .makeAggregateCall (
437427 aggFunction , List .of (field ), argList , ctx .relBuilder );
438- aggExternalFunctionRegistry .put (functionName , Pair . of ( signature , handler ) );
428+ aggExternalFunctionRegistry .put (functionName , handler );
439429 }
440430
441431 public RelBuilder .AggCall resolveAgg (
@@ -445,12 +435,10 @@ public RelBuilder.AggCall resolveAgg(
445435 List <RexNode > argList ,
446436 CalcitePlanContext context ) {
447437 var implementation = getImplementation (functionName );
448- var handler = implementation .getValue ();
449- return handler .apply (distinct , field , argList , context );
438+ return implementation .apply (distinct , field , argList , context );
450439 }
451440
452- private Pair <CalciteFuncSignature , AggHandler > getImplementation (
453- BuiltinFunctionName functionName ) {
441+ private AggHandler getImplementation (BuiltinFunctionName functionName ) {
454442 var implementation = aggExternalFunctionRegistry .get (functionName );
455443 if (implementation == null ) {
456444 implementation = aggFunctionRegistry .get (functionName );
@@ -474,7 +462,7 @@ public RexNode resolve(
474462 // Check the external function registry first. This allows the data-storage-dependent
475463 // function implementations to override the internal ones with the same name.
476464 // If the function is not part of the external registry, check the internal registry.
477- Pair < CalciteFuncSignature , FunctionImp > implementation =
465+ FunctionImp implementation =
478466 externalFunctionRegistry .get (functionName ) != null
479467 ? externalFunctionRegistry .get (functionName )
480468 : functionRegistry .get (functionName );
@@ -486,7 +474,7 @@ public RexNode resolve(
486474 // For example, the REDUCE function requires the second argument to be cast to the
487475 // return type of the lambda function.
488476 compulsoryCast (builder , functionName , args );
489- return implementation .getValue (). resolve (builder , args );
477+ return implementation .resolve (builder , args );
490478 }
491479
492480 /**
@@ -1092,39 +1080,33 @@ void populate() {
10921080 }
10931081
10941082 private static class Builder extends AbstractBuilder {
1095- private final Map <BuiltinFunctionName , Pair <CalciteFuncSignature , FunctionImp >> map =
1096- new HashMap <>();
1083+ private final Map <BuiltinFunctionName , FunctionImp > map = new HashMap <>();
10971084
10981085 @ Override
10991086 void register (
11001087 BuiltinFunctionName functionName ,
11011088 FunctionImp implement ,
11021089 SqlOperandTypeChecker typeChecker ) {
1103- CalciteFuncSignature signature =
1104- new CalciteFuncSignature (functionName .getName (), typeChecker );
11051090 if (map .containsKey (functionName )) {
11061091 throw new IllegalStateException (
11071092 String .format (
11081093 Locale .ROOT ,
11091094 "Each function can only be registered with one operator: %s" ,
11101095 functionName ));
11111096 }
1112- map .put (functionName , Pair . of ( signature , implement ) );
1097+ map .put (functionName , implement );
11131098 }
11141099 }
11151100
11161101 private static class AggBuilder {
11171102 private static final double MEDIAN_PERCENTILE = 50.0 ;
1118- private final Map <BuiltinFunctionName , Pair <CalciteFuncSignature , AggHandler >> map =
1119- new HashMap <>();
1103+ private final Map <BuiltinFunctionName , AggHandler > map = new HashMap <>();
11201104
11211105 void register (
11221106 BuiltinFunctionName functionName ,
11231107 AggHandler aggHandler ,
11241108 SqlOperandTypeChecker typeChecker ) {
1125- CalciteFuncSignature signature =
1126- new CalciteFuncSignature (functionName .getName (), typeChecker );
1127- map .put (functionName , Pair .of (signature , aggHandler ));
1109+ map .put (functionName , aggHandler );
11281110 }
11291111
11301112 void registerOperator (BuiltinFunctionName functionName , SqlAggFunction aggFunction ) {
0 commit comments