From a490a366e4f1b8fa17d1643bf54225e13dda6c82 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 29 Dec 2024 22:17:57 +0800 Subject: [PATCH] [improvement](statistics)Support get oracle jdbc row count. (#45214) (#46133) backport: https://github.com/apache/doris/pull/45214 --- .../datasource/jdbc/JdbcExternalTable.java | 5 ++++ .../jdbc/test_jdbc_row_count.groovy | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalTable.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalTable.java index f013891f1bac0a..95c9820a01387d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalTable.java @@ -67,6 +67,9 @@ public class JdbcExternalTable extends ExternalTable { public static final String SQLSERVER_ROW_COUNT_SQL = "SELECT sum(rows) as rows FROM sys.partitions " + "WHERE object_id = (SELECT object_id('${dbName}.${tblName}')) AND index_id IN (0, 1)"; + public static final String ORACLE_ROW_COUNT_SQL = "SELECT NUM_ROWS as \\\"rows\\\" FROM ALL_TABLES WHERE " + + "OWNER = '${dbName}' and TABLE_NAME = '${tblName}'"; + public static final String FETCH_ROW_COUNT_TEMPLATE = "SELECT * FROM QUERY" + "(\"catalog\"=\"${ctlName}\", \"query\"=\"${sql}\");"; @@ -211,6 +214,8 @@ public long fetchRowCount() { params.put("sql", SQLSERVER_ROW_COUNT_SQL); return getRowCount(params); case JdbcResource.ORACLE: + params.put("sql", ORACLE_ROW_COUNT_SQL); + return getRowCount(params); default: break; } diff --git a/regression-test/suites/external_table_p0/jdbc/test_jdbc_row_count.groovy b/regression-test/suites/external_table_p0/jdbc/test_jdbc_row_count.groovy index 576e0be8553f92..8e9ac2cd525947 100644 --- a/regression-test/suites/external_table_p0/jdbc/test_jdbc_row_count.groovy +++ b/regression-test/suites/external_table_p0/jdbc/test_jdbc_row_count.groovy @@ -105,6 +105,36 @@ suite("test_jdbc_row_count", "p0,external,mysql,external_docker,external_docker_ } assertEquals("3", result[0][2]) sql """drop catalog ${catalog_name}""" + + // Test oracle + catalog_name = "test_oracle_jdbc_row_count"; + String oracle_port = context.config.otherConfigs.get("oracle_11_port"); + String SID = "XE"; + driver_url = "https://${bucket}.${s3_endpoint}/regression/jdbc_driver/ojdbc8.jar" + sql """drop catalog if exists ${catalog_name} """ + sql """ + create catalog if not exists ${catalog_name} properties( + "type"="jdbc", + "user"="doris_test", + "password"="123456", + "jdbc_url" = "jdbc:oracle:thin:@${externalEnvIp}:${oracle_port}:${SID}", + "driver_url" = "${driver_url}", + "driver_class" = "oracle.jdbc.driver.OracleDriver" + ); + """ + sql """use ${catalog_name}.DORIS_TEST""" + result = sql """show table stats STUDENT""" + Thread.sleep(1000) + for (int i = 0; i < 30; i++) { + result = sql """show table stats STUDENT"""; + if (result[0][2] != "-1") { + break; + } + logger.info("Table row count not ready yet. Wait 1 second.") + Thread.sleep(1000) + } + assertTrue("4".equals(result[0][2]) || "-1".equals(result[0][2])) + sql """drop catalog ${catalog_name}""" } }