use of io.crate.types.CollectionType in project crate by crate.
the class Literal method explodeCollection.
public static Collection<Literal> explodeCollection(Literal collectionLiteral) {
Preconditions.checkArgument(DataTypes.isCollectionType(collectionLiteral.valueType()));
Iterable values;
int size;
Object literalValue = collectionLiteral.value();
if (literalValue instanceof Collection) {
values = (Iterable) literalValue;
size = ((Collection) literalValue).size();
} else {
values = FluentIterable.of((Object[]) literalValue);
size = ((Object[]) literalValue).length;
}
List<Literal> literals = new ArrayList<>(size);
for (Object value : values) {
literals.add(new Literal<>(((CollectionType) collectionLiteral.valueType()).innerType(), value));
}
return literals;
}
use of io.crate.types.CollectionType in project crate by crate.
the class CopyAnalyzer method convertCopyFrom.
CopyFromAnalyzedStatement convertCopyFrom(CopyFrom node, Analysis analysis) {
DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.of(node.table(), analysis.sessionContext().defaultSchema()));
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
Operation.blockedRaiseException(tableInfo, Operation.INSERT);
String partitionIdent = null;
if (!node.table().partitionProperties().isEmpty()) {
partitionIdent = PartitionPropertiesAnalyzer.toPartitionIdent(tableInfo, node.table().partitionProperties(), analysis.parameterContext().parameters());
}
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, tableRelation);
ExpressionAnalyzer expressionAnalyzer = createExpressionAnalyzer(analysis, tableRelation);
expressionAnalyzer.setResolveFieldsOperation(Operation.INSERT);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
Predicate<DiscoveryNode> nodeFilters = Predicates.alwaysTrue();
Settings settings = Settings.EMPTY;
if (node.genericProperties().isPresent()) {
// copy map as items are removed. The GenericProperties map is cached in the query cache and removing
// items would cause subsequent queries that hit the cache to have different genericProperties
Map<String, Expression> properties = new HashMap<>(node.genericProperties().get().properties());
nodeFilters = discoveryNodePredicate(analysis.parameterContext().parameters(), properties.remove(NodeFilters.NAME));
settings = settingsFromProperties(properties, expressionAnalyzer, expressionAnalysisContext);
}
Symbol uri = expressionAnalyzer.convert(node.path(), expressionAnalysisContext);
uri = normalizer.normalize(uri, analysis.transactionContext());
if (!(uri.valueType() == DataTypes.STRING || uri.valueType() instanceof CollectionType && ((CollectionType) uri.valueType()).innerType() == DataTypes.STRING)) {
throw CopyFromAnalyzedStatement.raiseInvalidType(uri.valueType());
}
return new CopyFromAnalyzedStatement(tableInfo, settings, uri, partitionIdent, nodeFilters);
}
Aggregations