Skip to content

Commit af45052

Browse files
viiryadongjoon-hyun
authored andcommitted
[SPARK-49373][PROTOBUF][TESTS] Fix ProtobufFunctionsSuite to be environment-independent
### What changes were proposed in this pull request? This patch modifies `ProtobufFunctionsSuite`'s test case `SPARK-49121: from_protobuf and to_protobuf SQL functions` to check the stop index depending on the file path length. ### Why are the changes needed? During debugging CI failure in #47843, we found that `ProtobufFunctionsSuite`'s test case `SPARK-49121: from_protobuf and to_protobuf SQL functions` is environment-dependent. In the test, it checks the start and stop indices of SQL text fragment but the fragment length depends on the repo name of the author of a PR. ### Does this PR introduce _any_ user-facing change? No, test only. ### How was this patch tested? Unit test ### Was this patch authored or co-authored using generative AI tooling? No Closes #47859 from viirya/fix_protobuf_test. Authored-by: Liang-Chi Hsieh <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent e95618f commit af45052

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

connector/protobuf/src/test/scala/org/apache/spark/sql/protobuf/ProtobufFunctionsSuite.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,7 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
20852085
)
20862086

20872087
// Negative tests for to_protobuf.
2088+
var fragment = s"to_protobuf(complex_struct, 42, '$testFileDescFile', map())"
20882089
checkError(
20892090
exception = intercept[AnalysisException](sql(
20902091
s"""
@@ -2099,9 +2100,9 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
20992100
"string representing the Protobuf message name"),
21002101
"hint" -> ""),
21012102
queryContext = Array(ExpectedContext(
2102-
fragment = s"to_protobuf(complex_struct, 42, '$testFileDescFile', map())",
2103+
fragment = fragment,
21032104
start = 10,
2104-
stop = 153))
2105+
stop = fragment.length + 9))
21052106
)
21062107
checkError(
21072108
exception = intercept[AnalysisException](sql(
@@ -2121,6 +2122,7 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
21212122
start = 10,
21222123
stop = 73))
21232124
)
2125+
fragment = s"to_protobuf(complex_struct, 'SimpleMessageJavaTypes', '$testFileDescFile', 42)"
21242126
checkError(
21252127
exception = intercept[AnalysisException](sql(
21262128
s"""
@@ -2137,13 +2139,13 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
21372139
"to Protobuf format"),
21382140
"hint" -> ""),
21392141
queryContext = Array(ExpectedContext(
2140-
fragment =
2141-
s"to_protobuf(complex_struct, 'SimpleMessageJavaTypes', '$testFileDescFile', 42)",
2142+
fragment = fragment,
21422143
start = 10,
2143-
stop = 172))
2144+
stop = fragment.length + 9))
21442145
)
21452146

21462147
// Negative tests for from_protobuf.
2148+
fragment = s"from_protobuf(protobuf_data, 42, '$testFileDescFile', map())"
21472149
checkError(
21482150
exception = intercept[AnalysisException](sql(
21492151
s"""
@@ -2157,9 +2159,9 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
21572159
"string representing the Protobuf message name"),
21582160
"hint" -> ""),
21592161
queryContext = Array(ExpectedContext(
2160-
fragment = s"from_protobuf(protobuf_data, 42, '$testFileDescFile', map())",
2162+
fragment = fragment,
21612163
start = 8,
2162-
stop = 152))
2164+
stop = fragment.length + 7))
21632165
)
21642166
checkError(
21652167
exception = intercept[AnalysisException](sql(
@@ -2178,6 +2180,7 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
21782180
start = 8,
21792181
stop = 72))
21802182
)
2183+
fragment = s"from_protobuf(protobuf_data, 'SimpleMessageJavaTypes', '$testFileDescFile', 42)"
21812184
checkError(
21822185
exception = intercept[AnalysisException](sql(
21832186
s"""
@@ -2194,10 +2197,9 @@ class ProtobufFunctionsSuite extends QueryTest with SharedSparkSession with Prot
21942197
"from Protobuf format"),
21952198
"hint" -> ""),
21962199
queryContext = Array(ExpectedContext(
2197-
fragment =
2198-
s"from_protobuf(protobuf_data, 'SimpleMessageJavaTypes', '$testFileDescFile', 42)",
2200+
fragment = fragment,
21992201
start = 10,
2200-
stop = 173))
2202+
stop = fragment.length + 9))
22012203
)
22022204
}
22032205
}

0 commit comments

Comments
 (0)