amaliujia commented on code in PR #38320:
URL: https://github.com/apache/spark/pull/38320#discussion_r1001279885
##########
connector/connect/src/main/scala/org/apache/spark/sql/connect/config/Connect.scala:
##########
@@ -26,4 +26,9 @@ private[spark] object Connect {
.intConf
.createWithDefault(15002)
+ val CONNECT_GRPC_INTERCEPTOR_CLASSES =
+ ConfigBuilder("spark.connect.grpc.interceptor.classes")
+ .version("3.4.0")
Review Comment:
add `.doc()` to document the class name separator is comma.
##########
core/src/main/resources/error/error-classes.json:
##########
@@ -4276,4 +4293,4 @@
"Not enough memory to build and broadcast the table to all worker nodes.
As a workaround, you can either disable broadcast by setting
<autoBroadcastjoinThreshold> to -1 or increase the spark driver memory by
setting <driverMemory> to a higher value<analyzeTblMsg>"
]
}
-}
+}
Review Comment:
This can be reverted?
##########
connector/connect/src/test/scala/org/apache/spark/sql/connect/service/InterceptorRegistryTest.scala:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connect.service
+
+import io.grpc.{Metadata, ServerCall, ServerCallHandler, ServerInterceptor}
+import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener
+import io.grpc.netty.NettyServerBuilder
+
+import org.apache.spark.{SparkEnv, SparkIllegalArgumentException,
SparkRuntimeException}
+import org.apache.spark.sql.connect.config.Connect
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * Used for testing only.
+ */
+class TestingInterceptorNoTrivialCtor(id: Int) extends ServerInterceptor {
+ override def interceptCall[ReqT, RespT](
+ call: ServerCall[ReqT, RespT],
+ headers: Metadata,
+ next: ServerCallHandler[ReqT, RespT]): ServerCall.Listener[ReqT] = {
+ val listener = next.startCall(call, headers)
+ new SimpleForwardingServerCallListener[ReqT](listener) {
+ override def onMessage(message: ReqT): Unit = {
+ delegate().onMessage(message)
+ }
+ }
+ }
+}
+
+/**
+ * Used for testing only.
+ */
+class TestingInterceptorInstantiationError extends ServerInterceptor {
+ throw new ArrayIndexOutOfBoundsException("Bad Error")
+
+ override def interceptCall[ReqT, RespT](
+ call: ServerCall[ReqT, RespT],
+ headers: Metadata,
+ next: ServerCallHandler[ReqT, RespT]): ServerCall.Listener[ReqT] = {
+ val listener = next.startCall(call, headers)
+ new SimpleForwardingServerCallListener[ReqT](listener) {
+ override def onMessage(message: ReqT): Unit = {
+ delegate().onMessage(message)
+ }
+ }
+ }
+}
+
+class InterceptorRegistryTest extends SharedSparkSession {
+
+ override def beforeEach(): Unit = {
+ if (SparkEnv.get.conf.contains(Connect.CONNECT_GRPC_INTERCEPTOR_CLASSES)) {
+ SparkEnv.get.conf.remove(Connect.CONNECT_GRPC_INTERCEPTOR_CLASSES)
Review Comment:
hmmm this seems to be `SQLConf` only. I am not sure actually for non SQL
config though.
##########
connector/connect/src/test/scala/org/apache/spark/sql/connect/service/InterceptorRegistryTest.scala:
##########
@@ -0,0 +1,134 @@
+/*
Review Comment:
Rename this file to `InterceptorRegistrySuite`?
##########
connector/connect/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectInterceptorRegistry.scala:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connect.service
+
+import java.lang.reflect.InvocationTargetException
+
+import io.grpc.{Metadata, ServerCall, ServerCallHandler, ServerInterceptor}
+import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener
+import io.grpc.netty.NettyServerBuilder
+
+import org.apache.spark.{SparkEnv, SparkIllegalArgumentException,
SparkRuntimeException}
+import org.apache.spark.sql.connect.config.Connect
+import org.apache.spark.util.Utils
+
+/**
+ * Used for testing only, does not do anything.
+ */
+class DummyInterceptor extends ServerInterceptor {
Review Comment:
Looks like this class is loaded by class name? In this case maybe just move
this class to test directory?
##########
core/src/main/resources/error/error-classes.json:
##########
@@ -698,6 +698,23 @@
],
"sqlState" : "22023"
},
+ "SPARK_CONNECT" : {
Review Comment:
Nit: we might not need `SPARK_` with the Spark repo? `CONNECT` is the
project/component name.
##########
connector/connect/src/test/scala/org/apache/spark/sql/connect/service/InterceptorRegistryTest.scala:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connect.service
+
+import io.grpc.{Metadata, ServerCall, ServerCallHandler, ServerInterceptor}
+import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener
+import io.grpc.netty.NettyServerBuilder
+
+import org.apache.spark.{SparkEnv, SparkIllegalArgumentException,
SparkRuntimeException}
+import org.apache.spark.sql.connect.config.Connect
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * Used for testing only.
+ */
+class TestingInterceptorNoTrivialCtor(id: Int) extends ServerInterceptor {
+ override def interceptCall[ReqT, RespT](
+ call: ServerCall[ReqT, RespT],
+ headers: Metadata,
+ next: ServerCallHandler[ReqT, RespT]): ServerCall.Listener[ReqT] = {
+ val listener = next.startCall(call, headers)
+ new SimpleForwardingServerCallListener[ReqT](listener) {
+ override def onMessage(message: ReqT): Unit = {
+ delegate().onMessage(message)
+ }
+ }
+ }
+}
+
+/**
+ * Used for testing only.
+ */
+class TestingInterceptorInstantiationError extends ServerInterceptor {
+ throw new ArrayIndexOutOfBoundsException("Bad Error")
+
+ override def interceptCall[ReqT, RespT](
+ call: ServerCall[ReqT, RespT],
+ headers: Metadata,
+ next: ServerCallHandler[ReqT, RespT]): ServerCall.Listener[ReqT] = {
+ val listener = next.startCall(call, headers)
+ new SimpleForwardingServerCallListener[ReqT](listener) {
+ override def onMessage(message: ReqT): Unit = {
+ delegate().onMessage(message)
+ }
+ }
+ }
+}
+
+class InterceptorRegistryTest extends SharedSparkSession {
+
+ override def beforeEach(): Unit = {
+ if (SparkEnv.get.conf.contains(Connect.CONNECT_GRPC_INTERCEPTOR_CLASSES)) {
+ SparkEnv.get.conf.remove(Connect.CONNECT_GRPC_INTERCEPTOR_CLASSES)
Review Comment:
You don't need this. There is a way to do per test case config setting. One
example is
```
test("SPARK-40389: Don't eliminate a cast which can cause overflow") {
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
withTable("dt") {
sql("create table dt using parquet as select 9000000000BD as d")
val msg = intercept[SparkException] {
sql("select cast(cast(d as int) as long) from dt").collect()
}.getCause.getMessage
assert(msg.contains("[CAST_OVERFLOW]"))
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]