Skip to content

Commit

Permalink
[improvement](statistics)Support get oracle jdbc row count. (#45214) (#…
Browse files Browse the repository at this point in the history
…46133)

backport: #45214
  • Loading branch information
Jibing-Li authored Dec 29, 2024
1 parent 6dd92be commit a490a36
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}\");";

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"""
}
}

0 comments on commit a490a36

Please sign in to comment.