Search in sources :

Example 76 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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 77 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class SchemasTest method testTableAliasIsNotWritable.

@Test
public void testTableAliasIsNotWritable() throws Exception {
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("foo.bar is an alias. Write, Drop or Alter operations are not supported");
    TableIdent tableIdent = new TableIdent("foo", "bar");
    SchemaInfo schemaInfo = mock(SchemaInfo.class);
    DocTableInfo tableInfo = mock(DocTableInfo.class);
    when(tableInfo.ident()).thenReturn(tableIdent);
    when(schemaInfo.getTableInfo(tableIdent.name())).thenReturn(tableInfo);
    when(schemaInfo.name()).thenReturn(tableIdent.schema());
    when(tableInfo.isAlias()).thenReturn(true);
    Schemas schemas = getReferenceInfos(schemaInfo);
    schemas.getWritableTable(tableIdent);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) Test(org.junit.Test)

Example 78 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class ESGetStatementPlanner method convert.

public static Plan convert(QueriedDocTable table, Planner.Context context) {
    QuerySpec querySpec = table.querySpec();
    Optional<DocKeys> optKeys = querySpec.where().docKeys();
    assert !querySpec.hasAggregates() : "Can't create ESGet plan for queries with aggregates";
    assert !querySpec.groupBy().isPresent() : "Can't create ESGet plan for queries with group by";
    assert optKeys.isPresent() : "Can't create ESGet without docKeys";
    DocTableInfo tableInfo = table.tableRelation().tableInfo();
    DocKeys docKeys = optKeys.get();
    if (docKeys.withVersions()) {
        throw new VersionInvalidException();
    }
    Limits limits = context.getLimits(querySpec);
    if (limits.hasLimit() && limits.finalLimit() == 0) {
        return new NoopPlan(context.jobId());
    }
    table.tableRelation().validateOrderBy(querySpec.orderBy());
    return new ESGet(context.nextExecutionPhaseId(), tableInfo, querySpec.outputs(), optKeys.get(), querySpec.orderBy(), limits.finalLimit(), limits.offset(), context.jobId());
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) NoopPlan(io.crate.planner.NoopPlan) Limits(io.crate.planner.Limits) DocKeys(io.crate.analyze.where.DocKeys) ESGet(io.crate.planner.node.dql.ESGet) QuerySpec(io.crate.analyze.QuerySpec) VersionInvalidException(io.crate.exceptions.VersionInvalidException)

Example 79 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTableParameters.

@Test
public void testBuildCreateTableParameters() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "id", DataTypes.LONG));
    ImmutableMap.Builder<String, Object> tableParameters = ImmutableMap.builder();
    tableParameters.put("refresh_interval", 10000L).put("param_array", new String[] { "foo", "bar" }).put("param_obj", new HashMap<String, Object>() {

        {
            put("foo", "bar");
            put("int", 42);
        }
    }).put("index.translog.flush_interval", 100L);
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "5", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, tableParameters.build(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.IGNORED);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" LONG\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'ignored',\n" + "   \"index.translog.flush_interval\" = 100,\n" + "   number_of_replicas = '5',\n" + "   param_array = ['foo','bar'],\n" + "   param_obj = {\"foo\"= 'bar', \"int\"= 42},\n" + "   refresh_interval = 10000\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) HashMap(java.util.HashMap) CreateTable(io.crate.sql.tree.CreateTable) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 80 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTablePrimaryKey.

@Test
public void testBuildCreateTablePrimaryKey() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "pk_col_one", DataTypes.LONG), newReference(ident, "pk_col_two", DataTypes.LONG));
    List<ColumnIdent> primaryKeys = ImmutableList.of(new ColumnIdent("pk_col_one"), new ColumnIdent("pk_col_two"));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), primaryKeys, null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.STRICT);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"pk_col_one\" LONG,\n" + "   \"pk_col_two\" LONG,\n" + "   PRIMARY KEY (\"pk_col_one\", \"pk_col_two\")\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'strict',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12