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