From 8599b0ed70811f630a5ef82517bf4b1886111788 Mon Sep 17 00:00:00 2001 From: Pat Buxton Date: Sun, 7 Jul 2024 16:28:49 +0100 Subject: [PATCH 1/4] Just match RegEx in full string "Databend Query vx.y.zzz" --- .../databend/jdbc/DatabendDatabaseMetaData.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java index dbb09715..70425cd9 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java @@ -1333,14 +1333,9 @@ public int getResultSetHoldability() throws SQLException { public int getDatabaseMajorVersion() throws SQLException { String version = getDatabaseProductVersion(); - // split by empty space - String[] versionArray = version.split(" "); - if (versionArray.length < 2) { - return -1; - } // regex matching v%d.%d.%d Pattern pattern = Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)"); - Matcher matcher = pattern.matcher(versionArray[1]); + Matcher matcher = pattern.matcher(version); if (matcher.find()) { return 10 * Integer.parseInt(matcher.group(1)) + Integer.parseInt(matcher.group(2)); } @@ -1352,14 +1347,9 @@ public int getDatabaseMajorVersion() public int getDatabaseMinorVersion() throws SQLException { String version = getDatabaseProductVersion(); - // split by empty space - String[] versionArray = version.split(" "); - if (versionArray.length < 2) { - return -1; - } // regex matching v%d.%d.%d Pattern pattern = Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)"); - Matcher matcher = pattern.matcher(versionArray[1]); + Matcher matcher = pattern.matcher(version); if (matcher.find()) { return Integer.parseInt(matcher.group(3)); } From 762418515ee9c2f7ece65623d46e6283f8f5e0a4 Mon Sep 17 00:00:00 2001 From: Pat Buxton Date: Mon, 8 Jul 2024 09:22:23 +0100 Subject: [PATCH 2/4] Adjust tests for Product Version --- .../jdbc/TestDatabendDatabaseMetaData.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java index 2454a45f..1b0987b8 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java @@ -86,14 +86,23 @@ public void testGetUrl() throws SQLException { } @Test(groups = {"IT"}) - public void testGetDatabaseProductVersion() + public void testGetDatabaseProductName() throws Exception { try (Connection connection = createConnection()) { DatabaseMetaData metaData = connection.getMetaData(); assertEquals(metaData.getDatabaseProductName(), "Databend"); - StringBuilder sb = new StringBuilder(); - sb.append(metaData.getDatabaseMinorVersion()); - Assert.assertTrue(metaData.getDatabaseProductVersion().contains(sb.toString())); + } + } + + @Test(groups = {"IT"}) + public void testGetDatabaseProductVersion() + throws Exception { + try (Connection connection = createConnection()) { + DatabaseMetaData metaData = connection.getMetaData(); + float majorVersion = (float)metaData.getDatabaseMajorVersion() / 10; + int minorVersion = metaData.getDatabaseMinorVersion(); + String checkVersion = String.format("v%.1f.%d", majorVersion, minorVersion); + Assert.assertTrue(metaData.getDatabaseProductVersion().contains(checkVersion)); } } From 4c9bdaae382dee7b5448077847e7ead99d79ef3d Mon Sep 17 00:00:00 2001 From: Pat Buxton Date: Mon, 8 Jul 2024 13:06:52 +0100 Subject: [PATCH 3/4] Fix getFunctions --- .../jdbc/DatabendDatabaseMetaData.java | 2 +- .../jdbc/TestDatabendDatabaseMetaData.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java index 70425cd9..288ab298 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java @@ -1440,7 +1440,7 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct " name as FUNCTION_NAME, " + " description as REMARKS, " + " 1 as FUNCTION_TYPE, " + - " name as SPECIFIC_NAME" + + " name as SPECIFIC_NAME " + "FROM system.functions"); List filters = new ArrayList<>(); optionalStringLikeFilter(filters, "function_name", functionNamePattern); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java index 1b0987b8..ab16102b 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java @@ -261,4 +261,32 @@ public void testTableTypes() throws Exception { } } } + + @Test(groups = {"IT"}) + public void testGetFunctions() throws Exception { + try (Connection connection = createConnection()) { + try (ResultSet rs = connection.getMetaData().getFunctions(null, null, "abs")) { + ResultSetMetaData metadata = rs.getMetaData(); + assertEquals(metadata.getColumnCount(), 6); + + assertEquals(metadata.getColumnLabel(1).toUpperCase(Locale.US), "FUNCTION_CAT"); + assertEquals(metadata.getColumnType(1), Types.VARCHAR); + + assertEquals(metadata.getColumnLabel(2).toUpperCase(Locale.US), "FUNCTION_SCHEMA"); + assertEquals(metadata.getColumnType(2), Types.VARCHAR); + + assertEquals(metadata.getColumnLabel(3).toUpperCase(Locale.US), "FUNCTION_NAME"); + assertEquals(metadata.getColumnType(3), Types.VARCHAR); + + assertEquals(metadata.getColumnLabel(4).toUpperCase(Locale.US), "REMARKS"); + assertEquals(metadata.getColumnType(4), Types.VARCHAR); + + assertEquals(metadata.getColumnLabel(5).toUpperCase(Locale.US), "FUNCTION_TYPE"); + assertEquals(metadata.getColumnType(5), Types.TINYINT); + + assertEquals(metadata.getColumnLabel(6).toUpperCase(Locale.US), "SPECIFIC_NAME"); + assertEquals(metadata.getColumnType(6), Types.VARCHAR); + } + } + } } From 040e8c8bebbbd26a1e792597f92772efaa8044b0 Mon Sep 17 00:00:00 2001 From: Pat Buxton Date: Tue, 9 Jul 2024 13:43:11 +0100 Subject: [PATCH 4/4] Fix github test workflow warnings --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14becf10..635a0ce2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,12 +30,12 @@ jobs: - 9000:9000 steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17'