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());
});
}
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();
}
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;
}
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;
}
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);
}
}
});
});
}
}
});
}
Aggregations