Skip to content

Commit

Permalink
[Fix] catalog queries fenodes compatibility (apache#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
JNSimba authored Dec 26, 2023
1 parent 9f75f59 commit f658c61
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -239,8 +240,20 @@ protected String queryFenodes() {
StringJoiner fenodes = new StringJoiner(",");
PreparedStatement ps = conn.prepareStatement("SHOW FRONTENDS");
ResultSet resultSet = ps.executeQuery();

// find target ip column name, Version 1.2 is IP, version 2.x is Host
String field = "";
ResultSetMetaData metaData = resultSet.getMetaData();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i);
if (columnName.equalsIgnoreCase("IP") || columnName.equalsIgnoreCase("Host")) {
field = columnName;
break;
}
}

while (resultSet.next()) {
String ip = resultSet.getString("IP");
String ip = resultSet.getString(field);
String port = resultSet.getString("HttpPort");
fenodes.add(ip + ":" + port);
}
Expand Down

0 comments on commit f658c61

Please sign in to comment.