-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1573] feat(spark-connector): Spark regression test system #3933
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9c6ca6e
spark test framework
FANNG1 5b8b124
polish
FANNG1 9fc0f26
polish
FANNG1 761d5e0
polish
FANNG1 9d494ae
add doc
FANNG1 bb156eb
modify github ci
FANNG1 f767f99
polish
FANNG1 fac4d08
polish
FANNG1 b4b4e81
polish
FANNG1 05ba96b
exclude test resources from jar
FANNG1 a0dd07d
polish
FANNG1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: "Apache Gravitino Spark connector integration test" | ||
slug: /spark-connector/spark-connector-integration-test | ||
keyword: spark connector integration test | ||
license: "This software is licensed under the Apache License version 2." | ||
--- | ||
|
||
## Overview | ||
|
||
There are two types of integration tests in spark connector, normal integration test like `SparkXXCatalogIT`, and the golden file integration test. | ||
|
||
## Normal integration test | ||
|
||
Normal integration test are mainly used to test the correctness of the metadata, it's enabled in the GitHub CI. You could run tests with specific Spark version like: | ||
|
||
``` | ||
./gradlew :spark-connector:spark3.3:test --tests "org.apache.gravitino.spark.connector.integration.test.hive.SparkHiveCatalogIT33.testCreateHiveFormatPartitionTable" | ||
``` | ||
|
||
## Golden file integration test | ||
|
||
Golden file integration test are mainly to test the correctness of the SQL result with massive data, it's disabled in the GitHub CI, you could run tests with following command: | ||
|
||
``` | ||
./gradlew :spark-connector:spark-3.3:test --tests "org.apache.gravitino.spark.connector.integration.test.sql.SparkSQLRegressionTest33" -PenableSparkSQLITs | ||
``` | ||
|
||
Please change the Spark version number if you want to test other Spark versions. | ||
If you want to change the test behaviour, please modify `spark-connector/spark-common/src/test/resources/spark-test.conf`. | ||
|
||
| Configuration item | Description | Default value | Required | Since Version | | ||
|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|----------|---------------| | ||
| `gravitino.spark.test.dir` | The Spark SQL test base dir, include `test-sqls` and `data`. | `spark-connector/spark-common/src/test/resources/` | No | 0.6.0 | | ||
| `gravitino.spark.test.sqls` | Specify the test SQLs, using directory to specify group of SQLs like `test-sqls/hive`, using file path to specify one SQL like `test-sqls/hive/basic.sql`, use `,` to split multi part | run all SQLs | No | 0.6.0 | | ||
| `gravitino.spark.test.generateGoldenFiles` | Whether generate golden files which are used to check the correctness of the SQL result | false | No | 0.6.0 | | ||
| `gravitino.spark.test.metalake` | The metalake name to run the test | `test` | No | 0.6.0 | | ||
| `gravitino.spark.test.setupEnv` | Whether to setup Gravitino and Hive environment | `false` | No | 0.6.0 | | ||
| `gravitino.spark.test.uri` | Gravitino uri address, only available when `gravitino.spark.test.setupEnv` is false | http://127.0.0.1:8090 | No | 0.6.0 | | ||
| `gravitino.spark.test.iceberg.warehouse` | The warehouse location, only available when `gravitino.spark.test.setupEnv` is false | hdfs://127.0.0.1:9000/user/hive/warehouse-spark-test | No | 0.6.0 | | ||
|
||
The test SQL files are located in `spark-connector/spark-common/src/test/resources/` by default. There are three directories: | ||
- `hive`, SQL tests for Hive catalog. | ||
- `lakehouse-iceberg`, SQL tests for Iceberg catalog. | ||
- `tpcds`, SQL tests for `tpcds` in Hive catalog. | ||
|
||
You could create a simple SQL file, like `hive/catalog.sql`, the program will check the output with `hive/catalog.sql.out`. For complex cases like `tpcds`, you could do some prepare work like create table&load data in `prepare.sql`. |
47 changes: 47 additions & 0 deletions
47
.../src/test/java/org/apache/gravitino/spark/connector/integration/test/sql/CatalogType.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,47 @@ | ||
/* | ||
* 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.gravitino.spark.connector.integration.test.sql; | ||
|
||
import java.util.Locale; | ||
|
||
public enum CatalogType { | ||
HIVE, | ||
ICEBERG, | ||
UNKNOWN; | ||
|
||
public static CatalogType fromString(String str) { | ||
if (str == null) { | ||
return UNKNOWN; | ||
} | ||
switch (str.toLowerCase(Locale.ROOT)) { | ||
case "hive": | ||
return HIVE; | ||
case "lakehouse-iceberg": | ||
return ICEBERG; | ||
default: | ||
return UNKNOWN; | ||
} | ||
} | ||
|
||
// To find the catalog type from the directory name, the first name in directory match CatalogType | ||
// determines the catalog type. | ||
public static CatalogType merge(CatalogType parentCatalogType, CatalogType childCatalogType) { | ||
FANNG1 marked this conversation as resolved.
Show resolved
Hide resolved
FANNG1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return parentCatalogType.equals(UNKNOWN) ? childCatalogType : parentCatalogType; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/test/java/org/apache/gravitino/spark/connector/integration/test/sql/QueryOutput.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,47 @@ | ||
/* | ||
* 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.gravitino.spark.connector.integration.test.sql; | ||
|
||
import lombok.Getter; | ||
|
||
/** The SQL execution output, include schemas and output */ | ||
@Getter | ||
public final class QueryOutput { | ||
private final String sql; | ||
private final String schema; | ||
private final String output; | ||
|
||
public QueryOutput(String sql, String schema, String output) { | ||
this.sql = sql; | ||
this.schema = schema; | ||
this.output = output; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "-- !query\n" | ||
+ sql | ||
+ "\n" | ||
+ "-- !query schema\n" | ||
+ schema | ||
+ "\n" | ||
+ "-- !query output\n" | ||
+ output; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...st/java/org/apache/gravitino/spark/connector/integration/test/sql/SQLQueryTestHelper.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,87 @@ | ||
/* | ||
* 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.gravitino.spark.connector.integration.test.sql; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.spark.sql.Dataset; | ||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.apache.spark.sql.execution.HiveResult; | ||
import org.apache.spark.sql.execution.SQLExecution; | ||
import org.apache.spark.sql.types.StructType; | ||
import scala.Option; | ||
import scala.collection.JavaConverters; | ||
|
||
public class SQLQueryTestHelper { | ||
private static final String notIncludedMsg = "[not included in comparison]"; | ||
private static final String clsName = SQLQueryTestHelper.class.getCanonicalName(); | ||
private static final String emptySchema = new StructType().catalogString(); | ||
|
||
private static String replaceNotIncludedMsg(String line) { | ||
line = | ||
line.replaceAll("#\\d+", "#x") | ||
.replaceAll("plan_id=\\d+", "plan_id=x") | ||
.replaceAll( | ||
"Location.*" + clsName + "/", "Location " + notIncludedMsg + "/{warehouse_dir}/") | ||
.replaceAll("file:[^\\s,]*" + clsName, "file:" + notIncludedMsg + "/{warehouse_dir}") | ||
.replaceAll("Created By.*", "Created By " + notIncludedMsg) | ||
.replaceAll("Created Time.*", "Created Time " + notIncludedMsg) | ||
.replaceAll("Last Access.*", "Last Access " + notIncludedMsg) | ||
.replaceAll("Partition Statistics\t\\d+", "Partition Statistics\t" + notIncludedMsg) | ||
.replaceAll("\\s+$", "") | ||
.replaceAll("\\*\\(\\d+\\) ", "*"); | ||
return line; | ||
} | ||
|
||
public static Pair<String, List<String>> getNormalizedResult(SparkSession session, String sql) { | ||
Dataset<Row> df = session.sql(sql); | ||
String schema = df.schema().catalogString(); | ||
List<String> answer = | ||
SQLExecution.withNewExecutionId( | ||
df.queryExecution(), | ||
Option.apply(""), | ||
() -> | ||
JavaConverters.seqAsJavaList( | ||
HiveResult.hiveResultString(df.queryExecution().executedPlan())) | ||
.stream() | ||
.map(s -> replaceNotIncludedMsg(s)) | ||
.filter(s -> !s.isEmpty()) | ||
.collect(Collectors.toList())); | ||
|
||
Collections.sort(answer); | ||
|
||
return Pair.of(schema, answer); | ||
} | ||
|
||
// Different Spark version may produce different exceptions, so here just produce | ||
// [SPARK_EXCEPTION] | ||
public static Pair<String, List<String>> handleExceptions( | ||
Supplier<Pair<String, List<String>>> result) { | ||
try { | ||
return result.get(); | ||
} catch (Throwable e) { | ||
return Pair.of(emptySchema, Arrays.asList("[SPARK_EXCEPTION]")); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
the first non-unknown
CatalogType
from parent to child determines the catalog type.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.
done