Search in sources :

Example 16 with TableInfo

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;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Example 17 with TableInfo

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));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 18 with TableInfo

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());
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 19 with TableInfo

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) Test(org.junit.Test)

Example 20 with TableInfo

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));
}
Also used : SessionContext(io.crate.action.sql.SessionContext) IntSet(com.carrotsearch.hppc.IntSet) TableInfo(io.crate.metadata.table.TableInfo) TestingTableInfo(io.crate.metadata.table.TestingTableInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

TableInfo (io.crate.metadata.table.TableInfo)30 Test (org.junit.Test)16 DocTableInfo (io.crate.metadata.doc.DocTableInfo)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)7 Symbol (io.crate.analyze.symbol.Symbol)6 WhereClause (io.crate.analyze.WhereClause)5 Function (io.crate.analyze.symbol.Function)5 SysClusterTableInfo (io.crate.metadata.sys.SysClusterTableInfo)5 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)4 SchemaInfo (io.crate.metadata.table.SchemaInfo)4 ArrayList (java.util.ArrayList)4 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)3 Bucket (io.crate.data.Bucket)3 CollectionBucket (io.crate.data.CollectionBucket)3 Table (io.crate.sql.tree.Table)3 SessionContext (io.crate.action.sql.SessionContext)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)2 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)2 DocTableRelation (io.crate.analyze.relations.DocTableRelation)2