From d8683efe20e0f5ac59add67c26cf3367c793f001 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 6 Jun 2023 19:45:29 -0700 Subject: [PATCH 1/2] Update `SHOW` and `DESCRIBE` queries. Signed-off-by: Yury-Fridlyand --- .../java/org/opensearch/jdbc/DatabaseMetaDataImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java b/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java index 8115ff8..0e2ef30 100644 --- a/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java +++ b/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java @@ -671,12 +671,12 @@ public ResultSet getProcedureColumns(String catalog, String schemaPattern, Strin @Override public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { - // TODO - when server plugin supports PreparedStatement fully, implement this as a preparedStatment with params + // TODO - when server plugin supports PreparedStatement fully, implement this as a preparedStatement with params log.debug(() -> logMessage("getTables(%s, %s, %s, %s)", catalog, schemaPattern, tableNamePattern, Arrays.toString(types))); - PreparedStatement pst = connection.prepareStatement("SHOW TABLES LIKE " + - (tableNamePattern == null ? "%" : tableNamePattern)); + PreparedStatement pst = connection.prepareStatement("SHOW TABLES LIKE '" + + (tableNamePattern == null ? "%" : tableNamePattern) + "'"); ResultSet resultSet = pst.executeQuery(); @@ -1207,8 +1207,8 @@ static class ColumnMetadataStatement extends PreparedStatementImpl { ColumnMetadataStatement(ConnectionImpl connection, String tableNamePattern, String columnNamePattern, Logger log) throws SQLException { // TODO - once sql plugin supports PreparedStatement fully, do this through a preparedStatement with params - super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern + - (columnNamePattern != null ? (" COLUMNS LIKE " + columnNamePattern) : ""), + super(connection, "DESCRIBE TABLES LIKE '" + tableNamePattern + + (columnNamePattern != null ? (" COLUMNS LIKE '" + columnNamePattern + "'") : "'"), log); } From e4a45461ccd9ac40b61d55e8914f691d14784f7a Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 7 Jun 2023 12:26:50 -0700 Subject: [PATCH 2/2] Fix a typo and update tests. Signed-off-by: Yury-Fridlyand --- src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java | 2 +- src/test/java/org/opensearch/jdbc/DatabaseMetaDataTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java b/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java index 0e2ef30..0dc6f97 100644 --- a/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java +++ b/src/main/java/org/opensearch/jdbc/DatabaseMetaDataImpl.java @@ -1208,7 +1208,7 @@ static class ColumnMetadataStatement extends PreparedStatementImpl { throws SQLException { // TODO - once sql plugin supports PreparedStatement fully, do this through a preparedStatement with params super(connection, "DESCRIBE TABLES LIKE '" + tableNamePattern + - (columnNamePattern != null ? (" COLUMNS LIKE '" + columnNamePattern + "'") : "'"), + (columnNamePattern != null ? ("' COLUMNS LIKE '" + columnNamePattern + "'") : "'"), log); } diff --git a/src/test/java/org/opensearch/jdbc/DatabaseMetaDataTests.java b/src/test/java/org/opensearch/jdbc/DatabaseMetaDataTests.java index ace0bd7..bce19a6 100644 --- a/src/test/java/org/opensearch/jdbc/DatabaseMetaDataTests.java +++ b/src/test/java/org/opensearch/jdbc/DatabaseMetaDataTests.java @@ -364,7 +364,7 @@ void testGetColumnsWithoutColumnNamePattern() throws Exception { Connection con = getMockConnection(); ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", null, NoOpLogger.INSTANCE); - assertEquals("DESCRIBE TABLES LIKE TABLE_%", stmt.sql); + assertEquals("DESCRIBE TABLES LIKE 'TABLE_%'", stmt.sql); assertDoesNotThrow(stmt::close); } @@ -373,7 +373,7 @@ void testGetColumnsWithColumnNamePattern() throws Exception { Connection con = getMockConnection(); ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", "COLUMN_%", NoOpLogger.INSTANCE); - assertEquals("DESCRIBE TABLES LIKE TABLE_% COLUMNS LIKE COLUMN_%", stmt.sql); + assertEquals("DESCRIBE TABLES LIKE 'TABLE_%' COLUMNS LIKE 'COLUMN_%'", stmt.sql); assertDoesNotThrow(stmt::close); }