use of io.crate.metadata.Reference in project crate by crate.
the class ShardUpsertRequest method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
// Stream References
if (updateColumns != null) {
out.writeVInt(updateColumns.length);
for (String column : updateColumns) {
out.writeString(column);
}
} else {
out.writeVInt(0);
}
if (insertColumns != null) {
out.writeVInt(insertColumns.length);
for (Reference reference : insertColumns) {
Reference.toStream(reference, out);
}
} else {
out.writeVInt(0);
}
out.writeBoolean(continueOnError);
out.writeBoolean(overwriteDuplicates);
out.writeBoolean(validateConstraints);
writeItems(out);
}
use of io.crate.metadata.Reference in project crate by crate.
the class Assignments method convert.
/**
* convert assignments into a tuple of fqn column names and the symbols.
* <p>
* <pre>
* {
* users.age: users.age + 1,
* users.name: users.name || 'foo'
*
* }
* </pre>
* becomes
* <pre>
* ( [users.age, users.name], [users.age + 1, users.name || 'foo'] )
* </pre>
*
* @return a tuple or null if the input is null.
*/
public static Tuple<String[], Symbol[]> convert(@Nonnull Map<Reference, ? extends Symbol> assignments) {
String[] assignmentColumns = new String[assignments.size()];
Symbol[] assignmentSymbols = new Symbol[assignments.size()];
int i = 0;
for (Map.Entry<Reference, ? extends Symbol> entry : assignments.entrySet()) {
Reference key = entry.getKey();
assignmentColumns[i] = key.ident().columnIdent().fqn();
assignmentSymbols[i] = entry.getValue();
i++;
}
return new Tuple<>(assignmentColumns, assignmentSymbols);
}
use of io.crate.metadata.Reference in project crate by crate.
the class TableReferenceResolver method resolveField.
@Override
public Reference resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation) {
List<String> parts = qualifiedName.getParts();
ColumnIdent columnIdent = new ColumnIdent(parts.get(parts.size() - 1), path);
if (parts.size() != 1) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Column reference \"%s\" has too many parts. " + "A column must not have a schema or a table here.", qualifiedName));
}
for (Reference reference : tableReferences) {
if (reference.ident().columnIdent().equals(columnIdent)) {
if (reference instanceof GeneratedReference) {
throw new IllegalArgumentException("A generated column cannot be based on a generated column");
}
references.add(reference);
return reference;
}
}
throw new ColumnUnknownException(columnIdent.sqlFqn());
}
use of io.crate.metadata.Reference in project crate by crate.
the class AbstractTableRelation method hasMatchingParent.
/**
* return true if the given {@linkplain com.google.common.base.Predicate}
* returns true for a parent column of this one.
* returns false if info has no parent column.
*/
private boolean hasMatchingParent(Reference info, Predicate<Reference> parentMatchPredicate) {
ColumnIdent parent = info.ident().columnIdent().getParent();
while (parent != null) {
Reference parentInfo = tableInfo.getReference(parent);
if (parentMatchPredicate.apply(parentInfo)) {
return true;
}
parent = parent.getParent();
}
return false;
}
use of io.crate.metadata.Reference in project crate by crate.
the class CopyToPlannerTest method testCopyToWithColumnsReferenceRewrite.
@Test
public void testCopyToWithColumnsReferenceRewrite() throws Exception {
Merge plan = e.plan("copy users (name) to directory '/tmp'");
Collect innerPlan = (Collect) plan.subPlan();
RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
Reference nameRef = (Reference) node.toCollect().get(0);
assertThat(nameRef.ident().columnIdent().name(), is(DocSysColumns.DOC.name()));
assertThat(nameRef.ident().columnIdent().path().get(0), is("name"));
}
Aggregations