Skip to content
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
1 change: 1 addition & 0 deletions doc/changes/changelog.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions doc/changes/changes_0.6.20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Udf Debugging Java 0.6.20, released 2026-07-16

Code name: Code Coverage > 80%

## Summary

In this release we fixed Sonar findings and raised the code coverage ot over 80%.

We added an integration test for `PushDownTesting`.

## Features

* Fixed Sonar findings and raised test coverage. (PR #86)

2 changes: 1 addition & 1 deletion pk_generated_parent.pom

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>udf-debugging-java</artifactId>
<version>0.6.19</version>
<version>0.6.20</version>
<name>udf-debugging-java</name>
<description>Utilities for debugging, profiling and code coverage measure for UDFs.</description>
<url>https://github.com/exasol/udf-debugging-java/</url>
Expand Down Expand Up @@ -147,7 +147,7 @@
<parent>
<artifactId>udf-debugging-java-generated-parent</artifactId>
<groupId>com.exasol</groupId>
<version>0.6.19</version>
<version>0.6.20</version>
<relativePath>pk_generated_parent.pom</relativePath>
</parent>
</project>
6 changes: 4 additions & 2 deletions src/main/java/com/exasol/udfdebugging/PushDownTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ private PushDownTesting() {
* @return generated push down query
* @throws SQLException if execution fails
*/
@SuppressWarnings("java:S2077") // Constructed SQL only used in tests.
public static String getPushDownSql(final Statement statement, final String query) throws SQLException {
try (final ResultSet pushDownSqlResult = statement
.executeQuery("SELECT PUSHDOWN_SQL FROM (EXPLAIN VIRTUAL " + query + ");")) {
.executeQuery("SELECT PUSHDOWN_SQL FROM (EXPLAIN VIRTUAL " + query + ")")) {
pushDownSqlResult.next();
return pushDownSqlResult.getString("PUSHDOWN_SQL");
}
Expand All @@ -37,10 +38,11 @@ public static String getPushDownSql(final Statement statement, final String quer
* @return selection (where clause)
* @throws SQLException if SQL statement fails
*/
@SuppressWarnings("java:S2077") // Constructed SQL only used in tests.
public static String getSelectionThatIsSentToTheAdapter(final Statement statement, final String query)
throws SQLException {
try (final ResultSet pushDownSqlResult = statement
.executeQuery("SELECT PUSHDOWN_JSON FROM (EXPLAIN VIRTUAL " + query + ");")) {
.executeQuery("SELECT PUSHDOWN_JSON FROM (EXPLAIN VIRTUAL " + query + ")")) {
pushDownSqlResult.next();
final String pushdownJson = pushDownSqlResult.getString("PUSHDOWN_JSON");
try (final JsonReader reader = Json.createReader(new StringReader(pushdownJson))) {
Expand Down
69 changes: 69 additions & 0 deletions src/test/java/com/exasol/udfdebugging/PushDownTestingIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.exasol.udfdebugging;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.jupiter.api.Test;

import com.exasol.udfdebugging.modules.TestSetup;

class PushDownTestingIT {
private static final String VS_SCHEMA = "VS_SCHEMA";
private static final String VS_ADAPTER = VS_SCHEMA + ".VS_ADAPTER";
private static final String VIRTUAL_SCHEMA_NAME = "TEST_VS";
private static final String TABLE_NAME = "THE_TABLE";

private static String loadAdapterScriptContent() {
try (InputStream adapterScriptStream = PushDownTestingIT.class.getClassLoader()
.getResourceAsStream("virtual_schema_stub.lua")) {
if (adapterScriptStream == null) {
throw new AssertionError("Failed to find adapter script resource on the classpath.");
}
return new String(adapterScriptStream.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException exception) {
throw new AssertionError("Failed to read adapter script resource.", exception);
}
}


@Test
void testGetPushDownSqlFromExplainVirtual() throws SQLException {
try (
final TestSetup testSetup = new TestSetup();
final Statement statement = testSetup.getConnection().createStatement()
) {
createVirtualSchema(statement);
final String pushDownSql = PushDownTesting.getPushDownSql(statement,
"SELECT THE_VALUE FROM " + VIRTUAL_SCHEMA_NAME + "." + TABLE_NAME);
assertThat(pushDownSql, equalTo("SELECT 'Hello VS!'"));
}
}

@Test
void testGetSelectionThatIsSentToTheAdapter() throws SQLException {
try (
final TestSetup testSetup = new TestSetup();
final Statement statement = testSetup.getConnection().createStatement()
) {
createVirtualSchema(statement);
final String pushDownSql = PushDownTesting.getSelectionThatIsSentToTheAdapter(statement,
"SELECT THE_VALUE FROM " + VIRTUAL_SCHEMA_NAME + "." + TABLE_NAME
+ " WHERE THE_VALUE = 'something'");
assertThat(pushDownSql, equalTo(TABLE_NAME +".THE_VALUE='something'"));
}
}

private void createVirtualSchema(final Statement statement) throws SQLException {
statement.execute("DROP SCHEMA IF EXISTS " + VS_SCHEMA + "CASCADE");
statement.execute("CREATE SCHEMA " + VS_SCHEMA);
statement.execute("CREATE TABLE ORIGIN_TABLE(THE_VALUE CHAR(9))");
statement.execute("CREATE LUA ADAPTER SCRIPT " + VS_ADAPTER + " AS\n" + loadAdapterScriptContent() + "\n/");
statement.execute("CREATE VIRTUAL SCHEMA " + VIRTUAL_SCHEMA_NAME + " USING " + VS_ADAPTER);
}
}
61 changes: 61 additions & 0 deletions src/test/resources/virtual_schema_stub.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- A minimal Lua virtual schema that allows testing VS interaction.
local cjson = require("cjson");

function report_schema()
return {
schemaMetadata = {
tables = {
{
name = "THE_TABLE",
columns = {
{
name = "THE_VALUE",
dataType = {
type = "CHAR",
size = 9
}
}
}
}
}
}
}
end

function report_capabilities()
return {
capabilities = { "SELECTLIST_PROJECTION", "FILTER_EXPRESSIONS", "FN_PRED_EQUAL", "LITERAL_STRING" }
}
end

function pushdown(request)
if (request.filter == nil) then
return {
type = "select",
sql = "SELECT 'Hello VS!'"
}
else
return {
type = "select",
sql = "SELECT 'Hello VS!' FROM VS_SCHEMA.ORIGIN_TABLE WHERE THE_VALUE = 'something'"
}
end
end

function adapter_call(request_as_json)
local request = cjson.decode(request_as_json)
local response;
if request.type == "createVirtualSchema" or request.type == "refresh" then
response = report_schema()
elseif request.type == "dropVirtualSchema" or request.type == "setProperties" then
response = {}
elseif request.type == "getCapabilities" then
response = report_capabilities()
elseif request.type == "pushdown" then
response = pushdown(request.pushdownRequest)
else
error("Unsupported adapter request: " .. (request.type or "'nil'"))
end
response.type = request.type
return cjson.encode(response)
end