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;
}
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");
}
}
}
}
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);
}
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));
});
}
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"));
}
Aggregations