use of io.crate.metadata.NodeContext in project crate by crate.
the class S3FileReadingCollectorTest method prepare.
@Before
public void prepare() throws Exception {
NodeContext nodeCtx = new NodeContext(new Functions(Map.of()));
inputFactory = new InputFactory(nodeCtx);
}
use of io.crate.metadata.NodeContext in project crate by crate.
the class UserActions method getUserPasswordProperty.
@VisibleForTesting
@Nullable
static SecureString getUserPasswordProperty(GenericProperties<Symbol> userStmtProperties, Row parameters, TransactionContext txnCtx, NodeContext nodeCtx) throws IllegalArgumentException {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, SubQueryResults.EMPTY);
Map<String, Object> properties = userStmtProperties.map(eval).properties();
final String PASSWORD_PROPERTY = "password";
for (String key : properties.keySet()) {
if (PASSWORD_PROPERTY.equals(key)) {
String value = DataTypes.STRING.sanitizeValue(properties.get(key));
if (value != null) {
return new SecureString(value.toCharArray());
}
// Password will be reset
return null;
} else {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "\"%s\" is not a valid user property", key));
}
}
return null;
}
use of io.crate.metadata.NodeContext 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.metadata.NodeContext in project crate by crate.
the class AlterTablePlan method bind.
public static BoundAlterTable bind(AnalyzedAlterTable analyzedAlterTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
DocTableInfo docTableInfo = analyzedAlterTable.tableInfo();
AlterTable<Object> alterTable = analyzedAlterTable.alterTable().map(eval);
Table<Object> table = alterTable.table();
PartitionName partitionName = PartitionPropertiesAnalyzer.createPartitionName(table.partitionProperties(), docTableInfo);
TableParameters tableParameters = getTableParameterInfo(table, partitionName);
TableParameter tableParameter = getTableParameter(alterTable, tableParameters);
maybeRaiseBlockedException(docTableInfo, tableParameter.settings());
return new BoundAlterTable(docTableInfo, partitionName, tableParameter, table.excludePartitions(), docTableInfo.isPartitioned());
}
use of io.crate.metadata.NodeContext in project crate by crate.
the class WindowProjector method fromProjection.
public static Projector fromProjection(WindowAggProjection projection, NodeContext nodeCtx, InputFactory inputFactory, TransactionContext txnCtx, RamAccounting ramAccounting, MemoryManager memoryManager, Version minNodeVersion, Version indexVersionCreated, IntSupplier numThreads, Executor executor) {
var windowFunctionSymbols = projection.windowFunctions();
var numWindowFunctions = windowFunctionSymbols.size();
assert numWindowFunctions > 0 : "WindowAggProjection must have at least 1 window function.";
ArrayList<WindowFunction> windowFunctions = new ArrayList<>(numWindowFunctions);
ArrayList<CollectExpression<Row, ?>> windowFuncArgsExpressions = new ArrayList<>(numWindowFunctions);
Input[][] windowFuncArgsInputs = new Input[numWindowFunctions][];
Boolean[] ignoreNulls = new Boolean[numWindowFunctions];
for (int idx = 0; idx < numWindowFunctions; idx++) {
var windowFunctionSymbol = windowFunctionSymbols.get(idx);
InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(txnCtx);
ctx.add(windowFunctionSymbol.arguments());
FunctionImplementation impl = nodeCtx.functions().getQualified(windowFunctionSymbol, txnCtx.sessionSettings().searchPath());
assert impl != null : "Function implementation not found using full qualified lookup";
if (impl instanceof AggregationFunction) {
var filterInputFactoryCtx = inputFactory.ctxForInputColumns(txnCtx);
var filterSymbol = windowFunctionSymbol.filter();
// noinspection unchecked
Input<Boolean> filterInput = filterSymbol == null ? Literal.BOOLEAN_TRUE : (Input<Boolean>) filterInputFactoryCtx.add(filterSymbol);
ExpressionsInput<Row, Boolean> filter = new ExpressionsInput<>(filterInput, filterInputFactoryCtx.expressions());
windowFunctions.add(new AggregateToWindowFunctionAdapter((AggregationFunction) impl, filter, indexVersionCreated, ramAccounting, memoryManager, minNodeVersion));
} else if (impl instanceof WindowFunction) {
windowFunctions.add((WindowFunction) impl);
} else {
throw new AssertionError("Function needs to be either a window or an aggregate function");
}
windowFuncArgsExpressions.addAll(ctx.expressions());
windowFuncArgsInputs[idx] = ctx.topLevelInputs().toArray(new Input[0]);
ignoreNulls[idx] = windowFunctionSymbol.ignoreNulls();
}
var windowDefinition = projection.windowDefinition();
var partitions = windowDefinition.partitions();
Supplier<InputFactory.Context<CollectExpression<Row, ?>>> createInputFactoryContext = () -> inputFactory.ctxForInputColumns(txnCtx);
int arrayListElementOverHead = 32;
RowAccountingWithEstimators accounting = new RowAccountingWithEstimators(Symbols.typeView(projection.standalone()), ramAccounting, arrayListElementOverHead);
Comparator<Object[]> cmpPartitionBy = partitions.isEmpty() ? null : createComparator(createInputFactoryContext, new OrderBy(windowDefinition.partitions()));
Comparator<Object[]> cmpOrderBy = createComparator(createInputFactoryContext, windowDefinition.orderBy());
int numCellsInSourceRow = projection.standalone().size();
ComputeFrameBoundary<Object[]> computeFrameStart = createComputeStartFrameBoundary(numCellsInSourceRow, txnCtx, nodeCtx, windowDefinition, cmpOrderBy);
ComputeFrameBoundary<Object[]> computeFrameEnd = createComputeEndFrameBoundary(numCellsInSourceRow, txnCtx, nodeCtx, windowDefinition, cmpOrderBy);
return sourceRows -> WindowFunctionBatchIterator.of(sourceRows, accounting, computeFrameStart, computeFrameEnd, cmpPartitionBy, cmpOrderBy, numCellsInSourceRow, numThreads, executor, windowFunctions, windowFuncArgsExpressions, ignoreNulls, windowFuncArgsInputs);
}
Aggregations