Search in sources :

Example 11 with ColumnMetaData

use of com.qlangtech.tis.plugin.ds.ColumnMetaData in project tis by qlangtech.

the class ERRules method createDefaultErRule.

/**
 * 使用默认DumpNode创建ERRule并且持久化
 *
 * @param topology
 * @throws Exception
 */
public static void createDefaultErRule(SqlTaskNodeMeta.SqlDataFlowTopology topology) throws Exception {
    // 还没有定义erRule
    DependencyNode dumpNode = topology.getFirstDumpNode();
    DataSourceFactoryPluginStore dsStore = TIS.getDataBasePluginStore(new PostedDSProp(dumpNode.getDbName()));
    TISTable tab = dsStore.loadTableMeta(dumpNode.getName());
    // String topologyName, DependencyNode node, TargetColumnMeta targetColMetas
    Optional<ColumnMetaData> firstPK = tab.getReflectCols().stream().filter((col) -> col.isPk()).findFirst();
    if (!firstPK.isPresent()) {
        throw new IllegalStateException("table:" + dumpNode.parseEntityName() + " can not find relevant PK cols");
    }
    createErRule(topology.getName(), dumpNode, firstPK.get());
}
Also used : IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) StringUtils(org.apache.commons.lang.StringUtils) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) TabExtraMeta(com.qlangtech.tis.sql.parser.meta.TabExtraMeta) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) TIS(com.qlangtech.tis.TIS) JSONField(com.alibaba.fastjson.annotation.JSONField) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) TISTable(com.qlangtech.tis.plugin.ds.TISTable) Yaml(org.yaml.snakeyaml.Yaml) DumperOptions(org.yaml.snakeyaml.DumperOptions) Node(org.yaml.snakeyaml.nodes.Node) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) Map(java.util.Map) PrimaryLinkKey(com.qlangtech.tis.sql.parser.meta.PrimaryLinkKey) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) Constructor(org.yaml.snakeyaml.constructor.Constructor) Property(org.yaml.snakeyaml.introspector.Property) FileUtils(org.apache.commons.io.FileUtils) Tag(org.yaml.snakeyaml.nodes.Tag) Collectors(java.util.stream.Collectors) File(java.io.File) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Objects(java.util.Objects) List(java.util.List) Representer(org.yaml.snakeyaml.representer.Representer) Optional(java.util.Optional) TypeDescription(org.yaml.snakeyaml.TypeDescription) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) TISTable(com.qlangtech.tis.plugin.ds.TISTable) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Example 12 with ColumnMetaData

use of com.qlangtech.tis.plugin.ds.ColumnMetaData in project tis by qlangtech.

the class TestSqlTaskNode method testDumpSqlReflect.

public void testDumpSqlReflect() {
    final String sql = "select A,b,c as cc,d,e as ee from A";
    Set<String> cols = Sets.newHashSet("a", "b", "c", "d", "e");
    List<ColumnMetaData> rows = SqlTaskNode.reflectTableCols(sql);
    for (ColumnMetaData r : rows) {
        assertTrue(r.getKey() + " must contain in set", cols.contains(r.getKey()));
    }
    assertEquals(5, rows.size());
}
Also used : ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Example 13 with ColumnMetaData

use of com.qlangtech.tis.plugin.ds.ColumnMetaData in project plugins by qlangtech.

the class ClickHouseSinkFactory method createSinkFunction.

