use of io.crate.metadata.table.TableInfo in project crate by crate.
the class RoutedCollectPhase method forQueriedTable.
public static RoutedCollectPhase forQueriedTable(Planner.Context plannerContext, QueriedTableRelation table, List<Symbol> toCollect, List<Projection> projections) {
TableInfo tableInfo = table.tableRelation().tableInfo();
WhereClause where = table.querySpec().where();
if (table.tableRelation() instanceof TableFunctionRelation) {
TableFunctionRelation tableFunctionRelation = (TableFunctionRelation) table.tableRelation();
plannerContext.normalizer().normalizeInplace(tableFunctionRelation.function().arguments(), plannerContext.transactionContext());
return new TableFunctionCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), plannerContext.allocateRouting(tableInfo, where, null), tableFunctionRelation, projections, toCollect, where);
}
return new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", plannerContext.allocateRouting(tableInfo, where, null), tableInfo.rowGranularity(), toCollect, projections, where, DistributionInfo.DEFAULT_BROADCAST);
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class CreateSnapshotAnalyzer method analyze.
public CreateSnapshotAnalyzedStatement analyze(CreateSnapshot node, Analysis analysis) {
Optional<QualifiedName> repositoryName = node.name().getPrefix();
// validate repository
Preconditions.checkArgument(repositoryName.isPresent(), "Snapshot must be specified by \"<repository_name>\".\"<snapshot_name>\"");
Preconditions.checkArgument(repositoryName.get().getParts().size() == 1, String.format(Locale.ENGLISH, "Invalid repository name '%s'", repositoryName.get()));
repositoryService.failIfRepositoryDoesNotExist(repositoryName.get().toString());
// snapshot existence in repo is validated upon execution
String snapshotName = node.name().getSuffix();
SnapshotId snapshotId = new SnapshotId(repositoryName.get().toString(), snapshotName);
// validate and extract settings
Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
boolean ignoreUnavailable = settings.getAsBoolean(IGNORE_UNAVAILABLE.name(), IGNORE_UNAVAILABLE.defaultValue());
// iterate tables
if (node.tableList().isPresent()) {
List<Table> tableList = node.tableList().get();
Set<String> snapshotIndices = new HashSet<>(tableList.size());
for (Table table : tableList) {
TableInfo tableInfo;
try {
tableInfo = schemas.getTableInfo(TableIdent.of(table, analysis.sessionContext().defaultSchema()));
} catch (ResourceUnknownException e) {
if (ignoreUnavailable) {
LOGGER.info("ignoring: {}", e.getMessage());
continue;
} else {
throw e;
}
}
if (!(tableInfo instanceof DocTableInfo)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot create snapshot of tables in schema '%s'", tableInfo.ident().schema()));
}
Operation.blockedRaiseException(tableInfo, Operation.READ);
DocTableInfo docTableInfo = (DocTableInfo) tableInfo;
if (table.partitionProperties().isEmpty()) {
snapshotIndices.addAll(Arrays.asList(docTableInfo.concreteIndices()));
} else {
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
if (!docTableInfo.partitions().contains(partitionName)) {
if (!ignoreUnavailable) {
throw new PartitionUnknownException(tableInfo.ident().fqn(), partitionName.ident());
} else {
LOGGER.info("ignoring unknown partition of table '{}' with ident '{}'", partitionName.tableIdent(), partitionName.ident());
}
} else {
snapshotIndices.add(partitionName.asIndexName());
}
}
}
/**
* For now, we always (in case there are indices to restore) include the globalMetaData,
* not only if one of the tables in the table list is partitioned.
* Previously we only included it in snapshots of full partitioned tables.
* However, to make restoring of shapshots of single partitions work
* we also need to include the global metadata (index templates).
*/
return CreateSnapshotAnalyzedStatement.forTables(snapshotId, settings, ImmutableList.copyOf(snapshotIndices), !snapshotIndices.isEmpty());
} else {
for (SchemaInfo schemaInfo : schemas) {
for (TableInfo tableInfo : schemaInfo) {
// only check for user generated tables
if (tableInfo instanceof DocTableInfo) {
Operation.blockedRaiseException(tableInfo, Operation.READ);
}
}
}
return CreateSnapshotAnalyzedStatement.all(snapshotId, settings);
}
}
use of io.crate.metadata.table.TableInfo in project crate by crate.
the class UpdateAnalyzer method analyze.
public AnalyzedStatement analyze(Update node, Analysis analysis) {
StatementAnalysisContext statementAnalysisContext = new StatementAnalysisContext(analysis.sessionContext(), analysis.parameterContext(), Operation.UPDATE, analysis.transactionContext());
RelationAnalysisContext currentRelationContext = statementAnalysisContext.startRelation();
AnalyzedRelation analyzedRelation = relationAnalyzer.analyze(node.relation(), statementAnalysisContext);
FieldResolver fieldResolver = (FieldResolver) analyzedRelation;
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, fieldResolver);
FieldProvider columnFieldProvider = new NameFieldProvider(analyzedRelation);
ExpressionAnalyzer columnExpressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), analysis.parameterContext(), columnFieldProvider, null);
columnExpressionAnalyzer.setResolveFieldsOperation(Operation.UPDATE);
assert Iterables.getOnlyElement(currentRelationContext.sources().values()) == analyzedRelation : "currentRelationContext.sources().values() must have one element and equal to analyzedRelation";
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), analysis.parameterContext(), new FullQualifedNameFieldProvider(currentRelationContext.sources()), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
int numNested = 1;
if (analysis.parameterContext().numBulkParams() > 0) {
numNested = analysis.parameterContext().numBulkParams();
}
WhereClauseAnalyzer whereClauseAnalyzer = null;
if (analyzedRelation instanceof DocTableRelation) {
whereClauseAnalyzer = new WhereClauseAnalyzer(functions, ((DocTableRelation) analyzedRelation));
}
TableInfo tableInfo = ((AbstractTableRelation) analyzedRelation).tableInfo();
List<UpdateAnalyzedStatement.NestedAnalyzedStatement> nestedAnalyzedStatements = new ArrayList<>(numNested);
for (int i = 0; i < numNested; i++) {
analysis.parameterContext().setBulkIdx(i);
Symbol querySymbol = expressionAnalyzer.generateQuerySymbol(node.whereClause(), expressionAnalysisContext);
WhereClause whereClause = new WhereClause(normalizer.normalize(querySymbol, analysis.transactionContext()));
if (whereClauseAnalyzer != null) {
whereClause = whereClauseAnalyzer.analyze(whereClause, analysis.transactionContext());
}
if (!whereClause.docKeys().isPresent() && Symbols.containsColumn(whereClause.query(), DocSysColumns.VERSION)) {
throw VERSION_SEARCH_EX;
}
UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalyzedStatement = new UpdateAnalyzedStatement.NestedAnalyzedStatement(whereClause);
for (Assignment assignment : node.assignements()) {
analyzeAssignment(assignment, nestedAnalyzedStatement, tableInfo, normalizer, expressionAnalyzer, columnExpressionAnalyzer, expressionAnalysisContext, analysis.transactionContext());
}
nestedAnalyzedStatements.add(nestedAnalyzedStatement);
}
statementAnalysisContext.endRelation();
return new UpdateAnalyzedStatement(analyzedRelation, nestedAnalyzedStatements);
}
use of io.crate.metadata.table.TableInfo 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.table.TableInfo 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;
}
Aggregations