use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.
the class Catalog method getTable.
public TiTableInfo getTable(TiDBInfo database, String tableName) {
Objects.requireNonNull(database, "database is null");
Objects.requireNonNull(tableName, "tableName is null");
reloadCache(true);
TiTableInfo table = metaCache.getTable(database, tableName);
if (showRowId && table != null) {
return table.copyTableWithRowId();
} else {
return table;
}
}
use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.
the class CatalogTransaction method getTables.
List<TiTableInfo> getTables(long dbId) {
ByteString dbKey = MetaCodec.encodeDatabaseID(dbId);
List<Pair<ByteString, ByteString>> fields = MetaCodec.hashGetFields(dbKey, this.snapshot);
ImmutableList.Builder<TiTableInfo> builder = ImmutableList.builder();
for (Pair<ByteString, ByteString> pair : fields) {
if (KeyUtils.hasPrefix(pair.first, ByteString.copyFromUtf8(MetaCodec.KEY_TABLE))) {
try {
TiTableInfo tableInfo = parseFromJson(pair.second, TiTableInfo.class);
if (!tableInfo.isSequence() && !tableInfo.isView()) {
builder.add(tableInfo);
}
} catch (TiClientInternalException e) {
logger.warn("fail to parse table from json!", e);
}
}
}
return builder.build();
}
use of com.pingcap.tikv.meta.TiTableInfo in project plugins by qlangtech.
the class TiKVDataSourceFactory method getDataDumpers.
public DataDumpers getDataDumpers(TISTable table, Optional<Long> regionId) {
// target cols
final List<ColumnMetaData> reflectCols = table.getReflectCols();
if (CollectionUtils.isEmpty(reflectCols)) {
throw new IllegalStateException("param reflectCols can not be null");
}
final AtomicReference<TiTableInfoWrapper> tabRef = new AtomicReference<>();
final List<TiPartition> parts = this.openTiDB((session, c, db) -> {
TiTableInfo tiTable = c.getTable(db, table.getTableName());
Objects.requireNonNull(tiTable, "table:" + table.getTableName() + " can not find relevant table in TiDB");
tabRef.set(new TiTableInfoWrapper(tiTable));
TiDAGRequest dagRequest = getTiDAGRequest(reflectCols, session, tiTable);
List<Long> prunedPhysicalIds = dagRequest.getPrunedPhysicalIds();
return prunedPhysicalIds.stream().flatMap((prunedPhysicalId) -> createPartitions(prunedPhysicalId, session, dagRequest.copyReqWithPhysicalId(prunedPhysicalId), regionId).stream()).collect(Collectors.toList());
});
int[] index = new int[1];
final int splitCount = parts.size();
Objects.requireNonNull(tabRef.get(), "instacne of TiTableInfo can not be null");
Iterator<IDataSourceDumper> dumpers = new Iterator<IDataSourceDumper>() {
@Override
public boolean hasNext() {
return index[0] < splitCount;
}
@Override
public IDataSourceDumper next() {
return new TiKVDataSourceDumper(TiKVDataSourceFactory.this, parts.get(index[0]++), tabRef.get(), reflectCols);
}
};
return new DataDumpers(splitCount, dumpers);
}
use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.
the class Catalog method getTable.
@VisibleForTesting
public TiTableInfo getTable(TiDBInfo database, long tableId) {
Objects.requireNonNull(database, "database is null");
Collection<TiTableInfo> tables = listTables(database);
for (TiTableInfo table : tables) {
if (table.getId() == tableId) {
if (showRowId) {
return table.copyTableWithRowId();
} else {
return table;
}
}
}
return null;
}
use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.
the class Catalog method getTableFromCache.
public TiTableInfo getTableFromCache(TiDBInfo database, String tableName) {
Objects.requireNonNull(database, "database is null");
Objects.requireNonNull(tableName, "tableName is null");
TiTableInfo table = metaCache.getTable(database, tableName);
if (showRowId && table != null) {
return table.copyTableWithRowId();
} else {
return table;
}
}
Aggregations