use of com.dtstack.dtcenter.loader.client.IClient in project Taier by DTStack.
the class JdbcServiceImpl method getAllDataBases.
@Override
public List<String> getAllDataBases(Long clusterId, EComponentType eComponentType, String schema) {
ISourceDTO iSourceDTO = Engine2DTOService.getByClusterId(clusterId, eComponentType, schema);
IClient client = ClientCache.getClient(iSourceDTO.getSourceType());
LOGGER.info("集群查询底层获取所有数据库名称,clusterId:{},eComponentType:{},schema:{}", clusterId, eComponentType.getTypeCode(), schema);
List<String> allDatabases = client.getAllDatabases(iSourceDTO, SqlQueryDTO.builder().build());
return allDatabases;
}
use of com.dtstack.dtcenter.loader.client.IClient in project Taier by DTStack.
the class JdbcServiceImpl method getTableList.
@Override
public List<String> getTableList(Long tenantId, EScheduleJobType eScheduleJobType, String schema) {
ISourceDTO iSourceDTO = Engine2DTOService.get(tenantId, null, eScheduleJobType, schema);
IClient client = ClientCache.getClient(iSourceDTO.getSourceType());
List<String> tableList = client.getTableList(iSourceDTO, SqlQueryDTO.builder().build());
LOGGER.info("集群查询底层获取所有表名称,tenantId:{},jobType:{},schema:{}", tenantId, eScheduleJobType.getType(), schema);
return tableList;
}
use of com.dtstack.dtcenter.loader.client.IClient in project Taier by DTStack.
the class JdbcServiceImpl method executeQueryWithVariables.
/**
* 执行查询
* @param tenantId
* @param userId
* @param eScheduleJobType
* @param schema
* @param sql
* @param variables
* @param connection
* @return
*/
@Override
public List<List<Object>> executeQueryWithVariables(Long tenantId, Long userId, EScheduleJobType eScheduleJobType, String schema, String sql, List<String> variables, Connection connection) {
List<List<Object>> returnList = new ArrayList<>();
JdbcInfo jdbcInfo = Engine2DTOService.getJdbcInfo(tenantId, userId, eScheduleJobType);
DataSourceType dataSourceType = Engine2DTOService.jobTypeTransitionDataSourceType(eScheduleJobType, jdbcInfo.getVersion());
ISourceDTO iSourceDTO = Engine2DTOService.get(tenantId, userId, dataSourceType.getVal(), schema, jdbcInfo);
IClient client = ClientCache.getClient(iSourceDTO.getSourceType());
List<Map<String, Object>> list = null;
iSourceDTO.setConnection(connection);
// 处理 variables SQL
if (CollectionUtils.isNotEmpty(variables)) {
variables.forEach(variable -> client.executeSqlWithoutResultSet(iSourceDTO, SqlQueryDTO.builder().sql(variable).limit(jdbcInfo.getMaxRows()).queryTimeout(jdbcInfo.getQueryTimeout()).build()));
list = client.executeQuery(iSourceDTO, SqlQueryDTO.builder().sql(sql).limit(jdbcInfo.getMaxRows()).queryTimeout(jdbcInfo.getQueryTimeout()).build());
} else {
list = client.executeQuery(iSourceDTO, SqlQueryDTO.builder().sql(sql).limit(jdbcInfo.getMaxRows()).queryTimeout(jdbcInfo.getQueryTimeout()).build());
}
LOGGER.info("集群执行SQL查询,tenantId:{},userId:{},jobType:{},schema:{},sql:{}", tenantId, userId, eScheduleJobType.getType(), schema, sql);
// 数据源插件化 查询出值不符合要求 进行转化
if (CollectionUtils.isNotEmpty(list)) {
List<Object> column = new ArrayList<>();
list.get(0).keySet().stream().forEach(bean -> {
column.add(bean);
});
returnList.add(column);
for (Map<String, Object> result : list) {
List<Object> value = new ArrayList<>();
result.values().forEach(bean -> {
value.add(bean);
});
returnList.add(value);
}
}
return returnList;
}
use of com.dtstack.dtcenter.loader.client.IClient in project Taier by DTStack.
the class DatasourceService method tablelist.
/**
* 数据同步-获得数据库中相关的表信息
*
* @param sourceId 数据源id
* @param schema 查询的schema
* @param name 模糊查询表名
* @return
*/
public List<String> tablelist(Long sourceId, String schema, String name) {
List<String> tables = new ArrayList<>();
BatchDataSource source = getOne(sourceId);
String dataJson = source.getDataJson();
JSONObject json = JSON.parseObject(dataJson);
// 查询的db
String dataSource = schema;
IClient client = ClientCache.getClient(source.getType());
ISourceDTO sourceDTO = SourceDTOType.getSourceDTO(json, source.getType(), fillKerberosConfig(source.getId()), Maps.newHashMap());
SqlQueryDTO sqlQueryDTO = SqlQueryDTO.builder().tableNamePattern(name).limit(5000).build();
sqlQueryDTO.setView(true);
sqlQueryDTO.setSchema(dataSource);
// 如果是hive类型的数据源 过滤脏数据表 和 临时表
tables = client.getTableList(sourceDTO, sqlQueryDTO);
return tables;
}
use of com.dtstack.dtcenter.loader.client.IClient in project Taier by DTStack.
the class DatasourceService method getAllSchemas.
/**
* 获取所有schema
* @param sourceId 数据源id
* @return
*/
public List<String> getAllSchemas(Long sourceId, String schema) {
BatchDataSource source = getOne(sourceId);
String dataJson = source.getDataJson();
JSONObject json = JSON.parseObject(dataJson);
ISourceDTO sourceDTO = SourceDTOType.getSourceDTO(json, source.getType(), fillKerberosConfig(sourceId), Maps.newHashMap());
IClient client = ClientCache.getClient(source.getType());
return client.getAllDatabases(sourceDTO, SqlQueryDTO.builder().schema(schema).build());
}
Aggregations