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

Add integration JDBC tests for cursor/fetch_size feature. #208

Merged
merged 6 commits into from
Feb 2, 2023

Conversation

Yury-Fridlyand
Copy link

@Yury-Fridlyand Yury-Fridlyand commented Jan 20, 2023

Signed-off-by: Yury-Fridlyand [email protected]

Description

Add new IT suite which uses JDBC to issue queries with and without fetch_size set.
fetch_size parameter invokes pagination feature (cursor) which is currently supported by legacy engine only.

New :integ-test tasks:

integJdbcTest

Run ITs from **/jdbc/*.java. Existing tests in CursorIT create and use DB connection using JDBC driver from maven artifact.

Optional parameters:

  • -Dtest.debug
    Enabled test debug.
  • --tests '<test_filter>
    Filter test using wildcard, could be specified multiple times.
  • -DjdbcDriverVersion=<version>
    Maven artifact version for JDBC driver to use; optional, defaulted to 1.2.0.0.

Test cluster log located in integ-test/build/testclusters/integJdbcTest-0/logs/integJdbcTest.log
Test report saved in integ-test/build/reports/tests/integJdbcTest

integDevJdbcTest

Run ITs from **/devJdbc/*.java. Existing tests in CursorIT create and use DB connection using JDBC driver from source code or existing binary.

Optional parameters:

  • -Dtest.debug
    Enabled test debug.
  • --tests '<test_filter>
    Filter test using wildcard, could be specified multiple times.
  • -DjdbcFile=<file>
    JDBC driver compiled binary (*.jar); if given, workflow uses it and ignores jdbcRepo and jdbcBranch parameters described below.
  • -DjdbcRepo=<repo_path>
    JDBC driver repo to checkout and build from; uses https://github.com/opensearch-project/sql by default.
  • -DjdbcBranch=<branch>
    Repository branch to pick code from; uses main by default.

Test cluster log located in integ-test/build/testclusters/integDevJdbcTest-0/logs/integDevJdbcTest.log
Test report saved in integ-test/build/reports/tests/integDevJdbcTest

Examples:

./gradlew :integ-test:integJdbcTest :integ-test:integDevJdbcTest

./gradlew :integ-test:integDevJdbcTest '-DjdbcFile=/mnt/c/GitHub/sql-jdbc/build/libs/opensearch-sql-jdbc-2.0.0.0.jar'

./gradlew :integ-test:integDevJdbcTest '-DjdbcRepo=https://github.com/Bit-Quill/sql-jdbc' '-DjdbcBranch=dev-feature-fix'

Output sample:

> Task :integ-test:integJdbcTest
org.opensearch.sql.jdbc.CursorIT.select_count_all_no_cursor(): SUCCESS 19.634s

CursorIT > select count all no cursor PASSED
org.opensearch.sql.jdbc.CursorIT.select_all_big_table_small_cursor(): SUCCESS 8.738s

CursorIT > select all big table small cursor PASSED
org.opensearch.sql.jdbc.CursorIT.select_all_small_table_small_cursor(): SUCCESS 0.238s

CursorIT > select all small table small cursor PASSED
org.opensearch.sql.jdbc.CursorIT.select_all_no_cursor(): SUCCESS 4.163s

CursorIT > select all no cursor PASSED
org.opensearch.sql.jdbc.CursorIT.select_all_small_table_big_cursor(): SUCCESS 0.132s

CursorIT > select all small table big cursor PASSED
org.opensearch.sql.jdbc.CursorIT.select_all_big_table_big_cursor(): SUCCESS 3.398s

CursorIT > select all big table big cursor PASSED

> Task :integ-test:integDevJdbcTest
org.opensearch.sql.devJdbc.CursorIT.dev_select_all_small_table_small_cursor(): SUCCESS 20.008s

CursorIT > dev_select_all_small_table_small_cursor() PASSED

Notes

Test filter in gradle

filter {
includeTestsMatching '*.jdbc.*'
}

requires

and doesn't work with JUnit 4. All IT framework uses Junit 4.
So, init() method of test classed isn't being called from superclasses automatically.
@BeforeAll/@BeforeClass require a static method, so I can't call initClient() there. I have to move initClient() to @BeforeEach with initialized flag.

New gradle tasks are not included into CI workflow.

Issues Resolved

N/A

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

What's the difference between small table and big table?

@Yury-Fridlyand
Copy link
Author

What's the difference between small table and big table?

calcs: 17 lines
bank: 7
account: 1k
online: 10k

@codecov

This comment was marked as spam.

@AfterClass
@SneakyThrows
public static void closeConnection() {
// TODO should we close Statement and ResultSet?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this answered or was this left on purpose for us to see?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not answered
I suppose we can leave things unclosed in tests.

integ-test/build.gradle Outdated Show resolved Hide resolved
file("sql-jdbc").deleteDir()
}

task cloneJdbcDriverRepo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
task cloneJdbcDriverRepo {
task jdbcShadowJarFromRepo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better yet, separate clone from build so that we don't need to delete/download the JDBC driver from repo each and every time.

Copy link
Author

@Yury-Fridlyand Yury-Fridlyand Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was your requirement to run tests on in-development JDBC driver. Note, this executed in :integ-test:integDevJdbcTest gradle task only if jdbcFile parameter not given. This gradle task is not a part of build or :integ-test:integTest tasks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I just think those two tasks could be split into separate tasks rather than having to download + build... in case the build fails.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a suggestion I think at this point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b817f4


exec {
// clone the sql-jdbc repo locally
commandLine 'git', 'clone', System.getProperty('jdbcRepo', 'https://github.com/opensearch-project/sql-jdbc.git')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also get a system property for sql-jdbc branch (System.getProperty("jdbcBranch", 'main'))?
That being said... don't default to main, you are assuming that main is the default branch in the repo, but that's defined by the repo and will download the default branch for you if you don't include --branch

git clone --branch <branchname> <remote-repo-url>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 482da6b

}
exec {
workingDir 'sql-jdbc'
commandLine 'git', 'switch', System.getProperty("jdbcBranch", 'main')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove to just clone the appropriate branch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 482da6b

}

filter {
includeTestsMatching '*.devJdbc.*'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this just one or two files...?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one file as of now, but I assume there would be more files in future.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should specify a project, like org.opensearch.sql.devJdbc.*

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d847404

@@ -406,4 +528,6 @@ task integTestRemote(type: RestIntegTestTask) {
exclude 'org/opensearch/sql/legacy/TermQueryExplainIT.class'
exclude 'org/opensearch/sql/legacy/QueryAnalysisIT.class'
exclude 'org/opensearch/sql/legacy/OrderIT.class'
exclude '**/jdbc/**'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd include the root directory structure... like

org/opensearch/sql/jdbc/**
org/opensearch/sql/devJdbc/**

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 482da6b

@@ -214,6 +326,10 @@ task comparisonTest(type: RestIntegTestTask) {
exclude 'org/opensearch/sql/ppl/**/*IT.class'
exclude 'org/opensearch/sql/legacy/**/*IT.class'

