-
Notifications
You must be signed in to change notification settings - Fork 248
chore: extract comparison into separate tool #2632
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2470980
chore: add TPC queries to be run by fuzzer correctness checker
comphead 3aea54e
chore: extract comparison tool from fuzzer
comphead ced0c0d
chore: extract comparison tool from fuzzer
comphead 3631b54
chore: extract comparison tool from fuzzer
comphead f381c3d
chore: extract comparison tool from fuzzer
comphead 720d77e
chore: extract comparison tool from fuzzer
comphead ce2a5b2
chore: extract comparison tool from fuzzer
comphead 6d28c0c
chore: extract comparison tool from fuzzer
comphead 95955be
chore: extract comparison tool from fuzzer
comphead c75ecfc
chore: extract comparison tool from fuzzer
comphead b811583
chore: extract comparison tool from fuzzer
comphead 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 hidden or 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 hidden or 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
143 changes: 143 additions & 0 deletions
143
fuzz-testing/src/main/scala/org/apache/comet/fuzz/ComparisonTool.scala
This file contains hidden or 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,143 @@ | ||
| /* | ||
| * 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.comet.fuzz | ||
|
|
||
| import java.io.File | ||
|
|
||
| import org.rogach.scallop.{ScallopConf, ScallopOption, Subcommand} | ||
|
|
||
| import org.apache.spark.sql.{functions, SparkSession} | ||
|
|
||
| class ComparisonToolConf(arguments: Seq[String]) extends ScallopConf(arguments) { | ||
| object compareParquet extends Subcommand("compareParquet") { | ||
| val inputSparkFolder: ScallopOption[String] = | ||
| opt[String](required = true, descr = "Folder with Spark produced results in Parquet format") | ||
| val inputCometFolder: ScallopOption[String] = | ||
| opt[String](required = true, descr = "Folder with Comet produced results in Parquet format") | ||
| } | ||
| addSubcommand(compareParquet) | ||
| verify() | ||
| } | ||
|
|
||
| object ComparisonTool { | ||
|
|
||
| lazy val spark: SparkSession = SparkSession | ||
| .builder() | ||
| .getOrCreate() | ||
|
|
||
| def main(args: Array[String]): Unit = { | ||
| val conf = new ComparisonToolConf(args.toIndexedSeq) | ||
| conf.subcommand match { | ||
| case Some(conf.compareParquet) => | ||
| compareParquetFolders( | ||
| spark, | ||
| conf.compareParquet.inputSparkFolder(), | ||
| conf.compareParquet.inputCometFolder()) | ||
|
|
||
| case _ => | ||
| // scalastyle:off println | ||
| println("Invalid subcommand") | ||
| // scalastyle:on println | ||
| sys.exit(-1) | ||
| } | ||
| } | ||
|
|
||
| private def compareParquetFolders( | ||
| spark: SparkSession, | ||
| sparkFolderPath: String, | ||
| cometFolderPath: String): Unit = { | ||
|
|
||
| val output = QueryRunner.createOutputMdFile() | ||
|
|
||
| try { | ||
| val sparkFolder = new File(sparkFolderPath) | ||
| val cometFolder = new File(cometFolderPath) | ||
|
|
||
| if (!sparkFolder.exists() || !sparkFolder.isDirectory) { | ||
| throw new IllegalArgumentException( | ||
| s"Spark folder does not exist or is not a directory: $sparkFolderPath") | ||
| } | ||
|
|
||
| if (!cometFolder.exists() || !cometFolder.isDirectory) { | ||
| throw new IllegalArgumentException( | ||
| s"Comet folder does not exist or is not a directory: $cometFolderPath") | ||
| } | ||
|
|
||
| // Get all subdirectories from the Spark folder | ||
| val sparkSubfolders = sparkFolder | ||
| .listFiles() | ||
| .filter(_.isDirectory) | ||
| .map(_.getName) | ||
| .sorted | ||
|
|
||
| output.write("# Comparing Parquet Folders\n\n") | ||
| output.write(s"Spark folder: $sparkFolderPath\n") | ||
| output.write(s"Comet folder: $cometFolderPath\n") | ||
| output.write(s"Found ${sparkSubfolders.length} subfolders to compare\n\n") | ||
|
|
||
| // Compare each subfolder | ||
| sparkSubfolders.foreach { subfolderName => | ||
| val sparkSubfolderPath = new File(sparkFolder, subfolderName) | ||
| val cometSubfolderPath = new File(cometFolder, subfolderName) | ||
|
|
||
| if (!cometSubfolderPath.exists() || !cometSubfolderPath.isDirectory) { | ||
| output.write(s"## Subfolder: $subfolderName\n") | ||
| output.write( | ||
| s"[WARNING] Comet subfolder not found: ${cometSubfolderPath.getAbsolutePath}\n\n") | ||
| } else { | ||
| output.write(s"## Comparing subfolder: $subfolderName\n\n") | ||
|
|
||
| try { | ||
| // Read Spark parquet files | ||
| spark.conf.set("spark.comet.enabled", "false") | ||
| val sparkDf = spark.read.parquet(sparkSubfolderPath.getAbsolutePath) | ||
| val sparkRows = sparkDf.orderBy(sparkDf.columns.map(functions.col): _*).collect() | ||
|
|
||
| // Read Comet parquet files | ||
| val cometDf = spark.read.parquet(cometSubfolderPath.getAbsolutePath) | ||
| val cometRows = cometDf.orderBy(cometDf.columns.map(functions.col): _*).collect() | ||
|
|
||
| // Compare the results | ||
| if (QueryComparison.assertSameRows(sparkRows, cometRows, output)) { | ||
| output.write(s"Subfolder $subfolderName: ${sparkRows.length} rows matched\n\n") | ||
| } | ||
| } catch { | ||
| case e: Exception => | ||
| output.write( | ||
| s"[ERROR] Failed to compare subfolder $subfolderName: ${e.getMessage}\n") | ||
| val sw = new java.io.StringWriter() | ||
| val p = new java.io.PrintWriter(sw) | ||
| e.printStackTrace(p) | ||
| p.close() | ||
| output.write(s"```\n${sw.toString}\n```\n\n") | ||
| } | ||
| } | ||
|
|
||
| output.flush() | ||
| } | ||
|
|
||
| output.write("\n# Comparison Complete\n") | ||
| output.write(s"Compared ${sparkSubfolders.length} subfolders\n") | ||
|
|
||
| } finally { | ||
| output.close() | ||
| } | ||
| } | ||
| } |
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.
spark complains on saving df with empty schema, this can happen for DDL statements which came across in TPC sets