Search in sources :

Example 16 with IClient

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;
}
Also used : IClient(com.dtstack.dtcenter.loader.client.IClient) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Example 17 with IClient

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;
}
Also used : IClient(com.dtstack.dtcenter.loader.client.IClient) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Example 18 with IClient

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;
}
Also used : ArrayList(java.util.ArrayList) IClient(com.dtstack.dtcenter.loader.client.IClient) DataSourceType(com.dtstack.dtcenter.loader.source.DataSourceType) ArrayList(java.util.ArrayList) List(java.util.List) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO) Map(java.util.Map) JdbcInfo(com.dtstack.taier.common.engine.JdbcInfo)

Example 19 with IClient

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;
}
Also used : BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) IClient(com.dtstack.dtcenter.loader.client.IClient) SqlQueryDTO(com.dtstack.dtcenter.loader.dto.SqlQueryDTO) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Example 20 with IClient

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());
}
Also used : BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) JSONObject(com.alibaba.fastjson.JSONObject) IClient(com.dtstack.dtcenter.loader.client.IClient) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO)

Aggregations

IClient (com.dtstack.dtcenter.loader.client.IClient)23 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)20 JSONObject (com.alibaba.fastjson.JSONObject)9 ArrayList (java.util.ArrayList)8 ColumnMetaDTO (com.dtstack.dtcenter.loader.dto.ColumnMetaDTO)7 SqlQueryDTO (com.dtstack.dtcenter.loader.dto.SqlQueryDTO)7 BatchDataSource (com.dtstack.taier.dao.domain.BatchDataSource)6 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)5 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)5 IOException (java.io.IOException)5 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)4 SftpException (com.jcraft.jsch.SftpException)4 Map (java.util.Map)4 DataSourceType (com.dtstack.dtcenter.loader.source.DataSourceType)3 JdbcInfo (com.dtstack.taier.common.engine.JdbcInfo)3 List (java.util.List)3 Connection (java.sql.Connection)2 ITable (com.dtstack.dtcenter.loader.client.ITable)1 Table (com.dtstack.dtcenter.loader.dto.Table)1 HdfsSourceDTO (com.dtstack.dtcenter.loader.dto.source.HdfsSourceDTO)1