Search in sources :

Example 41 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class DBUtil method loadDriverClass.

public static void loadDriverClass(String pluginType, String pluginName) {
    try {
        String pluginJsonPath = StringUtils.join(new String[] { System.getProperty("datax.home"), "plugin", pluginType, String.format("%s%s", pluginName, pluginType), "plugin.json" }, File.separator);
        Configuration configuration = Configuration.from(new File(pluginJsonPath));
        List<String> drivers = configuration.getList("drivers", String.class);
        for (String driver : drivers) {
            Class.forName(driver);
        }
    } catch (ClassNotFoundException e) {
        throw DataXException.asDataXException(DBUtilErrorCode.CONF_ERROR, "数据库驱动加载错误, 请确认libs目录有驱动jar包且plugin.json中drivers配置驱动类正确!", e);
    }
}
Also used : Configuration(com.alibaba.datax.common.util.Configuration) File(java.io.File)

Example 42 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class WriterUtil method preCheckPostSQL.

public static void preCheckPostSQL(Configuration originalConfig, DataBaseType type) {
    List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
    Configuration connConf = Configuration.from(conns.get(0).toString());
    String table = connConf.getList(Key.TABLE, String.class).get(0);
    List<String> postSqls = originalConfig.getList(Key.POST_SQL, String.class);
    List<String> renderedPostSqls = WriterUtil.renderPreOrPostSqls(postSqls, table);
    if (null != renderedPostSqls && !renderedPostSqls.isEmpty()) {
        LOG.info("Begin to preCheck postSqls:[{}].", StringUtils.join(renderedPostSqls, ";"));
        for (String sql : renderedPostSqls) {
            try {
                DBUtil.sqlValid(sql, type);
            } catch (ParserException e) {
                throw RdbmsException.asPostSQLParserException(type, e, sql);
            }
        }
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) Configuration(com.alibaba.datax.common.util.Configuration)

Example 43 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class WriterUtil method doSplit.

//TODO 切分报错
public static List<Configuration> doSplit(Configuration simplifiedConf, int adviceNumber) {
    List<Configuration> splitResultConfigs = new ArrayList<Configuration>();
    int tableNumber = simplifiedConf.getInt(Constant.TABLE_NUMBER_MARK);
    //处理单表的情况
    if (tableNumber == 1) {
        //由于在之前的  master prepare 中已经把 table,jdbcUrl 提取出来,所以这里处理十分简单
        for (int j = 0; j < adviceNumber; j++) {
            splitResultConfigs.add(simplifiedConf.clone());
        }
        return splitResultConfigs;
    }
    if (tableNumber != adviceNumber) {
        throw DataXException.asDataXException(DBUtilErrorCode.CONF_ERROR, String.format("您的配置文件中的列配置信息有误. 您要写入的目的端的表个数是:%s , 但是根据系统建议需要切分的份数是:%s. 请检查您的配置并作出修改.", tableNumber, adviceNumber));
    }
    String jdbcUrl;
    List<String> preSqls = simplifiedConf.getList(Key.PRE_SQL, String.class);
    List<String> postSqls = simplifiedConf.getList(Key.POST_SQL, String.class);
    List<Object> conns = simplifiedConf.getList(Constant.CONN_MARK, Object.class);
    for (Object conn : conns) {
        Configuration sliceConfig = simplifiedConf.clone();
        Configuration connConf = Configuration.from(conn.toString());
        jdbcUrl = connConf.getString(Key.JDBC_URL);
        sliceConfig.set(Key.JDBC_URL, jdbcUrl);
        sliceConfig.remove(Constant.CONN_MARK);
        List<String> tables = connConf.getList(Key.TABLE, String.class);
        for (String table : tables) {
            Configuration tempSlice = sliceConfig.clone();
            tempSlice.set(Key.TABLE, table);
            tempSlice.set(Key.PRE_SQL, renderPreOrPostSqls(preSqls, table));
            tempSlice.set(Key.POST_SQL, renderPreOrPostSqls(postSqls, table));
            splitResultConfigs.add(tempSlice);
        }
    }
    return splitResultConfigs;
}
Also used : Configuration(com.alibaba.datax.common.util.Configuration)

Example 44 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class WriterUtil method preCheckPrePareSQL.

public static void preCheckPrePareSQL(Configuration originalConfig, DataBaseType type) {
    List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
    Configuration connConf = Configuration.from(conns.get(0).toString());
    String table = connConf.getList(Key.TABLE, String.class).get(0);
    List<String> preSqls = originalConfig.getList(Key.PRE_SQL, String.class);
    List<String> renderedPreSqls = WriterUtil.renderPreOrPostSqls(preSqls, table);
    if (null != renderedPreSqls && !renderedPreSqls.isEmpty()) {
        LOG.info("Begin to preCheck preSqls:[{}].", StringUtils.join(renderedPreSqls, ";"));
        for (String sql : renderedPreSqls) {
            try {
                DBUtil.sqlValid(sql, type);
            } catch (ParserException e) {
                throw RdbmsException.asPreSQLParserException(type, e, sql);
            }
        }
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) Configuration(com.alibaba.datax.common.util.Configuration)

Example 45 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class OdpsSplitUtil method splitForNonPartitionedTable.

private static List<Configuration> splitForNonPartitionedTable(Odps odps, int adviceNum, Configuration sliceConfig) {
    List<Configuration> params = new ArrayList<Configuration>();
    String tunnelServer = sliceConfig.getString(Key.TUNNEL_SERVER);
    String tableName = sliceConfig.getString(Key.TABLE);
    String projectName = sliceConfig.getString(Key.PROJECT);
    DownloadSession session = OdpsUtil.createMasterSessionForNonPartitionedTable(odps, tunnelServer, projectName, tableName);
    String id = session.getId();
    long count = session.getRecordCount();
    List<Pair<Long, Long>> splitResult = splitRecordCount(count, adviceNum);
    for (Pair<Long, Long> pair : splitResult) {
        Configuration iParam = sliceConfig.clone();
        iParam.set(Constant.SESSION_ID, id);
        iParam.set(Constant.START_INDEX, pair.getLeft().longValue());
        iParam.set(Constant.STEP_COUNT, pair.getRight().longValue());
        params.add(iParam);
    }
    return params;
}
Also used : DownloadSession(com.aliyun.odps.tunnel.TableTunnel.DownloadSession) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Aggregations

Configuration (com.alibaba.datax.common.util.Configuration)82 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)19 Communication (com.alibaba.datax.core.statistics.communication.Communication)13 DataXException (com.alibaba.datax.common.exception.DataXException)9 Method (java.lang.reflect.Method)8 Record (com.alibaba.datax.common.element.Record)7 JobContainer (com.alibaba.datax.core.job.JobContainer)6 IOException (java.io.IOException)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 LongColumn (com.alibaba.datax.common.element.LongColumn)4 TaskPluginCollector (com.alibaba.datax.common.plugin.TaskPluginCollector)4 TaskGroupContainer (com.alibaba.datax.core.taskgroup.TaskGroupContainer)4 Channel (com.alibaba.datax.core.transport.channel.Channel)4 MemoryChannel (com.alibaba.datax.core.transport.channel.memory.MemoryChannel)4 DefaultRecord (com.alibaba.datax.core.transport.record.DefaultRecord)4 File (java.io.File)4 HashSet (java.util.HashSet)3 List (java.util.List)3 VMInfo (com.alibaba.datax.common.statistics.VMInfo)2