mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-02 20:21:16 +08:00
Merge pull request #50 from taosdata/dev/zyyang
fix: schema cache load column meta
This commit is contained in:
commit
59d1e3ab1b
@ -11,14 +11,12 @@ public class ColumnMeta {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ColumnMeta{" +
|
||||
"field='" + field + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", length=" + length +
|
||||
", note='" + note + '\'' +
|
||||
", isTag=" + isTag +
|
||||
", isPrimaryKey=" + isPrimaryKey +
|
||||
", value=" + value +
|
||||
'}';
|
||||
return "ColumnMeta{" + "field='" + field + '\'' + ", type='" + type + '\'' + ", length=" + length + ", note='" +
|
||||
note + '\'' + ", isTag=" + isTag + ", isPrimaryKey=" + isPrimaryKey + ", value=" + value + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ColumnMeta && this.field.equals(((ColumnMeta) obj).field);
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,10 @@ public final class SchemaCache {
|
||||
synchronized (SchemaCache.class) {
|
||||
if (columnMetas.get(tbname).isEmpty()) {
|
||||
List<String> column_name = config.getList(Key.COLUMN, String.class);
|
||||
|
||||
List<ColumnMeta> colMetaList = getColumnMetaListFromDb(tbname,
|
||||
(colMeta) -> column_name.contains(colMeta.field));
|
||||
|
||||
columnMetas.get(tbname).addAll(colMetaList);
|
||||
}
|
||||
}
|
||||
@ -88,7 +90,7 @@ public final class SchemaCache {
|
||||
}
|
||||
|
||||
private List<ColumnMeta> getColumnMetaListFromDb(String tableName, Predicate<ColumnMeta> filter) {
|
||||
List<ColumnMeta> columnMetaList = columnMetas.get(tableName);
|
||||
List<ColumnMeta> columnMetaList = new ArrayList<>();
|
||||
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("describe " + tableName);
|
||||
@ -98,6 +100,7 @@ public final class SchemaCache {
|
||||
if (filter.test(columnMeta))
|
||||
columnMetaList.add(columnMeta);
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
throw DataXException.asDataXException(TDengineWriterErrorCode.RUNTIME_EXCEPTION, e.getMessage());
|
||||
}
|
||||
@ -117,8 +120,10 @@ public final class SchemaCache {
|
||||
Object tagValue = null;
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
rs.next();
|
||||
tagValue = rs.getObject(tagName);
|
||||
|
||||
while (rs.next()) {
|
||||
tagValue = rs.getObject(tagName);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("failed to get tag value, use NULL, cause: {" + e.getMessage() + "}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user