Search in sources :

Example 6 with TiTableInfo

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;
    }
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo)

Example 7 with TiTableInfo

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();
}
Also used : TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) ByteString(com.google.protobuf.ByteString) ImmutableList(com.google.common.collect.ImmutableList) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) Pair(com.pingcap.tikv.util.Pair)

Example 8 with TiTableInfo

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);
}
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) AtomicReference(java.util.concurrent.atomic.AtomicReference) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo)

Example 9 with TiTableInfo

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;
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with TiTableInfo

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;
    }
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo)

Aggregations

TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)24 Test (org.junit.Test)17 Expression (com.pingcap.tikv.expression.Expression)11 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)9 ColumnRef (com.pingcap.tikv.expression.ColumnRef)5 ImmutableList (com.google.common.collect.ImmutableList)4 Constant (com.pingcap.tikv.expression.Constant)4 TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)4 ArrayList (java.util.ArrayList)4 TiDBInfo (com.pingcap.tikv.meta.TiDBInfo)3 List (java.util.List)3 Context (com.alibaba.citrus.turbine.Context)2 Range (com.google.common.collect.Range)2 ByteString (com.google.protobuf.ByteString)2 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 IndexMatcher (com.pingcap.tikv.expression.visitor.IndexMatcher)2