use of io.crate.common.annotations.VisibleForTesting in project crate by crate.
the class AlterTableAddColumnPlan method bind.
@VisibleForTesting
public static BoundAddColumn bind(AnalyzedAlterTableAddColumn alterTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults, FulltextAnalyzerResolver fulltextAnalyzerResolver) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
DocTableInfo tableInfo = alterTable.tableInfo();
AnalyzedTableElements<Object> tableElements = alterTable.analyzedTableElements().map(eval);
for (AnalyzedColumnDefinition<Object> column : tableElements.columns()) {
ensureColumnLeafsAreNew(column, tableInfo);
}
addExistingPrimaryKeys(tableInfo, tableElements);
ensureNoIndexDefinitions(tableElements.columns());
addExistingCheckConstraints(tableInfo, tableElements);
// validate table elements
AnalyzedTableElements<Symbol> tableElementsUnboundWithExpressions = alterTable.analyzedTableElementsWithExpressions();
Settings tableSettings = AnalyzedTableElements.validateAndBuildSettings(tableElements, fulltextAnalyzerResolver);
Map<String, Object> mapping = AnalyzedTableElements.finalizeAndValidate(tableInfo.ident(), tableElementsUnboundWithExpressions, tableElements);
int numCurrentPks = tableInfo.primaryKey().size();
if (tableInfo.primaryKey().contains(DocSysColumns.ID)) {
numCurrentPks -= 1;
}
boolean hasNewPrimaryKeys = AnalyzedTableElements.primaryKeys(tableElements).size() > numCurrentPks;
boolean hasGeneratedColumns = tableElementsUnboundWithExpressions.hasGeneratedColumns();
return new BoundAddColumn(tableInfo, tableElements, tableSettings, mapping, hasNewPrimaryKeys, hasGeneratedColumns);
}
use of io.crate.common.annotations.VisibleForTesting in project crate by crate.
the class UpdateSettingsPlan method buildSettingsFrom.
@VisibleForTesting
static Settings buildSettingsFrom(Collection<Assignment<Symbol>> assignments, Function<? super Symbol, Object> eval) {
Settings.Builder settingsBuilder = Settings.builder();
for (Assignment<Symbol> entry : assignments) {
String settingsName = eval.apply(entry.columnName()).toString();
if (CrateSettings.isValidSetting(settingsName) == false) {
throw new IllegalArgumentException("Setting '" + settingsName + "' is not supported");
}
Symbol expression = Lists2.getOnlyElement(entry.expressions());
Object value = eval.apply(expression);
CrateSettings.flattenSettings(settingsBuilder, settingsName, value);
}
Settings settings = settingsBuilder.build();
for (String checkForRuntime : settings.keySet()) {
CrateSettings.checkIfRuntimeSetting(checkForRuntime);
}
return settings;
}
use of io.crate.common.annotations.VisibleForTesting in project crate by crate.
the class Session method singleExec.
@VisibleForTesting
CompletableFuture<?> singleExec(Portal portal, ResultReceiver<?> resultReceiver, int maxRows) {
var activeConsumer = portal.activeConsumer();
if (activeConsumer != null && activeConsumer.suspended()) {
activeConsumer.replaceResultReceiver(resultReceiver, maxRows);
activeConsumer.resume();
return resultReceiver.completionFuture();
}
var jobId = UUIDs.dirtyUUID();
var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
var clusterState = executor.clusterService().state();
var txnCtx = new CoordinatorTxnCtx(sessionContext);
var nodeCtx = executor.nodeContext();
var params = new RowN(portal.params().toArray());
var plannerContext = new PlannerContext(clusterState, routingProvider, jobId, txnCtx, nodeCtx, maxRows, params);
var analyzedStmt = portal.analyzedStatement();
String rawStatement = portal.preparedStmt().rawStatement();
if (analyzedStmt == null) {
String errorMsg = "Statement must have been analyzed: " + rawStatement;
jobsLogs.logPreExecutionFailure(jobId, rawStatement, errorMsg, sessionContext.sessionUser());
throw new IllegalStateException(errorMsg);
}
Plan plan;
try {
plan = planner.plan(analyzedStmt, plannerContext);
} catch (Throwable t) {
jobsLogs.logPreExecutionFailure(jobId, rawStatement, SQLExceptions.messageOf(t), sessionContext.sessionUser());
throw t;
}
if (!analyzedStmt.isWriteOperation()) {
resultReceiver = new RetryOnFailureResultReceiver(executor.clusterService(), clusterState, indexName -> executor.clusterService().state().metadata().hasIndex(indexName), resultReceiver, jobId, (newJobId, resultRec) -> retryQuery(newJobId, analyzedStmt, routingProvider, new RowConsumerToResultReceiver(resultRec, maxRows, new JobsLogsUpdateListener(newJobId, jobsLogs)), params, txnCtx, nodeCtx));
}
jobsLogs.logExecutionStart(jobId, rawStatement, sessionContext.sessionUser(), StatementClassifier.classify(plan));
RowConsumerToResultReceiver consumer = new RowConsumerToResultReceiver(resultReceiver, maxRows, new JobsLogsUpdateListener(jobId, jobsLogs));
portal.setActiveConsumer(consumer);
plan.execute(executor, plannerContext, consumer, params, SubQueryResults.EMPTY);
return resultReceiver.completionFuture();
}
use of io.crate.common.annotations.VisibleForTesting in project crate by crate.
the class FileWriterCountCollector method createJsonBuilder.
@VisibleForTesting
static XContentBuilder createJsonBuilder(OutputStream outputStream) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder(outputStream);
builder.generator().configure(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM, false);
return builder;
}
use of io.crate.common.annotations.VisibleForTesting in project crate by crate.
the class TransportAnalyzeAction method createTableStats.
@VisibleForTesting
static Stats createTableStats(Samples samples, List<Reference> primitiveColumns) {
List<Row> records = samples.records;
List<Object> columnValues = new ArrayList<>(records.size());
Map<ColumnIdent, ColumnStats> statsByColumn = new HashMap<>(primitiveColumns.size());
for (int i = 0; i < primitiveColumns.size(); i++) {
Reference primitiveColumn = primitiveColumns.get(i);
columnValues.clear();
int nullCount = 0;
for (Row record : records) {
Object value = record.get(i);
if (value == null) {
nullCount++;
} else {
columnValues.add(value);
}
}
@SuppressWarnings("unchecked") DataType<Object> dataType = (DataType<Object>) primitiveColumn.valueType();
columnValues.sort(dataType::compare);
ColumnStats<?> columnStats = ColumnStats.fromSortedValues(columnValues, dataType, nullCount, samples.numTotalDocs);
statsByColumn.put(primitiveColumn.column(), columnStats);
}
return new Stats(samples.numTotalDocs, samples.numTotalSizeInBytes, statsByColumn);
}
Aggregations