com.exasol.udfdebugging.PushDownTesting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of udf-debugging-java Show documentation
Show all versions of udf-debugging-java Show documentation
Utilities for debugging, profiling and code coverage measure for UDFs.
The newest version!
package com.exasol.udfdebugging;
import java.io.StringReader;
import java.sql.*;
import jakarta.json.*;
/**
* This class contains helper functions for testing virtual schema push down queries.
*/
public class PushDownTesting {
/**
* Get the push-down SQL query generated by a Virtual Schema adapter call.
*
* @param statement SQL statement
* @param query query to a Virtual Schema table
* @return generated push down query
* @throws SQLException if execution fails
*/
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 + ");")) {
pushDownSqlResult.next();
return pushDownSqlResult.getString("PUSHDOWN_SQL");
}
}
/**
* Get the selection (where clause) that the Exasol database passed to the Virtual Schema adapter.
*
* @param statement SQL statement
* @param query query to a Virtual Schema table
* @return selection (where clause)
* @throws SQLException if SQL statement fails
*/
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 + ");")) {
pushDownSqlResult.next();
final String pushdownJson = pushDownSqlResult.getString("PUSHDOWN_JSON");
try (final JsonReader reader = Json.createReader(new StringReader(pushdownJson))) {
final JsonObject response = reader.readArray().get(2).asJsonObject();
return response.getJsonObject("pushdownRequest").getString("filter_expr_string_for_debug", "");
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy