Skip to content

[GLUTEN-1589][CH] support udf for clickhouse backend - #1596

Merged
baibaichen merged 3 commits into
apache:mainfrom
bigo-sg:gluten_1589
Jun 8, 2023
Merged

baibaichen merged 3 commits into
apache:mainfrom
bigo-sg:gluten_1589

Conversation

@taiyang-li

@taiyang-li taiyang-li commented May 9, 2023 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

(Please fill in changes proposed in this fix)

(Fixes: #1589)

除了支持udf之外,还解决了clickhouse中gtest和benchmark的编译失败问题。

@github-actions

github-actions Bot commented May 9, 2023

Copy link
Copy Markdown

#1589

@github-actions

github-actions Bot commented May 9, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li
taiyang-li marked this pull request as draft May 9, 2023 11:03
@github-actions

github-actions Bot commented May 9, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li

taiyang-li commented May 10, 2023 •

Copy link
Copy Markdown
Contributor Author

test hive udf

0: jdbc:hive2://localhost:10000/> CREATE temporary FUNCTION indigouidhash AS 'sg.bigo.hive.udf.IndigoUidHash' ;
+---------+
| Result  |
+---------+

+---------+
No rows selected (0.072 seconds)

0: jdbc:hive2://localhost:10000/> explain formatted select indigouidhash(cast(id as String)) from range(10);  

+----------------------------------------------------+
|                        plan                        |
+----------------------------------------------------+
| == Physical Plan ==
CHNativeColumnarToRow (5)
+- ^ ProjectExecTransformer (3)
   +- RowToCHNativeColumnar (2)
      +- * Range (1)


(1) Range [codegen id : 1]
Output [1]: [id#13L]
Arguments: Range (0, 10, step=1, splits=None)

(2) RowToCHNativeColumnar
Input [1]: [id#13L]

(3) ProjectExecTransformer
Input [1]: [id#13L]
Arguments: [HiveSimpleUDF#sg.bigo.hive.udf.IndigoUidHash(cast(id#13L as string)) AS indigouidhash(CAST(id AS STRING))#14]

(4) WholeStageCodegenTransformer (1)
Input [1]: [indigouidhash(CAST(id AS STRING))#14]

(5) CHNativeColumnarToRow
Input [1]: [indigouidhash(CAST(id AS STRING))#14]

 |
+----------------------------------------------------+

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li

taiyang-li commented May 10, 2023 •

Copy link
Copy Markdown
Contributor Author

test python udf:

#!/usr/bin/python3.7
import time

from pyspark import SparkConf
from pyspark.sql import SparkSession
from pyspark.sql.types import LongType

conf = SparkConf()
spark = SparkSession.builder.config(conf=conf).getOrCreate()
spark.sparkContext.setLogLevel("DEBUG")
# sc = SparkContext(conf=conf)
# spark = SparkSession.builder.master("local[1]").appName("test_udf").getOrCreate()


def my_add(x, y):
    return x + y


def print_nothing(x):
    pass


spark.udf.register("my_add", my_add, LongType())
start_time = time.time()

print(
    spark.sql(
        # "explain formatted select cast(id as String) from range(100)"
	"explain formatted select my_add(id, 1) from range(1000000)"
    ).collect()
)

end_time = time.time()
time_cost = end_time - start_time
print("Time cost: ", time_cost)
== Physical Plan ==
CHNativeColumnarToRow (6)
+- ^ ProjectExecTransformer (4)
   +- ^ EvalPythonExecTransformer (3)
      +- RowToCHNativeColumnar (2)
         +- * Range (1)


(1) Range [codegen id : 1]
Output [1]: [id#5L]
Arguments: Range (0, 1000000, step=1, splits=None)

(2) RowToCHNativeColumnar
Input [1]: [id#5L]

(3) EvalPythonExecTransformer
Input [1]: [id#5L]
Arguments: [my_add(id#5L, 1)], [pythonUDF0#8L]

(4) ProjectExecTransformer
Input [2]: [id#5L, pythonUDF0#8L]
Arguments: [pythonUDF0#8L AS my_add(id, 1)#7L]

(5) WholeStageCodegenTransformer (1)
Input [1]: [my_add(id, 1)#7L]

(6) CHNativeColumnarToRow
Input [1]: [my_add(id, 1)#7L]

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li

Copy link
Copy Markdown
Contributor Author

@philo-he @zzcclp do you have time to review this pr, thanks

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@philo-he philo-he left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some comments for common scala code part. Thanks!

Comment thread gluten-core/src/main/scala/io/glutenproject/expression/ExpressionConverter.scala Outdated
Comment thread gluten-core/src/main/scala/io/glutenproject/expression/ExpressionConverter.scala Outdated
Comment thread gluten-core/src/main/scala/io/glutenproject/expression/ExpressionConverter.scala Outdated
Comment thread gluten-core/src/main/scala/io/glutenproject/expression/PythonUDFTransformer.scala Outdated
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

2 similar comments
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

3 similar comments
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li
taiyang-li marked this pull request as ready for review May 15, 2023 08:51
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

Comment thread cpp-ch/local-engine/Functions/my_udf/myAdd.cpp Outdated
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@taiyang-li

taiyang-li commented May 25, 2023 •

Copy link
Copy Markdown
Contributor Author

@rui-mo velox failed with the same logs which appeared in other prs previously. Do you have time to take a look.

2023-05-24T12:56:32.6577333Z Failed queries (a failed query with correct row count indicates value mismatches): 
2023-05-24T12:56:32.6577605Z 
2023-05-24T12:56:32.6577957Z |       Query ID|     Was Passed|            Expected Row Count|              Actual Row Count|  Baseline Query Time (Millis)|           Query Time (Millis)|          Query Time Variation|
2023-05-24T12:56:32.6578507Z |            q95|          false|                           N/A|                           N/A|                           N/A|                           N/A|                           N/A|

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@rui-mo

rui-mo commented May 25, 2023

Copy link
Copy Markdown
Contributor

@taiyang-li Looks not relevant to this PR. Do we need to increase the memory limit? cc @zhztheplayer

2023-05-25T04:53:20.8886192Z Executing SQL query from resource path /tpcds-queries/q95.sql...
2023-05-25T04:53:27.3620707Z 23/05/25 12:53:27 ERROR TaskResources: Task 107 failed by error: 
2023-05-25T04:53:27.3622556Z org.apache.spark.SparkException: Can't acquire 67108864 bytes memory to build hash relation, got 56478455 bytes
2023-05-25T04:53:27.3624615Z 	at org.apache.spark.sql.errors.QueryExecutionErrors$.cannotAcquireMemoryToBuildLongHashedRelationError(QueryExecutionErrors.scala:795)
2023-05-25T04:53:27.3632966Z 	at org.apache.spark.sql.execution.joins.LongToUnsafeRowMap.ensureAcquireMemory(HashedRelation.scala:581)
2023-05-25T04:53:27.3649896Z 	at org.apache.spark.sql.execution.joins.LongToUnsafeRowMap.grow(HashedRelation.scala:813)
2023-05-25T04:53:27.3650603Z 	at org.apache.spark.sql.execution.joins.LongToUnsafeRowMap.append(HashedRelation.scala:761)
2023-05-25T04:53:27.3651254Z 	at org.apache.spark.sql.execution.joins.LongHashedRelation$.apply(HashedRelation.scala:1064)
2023-05-25T04:53:27.3730412Z 	at org.apache.spark.sql.execution.joins.HashedRelation$.apply(HashedRelation.scala:153)

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

2 similar comments
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@zzcclp

zzcclp commented May 31, 2023

Copy link
Copy Markdown
Contributor

please rebase

@github-actions

github-actions Bot commented Jun 6, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

2 similar comments
@github-actions

github-actions Bot commented Jun 6, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@github-actions

github-actions Bot commented Jun 6, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@baibaichen

Copy link
Copy Markdown
Contributor

LGTM

baibaichen
baibaichen previously approved these changes Jun 7, 2023
@github-actions

github-actions Bot commented Jun 7, 2023

Copy link
Copy Markdown

Run Gluten Clickhouse CI

@baibaichen
baibaichen merged commit 5e75698 into apache:main Jun 8, 2023
rui-mo added a commit to rui-mo/gazelle-jni that referenced this pull request Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CH] support pyspark/hive/scala udf for clickhouse backend

5 participants