use of io.crate.metadata.ColumnIdent in project crate by crate.
the class PartitionPropertiesAnalyzer method toPartitionName.
public static PartitionName toPartitionName(DocTableInfo tableInfo, List<Assignment> partitionProperties, Row parameters) {
Preconditions.checkArgument(tableInfo.isPartitioned(), "table '%s' is not partitioned", tableInfo.ident().fqn());
Preconditions.checkArgument(partitionProperties.size() == tableInfo.partitionedBy().size(), "The table \"%s\" is partitioned by %s columns but the PARTITION clause contains %s columns", tableInfo.ident().fqn(), tableInfo.partitionedBy().size(), partitionProperties.size());
Map<ColumnIdent, Object> properties = assignmentsToMap(partitionProperties, parameters);
BytesRef[] values = new BytesRef[properties.size()];
for (Map.Entry<ColumnIdent, Object> entry : properties.entrySet()) {
Object value = entry.getValue();
int idx = tableInfo.partitionedBy().indexOf(entry.getKey());
try {
Reference reference = tableInfo.partitionedByColumns().get(idx);
Object converted = reference.valueType().value(value);
values[idx] = converted == null ? null : DataTypes.STRING.value(converted);
} catch (IndexOutOfBoundsException ex) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "\"%s\" is no known partition column", entry.getKey().sqlFqn()));
}
}
return new PartitionName(tableInfo.ident(), Arrays.asList(values));
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class AnalyzedColumnDefinition method name.
public void name(String name) {
validateName(name);
this.name = name;
if (this.parent != null) {
this.ident = ColumnIdent.getChild(this.parent.ident, name);
} else {
this.ident = new ColumnIdent(name);
}
}
use of io.crate.metadata.ColumnIdent in project crate by crate.
the class ValueNormalizer method normalizeObjectValue.
@SuppressWarnings("unchecked")
private void normalizeObjectValue(Map<String, Object> value, Reference info) {
for (Map.Entry<String, Object> entry : value.entrySet()) {
AnalyzedColumnDefinition.validateName(entry.getKey());
ColumnIdent nestedIdent = ColumnIdent.getChild(info.ident().columnIdent(), entry.getKey());
TableInfo tableInfo = schemas.getTableInfo(info.ident().tableIdent());
Reference nestedInfo = tableInfo.getReference(nestedIdent);
if (nestedInfo == null) {
if (info.columnPolicy() == ColumnPolicy.IGNORED) {
continue;
}
DynamicReference dynamicReference = null;
if (tableInfo instanceof DocTableInfo) {
dynamicReference = ((DocTableInfo) tableInfo).getDynamic(nestedIdent, true);
}
if (dynamicReference == null) {
throw new ColumnUnknownException(nestedIdent.sqlFqn());
}
DataType type = DataTypes.guessType(entry.getValue());
if (type == null) {
throw new ColumnValidationException(info.ident().columnIdent().sqlFqn(), "Invalid value");
}
dynamicReference.valueType(type);
nestedInfo = dynamicReference;
} else {
if (entry.getValue() == null) {
continue;
}
}
if (nestedInfo.valueType() == DataTypes.OBJECT && entry.getValue() instanceof Map) {
normalizeObjectValue((Map<String, Object>) entry.getValue(), nestedInfo);
} else if (isObjectArray(nestedInfo.valueType()) && entry.getValue() instanceof Object[]) {
normalizeObjectArrayValue((Object[]) entry.getValue(), nestedInfo);
} else {
entry.setValue(normalizePrimitiveValue(entry.getValue(), nestedInfo));
}
}
}
use of io.crate.metadata.ColumnIdent 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.ColumnIdent 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);
}
Aggregations