Search in sources :

Example 1 with CollectionType

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;
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) CollectionType(io.crate.types.CollectionType)

Example 2 with CollectionType

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) CollectionType(io.crate.types.CollectionType) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

CollectionType (io.crate.types.CollectionType)2 FluentIterable (com.google.common.collect.FluentIterable)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 Symbol (io.crate.analyze.symbol.Symbol)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 Settings (org.elasticsearch.common.settings.Settings)1