Copilot commented on code in PR #61513:
URL: https://github.com/apache/doris/pull/61513#discussion_r2958180122
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/PaimonJdbcMetaStoreProperties.java:
##########
@@ -157,6 +161,20 @@ private void appendRawJdbcCatalogOptions() {
});
}
+ public Map<String, String> getBackendPaimonOptions() {
+ if (StringUtils.isBlank(driverUrl)) {
+ return Collections.emptyMap();
+ }
+ if (StringUtils.isBlank(driverClass)) {
+ throw new IllegalStateException("jdbc.driver_class or
paimon.jdbc.driver_class is required when "
Review Comment:
`getBackendPaimonOptions()` throws `IllegalStateException` when `driver_url`
is set but `driver_class` is missing, while `initializeCatalog()` validates the
same situation with `IllegalArgumentException`. This inconsistency can surface
as an internal error during planning/explain; consider using
`IllegalArgumentException` here as well (and keep the message consistent) since
this is user-provided configuration validation.
##########
fe/be-java-extensions/paimon-scanner/src/test/java/org/apache/doris/paimon/PaimonJdbcDriverUtilsTest.java:
##########
@@ -0,0 +1,119 @@
+// 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.doris.paimon;
+
+import org.apache.doris.common.classloader.JniScannerClassLoader;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.logging.Logger;
+
+public class PaimonJdbcDriverUtilsTest {
+ @Test
+ public void testRegisterDriverIfNeeded() throws Exception {
+ Path driverJar = createDriverJar();
+ Map<String, String> params = new HashMap<>();
+ params.put(PaimonJdbcDriverUtils.PAIMON_JDBC_DRIVER_URL,
driverJar.toUri().toURL().toString());
+ params.put(PaimonJdbcDriverUtils.PAIMON_JDBC_DRIVER_CLASS,
DummyJdbcDriver.class.getName());
+
+ JniScannerClassLoader scannerClassLoader = new
JniScannerClassLoader("paimon-test", List.of(), null);
+ PaimonJdbcDriverUtils.registerDriverIfNeeded(params,
scannerClassLoader);
+
+ Driver driver = DriverManager.getDriver("jdbc:dummy:test");
+ Assert.assertTrue(driver.acceptsURL("jdbc:dummy:test"));
+ }
+
+ @Test
+ public void testRegisterDriverIfNeededRequiresDriverClass() {
+ Map<String, String> params = new HashMap<>();
+ params.put(PaimonJdbcDriverUtils.PAIMON_JDBC_DRIVER_URL,
"file:///tmp/postgresql-42.5.0.jar");
+
+ IllegalArgumentException exception =
Assert.assertThrows(IllegalArgumentException.class,
+ () -> PaimonJdbcDriverUtils.registerDriverIfNeeded(params,
getClass().getClassLoader()));
+ Assert.assertTrue(exception.getMessage().contains("driver_class"));
+ }
+
+ private Path createDriverJar() throws IOException {
+ Path jarPath = Files.createTempFile("paimon-jdbc-driver", ".jar");
+ String resourceName = DummyJdbcDriver.class.getName().replace('.',
'/') + ".class";
+ try (JarOutputStream jarOutputStream = new
JarOutputStream(Files.newOutputStream(jarPath));
+ InputStream inputStream =
DummyJdbcDriver.class.getClassLoader().getResourceAsStream(resourceName)) {
+ Assert.assertNotNull(inputStream);
+ jarOutputStream.putNextEntry(new JarEntry(resourceName));
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) >= 0) {
+ jarOutputStream.write(buffer, 0, bytesRead);
+ }
+ jarOutputStream.closeEntry();
+ }
+ return jarPath;
+ }
Review Comment:
`createDriverJar()` creates a temp file but the test never deletes it. In CI
this can accumulate files under the temp directory; consider cleaning it up
(e.g., `try/finally` with `Files.deleteIfExists`, or
`jarPath.toFile().deleteOnExit()`).
##########
fe/be-java-extensions/paimon-scanner/src/test/java/org/apache/doris/paimon/PaimonJdbcDriverUtilsTest.java:
##########
@@ -0,0 +1,119 @@
+// 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.doris.paimon;
+
+import org.apache.doris.common.classloader.JniScannerClassLoader;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.logging.Logger;
+
+public class PaimonJdbcDriverUtilsTest {
+ @Test
+ public void testRegisterDriverIfNeeded() throws Exception {
+ Path driverJar = createDriverJar();
+ Map<String, String> params = new HashMap<>();
+ params.put(PaimonJdbcDriverUtils.PAIMON_JDBC_DRIVER_URL,
driverJar.toUri().toURL().toString());
+ params.put(PaimonJdbcDriverUtils.PAIMON_JDBC_DRIVER_CLASS,
DummyJdbcDriver.class.getName());
+
+ JniScannerClassLoader scannerClassLoader = new
JniScannerClassLoader("paimon-test", List.of(), null);
+ PaimonJdbcDriverUtils.registerDriverIfNeeded(params,
scannerClassLoader);
+
+ Driver driver = DriverManager.getDriver("jdbc:dummy:test");
+ Assert.assertTrue(driver.acceptsURL("jdbc:dummy:test"));
Review Comment:
This test registers a JDBC driver into the global `DriverManager` but never
deregisters it. That can leak global state across tests and lead to
order-dependent failures; consider deregistering the registered driver(s) in a
`finally` block or `@After` hook (and ideally delete the temp JAR as well).
--
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]