浏览代码

ESQL: Remove the possibility of CartesianPoint or GeoPoint literal to a long (#104197)

Ignacio Vera 1 年之前
父节点
当前提交
f64147f6c1

+ 0 - 2
docs/reference/esql/functions/types/to_long.asciidoc

@@ -2,10 +2,8 @@
 |===
 v | result
 boolean | long
-cartesian_point | long
 datetime | long
 double | long
-geo_point | long
 integer | long
 keyword | long
 long | long

+ 2 - 2
x-pack/plugin/esql/qa/testFixtures/src/main/resources/show.csv-spec

@@ -84,7 +84,7 @@ to_geopoint              |"geo_point to_geopoint(v:geo_point|keyword|text)"
 to_int                   |"integer to_int(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"                  |v   |"boolean|date|keyword|text|double|long|unsigned_long|integer"                                              |                                                    |integer                          | "Converts an input value to an integer value."                                                                                      |false                       |false           | false
 to_integer               |"integer to_integer(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"              |v   |"boolean|date|keyword|text|double|long|unsigned_long|integer"                                              |                                                    |integer                          | "Converts an input value to an integer value."                                                                                      |false                       |false           | false
 to_ip                    |"ip to_ip(v:ip|keyword|text)"                                                                    |v   |"ip|keyword|text"                                                                                          |                                                    |ip                               | "Converts an input string to an IP value."                                                                                      |false                       |false           | false
-to_long                  |"long to_long(v:boolean|date|keyword|text|double|long|unsigned_long|integer|geo_point|cartesian_point)"                               |v                         |"boolean|date|keyword|text|double|long|unsigned_long|integer|geo_point|cartesian_point"                     |                                                    |long                             | "Converts an input value to a long value."                                                                                      |false                       |false | false
+to_long                  |"long to_long(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"                    |v   |"boolean|date|keyword|text|double|long|unsigned_long|integer"                                              |                                                    |long                             | "Converts an input value to a long value."                                                                                      |false                       |false | false
 to_radians               |"double to_radians(v:double|integer|long|unsigned_long)"                                         |v   |"double|integer|long|unsigned_long"                                                                        |                                                    |double                           | "Converts a number in degrees to radians."                                                                                      |false                       |false | false
 to_str                   |"keyword to_str(v:boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version)"                  |v                         |"boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version"          |                                                    |keyword                          | "Converts a field into a string."                                                                                      |false                       |false | false
 to_string                |"keyword to_string(v:boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version)"               |v                         |"boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version"          |                                                    |keyword                          | "Converts a field into a string."                                                                                      |false                       |false | false
@@ -175,7 +175,7 @@ double tau()
 "integer to_int(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"
 "integer to_integer(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"
 "ip to_ip(v:ip|keyword|text)"
-"long to_long(v:boolean|date|keyword|text|double|long|unsigned_long|integer|geo_point|cartesian_point)"
+"long to_long(v:boolean|date|keyword|text|double|long|unsigned_long|integer)"
 "double to_radians(v:double|integer|long|unsigned_long)"
 "keyword to_str(v:boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version)"
 "keyword to_string(v:boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version)"

+ 0 - 111
x-pack/plugin/esql/src/main/java/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLongFromCartesianPointEvaluator.java

@@ -1,111 +0,0 @@
-// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
-// or more contributor license agreements. Licensed under the Elastic License
-// 2.0; you may not use this file except in compliance with the Elastic License
-// 2.0.
-package org.elasticsearch.xpack.esql.expression.function.scalar.convert;
-
-import java.lang.Override;
-import java.lang.String;
-import org.apache.lucene.util.BytesRef;
-import org.elasticsearch.compute.data.Block;
-import org.elasticsearch.compute.data.BytesRefBlock;
-import org.elasticsearch.compute.data.BytesRefVector;
-import org.elasticsearch.compute.data.LongBlock;
-import org.elasticsearch.compute.data.Vector;
-import org.elasticsearch.compute.operator.DriverContext;
-import org.elasticsearch.compute.operator.EvalOperator;
-import org.elasticsearch.xpack.ql.tree.Source;
-
-/**
- * {@link EvalOperator.ExpressionEvaluator} implementation for {@link ToLong}.
- * This class is generated. Do not edit it.
- */
-public final class ToLongFromCartesianPointEvaluator extends AbstractConvertFunction.AbstractEvaluator {
-  public ToLongFromCartesianPointEvaluator(EvalOperator.ExpressionEvaluator field, Source source,
-      DriverContext driverContext) {
-    super(driverContext, field, source);
-  }
-
-  @Override
-  public String name() {
-    return "ToLongFromCartesianPoint";
-  }
-
-  @Override
-  public Block evalVector(Vector v) {
-    BytesRefVector vector = (BytesRefVector) v;
-    int positionCount = v.getPositionCount();
-    BytesRef scratchPad = new BytesRef();
-    if (vector.isConstant()) {
-      return driverContext.blockFactory().newConstantLongBlockWith(evalValue(vector, 0, scratchPad), positionCount);
-    }
-    try (LongBlock.Builder builder = driverContext.blockFactory().newLongBlockBuilder(positionCount)) {
-      for (int p = 0; p < positionCount; p++) {
-        builder.appendLong(evalValue(vector, p, scratchPad));
-      }
-      return builder.build();
-    }
-  }
-
-  private static long evalValue(BytesRefVector container, int index, BytesRef scratchPad) {
-    BytesRef value = container.getBytesRef(index, scratchPad);
-    return ToLong.fromCartesianPoint(value);
-  }
-
-  @Override
-  public Block evalBlock(Block b) {
-    BytesRefBlock block = (BytesRefBlock) b;
-    int positionCount = block.getPositionCount();
-    try (LongBlock.Builder builder = driverContext.blockFactory().newLongBlockBuilder(positionCount)) {
-      BytesRef scratchPad = new BytesRef();
-      for (int p = 0; p < positionCount; p++) {
-        int valueCount = block.getValueCount(p);
-        int start = block.getFirstValueIndex(p);
-        int end = start + valueCount;
-        boolean positionOpened = false;
-        boolean valuesAppended = false;
-        for (int i = start; i < end; i++) {
-          long value = evalValue(block, i, scratchPad);
-          if (positionOpened == false && valueCount > 1) {
-            builder.beginPositionEntry();
-            positionOpened = true;
-          }
-          builder.appendLong(value);
-          valuesAppended = true;
-        }
-        if (valuesAppended == false) {
-          builder.appendNull();
-        } else if (positionOpened) {
-          builder.endPositionEntry();
-        }
-      }
-      return builder.build();
-    }
-  }
-
-  private static long evalValue(BytesRefBlock container, int index, BytesRef scratchPad) {
-    BytesRef value = container.getBytesRef(index, scratchPad);
-    return ToLong.fromCartesianPoint(value);
-  }
-
-  public static class Factory implements EvalOperator.ExpressionEvaluator.Factory {
-    private final Source source;
-
-    private final EvalOperator.ExpressionEvaluator.Factory field;
-
-    public Factory(EvalOperator.ExpressionEvaluator.Factory field, Source source) {
-      this.field = field;
-      this.source = source;
-    }
-
-    @Override
-    public ToLongFromCartesianPointEvaluator get(DriverContext context) {
-      return new ToLongFromCartesianPointEvaluator(field.get(context), source, context);
-    }
-
-    @Override
-    public String toString() {
-      return "ToLongFromCartesianPointEvaluator[field=" + field + "]";
-    }
-  }
-}

+ 0 - 111
x-pack/plugin/esql/src/main/java/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLongFromGeoPointEvaluator.java

@@ -1,111 +0,0 @@
-// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
-// or more contributor license agreements. Licensed under the Elastic License
-// 2.0; you may not use this file except in compliance with the Elastic License
-// 2.0.
-package org.elasticsearch.xpack.esql.expression.function.scalar.convert;
-
-import java.lang.Override;
-import java.lang.String;
-import org.apache.lucene.util.BytesRef;
-import org.elasticsearch.compute.data.Block;
-import org.elasticsearch.compute.data.BytesRefBlock;
-import org.elasticsearch.compute.data.BytesRefVector;
-import org.elasticsearch.compute.data.LongBlock;
-import org.elasticsearch.compute.data.Vector;
-import org.elasticsearch.compute.operator.DriverContext;
-import org.elasticsearch.compute.operator.EvalOperator;
-import org.elasticsearch.xpack.ql.tree.Source;
-
-/**
- * {@link EvalOperator.ExpressionEvaluator} implementation for {@link ToLong}.
- * This class is generated. Do not edit it.
- */
-public final class ToLongFromGeoPointEvaluator extends AbstractConvertFunction.AbstractEvaluator {
-  public ToLongFromGeoPointEvaluator(EvalOperator.ExpressionEvaluator field, Source source,
-      DriverContext driverContext) {
-    super(driverContext, field, source);
-  }
-
-  @Override
-  public String name() {
-    return "ToLongFromGeoPoint";
-  }
-
-  @Override
-  public Block evalVector(Vector v) {
-    BytesRefVector vector = (BytesRefVector) v;
-    int positionCount = v.getPositionCount();
-    BytesRef scratchPad = new BytesRef();
-    if (vector.isConstant()) {
-      return driverContext.blockFactory().newConstantLongBlockWith(evalValue(vector, 0, scratchPad), positionCount);
-    }
-    try (LongBlock.Builder builder = driverContext.blockFactory().newLongBlockBuilder(positionCount)) {
-      for (int p = 0; p < positionCount; p++) {
-        builder.appendLong(evalValue(vector, p, scratchPad));
-      }
-      return builder.build();
-    }
-  }
-
-  private static long evalValue(BytesRefVector container, int index, BytesRef scratchPad) {
-    BytesRef value = container.getBytesRef(index, scratchPad);
-    return ToLong.fromGeoPoint(value);
-  }
-
-  @Override
-  public Block evalBlock(Block b) {
-    BytesRefBlock block = (BytesRefBlock) b;
-    int positionCount = block.getPositionCount();
-    try (LongBlock.Builder builder = driverContext.blockFactory().newLongBlockBuilder(positionCount)) {
-      BytesRef scratchPad = new BytesRef();
-      for (int p = 0; p < positionCount; p++) {
-        int valueCount = block.getValueCount(p);
-        int start = block.getFirstValueIndex(p);
-        int end = start + valueCount;
-        boolean positionOpened = false;
-        boolean valuesAppended = false;
-        for (int i = start; i < end; i++) {
-          long value = evalValue(block, i, scratchPad);
-          if (positionOpened == false && valueCount > 1) {
-            builder.beginPositionEntry();
-            positionOpened = true;
-          }
-          builder.appendLong(value);
-          valuesAppended = true;
-        }
-        if (valuesAppended == false) {
-          builder.appendNull();
-        } else if (positionOpened) {
-          builder.endPositionEntry();
-        }
-      }
-      return builder.build();
-    }
-  }
-
-  private static long evalValue(BytesRefBlock container, int index, BytesRef scratchPad) {
-    BytesRef value = container.getBytesRef(index, scratchPad);
-    return ToLong.fromGeoPoint(value);
-  }
-
-  public static class Factory implements EvalOperator.ExpressionEvaluator.Factory {
-    private final Source source;
-
-    private final EvalOperator.ExpressionEvaluator.Factory field;
-
-    public Factory(EvalOperator.ExpressionEvaluator.Factory field, Source source) {
-      this.field = field;
-      this.source = source;
-    }
-
-    @Override
-    public ToLongFromGeoPointEvaluator get(DriverContext context) {
-      return new ToLongFromGeoPointEvaluator(field.get(context), source, context);
-    }
-
-    @Override
-    public String toString() {
-      return "ToLongFromGeoPointEvaluator[field=" + field + "]";
-    }
-  }
-}

+ 1 - 20
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLong.java

@@ -20,8 +20,6 @@ import org.elasticsearch.xpack.ql.type.DataType;
 import java.util.List;
 import java.util.Map;
 
-import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.CARTESIAN_POINT;
-import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.GEO_POINT;
 import static org.elasticsearch.xpack.ql.type.DataTypeConverter.safeDoubleToLong;
 import static org.elasticsearch.xpack.ql.type.DataTypeConverter.safeToLong;
 import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
@@ -33,16 +31,12 @@ import static org.elasticsearch.xpack.ql.type.DataTypes.LONG;
 import static org.elasticsearch.xpack.ql.type.DataTypes.TEXT;
 import static org.elasticsearch.xpack.ql.type.DataTypes.UNSIGNED_LONG;
 import static org.elasticsearch.xpack.ql.util.NumericUtils.unsignedLongAsNumber;
-import static org.elasticsearch.xpack.ql.util.SpatialCoordinateTypes.CARTESIAN;
-import static org.elasticsearch.xpack.ql.util.SpatialCoordinateTypes.GEO;
 
 public class ToLong extends AbstractConvertFunction {
 
     private static final Map<DataType, BuildFactory> EVALUATORS = Map.ofEntries(
         Map.entry(LONG, (fieldEval, source) -> fieldEval),
         Map.entry(DATETIME, (fieldEval, source) -> fieldEval),
-        Map.entry(GEO_POINT, ToLongFromGeoPointEvaluator.Factory::new),
-        Map.entry(CARTESIAN_POINT, ToLongFromCartesianPointEvaluator.Factory::new),
         Map.entry(BOOLEAN, ToLongFromBooleanEvaluator.Factory::new),
         Map.entry(KEYWORD, ToLongFromStringEvaluator.Factory::new),
         Map.entry(TEXT, ToLongFromStringEvaluator.Factory::new),
@@ -54,10 +48,7 @@ public class ToLong extends AbstractConvertFunction {
     @FunctionInfo(returnType = "long", description = "Converts an input value to a long value.")
     public ToLong(
         Source source,
-        @Param(
-            name = "v",
-            type = { "boolean", "date", "keyword", "text", "double", "long", "unsigned_long", "integer", "geo_point", "cartesian_point" }
-        ) Expression field
+        @Param(name = "v", type = { "boolean", "date", "keyword", "text", "double", "long", "unsigned_long", "integer" }) Expression field
     ) {
         super(source, field);
     }
@@ -115,14 +106,4 @@ public class ToLong extends AbstractConvertFunction {
     static long fromInt(int i) {
         return i;
     }
-
-    @ConvertEvaluator(extraName = "FromGeoPoint")
-    static long fromGeoPoint(BytesRef wkb) {
-        return GEO.wkbAsLong(wkb);
-    }
-
-    @ConvertEvaluator(extraName = "FromCartesianPoint")
-    static long fromCartesianPoint(BytesRef wkb) {
-        return CARTESIAN.wkbAsLong(wkb);
-    }
 }

+ 0 - 12
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLongTests.java

@@ -24,9 +24,6 @@ import java.util.List;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
-import static org.elasticsearch.xpack.ql.util.SpatialCoordinateTypes.CARTESIAN;
-import static org.elasticsearch.xpack.ql.util.SpatialCoordinateTypes.GEO;
-
 public class ToLongTests extends AbstractFunctionTestCase {
     public ToLongTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
         this.testCase = testCaseSupplier.get();
@@ -43,15 +40,6 @@ public class ToLongTests extends AbstractFunctionTestCase {
 
         TestCaseSupplier.forUnaryBoolean(suppliers, evaluatorName.apply("Boolean"), DataTypes.LONG, b -> b ? 1L : 0L, List.of());
 
-        // geo types
-        TestCaseSupplier.forUnaryGeoPoint(suppliers, evaluatorName.apply("GeoPoint"), DataTypes.LONG, GEO::wkbAsLong, List.of());
-        TestCaseSupplier.forUnaryCartesianPoint(
-            suppliers,
-            evaluatorName.apply("CartesianPoint"),
-            DataTypes.LONG,
-            CARTESIAN::wkbAsLong,
-            List.of()
-        );
         // datetimes
         TestCaseSupplier.forUnaryDatetime(suppliers, read, DataTypes.LONG, Instant::toEpochMilli, List.of());
         // random strings that don't look like a long