1616import org .apache .calcite .rel .type .RelDataType ;
1717import org .apache .calcite .rel .type .RelDataTypeFactory ;
1818import org .apache .calcite .rex .RexCall ;
19- import org .apache .calcite .sql .type .CompositeOperandTypeChecker ;
20- import org .apache .calcite .sql .type .OperandTypes ;
2119import org .apache .calcite .sql .type .SqlReturnTypeInference ;
22- import org .apache .calcite .sql .type .SqlTypeFamily ;
2320import org .apache .calcite .sql .type .SqlTypeName ;
2421import org .opensearch .geospatial .action .IpEnrichmentActionClient ;
2522import org .opensearch .sql .common .utils .StringUtils ;
23+ import org .opensearch .sql .data .model .ExprIpValue ;
2624import org .opensearch .sql .data .model .ExprStringValue ;
2725import org .opensearch .sql .data .model .ExprTupleValue ;
2826import org .opensearch .sql .data .model .ExprValue ;
27+ import org .opensearch .sql .data .type .ExprCoreType ;
2928import org .opensearch .sql .expression .function .ImplementorUDF ;
3029import org .opensearch .sql .expression .function .UDFOperandMetadata ;
3130import org .opensearch .transport .client .node .NodeClient ;
3837 * <p>Signatures:
3938 *
4039 * <ul>
41- * <li>(STRING, STRING ) -> MAP
42- * <li>(STRING, STRING , STRING) -> MAP
40+ * <li>(STRING, IP ) -> MAP
41+ * <li>(STRING, IP , STRING) -> MAP
4342 * </ul>
4443 */
4544public class GeoIpFunction extends ImplementorUDF {
@@ -59,11 +58,10 @@ public SqlReturnTypeInference getReturnTypeInference() {
5958
6059 @ Override
6160 public UDFOperandMetadata getOperandMetadata () {
62- return UDFOperandMetadata .wrap (
63- (CompositeOperandTypeChecker )
64- OperandTypes .CHARACTER_CHARACTER .or (
65- OperandTypes .family (
66- SqlTypeFamily .CHARACTER , SqlTypeFamily .CHARACTER , SqlTypeFamily .CHARACTER )));
61+ return UDFOperandMetadata .wrapUDT (
62+ List .of (
63+ List .of (ExprCoreType .STRING , ExprCoreType .IP ),
64+ List .of (ExprCoreType .STRING , ExprCoreType .IP , ExprCoreType .STRING )));
6765 }
6866
6967 public static class GeoIPImplementor implements NotNullImplementor {
@@ -87,16 +85,20 @@ public Expression implement(
8785 }
8886
8987 public static Map <String , ?> fetchIpEnrichment (
90- String dataSource , String ipAddress , NodeClient nodeClient ) {
91- return fetchIpEnrichment (dataSource , ipAddress , Collections .emptySet (), nodeClient );
88+ String dataSource , ExprIpValue ipAddress , NodeClient nodeClient ) {
89+ return fetchIpEnrichment (
90+ dataSource , ipAddress .toString (), Collections .emptySet (), nodeClient );
9291 }
9392
9493 public static Map <String , ?> fetchIpEnrichment (
95- String dataSource , String ipAddress , String commaSeparatedOptions , NodeClient nodeClient ) {
94+ String dataSource ,
95+ ExprIpValue ipAddress ,
96+ String commaSeparatedOptions ,
97+ NodeClient nodeClient ) {
9698 String unquotedOptions = StringUtils .unquoteText (commaSeparatedOptions );
9799 final Set <String > options =
98100 Arrays .stream (unquotedOptions .split ("," )).map (String ::trim ).collect (Collectors .toSet ());
99- return fetchIpEnrichment (dataSource , ipAddress , options , nodeClient );
101+ return fetchIpEnrichment (dataSource , ipAddress . toString () , options , nodeClient );
100102 }
101103
102104 private static Map <String , ?> fetchIpEnrichment (
0 commit comments