Skip to content
Closed
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
yaooqinn committed Jun 20, 2024
commit 64f3c3936cdcdf7543e2ea4101cd8ccd8c5b7f94
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
strExpr = StringDecode(Encode(strExpr, "utf-8"), "utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use a different expression for testing? The codegen size is greatly decreased after using StaticInvoke in Encode.

Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. StringTrim

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

}

val expressions = Seq(If(EqualTo(strExpr, strExpr), strExpr, strExpr))
val expressions = Seq(If(EqualTo(strExpr, strExpr), strExpr, strExpr)).map(replace)
val plan = GenerateMutableProjection.generate(expressions)
val actual = plan(null).toSeq(expressions.map(_.dataType))
assert(actual.length == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ trait ExpressionEvalHelper extends ScalaCheckDrivenPropertyChecks with PlanTestB
new ArrayBasedMapData(keyArray, valueArray)
}

protected def replace(expr: Expression): Expression = expr match {
case r: RuntimeReplaceable => replace(r.replacement)
case _ => expr.mapChildren(replace)
}

private def prepareEvaluation(expression: Expression): Expression = {
val serializer = new JavaSerializer(new SparkConf()).newInstance()
val resolver = ResolveTimeZone
val expr = resolver.resolveTimeZones(expression)
val expr = resolver.resolveTimeZones(replace(expression))
assert(expr.resolved)
serializer.deserialize(serializer.serialize(expr))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(StringDecode(b, Literal.create(null, StringType)), null, create_row(null))

// Test escaping of charset
GenerateUnsafeProjection.generate(Encode(a, Literal("\"quote")) :: Nil)
GenerateUnsafeProjection.generate(StringDecode(b, Literal("\"quote")) :: Nil)
GenerateUnsafeProjection.generate(Encode(a, Literal("\"quote")).replacement :: Nil)
GenerateUnsafeProjection.generate(StringDecode(b, Literal("\"quote")).replacement :: Nil)
}

test("initcap unit test") {
Expand Down