use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class FetchRewrite method createFetchSources.
public Map<RelationName, FetchSource> createFetchSources() {
HashMap<RelationName, FetchSource> fetchSources = new HashMap<>();
List<Symbol> outputs = plan.outputs();
for (int i = 0; i < outputs.size(); i++) {
Symbol output = outputs.get(i);
if (output instanceof FetchMarker) {
FetchMarker fetchMarker = (FetchMarker) output;
RelationName tableName = fetchMarker.fetchId().ident().tableIdent();
FetchSource fetchSource = fetchSources.get(tableName);
if (fetchSource == null) {
fetchSource = new FetchSource();
fetchSources.put(tableName, fetchSource);
}
fetchSource.addFetchIdColumn(new InputColumn(i, fetchMarker.valueType()));
for (Reference fetchRef : fetchMarker.fetchRefs()) {
fetchSource.addRefToFetch(fetchRef);
}
}
}
return fetchSources;
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InputColumns method tryCreateSubscriptOnRoot.
@Nullable
private static Symbol tryCreateSubscriptOnRoot(Symbol symbol, ColumnIdent column, HashMap<Symbol, InputColumn> inputs) {
if (column.isTopLevel()) {
return null;
}
ColumnIdent root = column.getRoot();
InputColumn rootIC = lookupValueByColumn(inputs, root);
if (rootIC == null) {
return symbol;
}
DataType<?> returnType = symbol.valueType();
List<String> path = column.path();
List<Symbol> arguments = mapTail(rootIC, path, Literal::of);
return new Function(SubscriptObjectFunction.SIGNATURE, arguments, returnType);
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InsertFromSubQueryPlanner method plan.
public static LogicalPlan plan(AnalyzedInsertStatement statement, PlannerContext plannerContext, LogicalPlanner logicalPlanner, SubqueryPlanner subqueryPlanner) {
if (statement.outputs() != null && !plannerContext.clusterState().getNodes().getMinNodeVersion().onOrAfter(Version.V_4_2_0)) {
throw new UnsupportedFeatureException(RETURNING_VERSION_ERROR_MSG);
}
List<Reference> targetColsExclPartitionCols = new ArrayList<>(statement.columns().size() - statement.tableInfo().partitionedBy().size());
for (Reference column : statement.columns()) {
if (statement.tableInfo().partitionedBy().contains(column.column())) {
continue;
}
targetColsExclPartitionCols.add(column);
}
List<Symbol> columnSymbols = InputColumns.create(targetColsExclPartitionCols, new InputColumns.SourceSymbols(statement.columns()));
// if fields are null default to number of rows imported
var outputs = statement.outputs() == null ? List.of(new InputColumn(0, DataTypes.LONG)) : statement.outputs();
ColumnIndexWriterProjection indexWriterProjection = new ColumnIndexWriterProjection(statement.tableInfo().ident(), null, statement.tableInfo().primaryKey(), statement.columns(), targetColsExclPartitionCols, columnSymbols, statement.isIgnoreDuplicateKeys(), statement.onDuplicateKeyAssignments(), statement.primaryKeySymbols(), statement.partitionedBySymbols(), statement.tableInfo().clusteredBy(), statement.clusteredBySymbol(), Settings.EMPTY, statement.tableInfo().isPartitioned(), outputs, statement.outputs() == null ? List.of() : statement.outputs());
LogicalPlan plannedSubQuery = logicalPlanner.plan(statement.subQueryRelation(), plannerContext, subqueryPlanner, true);
EvalProjection castOutputs = EvalProjection.castValues(Symbols.typeView(statement.columns()), plannedSubQuery.outputs());
return new Insert(plannedSubQuery, indexWriterProjection, castOutputs);
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class AnalyzedInsertStatement method symbolsFromTargetColumnPositionOrGeneratedExpression.
private List<Symbol> symbolsFromTargetColumnPositionOrGeneratedExpression(Map<ColumnIdent, Integer> targetColumnMap, List<Reference> targetColumns, List<ColumnIdent> columns, Map<ColumnIdent, GeneratedReference> generatedColumns, Map<ColumnIdent, Reference> defaultExpressionColumns, boolean alwaysRequireColumn) {
if (columns.isEmpty()) {
return Collections.emptyList();
}
List<Symbol> symbols = new ArrayList<>(columns.size());
InputColumns.SourceSymbols sourceSymbols = new InputColumns.SourceSymbols(targetColumns);
for (ColumnIdent column : columns) {
Integer position = targetColumnMap.get(column);
if (position == null) {
final Symbol symbol;
Reference reference = defaultExpressionColumns.get(column);
if (reference != null) {
symbol = InputColumns.create(requireNonNull(reference.defaultExpression(), "Column " + column + " must contain a default expression"), sourceSymbols);
} else {
GeneratedReference generatedRef = generatedColumns.get(column);
if (generatedRef == null) {
Reference columnRef = requireNonNull(targetTable.getReference(column), "Column " + column + " must exist in table " + targetTable.ident());
symbol = InputColumns.create(columnRef, sourceSymbols);
} else {
symbol = InputColumns.create(generatedRef.generatedExpression(), sourceSymbols);
}
}
if (SymbolVisitors.any(Symbols.IS_COLUMN, symbol)) {
if (alwaysRequireColumn) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Column \"%s\" is required but is missing from the insert statement", column.sqlFqn()));
} else {
symbols.add(Literal.NULL);
}
} else {
symbols.add(symbol);
}
} else {
symbols.add(new InputColumn(position, targetColumns.get(position).valueType()));
}
}
return symbols;
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class WindowProjector method createUpdateProbeValueFunction.
private static BiFunction<Object[], Object[], Object[]> createUpdateProbeValueFunction(WindowDefinition windowDefinition, BiFunction<DataType<?>, DataType<?>, BiFunction> getOffsetApplicationFunction, Object offsetValue, DataType<?> offsetType) {
OrderBy windowOrdering = windowDefinition.orderBy();
assert windowOrdering != null : "The window definition must be ordered if custom offsets are specified";
List<Symbol> orderBySymbols = windowOrdering.orderBySymbols();
if (orderBySymbols.size() != 1) {
throw new IllegalArgumentException("Must have exactly 1 ORDER BY expression if using <offset> FOLLOWING/PRECEDING");
}
int offsetColumnPosition;
Symbol orderSymbol = orderBySymbols.get(0);
BiFunction applyOffsetOnOrderingValue = getOffsetApplicationFunction.apply(orderSymbol.valueType(), offsetType);
if (orderSymbol.symbolType() == SymbolType.LITERAL) {
offsetColumnPosition = -1;
} else {
assert orderSymbol instanceof InputColumn : "ORDER BY expression must resolve to an InputColumn, but got: " + orderSymbol;
offsetColumnPosition = ((InputColumn) orderSymbol).index();
}
var finalOffsetValue = offsetType.id() == IntervalType.ID ? offsetType.sanitizeValue(offsetValue) : orderSymbol.valueType().sanitizeValue(offsetValue);
return (currentRow, x) -> {
// `null`)
if (offsetColumnPosition != -1) {
x[offsetColumnPosition] = applyOffsetOnOrderingValue.apply(currentRow[offsetColumnPosition], finalOffsetValue);
}
return x;
};
}
Aggregations