Search in sources :

Example 76 with Reference

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);
}
Also used : Reference(io.crate.metadata.Reference) BytesReference(org.elasticsearch.common.bytes.BytesReference)

Example 77 with Reference

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);
}
Also used : Reference(io.crate.metadata.Reference) Map(java.util.Map) Tuple(org.elasticsearch.common.collect.Tuple)

Example 78 with Reference

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());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GeneratedReference(io.crate.metadata.GeneratedReference) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference)

Example 79 with Reference

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;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference)

Example 80 with Reference

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"));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Reference (io.crate.metadata.Reference)84 Test (org.junit.Test)57 CrateUnitTest (io.crate.test.integration.CrateUnitTest)55 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)27 HashMap (java.util.HashMap)20 Map (java.util.Map)20 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)17 ColumnIdent (io.crate.metadata.ColumnIdent)15 Symbol (io.crate.analyze.symbol.Symbol)14 BytesRef (org.apache.lucene.util.BytesRef)11 TableIdent (io.crate.metadata.TableIdent)9 ReferenceIdent (io.crate.metadata.ReferenceIdent)8 InputColumn (io.crate.analyze.symbol.InputColumn)6 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)6 ShardId (org.elasticsearch.index.shard.ShardId)5 Routing (io.crate.metadata.Routing)4 UUID (java.util.UUID)4 OrderBy (io.crate.analyze.OrderBy)3 ShardResponse (io.crate.executor.transport.ShardResponse)3 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)3