use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class FetchRows method create.
public static FetchRows create(TransactionContext txnCtx, NodeContext nodeCtx, Map<RelationName, FetchSource> fetchSourceByTable, List<Symbol> outputSymbols) {
IntArrayList fetchIdPositions = new IntArrayList();
ArrayList<Object[]> nullRows = new ArrayList<>();
IntObjectHashMap<UnsafeArrayRow> fetchedRows = new IntObjectHashMap<>();
for (var fetchSource : fetchSourceByTable.values()) {
Object[] nullRow = new Object[fetchSource.references().size()];
for (InputColumn ic : fetchSource.fetchIdCols()) {
fetchIdPositions.add(ic.index());
nullRows.add(nullRow);
fetchedRows.put(ic.index(), new UnsafeArrayRow());
}
}
final UnsafeArrayRow inputRow = new UnsafeArrayRow();
var visitor = new BaseImplementationSymbolVisitor<Void>(txnCtx, nodeCtx) {
@Override
public Input<?> visitInputColumn(final InputColumn inputColumn, final Void context) {
final int idx = inputColumn.index();
return () -> inputRow.get(idx);
}
@Override
public Input<?> visitFetchReference(final FetchReference fetchReference, final Void context) {
var ref = fetchReference.ref();
UnsafeArrayRow row = fetchedRows.get(fetchReference.fetchId().index());
int posInFetchedRow = fetchSourceByTable.get(ref.ident().tableIdent()).references().indexOf(ref);
return () -> row.get(posInFetchedRow);
}
};
List<Input<?>> outputExpressions = Lists2.map(outputSymbols, x -> x.accept(visitor, null));
return new FetchRows(fetchIdPositions, outputExpressions, inputRow, fetchedRows, nullRows);
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InsertAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.
@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
var insert = "insert into users (id, name) (select id, name from users) " + "on conflict (id) do update set name = substr(excluded.name, 1, 1)";
AnalyzedInsertStatement statement = e.analyze(insert);
Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
assertThat(entry.getKey(), isReference("name"));
assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
Function function = (Function) entry.getValue();
assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
InputColumn inputColumn = (InputColumn) function.arguments().get(0);
assertThat(inputColumn.index(), is(1));
assertThat(inputColumn.valueType(), instanceOf(StringType.class));
}
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class RowShardResolverTest method testPrimaryKeyAndRouting.
@Test
public void testPrimaryKeyAndRouting() {
List<Symbol> primaryKeySymbols = List.of(new InputColumn(0), new InputColumn(1));
RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ci("id"), ci("foo")), primaryKeySymbols, ci("foo"), new InputColumn(1));
rowShardResolver.setNextRow(row(1, "hoschi"));
// compound encoded id, special routing
assertThat(rowShardResolver.id(), is("AgZob3NjaGkBMQ=="));
assertThat(rowShardResolver.routing(), is("hoschi"));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class RowShardResolverTest method testNoPrimaryKeyButRouting.
@Test
public void testNoPrimaryKeyButRouting() {
RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(), List.of(), ID_IDENT, new InputColumn(1));
rowShardResolver.setNextRow(row(1, "hoschi"));
// auto-generated id, special routing
assertNotNull(rowShardResolver.id());
assertThat(rowShardResolver.routing(), is("hoschi"));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class RowShardResolverTest method testIdPrimaryKeyNull.
@Test
public void testIdPrimaryKeyNull() {
List<Symbol> primaryKeySymbols = List.of(new InputColumn(2));
RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ID_IDENT), primaryKeySymbols, null, new InputColumn(1));
rowShardResolver.setNextRow(row(1, "hoschi", null));
// generated _id, special routing
assertNotNull(rowShardResolver.id());
assertThat(rowShardResolver.routing(), is("hoschi"));
}
Aggregations