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