morningman commented on code in PR #49836:
URL: https://github.com/apache/doris/pull/49836#discussion_r2032315426
##########
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:
why `resultSetIndex - 1`, add comment in code to explain.
Better give an example
##########
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);
+ }
do {
- for (int i = 0; i < columnCount; ++i) {
- ColumnType type = outputTable.getColumnType(i);
- block.get(i)[curBlockRows] = getColumnValue(i, type,
replaceStringList);
+ for (int j = 0; j < outputTable.getColumns().length; ++j) {
Review Comment:
```suggestion
for (int j = 0; j < outputColumnCount; ++j) {
```
##########
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);
+ }
do {
- for (int i = 0; i < columnCount; ++i) {
- ColumnType type = outputTable.getColumnType(i);
- block.get(i)[curBlockRows] = getColumnValue(i, type,
replaceStringList);
+ for (int j = 0; j < outputTable.getColumns().length; ++j) {
+ String outputColumnName = outputTable.getFields()[j];
+ Integer columnIndex = columnIndexMap.get(outputColumnName);
+
+ if (columnIndex != null) {
+ ColumnType type = outputTable.getColumnType(j);
+ block.get(j)[curBlockRows] =
getColumnValue(columnIndex, type, replaceStringList);
+ } else {
+ throw new RuntimeException("Column not found in result
set: " + outputColumnName);
+ }
}
curBlockRows++;
} while (curBlockRows < batchSize && resultSet.next());
- for (int i = 0; i < columnCount; ++i) {
- ColumnType type = outputTable.getColumnType(i);
- Object[] columnData = block.get(i);
- Class<?> componentType =
columnData.getClass().getComponentType();
- Object[] newColumn = (Object[])
Array.newInstance(componentType, curBlockRows);
- System.arraycopy(columnData, 0, newColumn, 0, curBlockRows);
- boolean isNullable = Boolean.parseBoolean(nullableList[i]);
- outputTable.appendData(i, newColumn, getOutputConverter(type,
replaceStringList[i]), isNullable);
+ for (int j = 0; j < outputTable.getColumns().length; ++j) {
Review Comment:
```suggestion
for (int j = 0; j < outputColumnCount; ++j) {
```
##########
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:
Is it possible that `colunm_count > materialize_num`?
How to handle that?
##########
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;
Review Comment:
why `outputTable.getColumns().length` is different from
`resultSetMetaData.getColumnCount()`
--
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]