Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Jul 23, 2024
1 parent 05d1baa commit 4bbede1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class UDTFRegistration(session: Session) extends Logging {
"UDTFRegistration",
funcName,
execName,
s"${UDXRegistrationHandler.className}.${UDXRegistrationHandler.methodName}",
UDXRegistrationHandler.udtfClassName,
execFilePath,
0)(func)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object OpenTelemetry extends Logging {
className,
funcName,
execName,
s"${UDXRegistrationHandler.className}.${UDXRegistrationHandler.methodName}",
UDXRegistrationHandler.udtfClassName,
execFilePath,
stackOffset + 2)(func.get())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object UDXRegistrationHandler {
val className = "SnowUDF"
// Method name for generated Java code
val methodName = "compute"
private val udtfClassName = className
val udtfClassName = "SnowparkGeneratedUDTF"
}

class UDXRegistrationHandler(session: Session) extends Logging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public void udf() {
public void udtf() {
String className = "snow.snowpark.UDTFRegistration";
getSession().udtf().registerTemporary(new MyJavaUDTFOf0());
checkUdfSpan(className, "registerTemporary", "", "");
checkUdtfSpan(className, "registerTemporary", "", "");
String funcName = randomFunctionName();
String funcName2 = randomFunctionName();
getSession().udtf().registerTemporary(funcName, new MyJavaUDTFOf0());
checkUdfSpan(className, "registerTemporary", funcName, "");
checkUdtfSpan(className, "registerTemporary", funcName, "");

String stageName = randomStageName();
try {
createStage(stageName, false);
getSession().udtf().registerPermanent(funcName2, new MyJavaUDTFOf2(), stageName);
checkUdfSpan(className, "registerPermanent", funcName2, stageName);
checkUdtfSpan(className, "registerPermanent", funcName2, stageName);
} finally {
getSession().sql("drop function " + funcName2 + "(int, int)").collect();
dropStage(stageName);
Expand Down Expand Up @@ -104,4 +104,18 @@ private void checkUdfSpan(
"SnowUDF.compute",
execFilePath);
}

private void checkUdtfSpan(
String className, String funcName, String execName, String execFilePath) {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement file = stack[2];
checkSpan(
className,
funcName,
"JavaUDXOpenTelemetrySuite.java",
file.getLineNumber() - 1,
execName,
"SnowparkGeneratedUDTF",
execFilePath);
}
}
7 changes: 2 additions & 5 deletions src/test/scala/com/snowflake/snowpark/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ object TestUtils extends Logging {
classOf[BeforeAndAfterAll], // scala test jar
classOf[org.scalactic.TripleEquals], // scalactic jar
classOf[io.opentelemetry.exporters.inmemory.InMemorySpanExporter],
classOf[io.opentelemetry.sdk.trace.export.SpanExporter],
classOf[scala.collection.Iterator[_]],
classOf[scala.reflect.api.TypeTags])
classOf[io.opentelemetry.sdk.trace.export.SpanExporter])
.flatMap(UDFClassPath.getPathForClass(_))
.foreach(path => {
val file = new File(path)
Expand Down Expand Up @@ -178,8 +176,7 @@ object TestUtils extends Logging {
classOf[BeforeAndAfterAll], // scala test jar
classOf[org.scalactic.TripleEquals], // scalactic jar
classOf[io.opentelemetry.exporters.inmemory.InMemorySpanExporter],
classOf[io.opentelemetry.sdk.trace.export.SpanExporter],
classOf[scala.Function0[_]])
classOf[io.opentelemetry.sdk.trace.export.SpanExporter])
.flatMap(UDFClassPath.getPathForClass(_))
.foreach(path => {
val file = new File(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class UdxOpenTelemetrySuite extends OpenTelemetryEnabled {
override def outputSchema(): StructType = StructType(StructField("sum", IntegerType))
}
session.udtf.registerTemporary(new MyUDTF0())
checkUdfSpan(className, "registerTemporary", "", "")
checkUdtfSpan(className, "registerTemporary", "", "")
val udtfName = randomFunctionName()
session.udtf.registerTemporary(udtfName, new MyUDTF0)
checkUdfSpan(className, "registerTemporary", udtfName, "")
checkUdtfSpan(className, "registerTemporary", udtfName, "")

val stageName: String = randomName()
val udtfName2 = randomFunctionName()
try {
createStage(stageName, isTemporary = false)
session.udtf.registerPermanent(udtfName2, new MyUDTF0(), stageName)
checkUdfSpan(className, "registerPermanent", udtfName2, stageName)
checkUdtfSpan(className, "registerPermanent", udtfName2, stageName)
} finally {
runQuery(s"drop function $udtfName2()", session)
dropStage(stageName)
Expand Down Expand Up @@ -97,4 +97,21 @@ class UdxOpenTelemetrySuite extends OpenTelemetryEnabled {
"SnowUDF.compute",
execFilePath)
}

def checkUdtfSpan(
className: String,
funcName: String,
execName: String,
execFilePath: String): Unit = {
val stack = Thread.currentThread().getStackTrace
val file = stack(2) // this file
checkSpan(
className,
funcName,
"UdxOpenTelemetrySuite.scala",
file.getLineNumber - 1,
execName,
"SnowparkGeneratedUDTF",
execFilePath)
}
}

0 comments on commit 4bbede1

Please sign in to comment.