From f658c6149e6d567c5c1d5aa36281f4b4b59fde08 Mon Sep 17 00:00:00 2001 From: wudi <676366545@qq.com> Date: Tue, 26 Dec 2023 15:57:03 +0800 Subject: [PATCH] [Fix] catalog queries fenodes compatibility (#281) --- .../apache/doris/flink/catalog/DorisCatalog.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flink-doris-connector/src/main/java/org/apache/doris/flink/catalog/DorisCatalog.java b/flink-doris-connector/src/main/java/org/apache/doris/flink/catalog/DorisCatalog.java index a6535cd51..99ca0a4f5 100644 --- a/flink-doris-connector/src/main/java/org/apache/doris/flink/catalog/DorisCatalog.java +++ b/flink-doris-connector/src/main/java/org/apache/doris/flink/catalog/DorisCatalog.java @@ -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; @@ -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); }