// Exclude JDBC related tests
exclude '**/jdbc/**'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd include the root directory structure... like

org/opensearch/sql/jdbc/**
org/opensearch/sql/devJdbc/**

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 482da6b

@@ -192,10 +297,17 @@ integTest {

// Skip this IT because all assertions are against explain output
exclude 'org/opensearch/sql/legacy/OrderIT.class'

// Exclude JDBC related tests
exclude '**/jdbc/**'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd include the root directory structure... like

org/opensearch/sql/jdbc/**
org/opensearch/sql/devJdbc/**

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 482da6b

@BeforeEach
@SneakyThrows
public void init() {
if (!initialized) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this under the @BeforeAll below?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I call initClient from init, which can't be called from a static method. @BeforeAll requires method to be static.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do

if (client() == null) {
      initClient();
    }

like the other classes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initClient doesn't work in a static context

Copy link

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yury-Fridlyand Could you split the integration tests from the build changes?

The integration tests look good, but support for a custom JDBC driver can be done in more standard way.

After applying the diffs below, you'll be able to use a custom JDBC driver by building it with ./gradlew publishToMavenLocal -Pversion=1.13.0-MAXSPECIAL
and then using 1.13.0-MAXSPECIAL in integration tests by running ./gradlew :integTest:build -Pjdbc_driver_version=1.99.0-MAXSPECIAL

This would also support snapshot builds of JDBC driver if OpenSearch project ever provides them.

The above requires this change to sqj-jdbc:

diff --git a/build.gradle b/build.gradle
index 436cad3..b91f7de 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,9 +24,6 @@ plugins {

 group 'org.opensearch.driver'

-// keep version in sync with version in Driver source
-version '1.2.0.0'
-
 boolean snapshot = "true".equals(System.getProperty("build.snapshot", "false"));
 if (snapshot) {
     version += "-SNAPSHOT"

and this change to sql:

diff --git a/gradle.properties b/gradle.properties
index 5cf428415..81338cd21 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,4 +3,5 @@
 # SPDX-License-Identifier: Apache-2.0

 version=1.13.0
+jdbc_driver_version=1.2.0.0
 org.gradle.jvmargs=-Duser.language=en -Duser.country=US
diff --git a/integ-test/build.gradle b/integ-test/build.gradle
index c948dc77c..fc04f66f8 100644
--- a/integ-test/build.gradle
+++ b/integ-test/build.gradle
@@ -80,7 +80,7 @@ dependencies {
     testImplementation group: 'org.opensearch.test', name: 'framework', version: "${opensearch_version}"
     testImplementation group: 'org.opensearch.client', name: 'opensearch-rest-high-level-client', version: "${opensearch_version}"
     testImplementation group: 'org.opensearch.client', name: 'opensearch-rest-client', version: "${opensearch_version}"
-    testImplementation group: 'org.opensearch.driver', name: 'opensearch-sql-jdbc', version: '1.2.0.0'
+    testImplementation group: 'org.opensearch.driver', name: 'opensearch-sql-jdbc', version: "${jdbc_driver_version}"
     testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
     implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.17.1'
     testImplementation project(':opensearch-sql-plugin')

@Yury-Fridlyand
Copy link
Author

Fixed in e9df987.
I slightly modified your idea. It works fine even without JDBC changes.
Prepend -DjdbcDriverVersion=<version> to :integ-test command line.

file("sql-jdbc").deleteDir()
}

task cloneJdbcDriverRepo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I just think those two tasks could be split into separate tasks rather than having to download + build... in case the build fails.

file("sql-jdbc").deleteDir()
}

task cloneJdbcDriverRepo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a suggestion I think at this point.

}

filter {
includeTestsMatching '*.devJdbc.*'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should specify a project, like org.opensearch.sql.devJdbc.*

@BeforeEach
@SneakyThrows
public void init() {
if (!initialized) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do

if (client() == null) {
      initClient();
    }

like the other classes.

@Yury-Fridlyand Yury-Fridlyand merged commit 07fcd30 into integ-it-pagination-jdbc Feb 2, 2023
@Yury-Fridlyand Yury-Fridlyand deleted the dev-it-pagination-jdbc branch February 2, 2023 17:47
Yury-Fridlyand added a commit that referenced this pull request Mar 3, 2023
* Add integration JDBC tests for cursor/fetch_size feature.

Signed-off-by: Yury-Fridlyand <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants