This is an automated email from the ASF dual-hosted git repository.

lijibing pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 323fa12c0f9 branch-3.0: [improvement](statistics)Support get oracle 
jdbc row count. #45214 (#45226)
323fa12c0f9 is described below

commit 323fa12c0f95cf904390293584a22e0aae9d03da
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 10 17:37:22 2024 +0800

    branch-3.0: [improvement](statistics)Support get oracle jdbc row count. 
#45214 (#45226)
    
    Cherry-picked from #45214
    
    Co-authored-by: James <lijib...@selectdb.com>
---
 .../doris/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 9e188a711b0..772c366850b 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
@@ -63,6 +63,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}\");";
 
@@ -144,6 +147,8 @@ public class JdbcExternalTable extends ExternalTable {
                 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 5cb1f6267e3..c8220ce13dd 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
@@ -102,6 +102,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}"""
     }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to