Search in sources :

Example 1 with Public

use of com.qlangtech.tis.annotation.Public in project plugins by qlangtech.

the class TiKVDataSourceFactory method getTableMetadata.

@Override
public List<ColumnMetaData> getTableMetadata(String table) {
    return this.openTiDB((session, c, db) -> {
        TiTableInfo table1 = c.getTable(db, table);
        int[] index = new int[1];
        if (table1 == null) {
            throw new IllegalStateException("table:" + table + " can not find relevant table in db:" + db.getName());
        }
        return table1.getColumns().stream().map((col) -> {
            // ref: com.pingcap.tikv.types.MySQLType
            ColumnMetaData cmd = new ColumnMetaData(index[0]++, col.getName(), map2JdbcType(col.getName(), col.getType()), col.isPrimaryKey(), !col.getType().isNotNull());
            cmd.setSchemaFieldType(typeMap(col.getType()));
            return cmd;
        }).collect(Collectors.toList());
    });
}
Also used : TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) FormField(com.qlangtech.tis.plugin.annotation.FormField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Context(com.alibaba.citrus.turbine.Context) TiSession(com.pingcap.tikv.TiSession) CollectionUtils(org.apache.commons.collections.CollectionUtils) Lists(com.pingcap.com.google.common.collect.Lists) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) Logger(org.slf4j.Logger) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) RangeSplitter(com.pingcap.tikv.util.RangeSplitter) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) TiConfiguration(com.pingcap.tikv.TiConfiguration) Public(com.qlangtech.tis.annotation.Public) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Catalog(com.pingcap.tikv.catalog.Catalog) Maps(com.pingcap.com.google.common.collect.Maps) Types(java.sql.Types) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo)

Example 2 with Public

use of com.qlangtech.tis.annotation.Public in project plugins by qlangtech.

the class DataXPostgresqlWriter method generateCreateDDL.

@Override
public StringBuffer generateCreateDDL(IDataxProcessor.TableMap tableMapper) {
    if (!this.autoCreateTable) {
        return null;
    }
    // 多个主键
    boolean multiPk = tableMapper.getSourceCols().stream().filter((col) -> col.isPk()).count() > 1;
    final CreateTableSqlBuilder createTableSqlBuilder = new CreateTableSqlBuilder(tableMapper) {

        @Override
        protected void appendExtraColDef(List<ColWrapper> pks) {
            // }
            if (multiPk) {
                this.script.append(", CONSTRAINT ").append("uk_" + getCreateTableName() + "_unique_" + pks.stream().map((c) -> c.getName()).collect(Collectors.joining("_"))).append(" UNIQUE(").append(pks.stream().map((c) -> c.getName()).collect(Collectors.joining(","))).append(")");
            }
        }

        @Override
        protected char colEscapeChar() {
            return '\"';
        }

        @Override
        protected ColWrapper createColWrapper(ISelectedTab.ColMeta c) {
            return new ColWrapper(c) {

                @Override
                public String getMapperType() {
                    return convertType(this.meta);
                }
            };
        }

        @Override
        protected void appendTabMeta(List<ColWrapper> pks) {
        }

        /**
         * https://www.runoob.com/mysql/mysql-data-types.html
         * @param col
         * @return
         */
        private String convertType(ISelectedTab.ColMeta col) {
            DataType type = col.getType();
            String colType = type.accept(new DataType.TypeVisitor<String>() {

                @Override
                public String longType(DataType type) {
                    return "BIGINT";
                }

                @Override
                public String doubleType(DataType type) {
                    return "FLOAT8";
                }

                @Override
                public String dateType(DataType type) {
                    return "DATE";
                }

                @Override
                public String timestampType(DataType type) {
                    return "TIMESTAMP";
                }

                @Override
                public String bitType(DataType type) {
                    return "BIT";
                }

                @Override
                public String blobType(DataType type) {
                    return "BYTEA";
                }

                @Override
                public String varcharType(DataType type) {
                    return "VARCHAR(" + type.columnSize + ")";
                }

                @Override
                public String intType(DataType type) {
                    return "INTEGER";
                }

                @Override
                public String floatType(DataType type) {
                    return "FLOAT4";
                }

                @Override
                public String decimalType(DataType type) {
                    return "DECIMAL";
                }

                @Override
                public String timeType(DataType type) {
                    return "TIME";
                }

                @Override
                public String tinyIntType(DataType dataType) {
                    return smallIntType(dataType);
                }

                @Override
                public String smallIntType(DataType dataType) {
                    return "SMALLINT";
                }
            });
            return colType + (!multiPk && col.isPk() ? " PRIMARY KEY" : StringUtils.EMPTY);
        }
    };
    return createTableSqlBuilder.build();
}
Also used : TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) InitWriterTable(com.qlangtech.tis.plugin.datax.common.InitWriterTable) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxContext(com.qlangtech.tis.datax.IDataxContext) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) Collectors(java.util.stream.Collectors) List(java.util.List) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) BasicDataXRdbmsWriter(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsWriter) Public(com.qlangtech.tis.annotation.Public) DataType(com.qlangtech.tis.plugin.ds.DataType) PGDataSourceFactory(com.qlangtech.tis.plugin.ds.postgresql.PGDataSourceFactory) Optional(java.util.Optional) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) DataType(com.qlangtech.tis.plugin.ds.DataType) List(java.util.List)

