[opt](Nereids) add graph sql function and one arg truncate (#29864)

This commit is contained in:
morrySnow
2024-01-12 14:11:47 +08:00
committed by yiguolei
parent f79ec8ea7e
commit fd4795dace
8 changed files with 97 additions and 9 deletions

View File

@ -34,7 +34,7 @@ under the License.
`VARCHAR json_insert(VARCHAR json_str, VARCHAR path, VARCHAR val[, VARCHAR path, VARCHAR val] ...)`
`json_set` function inserts data in a JSON and returns the result.Returns NULL if `json_str` or `path` is NULL. Otherwise, an error occurs if the `json_str` argument is not a valid JSON or any path argument is not a valid path expression or contains a * wildcard.
`json_insert` function inserts data in a JSON and returns the result.Returns NULL if `json_str` or `path` is NULL. Otherwise, an error occurs if the `json_str` argument is not a valid JSON or any path argument is not a valid path expression or contains a * wildcard.
The path-value pairs are evaluated left to right.

View File

@ -34,7 +34,7 @@ under the License.
`VARCHAR json_insert(VARCHAR json_str, VARCHAR path, VARCHAR val[, VARCHAR path, VARCHAR val] ...)`
`json_set` 函数在 JSON 中插入数据并返回结果。如果 `json_str``path` 为 NULL,则返回 NULL。否则,如果 `json_str` 不是有效的 JSON 或任何 `path` 参数不是有效的路径表达式或包含了 * 通配符,则会返回错误。
`json_insert` 函数在 JSON 中插入数据并返回结果。如果 `json_str``path` 为 NULL,则返回 NULL。否则,如果 `json_str` 不是有效的 JSON 或任何 `path` 参数不是有效的路径表达式或包含了 * 通配符,则会返回错误。
路径值对按从左到右的顺序进行评估。

View File

@ -34,7 +34,7 @@ under the License.
`VARCHAR json_replace(VARCHAR json_str, VARCHAR path, VARCHAR val[, VARCHAR path, VARCHAR val] ...)`
`json_set` 函数在 JSON 中更新数据并返回结果。如果 `json_str``path` 为 NULL,则返回 NULL。否则,如果 `json_str` 不是有效的 JSON 或任何 `path` 参数不是有效的路径表达式或包含了 * 通配符,则会返回错误。
`json_replace` 函数在 JSON 中更新数据并返回结果。如果 `json_str``path` 为 NULL,则返回 NULL。否则,如果 `json_str` 不是有效的 JSON 或任何 `path` 参数不是有效的路径表达式或包含了 * 通配符,则会返回错误。
路径值对按从左到右的顺序进行评估。

View File

@ -168,6 +168,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.FromMicroseco
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromMillisecond;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromSecond;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromUnixtime;
import org.apache.doris.nereids.trees.expressions.functions.scalar.G;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonBigInt;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonDouble;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonInt;
@ -572,6 +573,7 @@ public class BuiltinScalarFunctions implements FunctionHelper {
scalar(FromBase64.class, "from_base64"),
scalar(FromDays.class, "from_days"),
scalar(FromUnixtime.class, "from_unixtime"),
scalar(G.class, "g"),
scalar(GetJsonBigInt.class, "get_json_bigint"),
scalar(GetJsonDouble.class, "get_json_double"),
scalar(GetJsonInt.class, "get_json_int"),

View File

@ -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.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BooleanType;
import org.apache.doris.nereids.types.VarcharType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
* used for accept graph sql
*/
public class G extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BooleanType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT)
);
/**
* constructor with 1 argument.
*/
public G(Expression arg) {
super("g", arg);
}
/**
* withChildren.
*/
@Override
public G withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 1);
return new G(children.get(0));
}
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitG(this, context);
}
}

View File

@ -41,9 +41,17 @@ public class Truncate extends ScalarFunction
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE)
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE)
);
/**
* constructor with 1 argument.
*/
public Truncate(Expression arg0) {
super("truncate", arg0);
}
/**
* constructor with 2 arguments.
*/
@ -56,8 +64,12 @@ public class Truncate extends ScalarFunction
*/
@Override
public Truncate withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 2);
return new Truncate(children.get(0), children.get(1));
Preconditions.checkArgument(children.size() == 1 || children.size() == 2);
if (children.size() == 1) {
return new Truncate(children.get(0));
} else {
return new Truncate(children.get(0), children.get(1));
}
}
@Override

View File

@ -166,6 +166,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Fpow;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromBase64;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromDays;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromUnixtime;
import org.apache.doris.nereids.trees.expressions.functions.scalar.G;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonBigInt;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonDouble;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GetJsonInt;
@ -1051,6 +1052,10 @@ public interface ScalarFunctionVisitor<R, C> {
return visitScalarFunction(getJsonString, context);
}
default R visitG(G g, C context) {
return visitScalarFunction(g, context);
}
default R visitGreatest(Greatest greatest, C context) {
return visitScalarFunction(greatest, context);
}

View File

@ -1791,9 +1791,9 @@ visible_functions = {
[['json_unquote'], 'VARCHAR', ['VARCHAR'], 'ALWAYS_NULLABLE'],
[['json_extract'], 'VARCHAR', ['VARCHAR', 'VARCHAR', '...'], 'ALWAYS_NULLABLE'],
[['json_extract'], 'STRING', ['STRING', 'STRING', '...'], 'ALWAYS_NULLABLE'],
[['json_insert'], 'VARCHAR', ['VARCHAR', 'VARCHAR', '...'], ''],
[['json_replace'], 'VARCHAR', ['VARCHAR', 'VARCHAR', '...'], ''],
[['json_set'], 'VARCHAR', ['VARCHAR', 'VARCHAR', '...'], '']
[['json_insert'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'VARCHAR', '...'], ''],
[['json_replace'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'VARCHAR', '...'], ''],
[['json_set'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'VARCHAR', '...'], '']
],