[fix](nereids)Fix dlog1, trim, extract_url_parameter and parse_url FE constant calculate bug. (#49074) (#49224)
backport: https://github.com/apache/doris/pull/49074
This commit is contained in:
@ -156,7 +156,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Degrees;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dexp;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dfloor;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.DigitalMasking;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dlog1;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dlog10;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Domain;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.DomainWithoutWww;
|
||||
@ -614,7 +613,6 @@ public class BuiltinScalarFunctions implements FunctionHelper {
|
||||
scalar(Dexp.class, "dexp"),
|
||||
scalar(Dfloor.class, "dfloor"),
|
||||
scalar(DigitalMasking.class, "digital_masking"),
|
||||
scalar(Dlog1.class, "dlog1"),
|
||||
scalar(Dlog10.class, "dlog10"),
|
||||
scalar(Domain.class, "domain"),
|
||||
scalar(DomainWithoutWww.class, "domain_without_www"),
|
||||
@ -744,7 +742,7 @@ public class BuiltinScalarFunctions implements FunctionHelper {
|
||||
scalar(Length.class, "length"),
|
||||
scalar(Crc32.class, "crc32"),
|
||||
scalar(Like.class, "like"),
|
||||
scalar(Ln.class, "ln"),
|
||||
scalar(Ln.class, "ln", "dlog1"),
|
||||
scalar(Locate.class, "locate"),
|
||||
scalar(Log.class, "log"),
|
||||
scalar(Log10.class, "log10"),
|
||||
|
||||
@ -1064,17 +1064,6 @@ public class NumericArithmetic {
|
||||
return checkOutputBoundary(new DoubleLiteral(exp));
|
||||
}
|
||||
|
||||
/**
|
||||
* dlog1
|
||||
*/
|
||||
@ExecFunction(name = "dlog1")
|
||||
public static Expression dlog1(DoubleLiteral first) {
|
||||
if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
|
||||
return new NullLiteral(DoubleType.INSTANCE);
|
||||
}
|
||||
return checkOutputBoundary(new DoubleLiteral(Math.log1p(first.getValue())));
|
||||
}
|
||||
|
||||
/**
|
||||
* dlog10
|
||||
*/
|
||||
|
||||
@ -145,13 +145,17 @@ public class StringArithmetic {
|
||||
if (left) {
|
||||
do {
|
||||
result = afterReplace;
|
||||
afterReplace = result.replaceFirst("^" + second, "");
|
||||
if (result.startsWith(second)) {
|
||||
afterReplace = result.substring(second.length());
|
||||
}
|
||||
} while (!afterReplace.equals(result));
|
||||
}
|
||||
if (right) {
|
||||
do {
|
||||
result = afterReplace;
|
||||
afterReplace = result.replaceFirst(second + "$", "");
|
||||
if (result.endsWith(second)) {
|
||||
afterReplace = result.substring(0, result.length() - second.length());
|
||||
}
|
||||
} while (!afterReplace.equals(result));
|
||||
}
|
||||
return result;
|
||||
@ -846,39 +850,71 @@ public class StringArithmetic {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (second.getValue().toUpperCase()) {
|
||||
case "PROTOCOL":
|
||||
sb.append(uri.getScheme()); // e.g., http, https
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(scheme); // e.g., http, https
|
||||
break;
|
||||
case "HOST":
|
||||
sb.append(uri.getHost()); // e.g., www.example.com
|
||||
String host = uri.getHost();
|
||||
if (host == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(host); // e.g., www.example.com
|
||||
break;
|
||||
case "PATH":
|
||||
sb.append(uri.getPath()); // e.g., /page
|
||||
String path = uri.getPath();
|
||||
if (path == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(path); // e.g., /page
|
||||
break;
|
||||
case "REF":
|
||||
try {
|
||||
sb.append(uri.toURL().getRef()); // e.g., /page
|
||||
String ref = uri.toURL().getRef();
|
||||
if (ref == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(ref); // e.g., /page
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
case "AUTHORITY":
|
||||
sb.append(uri.getAuthority()); // e.g., param1=value1¶m2=value2
|
||||
String authority = uri.getAuthority();
|
||||
if (authority == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(authority); // e.g., param1=value1¶m2=value2
|
||||
break;
|
||||
case "FILE":
|
||||
try {
|
||||
sb.append(uri.toURL().getFile()); // e.g., param1=value1¶m2=value2
|
||||
String file = uri.toURL().getFile();
|
||||
if (file == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(file); // e.g., param1=value1¶m2=value2
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
case "QUERY":
|
||||
sb.append(uri.getQuery()); // e.g., param1=value1¶m2=value2
|
||||
String query = uri.getQuery();
|
||||
if (query == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(query); // e.g., param1=value1¶m2=value2
|
||||
break;
|
||||
case "PORT":
|
||||
sb.append(uri.getPort());
|
||||
break;
|
||||
case "USERINFO":
|
||||
sb.append(uri.getUserInfo()); // e.g., user:pass
|
||||
String userInfo = uri.getUserInfo();
|
||||
if (userInfo == null) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
}
|
||||
sb.append(userInfo); // e.g., user:pass
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Valid URL parts are 'PROTOCOL', 'HOST', "
|
||||
@ -934,10 +970,15 @@ public class StringArithmetic {
|
||||
if (first.getValue() == null || first.getValue().indexOf('?') == -1) {
|
||||
return castStringLikeLiteral(first, "");
|
||||
}
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(first.getValue());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String[] urlParts = first.getValue().split("\\?", -1);
|
||||
if (urlParts.length > 1) {
|
||||
String query = urlParts[1];
|
||||
String query = uri.getQuery();
|
||||
if (query != null) {
|
||||
String[] pairs = query.split("&", -1);
|
||||
|
||||
for (String pair : pairs) {
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
// 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.UnaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DoubleType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ScalarFunction 'dlog1'. This class is generated by GenerateFunction.
|
||||
*/
|
||||
public class Dlog1 extends ScalarFunction
|
||||
implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable {
|
||||
|
||||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE)
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor with 1 argument.
|
||||
*/
|
||||
public Dlog1(Expression arg) {
|
||||
super("dlog1", arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* withChildren.
|
||||
*/
|
||||
@Override
|
||||
public Dlog1 withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 1);
|
||||
return new Dlog1(children.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return SIGNATURES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitDlog1(this, context);
|
||||
}
|
||||
}
|
||||
@ -163,7 +163,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Degrees;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dexp;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dfloor;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.DigitalMasking;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dlog1;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Dlog10;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.Domain;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.scalar.DomainWithoutWww;
|
||||
@ -1079,10 +1078,6 @@ public interface ScalarFunctionVisitor<R, C> {
|
||||
return visitScalarFunction(dfloor, context);
|
||||
}
|
||||
|
||||
default R visitDlog1(Dlog1 dlog1, C context) {
|
||||
return visitScalarFunction(dlog1, context);
|
||||
}
|
||||
|
||||
default R visitDlog10(Dlog10 dlog10, C context) {
|
||||
return visitScalarFunction(dlog10, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user