XnY-wei commented on code in PR #49836:
URL: https://github.com/apache/doris/pull/49836#discussion_r2199808155
##########
be/src/vec/exec/vjdbc_connector.cpp:
##########
@@ -209,9 +209,11 @@ Status JdbcConnector::query() {
return Status::InternalError("GetJniExceptionMsg meet error,
query={}, msg={}",
_conn_param.query_string,
status.to_string());
}
- if (colunm_count != materialize_num) {
- return Status::InternalError("input and output column num not
equal of jdbc query.");
- }
+ if (colunm_count < materialize_num) {
Review Comment:
Yes, it is possible that column_count is greater than or equal to
materialize_num. In the given SQL example, the SQL query select r_regionkey
from query("catalog" = "hive", "query" = "select r_regionkey, r_name from
dev.region") returns only one column (r_regionkey), but the original query
inside the query() function has two columns (r_regionkey and r_name).
##########
be/src/vec/exec/vjdbc_connector.cpp:
##########
@@ -209,9 +209,11 @@ Status JdbcConnector::query() {
return Status::InternalError("GetJniExceptionMsg meet error,
query={}, msg={}",
_conn_param.query_string,
status.to_string());
}
- if (colunm_count != materialize_num) {
- return Status::InternalError("input and output column num not
equal of jdbc query.");
- }
+ if (colunm_count < materialize_num) {
Review Comment:
Yes, it is possible that column_count is greater than or equal to
materialize_num. In the given SQL example, the SQL query select r_regionkey
from query("catalog" = "hive", "query" = "select r_regionkey, r_name from
dev.region") returns only one column (r_regionkey), but the original query
inside the query() function has two columns (r_regionkey and r_name).
##########
fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java:
##########
@@ -207,32 +208,68 @@ public long getBlockAddress(int batchSize, Map<String,
String> outputParams) thr
if (isNullableString == null || replaceString == null) {
throw new IllegalArgumentException(
- "Output parameters 'is_nullable' and 'replace_string'
are required.");
+ "Output parameters 'is_nullable' and 'replace_string' are
required.");
}
String[] nullableList = isNullableString.split(",");
String[] replaceStringList = replaceString.split(",");
curBlockRows = 0;
- int columnCount = resultSetMetaData.getColumnCount();
- initializeBlock(columnCount, replaceStringList, batchSize,
outputTable);
+ int outputColumnCount = outputTable.getColumns().length;
+ initializeBlock(outputColumnCount, replaceStringList, batchSize,
outputTable);
+
+ Map<String, Integer> resultSetColumnMap = new HashMap<>();
+ int resultSetColumnCount = resultSetMetaData.getColumnCount();
+ for (int i = 1; i <= resultSetColumnCount; i++) {
+ String columnName =
resultSetMetaData.getColumnName(i).trim().toLowerCase();
+ resultSetColumnMap.put(columnName, i);
+ }
+
+ Map<String, Integer> columnIndexMap = new HashMap<>();
+ for (int j = 0; j < outputColumnCount; j++) {
+ String outputColumnName =
outputTable.getFields()[j].trim().toLowerCase();
+ Integer resultSetIndex =
resultSetColumnMap.get(outputColumnName);
+ if (resultSetIndex == null) {
+ throw new RuntimeException("Column not found: " +
outputColumnName);
+ }
+ columnIndexMap.put(outputColumnName, resultSetIndex - 1);
Review Comment:
JDBC’s ResultSet column indices are one-based
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]