Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent jar handling for Local and Remote UDFs #849

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public FileResourceResolver(Path baseDir) {
this.baseDir = baseDir;
}

public Optional<URI> resolve(Path path) {
return Optional.of(path.toFile().toURI());
}

@Override
public String toString() {
return "FileResourceResolver[" + baseDir + ']';
Expand All @@ -51,4 +47,13 @@ public Optional<Path> resolveFile(NamePath namePath) {
}
return Optional.of(path);
}

@Override
public Optional<Path> resolve(Path relativePath) {
Path resolvedPath = baseDir.resolve(relativePath);
if (Files.exists(resolvedPath)) {
return Optional.of(resolvedPath);
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface ResourceResolver {

Optional<Path> resolveFile(NamePath namePath);

Optional<Path> resolve(Path relativePath);

static URL toURL(URI uri) {
try {
return uri.toURL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.datasqrl.util.StringUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
Expand Down Expand Up @@ -180,8 +179,9 @@ private List<NamespaceObject> loadFunction(Path path, NamePath namePath) {
String jarPath = json.get("jarPath").asText();
String functionClassName = json.get("functionClass").asText();

URL jarUrl = new File(jarPath).toURI().toURL();
Class<?> functionClass = loadClass(jarPath, functionClassName);
Optional<Path> resolvedJarPath = resourceResolver.resolve(Path.of(jarPath));
URL jarUrl = resolvedJarPath.get().toUri().toURL();
Class<?> functionClass = loadClass(jarUrl, functionClassName);
Preconditions.checkArgument(UDF_FUNCTION_CLASS.isAssignableFrom(functionClass), "Class is not a UserDefinedFunction");

UserDefinedFunction udf = (UserDefinedFunction) functionClass.getDeclaredConstructor().newInstance();
Expand All @@ -191,8 +191,8 @@ private List<NamespaceObject> loadFunction(Path path, NamePath namePath) {
}

@SneakyThrows
private Class<?> loadClass(String jarPath, String functionClassName) {
URL[] urls = {new File(jarPath).toURI().toURL()};
private Class<?> loadClass(URL jarUrl, String functionClassName) {
URL[] urls = { jarUrl };
URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
return Class.forName(functionClassName, true, classLoader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ private Void processJarEntry(JarEntry entry, JarFile file,
processorContext.addLibrary(path);
}

processorContext.addDependency(path);

return null;
}

/**
* Checks if the jar entry is valid
*/
Expand Down
Loading