forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature](function) support ip functions named to_ipv4[or_default, or…
…_null](string) and to_ipv6[or_default, or_null](string) (apache#29838)
- Loading branch information
Showing
13 changed files
with
720 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ore/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToIpv4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.AlwaysNotNullable; | ||
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.IPv4Type; | ||
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; | ||
|
||
/** | ||
* scalar function to_ipv4 | ||
*/ | ||
public class ToIpv4 extends ScalarFunction | ||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(VarcharType.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(StringType.INSTANCE)); | ||
|
||
public ToIpv4(Expression arg0) { | ||
super("to_ipv4", arg0); | ||
} | ||
|
||
@Override | ||
public ToIpv4 withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1, | ||
"to_ipv4 accept 1 args, but got %s (%s)", | ||
children.size(), | ||
children); | ||
return new ToIpv4(children.get(0)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitToIpv4(this, context); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ain/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToIpv4OrDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.AlwaysNotNullable; | ||
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.IPv4Type; | ||
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; | ||
|
||
/** | ||
* scalar function to_ipv4_or_default | ||
*/ | ||
public class ToIpv4OrDefault extends ScalarFunction | ||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(VarcharType.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(StringType.INSTANCE)); | ||
|
||
public ToIpv4OrDefault(Expression arg0) { | ||
super("to_ipv4_or_default", arg0); | ||
} | ||
|
||
@Override | ||
public ToIpv4OrDefault withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1, | ||
"to_ipv4_or_default accept 1 args, but got %s (%s)", | ||
children.size(), | ||
children); | ||
return new ToIpv4OrDefault(children.get(0)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitToIpv4OrDefault(this, context); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...c/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToIpv4OrNull.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.IPv4Type; | ||
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; | ||
|
||
/** | ||
* scalar function to_ipv4_or_null | ||
*/ | ||
public class ToIpv4OrNull extends ScalarFunction | ||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(VarcharType.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(IPv4Type.INSTANCE).args(StringType.INSTANCE)); | ||
|
||
public ToIpv4OrNull(Expression arg0) { | ||
super("to_ipv4_or_null", arg0); | ||
} | ||
|
||
@Override | ||
public ToIpv4OrNull withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1, | ||
"to_ipv4_or_null accept 1 args, but got %s (%s)", | ||
children.size(), | ||
children); | ||
return new ToIpv4OrNull(children.get(0)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitToIpv4OrNull(this, context); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ore/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToIpv6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.AlwaysNotNullable; | ||
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.IPv6Type; | ||
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; | ||
|
||
/** | ||
* scalar function to_ipv6 | ||
*/ | ||
public class ToIpv6 extends ScalarFunction | ||
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(IPv6Type.INSTANCE).args(VarcharType.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(IPv6Type.INSTANCE).args(StringType.INSTANCE)); | ||
|
||
public ToIpv6(Expression arg0) { | ||
super("to_ipv6", arg0); | ||
} | ||
|
||
@Override | ||
public ToIpv6 withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1, | ||
"to_ipv6 accept 1 args, but got %s (%s)", | ||
children.size(), | ||
children); | ||
return new ToIpv6(children.get(0)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitToIpv6(this, context); | ||
} | ||
} |
Oops, something went wrong.