Search in sources :

Example 11 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class CatalogTest method listTablesTest.

@Test
public void listTablesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.setSchemaVersion(666);
    helper.addDatabase(130, "global_temp");
    helper.addDatabase(264, "tpch_001");
    helper.addTable(130, 42, "test");
    helper.addTable(130, 43, "test1");
    Catalog cat = session.getCatalog();
    TiDBInfo db = cat.getDatabase("gLObal_temp");
    List<TiTableInfo> tables = cat.listTables(db);
    List<String> names = tables.stream().map(TiTableInfo::getName).sorted().collect(Collectors.toList());
    assertEquals(2, tables.size());
    assertEquals("test", names.get(0));
    assertEquals("test1", names.get(1));
    assertEquals("test", cat.getTable(db, 42).getName());
    assertEquals("test1", cat.getTable(db, 43).getName());
    assertNull(cat.getTable(db, 44));
    helper.addTable(130, 44, "other");
    helper.setSchemaVersion(667);
    ReflectionWrapper wrapper = new ReflectionWrapper(cat, boolean.class);
    wrapper.call("reloadCache", true);
    tables = cat.listTables(db);
    names = tables.stream().map(TiTableInfo::getName).sorted().collect(Collectors.toList());
    assertEquals(3, tables.size());
    assertEquals("other", names.get(0));
    assertEquals("test", names.get(1));
    assertEquals("test1", names.get(2));
    assertEquals(42, cat.getTable("global_temp", "test").getId());
    assertNull(cat.getTable("global_temp", "test111"));
    helper.dropTable(db.getId(), tables.get(0).getId());
    helper.setSchemaVersion(668);
    wrapper.call("reloadCache", true);
    tables = cat.listTables(db);
    assertEquals(2, tables.size());
    db = cat.getDatabase("TpCH_001");
    tables = cat.listTables(db);
    assertTrue(tables.isEmpty());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) ReflectionWrapper(com.pingcap.tikv.util.ReflectionWrapper) PDMockServerTest(com.pingcap.tikv.PDMockServerTest) Test(org.junit.Test)

Example 12 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class CatalogTransactionTest method getTablesTest.

@Test
public void getTablesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.addTable(130, 42, "test");
    helper.addTable(130, 43, "test1");
    CatalogTransaction trx = new CatalogTransaction(session.createSnapshot());
    List<TiTableInfo> tables = trx.getTables(130);
    assertEquals(2, tables.size());
    assertEquals("test", tables.get(0).getName());
    assertEquals("test1", tables.get(1).getName());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) Test(org.junit.Test)

Example 13 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class RegionUtils method getRegionTasks.

private static List<RegionTask> getRegionTasks(TiSession session, String databaseName, String tableName) {
    requireNonNull(session, "session is null");
    requireNonNull(databaseName, "databaseName is null");
    requireNonNull(tableName, "tableName is null");
    TiTableInfo table = session.getCatalog().getTable(databaseName, tableName);
    requireNonNull(table, String.format("Table not found %s.%s", databaseName, tableName));
    TiKVScanAnalyzer builder = new TiKVScanAnalyzer();
    TiDAGRequest dagRequest = builder.buildTiDAGReq(ImmutableList.of(), ImmutableList.of(), table, session.getTimestamp(), new TiDAGRequest(PushDownType.NORMAL));
    List<KeyRange> ranges = new ArrayList<>();
    dagRequest.getRangesMaps().forEach((k, v) -> ranges.addAll(v));
    return RangeSplitter.newSplitter(session.getRegionManager()).splitRangeByRegion(ranges);
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) ArrayList(java.util.ArrayList) TiKVScanAnalyzer(com.pingcap.tikv.predicates.TiKVScanAnalyzer) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest)

Example 14 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class TiParserTest method TestParseWithTableInfo.

@Test
public void TestParseWithTableInfo() {
    TiTableInfo tableInfo = createTaleInfoWithParts();
    TiParser parser = new TiParser(tableInfo);
    Expression expr = parser.parseExpression("`a` < 5");
    Assert.assertEquals(expr.toString(), "[a@LONG LESS_THAN 5]");
}
Also used : Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) Test(org.junit.Test)

Example 15 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class IndexMatcherTest method matchOnlyEq.

@Test
public void matchOnlyEq() {
    TiTableInfo table = createTable();
    TiIndexInfo index = table.getIndices().get(0);
    TiIndexColumn col = index.getIndexColumns().get(0);
    IndexMatcher matcher = IndexMatcher.equalOnlyMatcher(col);
    Constant c0 = Constant.create(0, IntegerType.INT);
    Constant c1 = Constant.create(1, IntegerType.INT);
    Constant c2 = Constant.create(2, IntegerType.INT);
    ColumnRef col1 = ColumnRef.create("c1", table);
    ColumnRef col2 = ColumnRef.create("c2", table);
    // index col = c1, long
    Expression cond = equal(col1, c1);
    assertTrue(matcher.match(cond));
    cond = equal(c1, col1);
    assertTrue(matcher.match(cond));
    cond = equal(col2, col1);
    assertFalse(matcher.match(cond));
    cond = equal(c1, c1);
    assertFalse(matcher.match(cond));
    cond = and(equal(c1, col1), equal(col1, c2));
    assertFalse(matcher.match(cond));
    cond = or(equal(c1, col1), equal(col1, c2));
    assertTrue(matcher.match(cond));
    cond = lessEqual(c0, col1);
    assertFalse(matcher.match(cond));
}
Also used : TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) IndexMatcher(com.pingcap.tikv.expression.visitor.IndexMatcher) Expression(com.pingcap.tikv.expression.Expression) Constant(com.pingcap.tikv.expression.Constant) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) ColumnRef(com.pingcap.tikv.expression.ColumnRef) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

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