Example 3 with Public

use of com.qlangtech.tis.annotation.Public in project plugins by qlangtech.

the class DataXOssReader method verifyFormOSSRelative.

public static boolean verifyFormOSSRelative(IControlMsgHandler msgHandler, Context context, Descriptor.PostFormVals postFormVals) {
    String endpoint = postFormVals.getField(FIELD_ENDPOINT);
    String bucket = postFormVals.getField(FIELD_BUCKET);
    HttpEndpoint end = ParamsConfig.getItem(endpoint, HttpEndpoint.KEY_DISPLAY_NAME);
    try {
        OSS ossClient = new OSSClientBuilder().build(end.getEndpoint(), end.getAccessKeyId(), end.getAccessKeySecret());
        List<Bucket> buckets = ossClient.listBuckets();
        if (buckets.size() < 1) {
            msgHandler.addErrorMessage(context, "buckets不能为空");
            return false;
        }
        Optional<Bucket> bucketFind = buckets.stream().filter((b) -> StringUtils.equals(bucket, b.getName())).findFirst();
        if (!bucketFind.isPresent()) {
            // msgHandler.addErrorMessage(context, );
            msgHandler.addFieldError(context, FIELD_BUCKET, "还未创建bucket:" + bucket);
            return false;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ParamsConfig(com.qlangtech.tis.config.ParamsConfig) LoggerFactory(org.slf4j.LoggerFactory) FormField(com.qlangtech.tis.plugin.annotation.FormField) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) IGroupChildTaskIterator(com.qlangtech.tis.datax.IGroupChildTaskIterator) HttpEndpoint(com.qlangtech.tis.plugin.aliyun.HttpEndpoint) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) Logger(org.slf4j.Logger) IHttpToken(com.qlangtech.tis.config.aliyun.IHttpToken) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Descriptor(com.qlangtech.tis.extension.Descriptor) OSS(com.aliyun.oss.OSS) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Public(com.qlangtech.tis.annotation.Public) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) PluginFieldValidators(com.qlangtech.tis.plugin.datax.common.PluginFieldValidators) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Bucket(com.aliyun.oss.model.Bucket) Collections(java.util.Collections) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) Bucket(com.aliyun.oss.model.Bucket) HttpEndpoint(com.qlangtech.tis.plugin.aliyun.HttpEndpoint) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder)

Example 4 with Public

use of com.qlangtech.tis.annotation.Public in project plugins by qlangtech.

the class DataXClickhouseWriter method generateCreateDDL.

