This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
[NSE-926] Support a UDF: URLDecoder #925
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a3d777
Initial commit
PHILO-HE 90bfa7a
Fix bugs
PHILO-HE 48a0d5e
Let supportColumnarCodegen return false
PHILO-HE fa7a444
Align the UDF name with the real
PHILO-HE 72a5fe8
Add scala udf support and a unit test
PHILO-HE 888a30a
Change arrow branch for test [will revert at last]
PHILO-HE 1865752
Revert "Change arrow branch for test [will revert at last]"
PHILO-HE d91b46d
Consider None in getting udfName
PHILO-HE fa7c51e
Ignore case in matching UDF name
PHILO-HE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
116 changes: 116 additions & 0 deletions
116
native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarUDF.scala
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,116 @@ | ||
/* | ||
* 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 com.intel.oap.expression | ||
|
||
import com.google.common.collect.Lists | ||
import org.apache.arrow.gandiva.expression.{TreeBuilder, TreeNode} | ||
import org.apache.arrow.vector.types.pojo.ArrowType | ||
|
||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.expressions._ | ||
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode} | ||
import org.apache.spark.sql.types.DataType | ||
import org.apache.spark.sql.types.StringType | ||
|
||
|
||
case class ColumnarURLDecoder(input: Expression) extends Expression with ColumnarExpression { | ||
def nullable: Boolean = { | ||
true | ||
} | ||
|
||
def children: Seq[Expression] = { | ||
Seq(input) | ||
} | ||
|
||
def dataType: DataType = { | ||
StringType | ||
} | ||
|
||
def eval(input: InternalRow): Any = { | ||
throw new UnsupportedOperationException("Should not trigger eval!") | ||
} | ||
|
||
def child: Expression = { | ||
input | ||
} | ||
|
||
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
throw new UnsupportedOperationException("Should not trigger code gen!") | ||
} | ||
|
||
protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]): ColumnarURLDecoder = { | ||
copy(input = newChildren.head) | ||
} | ||
|
||
buildCheck | ||
|
||
def buildCheck: Unit = { | ||
val supportedTypes = List(StringType) | ||
if (!supportedTypes.contains(input.dataType)) { | ||
throw new UnsupportedOperationException("Only StringType input is supported!") | ||
} | ||
} | ||
|
||
override def supportColumnarCodegen(args: java.lang.Object): Boolean = { | ||
false | ||
} | ||
|
||
override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { | ||
val (inputNode, _): (TreeNode, ArrowType) = | ||
input.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) | ||
val resultType = new ArrowType.Utf8() | ||
val funcNode = | ||
TreeBuilder.makeFunction( | ||
"url_decoder", | ||
Lists.newArrayList(inputNode), | ||
resultType) | ||
(funcNode, resultType) | ||
} | ||
} | ||
|
||
object ColumnarUDF { | ||
// Keep the supported UDF name. The name is specified in registering the | ||
// row based function in spark, e.g., | ||
// CREATE TEMPORARY FUNCTION UrlDecoder AS 'com.intel.test.URLDecoderNew'; | ||
val supportList = {"UrlDecoder"} | ||
|
||
def isSupportedUDF(name: String): Boolean = { | ||
if (name == null) { | ||
return false; | ||
} | ||
return supportList.contains(name) | ||
} | ||
|
||
def create(children: Seq[Expression], original: Expression): Expression = { | ||
original.prettyName match { | ||
// Hive UDF. | ||
case "UrlDecoder" => | ||
ColumnarURLDecoder(children.head) | ||
// Scala UDF. | ||
case "scalaudf" => | ||
original.asInstanceOf[ScalaUDF].udfName.get match { | ||
case "UrlDecoder" => | ||
ColumnarURLDecoder(children.head) | ||
case other => | ||
throw new UnsupportedOperationException(s"not currently supported: $other.") | ||
} | ||
case other => | ||
throw new UnsupportedOperationException(s"not currently supported: $other.") | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean the UDF name is case sensitive? e.g., urlDecoder and UrlDecoder are different UDF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ignore case in the latest commit which has been validated by some simple tests.