mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
(fix)(headless)Add null handling to avoid NPEs.
This commit is contained in:
@@ -5,7 +5,6 @@ import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.FieldType;
|
||||
import com.tencent.supersonic.headless.core.pojo.ConnectInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -148,7 +147,8 @@ public abstract class BaseDbAdaptor implements DbAdaptor {
|
||||
String url = connectionInfo.getUrl().toLowerCase();
|
||||
|
||||
// 设置通用属性
|
||||
properties.setProperty("user", connectionInfo.getUserName());
|
||||
String userName = Optional.ofNullable(connectionInfo.getUserName()).orElse("");
|
||||
properties.setProperty("user", userName);
|
||||
|
||||
|
||||
String password = Optional.ofNullable(connectionInfo.getPassword()).orElse("");
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
public class DuckdbAdaptor extends DefaultDbAdaptor {
|
||||
@@ -23,7 +24,7 @@ public class DuckdbAdaptor extends DefaultDbAdaptor {
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = Lists.newArrayList();
|
||||
DatabaseMetaData metaData = getDatabaseMetaData(connectInfo);
|
||||
ResultSet columns = metaData.getColumns(schemaName, null, tableName, null);
|
||||
ResultSet columns = metaData.getColumns(null, schemaName, tableName, null);
|
||||
while (columns.next()) {
|
||||
String columnName = columns.getString("COLUMN_NAME");
|
||||
String dataType = columns.getString("TYPE_NAME");
|
||||
@@ -42,4 +43,9 @@ public class DuckdbAdaptor extends DefaultDbAdaptor {
|
||||
return sql.replaceAll("`", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getProperties(ConnectInfo connectionInfo) {
|
||||
return new Properties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public class DataModelNode extends SemanticNode {
|
||||
&& !dataModel.getModelDetail().getSqlQuery().isEmpty()) {
|
||||
sqlTable = dataModel.getModelDetail().getSqlQuery();
|
||||
// if model has sqlVariables, parse sqlVariables
|
||||
if (Objects.nonNull(dataModel.getModelDetail().getSqlVariables()) &&
|
||||
!(CollectionUtils.isEmpty(dataModel.getModelDetail().getSqlVariables()))) {
|
||||
if (Objects.nonNull(dataModel.getModelDetail().getSqlVariables())
|
||||
&& !(CollectionUtils.isEmpty(dataModel.getModelDetail().getSqlVariables()))) {
|
||||
sqlTable = SqlVariableParseUtils.parse(sqlTable,
|
||||
dataModel.getModelDetail().getSqlVariables(), Lists.newArrayList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user