use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class RestoreSnapshotAnalyzer method analyze.
public RestoreSnapshotAnalyzedStatement analyze(RestoreSnapshot node, Analysis analysis) {
List<String> nameParts = node.name().getParts();
Preconditions.checkArgument(nameParts.size() == 2, "Snapshot name not supported, only <repository>.<snapshot> works.");
String repositoryName = nameParts.get(0);
repositoryService.failIfRepositoryDoesNotExist(repositoryName);
// validate and extract settings
Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
if (node.tableList().isPresent()) {
List<Table> tableList = node.tableList().get();
Set<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> restoreTables = new HashSet<>(tableList.size());
for (Table table : tableList) {
TableIdent tableIdent = TableIdent.of(table, analysis.sessionContext().defaultSchema());
boolean tableExists = schemas.tableExists(tableIdent);
if (tableExists) {
if (table.partitionProperties().isEmpty()) {
throw new TableAlreadyExistsException(tableIdent);
}
TableInfo tableInfo = schemas.getTableInfo(tableIdent);
if (!(tableInfo instanceof DocTableInfo)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot restore snapshot of tables in schema '%s'", tableInfo.ident().schema()));
}
DocTableInfo docTableInfo = ((DocTableInfo) tableInfo);
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
if (docTableInfo.partitions().contains(partitionName)) {
throw new PartitionAlreadyExistsException(partitionName);
}
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
} else {
if (table.partitionProperties().isEmpty()) {
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, null));
} else {
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, null, table.partitionProperties(), analysis.parameterContext().parameters());
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
}
}
}
return RestoreSnapshotAnalyzedStatement.forTables(nameParts.get(1), repositoryName, settings, ImmutableList.copyOf(restoreTables));
} else {
return RestoreSnapshotAnalyzedStatement.all(nameParts.get(1), repositoryName, settings);
}
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class TableAnalyzer method filteredIndices.
static Collection<String> filteredIndices(ParameterContext parameterContext, List<Assignment> partitionProperties, DocTableInfo tableInfo) {
if (partitionProperties.isEmpty()) {
return Arrays.asList(tableInfo.concreteIndices());
} else {
DocTableInfo docTableInfo = tableInfo;
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(docTableInfo, partitionProperties, parameterContext.parameters());
if (!docTableInfo.partitions().contains(partitionName)) {
throw new PartitionUnknownException(tableInfo.ident().fqn(), partitionName.ident());
}
return Collections.singletonList(partitionName.asIndexName());
}
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class RelationAnalyzer method visitTable.
@Override
protected AnalyzedRelation visitTable(Table node, StatementAnalysisContext context) {
TableInfo tableInfo = schemas.getTableInfo(TableIdent.of(node, context.sessionContext().defaultSchema()));
Operation.blockedRaiseException(tableInfo, context.currentOperation());
AnalyzedRelation tableRelation;
// Dispatching of doc relations is based on the returned class of the schema information.
if (tableInfo instanceof DocTableInfo) {
tableRelation = new DocTableRelation((DocTableInfo) tableInfo);
} else {
tableRelation = new TableRelation(tableInfo);
}
context.currentRelationContext().addSourceRelation(tableInfo.ident().schema(), tableInfo.ident().name(), tableRelation);
return tableRelation;
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class AlterTableAnalyzer method analyze.
public AlterTableAnalyzedStatement analyze(AlterTable node, Row parameters, String defaultSchema) {
Table table = node.table();
DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.of(table, defaultSchema));
PartitionName partitionName = getPartitionName(table.partitionProperties(), tableInfo, parameters);
TableParameterInfo tableParameterInfo = getTableParameterInfo(table, tableInfo, partitionName);
TableParameter tableParameter = getTableParameter(node, parameters, tableParameterInfo);
maybeRaiseBlockedException(tableInfo, tableParameter.settings());
return new AlterTableAnalyzedStatement(tableInfo, partitionName, tableParameter, table.excludePartitions());
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class LuceneQueryBuilderTest method prepare.
@Before
public void prepare() throws Exception {
DocTableInfo users = TestingTableInfo.builder(new TableIdent(null, "users"), null).add("name", DataTypes.STRING).add("x", DataTypes.INTEGER).add("d", DataTypes.DOUBLE).add("d_array", new ArrayType(DataTypes.DOUBLE)).add("y_array", new ArrayType(DataTypes.LONG)).add("shape", DataTypes.GEO_SHAPE).add("point", DataTypes.GEO_POINT).build();
TableRelation usersTr = new TableRelation(users);
sources = ImmutableMap.of(new QualifiedName("users"), usersTr);
expressions = new SqlExpressions(sources, usersTr);
builder = new LuceneQueryBuilder(expressions.getInstance(Functions.class));
indexCache = mock(IndexCache.class, Answers.RETURNS_MOCKS.get());
Path tempDir = createTempDir();
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", tempDir).build();
Index index = new Index(users.ident().indexName());
when(indexCache.indexSettings()).thenReturn(indexSettings);
AnalysisService analysisService = createAnalysisService(indexSettings, index);
mapperService = createMapperService(index, indexSettings, analysisService);
// @formatter:off
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("default").startObject("properties").startObject("name").field("type", "string").endObject().startObject("x").field("type", "integer").endObject().startObject("d").field("type", "double").endObject().startObject("point").field("type", "geo_point").endObject().startObject("shape").field("type", "geo_shape").endObject().startObject("d_array").field("type", "array").startObject("inner").field("type", "double").endObject().endObject().startObject("y_array").field("type", "array").startObject("inner").field("type", "integer").endObject().endObject().endObject().endObject().endObject();
// @formatter:on
mapperService.merge("default", new CompressedXContent(xContentBuilder.bytes()), MapperService.MergeReason.MAPPING_UPDATE, true);
indexFieldDataService = mock(IndexFieldDataService.class);
IndexFieldData geoFieldData = mock(IndexGeoPointFieldData.class);
when(geoFieldData.getFieldNames()).thenReturn(new MappedFieldType.Names("point"));
when(indexFieldDataService.getForField(mapperService.smartNameFieldType("point"))).thenReturn(geoFieldData);
}
Aggregations