@Override
public StringBuffer generateCreateDDL(IDataxProcessor.TableMap tableMapper) {
    if (!this.autoCreateTable) {
        return null;
    }
    final CreateTableSqlBuilder createTableSqlBuilder = new CreateTableSqlBuilder(tableMapper) {

        @Override
        protected void appendExtraColDef(List<ColWrapper> pks) {
            script.append("   ,`__cc_ck_sign` Int8 DEFAULT 1").append("\n");
        }

        @Override
        protected ColWrapper createColWrapper(ISelectedTab.ColMeta c) {
            return new ColWrapper(c) {

                @Override
                public String getMapperType() {
                    return convertType(this.meta);
                }
            };
        }

        @Override
        protected void appendTabMeta(List<ColWrapper> pk) {
            script.append(" ENGINE = CollapsingMergeTree(__cc_ck_sign)").append("\n");
            if (CollectionUtils.isNotEmpty(pk)) {
                script.append(" ORDER BY ").append(pk.stream().map((p) -> "`" + p.getName() + "`").collect(Collectors.joining(","))).append("\n");
            }
            script.append(" SETTINGS index_granularity = 8192");
        }

        private String convertType(ISelectedTab.ColMeta col) {
            DataType type = col.getType();
            switch(type.type) {
                case Types.INTEGER:
                case Types.TINYINT:
                case Types.SMALLINT:
                    return "Int32";
                case Types.BIGINT:
                    return "Int64";
                case Types.FLOAT:
                    return "Float32";
                case Types.DOUBLE:
                case Types.DECIMAL:
                    return "Float64";
                case Types.DATE:
                    return "Date";
                case Types.TIME:
                case Types.TIMESTAMP:
                    return "DateTime";
                case Types.BIT:
                case Types.BOOLEAN:
                    return "UInt8";
                case Types.BLOB:
                case Types.BINARY:
                case Types.LONGVARBINARY:
                case Types.VARBINARY:
                default:
                    return "String";
            }
        }
    };
    return createTableSqlBuilder.build();
// List<ColumnMetaData> tableMetadata = this.getDataSourceFactory().getTableMetadata(tableMapper.getTo());
// Set<String> pks = tableMetadata.stream().filter((t) -> t.isPk()).map((t) -> t.getName()).collect(Collectors.toSet());
// StringBuffer script = new StringBuffer();
// script.append("CREATE TABLE ").append(tableMapper.getTo()).append("\n");
// script.append("(\n");
// ISelectedTab.ColMeta pk = null;
// int maxColNameLength = 0;
// for (ISelectedTab.ColMeta col : tableMapper.getSourceCols()) {
// int m = StringUtils.length(col.getName());
// if (m > maxColNameLength) {
// maxColNameLength = m;
// }
// }
// maxColNameLength += 4;
// for (ISelectedTab.ColMeta col : tableMapper.getSourceCols()) {
// if (pk == null && col.isPk()) {
// pk = col;
// }
// script.append("    `").append(String.format("%-" + (maxColNameLength) + "s", col.getName() + "`"))
// .append(convert2ClickhouseType(col.getType())).append(",").append("\n");
// }
// script.append("    `__cc_ck_sign` Int8 DEFAULT 1").append("\n");
// script.append(")\n");
// script.append(" ENGINE = CollapsingMergeTree(__cc_ck_sign)").append("\n");
// // Objects.requireNonNull(pk, "pk can not be null");
// if (pk != null) {
// script.append(" ORDER BY `").append(pk.getName()).append("`\n");
// }
// script.append(" SETTINGS index_granularity = 8192");
// CREATE TABLE tis.customer_order_relation
// (
// `customerregister_id` String,
// `waitingorder_id` String,
// `worker_id` String,
// `kind` Int8,
// `create_time` Int64,
// `last_ver` Int8,
// `__cc_ck_sign` Int8 DEFAULT 1
// )
// ENGINE = CollapsingMergeTree(__cc_ck_sign)
// ORDER BY customerregister_id
// SETTINGS index_granularity = 8192
// return script;
}
Also used : Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) InitWriterTable(com.qlangtech.tis.plugin.datax.common.InitWriterTable) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxContext(com.qlangtech.tis.datax.IDataxContext) FormField(com.qlangtech.tis.plugin.annotation.FormField) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) Collectors(java.util.stream.Collectors) List(java.util.List) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) ClickHouseDataSourceFactory(com.qlangtech.tis.plugin.ds.clickhouse.ClickHouseDataSourceFactory) BasicDataXRdbmsWriter(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsWriter) Public(com.qlangtech.tis.annotation.Public) CollectionUtils(org.apache.commons.collections.CollectionUtils) DataType(com.qlangtech.tis.plugin.ds.DataType) Optional(java.util.Optional) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Types(java.sql.Types) DataType(com.qlangtech.tis.plugin.ds.DataType) List(java.util.List)

