Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
liugddx committed Feb 27, 2024
1 parent 0cd0a94 commit 0035c8d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
import org.apache.doris.nereids.trees.expressions.functions.scalar.Quarter;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Radians;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Random;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RandomBytes;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpExtract;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpExtractAll;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpReplace;
Expand Down Expand Up @@ -796,6 +797,7 @@ public class BuiltinScalarFunctions implements FunctionHelper {
scalar(SecondTimestamp.class, "second_timestamp"),
scalar(MilliSecondTimestamp.class, "millisecond_timestamp"),
scalar(MicroSecondTimestamp.class, "microsecond_timestamp"),
scalar(RandomBytes.class, "random_bytes"),
scalar(Sha1.class, "sha1", "sha"),
scalar(Sha2.class, "sha2"),
scalar(Sign.class, "sign"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.VarcharType;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import java.util.List;

/**
* ScalarFunction 'random_bytes'. This class is generated by GenerateFunction.
*/
public class RandomBytes extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable {

public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(SmallIntType.INSTANCE),
FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)).args(SmallIntType.INSTANCE)
);

/**
* constructor with 1 argument.
*/
public RandomBytes(Expression arg0) {
super("random_bytes", arg0);
}


/**
* withChildren.
*/
@Override
public RandomBytes withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 1);
return new RandomBytes(children.get(0));
}

@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitRandomBytes(this, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
import org.apache.doris.nereids.trees.expressions.functions.scalar.Quarter;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Radians;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Random;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RandomBytes;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpExtract;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpExtractAll;
import org.apache.doris.nereids.trees.expressions.functions.scalar.RegexpReplace;
Expand Down Expand Up @@ -1592,6 +1593,10 @@ default R visitUrlDecode(UrlDecode urlDecode, C context) {
return visitScalarFunction(urlDecode, context);
}

default R visitRandomBytes(RandomBytes randomBytes, C context) {
return visitScalarFunction(randomBytes, context);
}

default R visitPassword(Password password, C context) {
return visitScalarFunction(password, context);
}
Expand Down
4 changes: 3 additions & 1 deletion gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@
[['substring_index'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'INT'], 'DEPEND_ON_ARGUMENT'],
[['extract_url_parameter'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], ''],
[['url_decode'], 'VARCHAR', ['VARCHAR'], ''],
[['random_bytes'], 'ARRAY_VARCHAR', ['SMALLINT'], ''],

[['sub_replace'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'INT'], 'ALWAYS_NULLABLE'],
[['sub_replace'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'INT', 'INT'], 'ALWAYS_NULLABLE'],
Expand Down Expand Up @@ -1666,7 +1667,8 @@
[['money_format'], 'STRING', ['DECIMAL128'], ''],
[['split_part'], 'STRING', ['STRING', 'STRING', 'INT'], 'ALWAYS_NULLABLE'],
[['substring_index'], 'STRING', ['STRING', 'STRING', 'INT'], 'DEPEND_ON_ARGUMENT'],
[['url_decode'], 'STRING', ['STRING'], '']
[['url_decode'], 'STRING', ['STRING'], ''],
[['random_bytes'], 'ARRAY_STRING', ['SMALLINT'], '']
],


Expand Down

0 comments on commit 0035c8d

Please sign in to comment.