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-762] Add complex types support for ColumnarSortExec #763
Merged
zhouyuan
merged 10 commits into
oap-project:master
from
zhixingheyi-tian:ComplexTypesforSort
Mar 22, 2022
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba1132e
Add complex types support for ColumnarSortExec
zhixingheyi-tian 9a0ce12
Add struct/map support
zhixingheyi-tian 5f6d503
Fix clang format
zhixingheyi-tian 1261ffa
Add Key check and fix Attr parse issue
zhixingheyi-tian e5ebf15
Fix remaining UTs
zhixingheyi-tian 42e25eb
Correct typo
zhixingheyi-tian be3b9b6
Correct Typos
zhixingheyi-tian 9556361
Merge remote-tracking branch 'upstream/master' into ComplexTypesforSort
zhixingheyi-tian 0c6f9ba
Add enable/disable config in ColumnarSort
zhixingheyi-tian 6792c4f
Correct Error message
zhixingheyi-tian 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
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
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
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
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
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
198 changes: 198 additions & 0 deletions
198
native-sql-engine/core/src/test/scala/com/intel/oap/execution/PayloadSuite.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,198 @@ | ||
/* | ||
* 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.execution | ||
|
||
import java.nio.file.Files | ||
|
||
import com.intel.oap.tpc.util.TPCRunner | ||
import org.apache.log4j.{Level, LogManager} | ||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.QueryTest | ||
import org.apache.spark.sql.execution.ColumnarShuffleExchangeExec | ||
import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec | ||
import org.apache.spark.sql.functions.{col, expr} | ||
import org.apache.spark.sql.test.SharedSparkSession | ||
|
||
class PayloadSuite extends QueryTest with SharedSparkSession { | ||
|
||
private val MAX_DIRECT_MEMORY = "5000m" | ||
private var runner: TPCRunner = _ | ||
|
||
private var lPath: String = _ | ||
private var rPath: String = _ | ||
private val scale = 100 | ||
|
||
override protected def sparkConf: SparkConf = { | ||
val conf = super.sparkConf | ||
conf.set("spark.memory.offHeap.size", String.valueOf(MAX_DIRECT_MEMORY)) | ||
.set("spark.plugins", "com.intel.oap.GazellePlugin") | ||
.set("spark.sql.codegen.wholeStage", "false") | ||
.set("spark.sql.sources.useV1SourceList", "") | ||
.set("spark.oap.sql.columnar.tmp_dir", "/tmp/") | ||
.set("spark.sql.columnar.sort.broadcastJoin", "true") | ||
.set("spark.storage.blockManagerSlaveTimeoutMs", "3600000") | ||
.set("spark.executor.heartbeatInterval", "3600000") | ||
.set("spark.network.timeout", "3601s") | ||
.set("spark.oap.sql.columnar.preferColumnar", "true") | ||
.set("spark.oap.sql.columnar.sortmergejoin", "true") | ||
.set("spark.sql.columnar.codegen.hashAggregate", "false") | ||
.set("spark.sql.columnar.sort", "true") | ||
.set("spark.sql.columnar.window", "true") | ||
.set("spark.shuffle.manager", "org.apache.spark.shuffle.sort.ColumnarShuffleManager") | ||
.set("spark.unsafe.exceptionOnMemoryLeak", "false") | ||
.set("spark.network.io.preferDirectBufs", "false") | ||
.set("spark.sql.sources.useV1SourceList", "arrow,parquet") | ||
.set("spark.sql.autoBroadcastJoinThreshold", "-1") | ||
.set("spark.oap.sql.columnar.sortmergejoin.lazyread", "true") | ||
.set("spark.oap.sql.columnar.autorelease", "false") | ||
.set("spark.sql.shuffle.partitions", "50") | ||
.set("spark.sql.adaptive.coalescePartitions.initialPartitionNum", "5") | ||
.set("spark.oap.sql.columnar.shuffledhashjoin.buildsizelimit", "200m") | ||
// .set("spark.oap.sql.columnar.rowtocolumnar", "false") | ||
// .set("spark.oap.sql.columnar.columnartorow", "false") | ||
return conf | ||
} | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
LogManager.getRootLogger.setLevel(Level.WARN) | ||
|
||
val lfile = Files.createTempFile("", ".parquet").toFile | ||
lfile.deleteOnExit() | ||
lPath = lfile.getAbsolutePath | ||
spark.range(2).select(col("id"), expr("1").as("kind"), | ||
expr("1").as("key"), | ||
expr("array(1, 2)").as("arr_field"), | ||
expr("array(array(1, 2), array(3, 4))").as("arr_arr_field"), | ||
expr("array(struct(1, 2), struct(1, 2))").as("arr_struct_field"), | ||
expr("array(map(1, 2), map(3,4))").as("arr_map_field"), | ||
expr("struct(1, 2)").as("struct_field"), | ||
expr("struct(1, struct(1, 2))").as("struct_struct_field"), | ||
expr("struct(1, array(1, 2))").as("struct_array_field"), | ||
expr("map(1, 2)").as("map_field"), | ||
expr("map(1, map(3,4))").as("map_map_field"), | ||
expr("map(1, array(1, 2))").as("map_arr_field"), | ||
expr("map(struct(1, 2), 2)").as("map_struct_field")) | ||
.coalesce(1) | ||
.write | ||
.format("parquet") | ||
.mode("overwrite") | ||
.parquet(lPath) | ||
|
||
val rfile = Files.createTempFile("", ".parquet").toFile | ||
rfile.deleteOnExit() | ||
rPath = rfile.getAbsolutePath | ||
spark.range(2).select(col("id"), expr("id % 2").as("kind"), | ||
expr("id % 2").as("key"), | ||
expr("array(1, 2)").as("arr_field"), | ||
expr("struct(1, 2)").as("struct_field")) | ||
.coalesce(1) | ||
.write | ||
.format("parquet") | ||
.mode("overwrite") | ||
.parquet(rPath) | ||
|
||
spark.catalog.createTable("ltab", lPath, "arrow") | ||
spark.catalog.createTable("rtab", rPath, "arrow") | ||
} | ||
|
||
test("Test Array in Sort") { | ||
// spark.sql("SELECT * FROM ltab").printSchema() | ||
val df = spark.sql("SELECT ltab.arr_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count == 2) | ||
} | ||
|
||
test("Test Nest Array in Sort") { | ||
val df = spark.sql("SELECT ltab.arr_arr_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count == 2) | ||
} | ||
|
||
test("Test Nest Array in multi-keys Sort") { | ||
val df = spark.sql("SELECT ltab.arr_arr_field FROM ltab order by ltab.kind, ltab.key") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count == 2) | ||
} | ||
|
||
test("Test Struct in Sort") { | ||
val df = spark.sql("SELECT ltab.struct_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Nest Struct in Sort") { | ||
val df = spark.sql("SELECT ltab.struct_struct_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Struct_Array in Sort") { | ||
val df = spark.sql("SELECT ltab.struct_array_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Map in Sort") { | ||
val df = spark.sql("SELECT ltab.map_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Nest Map in Sort") { | ||
val df = spark.sql("SELECT ltab.map_map_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Map_Array in Sort") { | ||
val df = spark.sql("SELECT ltab.map_arr_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
test("Test Map_Struct in Sort") { | ||
val df = spark.sql("SELECT ltab.map_struct_field FROM ltab order by ltab.kind") | ||
df.explain(false) | ||
df.show() | ||
assert(df.queryExecution.executedPlan.find(_.isInstanceOf[ColumnarSortExec]).isDefined) | ||
assert(df.count() == 2) | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
super.afterAll() | ||
} | ||
} |
Oops, something went wrong.
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.
checkIfNestTypeSupported?
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.
checkIfNestTypeSupported is for non-nest.