Example 5 with Public

use of com.qlangtech.tis.annotation.Public in project tis by qlangtech.

the class DataxReader method createDataXReaderKey.

private static TIS.DataXReaderAppKey createDataXReaderKey(IPluginContext pluginContext, boolean db, String appname) {
    return new TIS.DataXReaderAppKey(pluginContext, db, appname, new PluginStore.IPluginProcessCallback<DataxReader>() {

        @Override
        public void afterDeserialize(final DataxReader reader) {
            List<PluginFormProperties> subFieldFormPropertyTypes = reader.getDescriptor().getSubPluginFormPropertyTypes();
            if (subFieldFormPropertyTypes.size() > 0) {
                // 加载子字段
                subFieldFormPropertyTypes.forEach((pt) -> {
                    pt.accept(new PluginFormProperties.IVisitor() {

                        @Override
                        public Void visit(final SuFormProperties props) {
                            SubFieldFormAppKey<DataxReader> subFieldKey = new SubFieldFormAppKey<>(pluginContext, db, appname, props, DataxReader.class);
                            KeyedPluginStore<DataxReader> subFieldStore = KeyedPluginStore.getPluginStore(subFieldKey);
                            // 子表单中的内容更新了之后,要同步父表单中的状态
                            subFieldStore.addPluginsUpdateListener(new PluginStore.PluginsUpdateListener<DataxReader>(subFieldKey.getSerializeFileName(), reader) {

                                @Override
                                public void accept(PluginStore<DataxReader> pluginStore) {
                                    setReaderSubFormProp(props, pluginStore.getPlugin());
                                }
                            });
                            DataxReader subFieldReader = subFieldStore.getPlugin();
                            if (subFieldReader == null) {
                                return null;
                            }
                            setReaderSubFormProp(props, subFieldReader);
                            return null;
                        }

                        private void setReaderSubFormProp(SuFormProperties props, DataxReader subFieldReader) {
                            setReaderSubFormProp(props, reader, subFieldReader);
                        }

                        private void setReaderSubFormProp(SuFormProperties props, DataxReader reader, DataxReader subFieldReader) {
                            if (reader == null) {
                                return;
                            }
                            try {
                                props.subFormField.set(reader, props.subFormField.get(subFieldReader));
                            } catch (IllegalAccessException e) {
                                throw new RuntimeException("get subField:" + props.getSubFormFieldName(), e);
                            }
                        }
                    });
                });
            }
        }
    });
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) PluginStore(com.qlangtech.tis.plugin.PluginStore) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) IPluginContext(com.qlangtech.tis.util.IPluginContext) Lists(com.google.common.collect.Lists) Public(com.qlangtech.tis.annotation.Public) IDataXPluginMeta(com.qlangtech.tis.datax.IDataXPluginMeta) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) Describable(com.qlangtech.tis.extension.Describable) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) IDataxReader(com.qlangtech.tis.datax.IDataxReader) PluginStore(com.qlangtech.tis.plugin.PluginStore) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties)

Aggregations

Public (com.qlangtech.tis.annotation.Public)7 TISExtension (com.qlangtech.tis.extension.TISExtension)6 FormField (com.qlangtech.tis.plugin.annotation.FormField)5 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)5 Validator (com.qlangtech.tis.plugin.annotation.Validator)5 Context (com.alibaba.citrus.turbine.Context)4 IOUtils (com.qlangtech.tis.extension.impl.IOUtils)4 StringUtils (org.apache.commons.lang.StringUtils)4 IDataxContext (com.qlangtech.tis.datax.IDataxContext)3 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)3 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)3 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Lists (com.pingcap.com.google.common.collect.Lists)2 Maps (com.pingcap.com.google.common.collect.Maps)2 TiConfiguration (com.pingcap.tikv.TiConfiguration)2 TiSession (com.pingcap.tikv.TiSession)2 Catalog (com.pingcap.tikv.catalog.Catalog)2