Search in sources :

Example 26 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class AbstractTableRelation method checkNestedArray.

protected Reference checkNestedArray(ColumnIdent ci, Reference reference) {
    // TODO: build type correctly as array when the tableInfo is created and remove the conversion here
    DataType dataType = null;
    ColumnIdent tmpCI = ci;
    Reference tmpRI = reference;
    while (!tmpCI.isColumn() && hasMatchingParent(tmpRI, IS_OBJECT_ARRAY)) {
        if (DataTypes.isCollectionType(reference.valueType())) {
            // TODO: remove this limitation with next type refactoring
            throw new UnsupportedOperationException("cannot query for arrays inside object arrays explicitly");
        }
        // return references of primitive types as array
        if (dataType == null) {
            dataType = new ArrayType(reference.valueType());
            if (hasNestedObjectReference(tmpRI))
                break;
        } else {
            dataType = new ArrayType(dataType);
        }
        tmpCI = tmpCI.getParent();
        tmpRI = tableInfo.getReference(tmpCI);
    }
    if (dataType != null) {
        return new Reference(reference.ident(), reference.granularity(), dataType, reference.columnPolicy(), reference.indexType(), reference.isNullable());
    } else {
        return reference;
    }
}
Also used : ArrayType(io.crate.types.ArrayType) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType)

Example 27 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class AbstractTableRelation method getField.

@Nullable
public Field getField(Path path) {
    ColumnIdent ci = toColumnIdent(path);
    Reference reference = tableInfo.getReference(ci);
    if (reference == null) {
        return null;
    }
    reference = checkNestedArray(ci, reference);
    return allocate(ci, reference);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) Nullable(javax.annotation.Nullable)

Example 28 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class AbstractTableRelation method fields.

@Override
public List<Field> fields() {
    if (outputs == null) {
        outputs = new ArrayList<>(tableInfo.columns().size());
        for (Reference reference : tableInfo.columns()) {
            if (reference.valueType().equals(DataTypes.NOT_SUPPORTED)) {
                continue;
            }
            ColumnIdent columnIdent = reference.ident().columnIdent();
            outputs.add(getField(columnIdent));
        }
    }
    return outputs;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference)

Example 29 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class DocTableRelation method ensureColumnCanBeUpdated.

/**
     * @throws io.crate.exceptions.ColumnValidationException if the column cannot be updated
     */
private void ensureColumnCanBeUpdated(ColumnIdent ci) {
    if (ci.isSystemColumn()) {
        throw new ColumnValidationException(ci.toString(), "Updating a system column is not supported");
    }
    if (tableInfo.clusteredBy() != null) {
        ensureNotUpdated(ci, tableInfo.clusteredBy(), "Updating a clustered-by column is not supported");
    }
    for (ColumnIdent pkIdent : tableInfo.primaryKey()) {
        ensureNotUpdated(ci, pkIdent, "Updating a primary key is not supported");
    }
    List<GeneratedReference> generatedReferences = tableInfo.generatedColumns();
    for (ColumnIdent partitionIdent : tableInfo.partitionedBy()) {
        ensureNotUpdated(ci, partitionIdent, "Updating a partitioned-by column is not supported");
        int idx = generatedReferences.indexOf(tableInfo.getReference(partitionIdent));
        if (idx >= 0) {
            GeneratedReference generatedReference = generatedReferences.get(idx);
            for (Reference reference : generatedReference.referencedReferences()) {
                ensureNotUpdated(ci, reference.ident().columnIdent(), "Updating a column which is referenced in a partitioned by generated column expression is not supported");
            }
        }
    }
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GeneratedReference(io.crate.metadata.GeneratedReference) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference) ColumnValidationException(io.crate.exceptions.ColumnValidationException)

Example 30 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class DocTableRelation method getField.

@Override
public Field getField(Path path, Operation operation) throws UnsupportedOperationException, ColumnUnknownException {
    ColumnIdent ci = toColumnIdent(path);
    if (HIDDEN_COLUMNS.contains(ci)) {
        return null;
    }
    if (operation == Operation.UPDATE) {
        ensureColumnCanBeUpdated(ci);
    }
    Reference reference = tableInfo.getReference(ci);
    if (reference == null) {
        reference = tableInfo.indexColumn(ci);
        if (reference == null) {
            DynamicReference dynamic = tableInfo.getDynamic(ci, operation == Operation.INSERT || operation == Operation.UPDATE);
            if (dynamic == null) {
                return null;
            } else {
                return allocate(ci, dynamic);
            }
        }
    }
    reference = checkNestedArray(ci, reference);
    // TODO: check allocated fields first?
    return allocate(ci, reference);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference)

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