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