Search in sources :

Example 16 with OSQLFunctionRuntime

use of com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime in project orientdb by orientechnologies.

the class ODistributedStorage method mergeResultByAggregation.

protected Object mergeResultByAggregation(final OCommandExecutorSQLSelect select, final Map<String, Object> iResults) {
    final List<Object> list = new ArrayList<Object>();
    final ODocument doc = new ODocument();
    list.add(doc);
    boolean hasNonAggregates = false;
    final Map<String, Object> proj = select.getProjections();
    for (Map.Entry<String, Object> p : proj.entrySet()) {
        if (!(p.getValue() instanceof OSQLFunctionRuntime)) {
            hasNonAggregates = true;
            break;
        }
    }
    if (hasNonAggregates) {
        // MERGE NON AGGREGATED FIELDS
        for (Map.Entry<String, Object> entry : iResults.entrySet()) {
            final List<Object> resultSet = (List<Object>) entry.getValue();
            for (Object r : resultSet) {
                if (r instanceof ODocument) {
                    final ODocument d = (ODocument) r;
                    for (Map.Entry<String, Object> p : proj.entrySet()) {
                        // WRITE THE FIELD AS IS
                        if (!(p.getValue() instanceof OSQLFunctionRuntime))
                            doc.field(p.getKey(), ((ODocument) r).field(p.getKey()));
                    }
                }
            }
        }
    }
    final List<Object> toMerge = new ArrayList<Object>();
    // MERGE AGGREGATED FIELDS
    for (Map.Entry<String, Object> p : proj.entrySet()) {
        if (p.getValue() instanceof OSQLFunctionRuntime) {
            // MERGE RESULTS
            final OSQLFunctionRuntime f = (OSQLFunctionRuntime) p.getValue();
            toMerge.clear();
            for (Map.Entry<String, Object> entry : iResults.entrySet()) {
                final List<Object> resultSet = (List<Object>) entry.getValue();
                for (Object r : resultSet) {
                    if (r instanceof ODocument) {
                        final ODocument d = (ODocument) r;
                        toMerge.add(d.rawField(p.getKey()));
                    }
                }
            }
            // WRITE THE FINAL MERGED RESULT
            doc.field(p.getKey(), f.getFunction().mergeDistributedResult(toMerge));
        }
    }
    return list;
}
Also used : OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OSQLFunctionRuntime

use of com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreateVertex method execute.

/**
   * Execute the command and return the ODocument object created.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (clazz == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    // CREATE VERTEX DOES NOT HAVE TO BE IN TX
    return OGraphCommandExecutorSQLFactory.runWithAnyGraph(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {

        @Override
        public Object call(final OrientBaseGraph graph) {
            final OrientVertex vertex = graph.addTemporaryVertex(clazz.getName());
            if (fields != null)
                // EVALUATE FIELDS
                for (final OPair<String, Object> f : fields) {
                    if (f.getValue() instanceof OSQLFunctionRuntime)
                        f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context));
                }
            OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context);
            if (content != null)
                vertex.getRecord().merge(content, true, false);
            if (clusterName != null)
                vertex.save(clusterName);
            else
                vertex.save();
            return vertex.getRecord();
        }
    });
}
Also used : OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OCommandParameters(com.orientechnologies.orient.core.sql.OCommandParameters) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Aggregations

OSQLFunctionRuntime (com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)5 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecord (com.orientechnologies.orient.core.record.ORecord)3 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)3 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)2 OCommandParameters (com.orientechnologies.orient.core.sql.OCommandParameters)2 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)2 OSQLFunctionCount (com.orientechnologies.orient.core.sql.functions.misc.OSQLFunctionCount)2 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)2 ArrayList (java.util.ArrayList)2 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1 OSortedMultiIterator (com.orientechnologies.common.collection.OSortedMultiIterator)1 OException (com.orientechnologies.common.exception.OException)1 OProfiler (com.orientechnologies.common.profiler.OProfiler)1 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)1 OPair (com.orientechnologies.common.util.OPair)1 OResettable (com.orientechnologies.common.util.OResettable)1