mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(improvement)(headless) When performing semantic modeling, support simultaneous querying of both TABLE and VIEW. (#1551)
This commit is contained in:
@@ -10,6 +10,7 @@ import java.sql.DatabaseMetaData;
|
|||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -40,14 +41,19 @@ public abstract class BaseDbAdaptor implements DbAdaptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTables(ConnectInfo connectionInfo, String schemaName) throws SQLException {
|
public List<String> getTables(ConnectInfo connectionInfo, String schemaName) throws SQLException {
|
||||||
List<String> tables = Lists.newArrayList();
|
List<String> tablesAndViews = new ArrayList<>();
|
||||||
DatabaseMetaData metaData = getDatabaseMetaData(connectionInfo);
|
DatabaseMetaData metaData = getDatabaseMetaData(connectionInfo);
|
||||||
ResultSet tableSet = metaData.getTables(schemaName, schemaName, null, new String[]{"TABLE"});
|
|
||||||
while (tableSet.next()) {
|
try (ResultSet resultSet = metaData.getTables(null, schemaName, null,
|
||||||
String tableName = tableSet.getString("TABLE_NAME");
|
new String[]{"TABLE", "VIEW"})) {
|
||||||
tables.add(tableName);
|
while (resultSet.next()) {
|
||||||
|
String name = resultSet.getString("TABLE_NAME");
|
||||||
|
tablesAndViews.add(name);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Failed to get tables and views", e);
|
||||||
}
|
}
|
||||||
return tables;
|
return tablesAndViews;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String schemaName, String tableName) throws SQLException {
|
public List<DBColumn> getColumns(ConnectInfo connectInfo, String schemaName, String tableName) throws SQLException {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.tencent.supersonic.common.pojo.Constants;
|
|||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||||
import com.tencent.supersonic.headless.core.pojo.ConnectInfo;
|
import com.tencent.supersonic.headless.core.pojo.ConnectInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.expression.StringValue;
|
import net.sf.jsqlparser.expression.StringValue;
|
||||||
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class PostgresqlAdaptor extends BaseDbAdaptor {
|
public class PostgresqlAdaptor extends BaseDbAdaptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,14 +79,18 @@ public class PostgresqlAdaptor extends BaseDbAdaptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTables(ConnectInfo connectionInfo, String schemaName) throws SQLException {
|
public List<String> getTables(ConnectInfo connectionInfo, String schemaName) throws SQLException {
|
||||||
List<String> tables = Lists.newArrayList();
|
List<String> tablesAndViews = Lists.newArrayList();
|
||||||
DatabaseMetaData metaData = getDatabaseMetaData(connectionInfo);
|
DatabaseMetaData metaData = getDatabaseMetaData(connectionInfo);
|
||||||
ResultSet tableSet = metaData.getTables(null, null, null, new String[]{"TABLE"});
|
try (ResultSet resultSet = metaData.getTables(null, null, null,
|
||||||
while (tableSet.next()) {
|
new String[]{"TABLE", "VIEW"})) {
|
||||||
String tableName = tableSet.getString("TABLE_NAME");
|
while (resultSet.next()) {
|
||||||
tables.add(tableName);
|
String name = resultSet.getString("TABLE_NAME");
|
||||||
|
tablesAndViews.add(name);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Failed to get tables and views", e);
|
||||||
}
|
}
|
||||||
return tables;
|
return tablesAndViews;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String schemaName, String tableName) throws SQLException {
|
public List<DBColumn> getColumns(ConnectInfo connectInfo, String schemaName, String tableName) throws SQLException {
|
||||||
|
|||||||
Reference in New Issue
Block a user