use of io.crate.metadata.table.TableInfo in project crate by crate.
the class Schemas method tableExists.
public boolean tableExists(TableIdent tableIdent) {
SchemaInfo schemaInfo = schemas.get(firstNonNull(tableIdent.schema(), DEFAULT_SCHEMA_NAME));
if (schemaInfo == null) {
return false;
}
schemaInfo.invalidateTableCache(tableIdent.name());
TableInfo tableInfo = schemaInfo.getTableInfo(tableIdent.name());
if (tableInfo == null) {
return false;
} else if ((tableInfo instanceof DocTableInfo)) {
return !isOrphanedAlias((DocTableInfo) tableInfo);
}
return true;
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class SchemasITest method testShardsTable.
@Test
public void testShardsTable() throws Exception {
execute("create table t2 (id int primary key) clustered into 4 shards with(number_of_replicas=0)");
execute("create table t3 (id int primary key) clustered into 8 shards with(number_of_replicas=0)");
ensureYellow();
TableInfo ti = schemas.getTableInfo(new TableIdent("sys", "shards"));
Routing routing = ti.getRouting(null, null);
Set<String> tables = new HashSet<>();
Set<String> expectedTables = Sets.newHashSet("t2", "t3");
int numShards = 0;
for (Map.Entry<String, Map<String, List<Integer>>> nodeEntry : routing.locations().entrySet()) {
for (Map.Entry<String, List<Integer>> indexEntry : nodeEntry.getValue().entrySet()) {
tables.add(indexEntry.getKey());
numShards += indexEntry.getValue().size();
}
}
assertThat(numShards, is(12));
assertThat(tables, is(expectedTables));
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class SchemasITest method testNodesTable.
@Test
public void testNodesTable() throws Exception {
TableInfo ti = schemas.getTableInfo(new TableIdent("sys", "nodes"));
Routing routing = ti.getRouting(null, null);
assertTrue(routing.hasLocations());
assertEquals(1, routing.nodes().size());
for (Map<String, List<Integer>> indices : routing.locations().values()) {
assertEquals(1, indices.size());
}
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class SchemasTest method testSystemSchemaIsNotWritable.
@Test
public void testSystemSchemaIsNotWritable() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("The table foo.bar is read-only. Write, Drop or Alter operations are not supported");
TableIdent tableIdent = new TableIdent("foo", "bar");
SchemaInfo schemaInfo = mock(SchemaInfo.class);
TableInfo tableInfo = mock(TableInfo.class);
when(tableInfo.ident()).thenReturn(tableIdent);
when(schemaInfo.getTableInfo(tableIdent.name())).thenReturn(tableInfo);
when(schemaInfo.name()).thenReturn(tableIdent.schema());
Schemas schemas = getReferenceInfos(schemaInfo);
schemas.getWritableTable(tableIdent);
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class PlannerTest method testBuildReaderAllocations.
@Test
public void testBuildReaderAllocations() throws Exception {
TableIdent custom = new TableIdent("custom", "t1");
TableInfo tableInfo = TestingTableInfo.builder(custom, shardRouting("t1")).add("id", DataTypes.INTEGER, null).build();
Planner.Context plannerContext = new Planner.Context(e.planner, clusterService, UUID.randomUUID(), null, normalizer, new TransactionContext(SessionContext.SYSTEM_SESSION), 0, 0);
plannerContext.allocateRouting(tableInfo, WhereClause.MATCH_ALL, null);
Planner.Context.ReaderAllocations readerAllocations = plannerContext.buildReaderAllocations();
assertThat(readerAllocations.indices().size(), is(1));
assertThat(readerAllocations.indices().get(0), is("t1"));
assertThat(readerAllocations.nodeReaders().size(), is(2));
IntSet n1 = readerAllocations.nodeReaders().get("nodeOne");
assertThat(n1.size(), is(2));
assertTrue(n1.contains(1));
assertTrue(n1.contains(2));
IntSet n2 = readerAllocations.nodeReaders().get("nodeTwo");
assertThat(n2.size(), is(2));
assertTrue(n2.contains(3));
assertTrue(n2.contains(4));
assertThat(readerAllocations.bases().get("t1"), is(0));
// allocations must stay same on multiple calls
Planner.Context.ReaderAllocations readerAllocations2 = plannerContext.buildReaderAllocations();
assertThat(readerAllocations, is(readerAllocations2));
}
Aggregations