private SinkFunction<DTO> createSinkFunction(String dbName, final String targetTabName, ISelectedTab tab, String jdbcUrl, ClickHouseDataSourceFactory dsFactory) {
    // create props for sink
    Properties props = new Properties();
    props.put(ClickHouseSinkConst.TARGET_TABLE_NAME, targetTabName);
    Objects.requireNonNull(maxBufferSize, "maxBufferSize can not be null");
    props.put(ClickHouseSinkConst.MAX_BUFFER_SIZE, String.valueOf(maxBufferSize));
    Map<String, String> globalParams = Maps.newHashMap();
    // ClickHouse cluster properties
    // "http://" + clickHouse.getContainerIpAddress() + ":" + dockerActualPort
    List<String> clickhouseHosts = Lists.newArrayList();
    DBConfig dbCfg = dsFactory.getDbConfig();
    try {
        dbCfg.vistDbName((cfg, ip, _dbName) -> {
            clickhouseHosts.add("http://" + ip + ":" + dsFactory.port + "/?database=" + _dbName);
            return false;
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (clickhouseHosts.size() < 1) {
        throw new IllegalStateException("clickhouseHosts size can not small than 1");
    }
    globalParams.put(ClickHouseClusterSettings.CLICKHOUSE_HOSTS, clickhouseHosts.stream().collect(Collectors.joining(",")));
    globalParams.put(ClickHouseClusterSettings.CLICKHOUSE_USER, dsFactory.getUserName());
    globalParams.put(ClickHouseClusterSettings.CLICKHOUSE_PASSWORD, StringUtils.trimToEmpty(dsFactory.getPassword()));
    // sink common
    globalParams.put(ClickHouseSinkConst.TIMEOUT_SEC, String.valueOf(this.timeout));
    globalParams.put(ClickHouseSinkConst.FAILED_RECORDS_PATH, "/tmp/tis-clickhouse-sink");
    globalParams.put(ClickHouseSinkConst.NUM_WRITERS, String.valueOf(this.numWriters));
    globalParams.put(ClickHouseSinkConst.NUM_RETRIES, String.valueOf(this.numRetries));
    globalParams.put(ClickHouseSinkConst.QUEUE_MAX_CAPACITY, String.valueOf(this.queueMaxCapacity));
    globalParams.put(ClickHouseSinkConst.IGNORING_CLICKHOUSE_SENDING_EXCEPTION_ENABLED, String.valueOf(this.ignoringSendingException));
    List<ColumnMetaData> colsMeta = dsFactory.getTableMetadata(targetTabName);
    if (CollectionUtils.isEmpty(colsMeta)) {
        throw new IllegalStateException("targetTabName relevant colsMeta can not be empty");
    }
    return new TISClickHouseSink(globalParams, props, colsMeta.stream().map((c) -> new ColMeta(c.getKey(), c.getType())).collect(Collectors.toList()));
}
Also used : ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig)

Example 14 with ColumnMetaData

use of com.qlangtech.tis.plugin.ds.ColumnMetaData in project plugins by qlangtech.

the class SelectedTab method getContextTableCols.

public static List<Option> getContextTableCols(Function<List<ColumnMetaData>, Stream<ColumnMetaData>> func) {
    SuFormProperties.SuFormGetterContext context = SuFormProperties.subFormGetterProcessThreadLocal.get();
    if (context == null || context.plugin == null) {
        return Collections.emptyList();
    }
    Describable plugin = Objects.requireNonNull(context.plugin, "context.plugin can not be null");
    if (!(plugin instanceof DataSourceMeta)) {
        throw new IllegalStateException("plugin must be type of " + DataSourceMeta.class.getName() + ", now type of " + plugin.getClass().getName());
    }
    DataSourceMeta dsMeta = (DataSourceMeta) plugin;
    List<ColumnMetaData> cols = context.getContextAttr(KEY_TABLE_COLS, (key) -> dsMeta.getTableMetadata(context.getSubFormIdentityField()));
    return func.apply(cols).map((c) -> c).collect(Collectors.toList());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DataSourceMeta(com.qlangtech.tis.plugin.ds.DataSourceMeta) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) LoggerFactory(org.slf4j.LoggerFactory) Option(com.qlangtech.tis.manage.common.Option) FormField(com.qlangtech.tis.plugin.annotation.FormField) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) Function(java.util.function.Function) Context(com.alibaba.citrus.turbine.Context) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) Logger(org.slf4j.Logger) Descriptor(com.qlangtech.tis.extension.Descriptor) IdentityName(com.qlangtech.tis.plugin.IdentityName) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) Stream(java.util.stream.Stream) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Optional(java.util.Optional) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Collections(java.util.Collections) Describable(com.qlangtech.tis.extension.Describable) Describable(com.qlangtech.tis.extension.Describable) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) DataSourceMeta(com.qlangtech.tis.plugin.ds.DataSourceMeta)

Example 15 with ColumnMetaData

use of com.qlangtech.tis.plugin.ds.ColumnMetaData in project plugins by qlangtech.

the class TisDataXTiDBReader method getTiKVDataSource.

private static final List<IDataSourceDumper> getTiKVDataSource(Configuration config, Optional<Long> regionId) {
    List<String> cols = config.getList("column", String.class);
    String tableName = config.getString("table");
    Configuration connection = config.getConfiguration("connection");
    TiKVDataSourceFactory sourceFactory = new TiKVDataSourceFactory();
    sourceFactory.pdAddrs = connection.getString("[0].pdAddrs");
    sourceFactory.dbName = connection.getString("[0].dbName");
    // sourceFactory.datetimeFormat = connection.getBool("datetimeFormat");
    if (StringUtils.isBlank(sourceFactory.pdAddrs) || StringUtils.isBlank(sourceFactory.dbName)) {
        throw new IllegalStateException("param 'pdAddrs' or 'dbName' can not be null,connection:" + connection.toJSON());
    }
    List<ColumnMetaData> tableMetadata = sourceFactory.getTableMetadata(tableName);
    TISTable table = new TISTable();
    table.setTableName(tableName);
    table.setReflectCols(tableMetadata.stream().filter((cmeta) -> cols.contains(cmeta.getKey())).collect(Collectors.toList()));
    DataDumpers dataDumpers = sourceFactory.getDataDumpers(table, regionId);
    List<IDataSourceDumper> dumpers = Lists.newArrayList(dataDumpers.dumpers);
    return dumpers;
}
Also used : TiKVDataSourceFactory(com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory) DataDumpers(com.qlangtech.tis.plugin.ds.DataDumpers) Configuration(com.alibaba.datax.common.util.Configuration) IDataSourceDumper(com.qlangtech.tis.plugin.ds.IDataSourceDumper) TISTable(com.qlangtech.tis.plugin.ds.TISTable) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Aggregations

ColumnMetaData (com.qlangtech.tis.plugin.ds.ColumnMetaData)16 Collectors (java.util.stream.Collectors)5 StringUtils (org.apache.commons.lang.StringUtils)4 List (java.util.List)3 Map (java.util.Map)3 Context (com.alibaba.citrus.turbine.Context)2 Lists (com.google.common.collect.Lists)2 TIS (com.qlangtech.tis.TIS)2 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)2 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 TISExtension (com.qlangtech.tis.extension.TISExtension)2 Validator (com.qlangtech.tis.plugin.annotation.Validator)2 DataType (com.qlangtech.tis.plugin.ds.DataType)2 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)2 TISTable (com.qlangtech.tis.plugin.ds.TISTable)2 File (java.io.File)2 Optional (java.util.Optional)2 FileUtils (org.apache.commons.io.FileUtils)2 Configuration (com.alibaba.datax.common.util.Configuration)1 JSON (com.alibaba.fastjson.JSON)1