Skip to content
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

Add test and modification to bestCandidate Calculation #765

Merged
merged 8 commits into from
Mar 19, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ object DefaultQueryPipelineFactory extends Logging {
}
} else {
if (a._5 == b._5) {
a._3 < b._3
if(a._4 == b._4){
a._3 < b._3
} else {
a._4 < b._4
}
} else {
a._5 < b._5
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,99 @@ class QueryPipelineWithFallbackTest extends AnyFunSuite with Matchers with Befor
pipeline = builder._1.toOption.get.build()
assert(pipeline.fallbackQueryChainOption.isEmpty, s"No fallback query expected: $pipeline")
}

private[this] def aLessThanBByLevelAndCostAndCardinality(a: (String, Engine, Long, Int, Int), b: (String, Engine, Long, Int, Int)): Boolean = {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of replicating code here, we can expose public wrapper method to test this comparator in the DefaultQueryPipelineFactory.

if (a._2 == b._2) {
if (a._4 == b._4) {
a._3 < b._3
} else {
a._4 < b._4
}
} else {
if (a._5 == b._5) {
if(a._4 == b._4){
a._3 < b._3
} else {
a._4 < b._4
}
} else {
a._5 < b._5
}
}
}

test("Show the comparator result") {
def aLessThanBByLevelAndCostAndCardinalityOldMethod(a: (String, Engine, Long, Int, Int), b: (String, Engine, Long, Int, Int)): Boolean = {
if (a._2 == b._2) {
if (a._4 == b._4) {
a._3 < b._3
} else {
a._4 < b._4
}
} else {
if (a._5 == b._5) {
a._3 < b._3
} else {
a._5 < b._5
}
}
}

def aLessThanBByLevelAndCostAndCardinality(a: (String, Engine, Long, Int, Int), b: (String, Engine, Long, Int, Int)): Boolean = {
if (a._2 == b._2) {
if (a._4 == b._4) {
a._3 < b._3
} else {
a._4 < b._4
}
} else {
if (a._5 == b._5) {
if(a._4 == b._4){
a._3 < b._3
} else {
a._4 < b._4
}
} else {
a._5 < b._5
}
}
}

val t1 = ("dr_stats_hourly", DruidEngine, 1600L, 9993, 8675309)
val t2 = ("dr_ad_stats_hourly", DruidEngine, 1600L, 9995, 8675309)
val t3 = ("oracle_stats", OracleEngine, 1600L, 9992, 8675309)
val t4 = ("oracle_ad_stats", OracleEngine, 1600L, 9994, 8675309)
val t5 = ("dr_teacher_ad_stats", DruidEngine, 1600L, 9998, 8675309)
val t6 = ("oracle_teacher_stats", OracleEngine, 1600L, 9991, 8675309)
val t7 = ("dr_teacher_stats_hourly", DruidEngine, 1600L, 9992, 8675309)
val t8 = ("dr_teacher_ad_stats_hourly", DruidEngine, 1600L, 9997, 8675309)


val oldResult = Vector(t1,t2,t3,t4,t5,t6,t7,t8).sortWith(aLessThanBByLevelAndCostAndCardinalityOldMethod)
val newResult = Vector(t1,t2,t3,t4,t5,t6,t7,t8).sortWith(aLessThanBByLevelAndCostAndCardinality)

println(oldResult.mkString("\n"))
println(newResult.mkString("\n"))

assert(oldResult.mkString("\n").equals(
"(dr_stats_hourly,Druid,1600,9993,8675309)\n" +
"(dr_ad_stats_hourly,Druid,1600,9995,8675309)\n" +
"(oracle_stats,Oracle,1600,9992,8675309)\n" +
"(oracle_ad_stats,Oracle,1600,9994,8675309)\n" +
"(dr_teacher_ad_stats,Druid,1600,9998,8675309)\n" +
"(oracle_teacher_stats,Oracle,1600,9991,8675309)\n" +
"(dr_teacher_stats_hourly,Druid,1600,9992,8675309)\n" +
"(dr_teacher_ad_stats_hourly,Druid,1600,9997,8675309)"
))
assert(newResult.mkString("\n").equals(
"(oracle_teacher_stats,Oracle,1600,9991,8675309)\n" +
"(oracle_stats,Oracle,1600,9992,8675309)\n" +
"(dr_teacher_stats_hourly,Druid,1600,9992,8675309)\n" +
"(dr_stats_hourly,Druid,1600,9993,8675309)\n" +
"(oracle_ad_stats,Oracle,1600,9994,8675309)\n" +
"(dr_ad_stats_hourly,Druid,1600,9995,8675309)\n" +
"(dr_teacher_ad_stats_hourly,Druid,1600,9997,8675309)\n" +
"(dr_teacher_ad_stats,Druid,1600,9998,8675309)"
))
}
}