[feature](function)Add St_Angle/St_Azimuth function (#18293)
Add St_Angle/St_azimuth function: St_Angle: Enter three point, which represent two intersecting lines. Returns the angle between these lines. Point 2 and point 1 represent the first line and point 2 and point 3 represent the second line. The angle between these lines is in radians, in the range [0, 2pi). The angle is measured clockwise from the first line to the second line. ` mysql> SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(0, 1)); +----------------------------------------------------------------------+ | st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(0.0, 1.0)) | +----------------------------------------------------------------------+ | 4.71238898038469 | +----------------------------------------------------------------------+ 1 row in set (0.04 sec) ` St_azimuth: Enter two point, and returns the azimuth of the line segment formed by points 1 and 2. The azimuth is the angle in radians measured between the line from point 1 facing true North to the line segment from point 1 to point 2. ` mysql> SELECT st_azimuth(ST_Point(0, 0),ST_Point(1, 0)); +----------------------------------------------------+ | st_azimuth(st_point(0.0, 0.0), st_point(1.0, 0.0)) | +----------------------------------------------------+ | 1.5707963267948966 | +----------------------------------------------------+ 1 row in set (0.04 sec)
This commit is contained in:
@ -267,11 +267,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitByChar;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitByString;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitPart;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Sqrt;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAngle;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAngleSphere;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAreaSquareKm;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAreaSquareMeters;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAstext;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAswkt;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAzimuth;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StCircle;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StContains;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StDistanceSphere;
|
||||
@ -598,6 +600,8 @@ public class BuiltinScalarFunctions implements FunctionHelper {
|
||||
scalar(StContains.class, "st_contains"),
|
||||
scalar(StDistanceSphere.class, "st_distance_sphere"),
|
||||
scalar(StAngleSphere.class, "st_angle_sphere"),
|
||||
scalar(StAngle.class, "st_angle"),
|
||||
scalar(StAzimuth.class, "st_azimuth"),
|
||||
scalar(StAreaSquareMeters.class, "st_area_square_meters"),
|
||||
scalar(StAreaSquareKm.class, "st_area_square_km"),
|
||||
scalar(StGeometryfromtext.class, "st_geometryfromtext"),
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions.scalar;
|
||||
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DoubleType;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ScalarFunction 'st_angle'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
|
||||
public class StAngle extends ScalarFunction
|
||||
implements TernaryExpression, ExplicitlyCastableSignature, AlwaysNullable {
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(DoubleType.INSTANCE)
|
||||
.args(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT)
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor with 3 argument.
|
||||
*/
|
||||
public StAngle(Expression arg0, Expression arg1, Expression arg2) {
|
||||
super("st_angle", arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
/**
|
||||
* withChildren.
|
||||
*/
|
||||
@Override
|
||||
public StAngle withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 3);
|
||||
return new StAngle(children.get(0), children.get(1), children.get(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return SIGNATURES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitStAngle(this, context);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions.scalar;
|
||||
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DoubleType;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ScalarFunction 'st_azimuth'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
|
||||
public class StAzimuth extends ScalarFunction
|
||||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable {
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(DoubleType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT)
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor with 2 argument.
|
||||
*/
|
||||
public StAzimuth(Expression arg0, Expression arg1) {
|
||||
super("st_azimuth", arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* withChildren.
|
||||
*/
|
||||
@Override
|
||||
public StAzimuth withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 2);
|
||||
return new StAzimuth(children.get(0), children.get(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return SIGNATURES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitStAzimuth(this, context);
|
||||
}
|
||||
}
|
||||
@ -269,11 +269,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitByChar;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitByString;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.SplitPart;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Sqrt;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAngle;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAngleSphere;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAreaSquareKm;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAreaSquareMeters;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAstext;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAswkt;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StAzimuth;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StCircle;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StContains;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.StDistanceSphere;
|
||||
@ -1373,6 +1375,14 @@ public interface ScalarFunctionVisitor<R, C> {
|
||||
return visitScalarFunction(stAngleSphere, context);
|
||||
}
|
||||
|
||||
default R visitStAngle(StAngle stAngle, C context) {
|
||||
return visitScalarFunction(stAngle, context);
|
||||
}
|
||||
|
||||
default R visitStAzimuth(StAzimuth stAzimuth, C context) {
|
||||
return visitScalarFunction(stAzimuth, context);
|
||||
}
|
||||
|
||||
default R visitStAreaSquareMeters(StAreaSquareMeters stAreaSquareMeters, C context) {
|
||||
return visitScalarFunction(stAreaSquareMeters, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user