Search in sources :

Example 16 with ColumnIdent

use of io.crate.metadata.ColumnIdent 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 17 with ColumnIdent

use of io.crate.metadata.ColumnIdent 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 18 with ColumnIdent

use of io.crate.metadata.ColumnIdent 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)

Example 19 with ColumnIdent

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

the class GetResponseRefResolver method getImplementation.

@Override
public CollectExpression<GetResponse, ?> getImplementation(Reference ref) {
    ColumnIdent columnIdent = ref.ident().columnIdent();
    columnConsumer.accept(columnIdent);
    String fqn = columnIdent.fqn();
    switch(fqn) {
        case DocSysColumns.Names.VERSION:
            return CollectExpression.of(GetResponse::getVersion);
        case DocSysColumns.Names.ID:
            return CollectExpression.of(GetResponse::getId);
        case DocSysColumns.Names.RAW:
            return CollectExpression.of(r -> r.getSourceAsBytesRef().toBytesRef());
        case DocSysColumns.Names.DOC:
            return CollectExpression.of(GetResponse::getSource);
    }
    if (docTableInfo.isPartitioned() && docTableInfo.partitionedBy().contains(columnIdent)) {
        int pkPos = docTableInfo.primaryKey().indexOf(columnIdent);
        if (pkPos >= 0) {
            return CollectExpression.of(response -> ValueSymbolVisitor.VALUE.process(ids2Keys.get(response.getId()).values().get(pkPos)));
        }
    }
    return CollectExpression.of(response -> {
        Map<String, Object> sourceAsMap = response.getSourceAsMap();
        return ref.valueType().value(XContentMapValues.extractValue(fqn, sourceAsMap));
    });
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 20 with ColumnIdent

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

the class FileWriterProjectorTest method testToNestedStringObjectMap.

@Test
public void testToNestedStringObjectMap() throws Exception {
    Map<ColumnIdent, Object> columnIdentMap = new HashMap<>();
    columnIdentMap.put(new ColumnIdent("some", Arrays.asList("nested", "column")), "foo");
    Map<String, Object> convertedMap = FileWriterCountCollector.toNestedStringObjectMap(columnIdentMap);
    Map someMap = (Map) convertedMap.get("some");
    Map nestedMap = (Map) someMap.get("nested");
    assertThat(nestedMap.get("column"), is("foo"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ColumnIdent (io.crate.metadata.ColumnIdent)34 Reference (io.crate.metadata.Reference)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)12 Test (org.junit.Test)12 Map (java.util.Map)5 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)4 GeneratedReference (io.crate.metadata.GeneratedReference)4 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)3 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)3 ArrayType (io.crate.types.ArrayType)3 HashMap (java.util.HashMap)3 Field (io.crate.analyze.symbol.Field)2 Symbol (io.crate.analyze.symbol.Symbol)2 ColumnValidationException (io.crate.exceptions.ColumnValidationException)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 FileUriCollectPhase (io.crate.planner.node.dql.FileUriCollectPhase)2 DataType (io.crate.types.DataType)2 BytesRef (org.apache.lucene.util.BytesRef)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1