Skip to content

Commit

Permalink
add unary math
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Jun 5, 2024
1 parent cfe8c72 commit 449cb92
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 0 additions & 1 deletion fuzz-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Planned areas of improvement:

- ANSI mode
- Support for all data types, expressions, and operators supported by Comet
- Unary and binary arithmetic expressions
- IF and CASE WHEN expressions
- Complex (nested) expressions
- Literal scalar values in queries
Expand Down
4 changes: 3 additions & 1 deletion fuzz-testing/src/main/scala/org/apache/comet/fuzz/Meta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ object Meta {
Function("stddev_samp", 1),
Function("corr", 2))

val arithmeticOps: Seq[String] = Seq("+", "-", "*", "/", "%")
val unaryArithmeticOps: Seq[String] = Seq("+", "-")

val binaryArithmeticOps: Seq[String] = Seq("+", "-", "*", "/", "%")

}
22 changes: 18 additions & 4 deletions fuzz-testing/src/main/scala/org/apache/comet/fuzz/QueryGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ object QueryGen {
val uniqueQueries = mutable.HashSet[String]()

for (_ <- 0 until numQueries) {
val sql = r.nextInt().abs % 5 match {
val sql = r.nextInt().abs % 6 match {
case 0 => generateJoin(r, spark, numFiles)
case 1 => generateAggregate(r, spark, numFiles)
case 2 => generateScalar(r, spark, numFiles)
case 3 => generateCast(r, spark, numFiles)
case 4 => generateArithmetic(r, spark, numFiles)
case 4 => generateUnaryArithmetic(r, spark, numFiles)
case 5 => generateBinaryArithmetic(r, spark, numFiles)
}
if (!uniqueQueries.contains(sql)) {
uniqueQueries += sql
Expand Down Expand Up @@ -93,11 +94,24 @@ object QueryGen {
s"ORDER BY ${args.mkString(", ")};"
}

private def generateArithmetic(r: Random, spark: SparkSession, numFiles: Int): String = {
private def generateUnaryArithmetic(r: Random, spark: SparkSession, numFiles: Int): String = {
val tableName = s"test${r.nextInt(numFiles)}"
val table = spark.table(tableName)

val op = Utils.randomChoice(Meta.arithmeticOps, r)
val op = Utils.randomChoice(Meta.unaryArithmeticOps, r)
val a = Utils.randomChoice(table.columns, r)

// Example SELECT a, -a FROM test0
s"SELECT $a, $op$a " +
s"FROM $tableName " +
s"ORDER BY $a;"
}

private def generateBinaryArithmetic(r: Random, spark: SparkSession, numFiles: Int): String = {
val tableName = s"test${r.nextInt(numFiles)}"
val table = spark.table(tableName)

val op = Utils.randomChoice(Meta.binaryArithmeticOps, r)
val a = Utils.randomChoice(table.columns, r)
val b = Utils.randomChoice(table.columns, r)

Expand Down

0 comments on commit 449cb92

Please sign in to comment.