Skip to content

Instantly share code, notes, and snippets.

View okram's full-sized avatar
🏠
Working from home

Marko A. Rodriguez okram

🏠
Working from home
View GitHub Profile
package com.tinkerpop.gremlin.giraph.process.olap;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.tinkerpop.gremlin.process.PathHolder;
import com.tinkerpop.gremlin.process.SimpleHolder;
import org.apache.hadoop.io.Writable;
import java.io.ByteArrayInputStream;
public void mergeResults(final Graph original, final Graph computed, final Map<String, String> keyMapping) {
computed.V().forEach(v1 -> {
Vertex v2 = original.v(v1.getId());
keyMapping.forEach((k, v) -> {
if (v1.getProperty(k).isPresent()) {
v2.setProperty(v, v1.getProperty(k).get());
}
});
});
}
@Override
public <V> Property<V> setProperty(final String key, final V value) {
this.strategyWrappedGraph.strategy().compose(
s -> s.<V>getElementSetProperty(elementStrategyContext),
this.baseElement::setProperty).accept(key, value);
}
public default Set<String> getPropertyKeys() {
return this.getProperties().keySet();
}
public Map<String, Property> getProperties();
@Override
public <V> Property<V> setProperty(final String key, final V value) {
this.strategyWrappedGraph.strategy().compose(
s -> s.<V>getElementSetProperty(elementStrategyContext),
this.baseElement::setProperty).accept(key, value);
return null; // TODO: Stephen, help please! This needs to return the created Property<V>
}
//////
public GraphTraversal<Edge, Edge> start() {
final TinkerEdge edge = this;
final GraphTraversal<Edge, Edge> traversal = new DefaultGraphTraversal<Edge, Edge>() {
public GraphTraversal<Edge, Edge> submit(final TraversalEngine engine) {
if (engine instanceof GraphComputer) {
this.optimizers().unregister(TinkerGraphStepOptimizer.class);
final String label = this.getSteps().get(0).getAs();
TraversalHelper.removeStep(0, this);
gremlin> marko.out('knows').name
==>vadas
==>josh
-----------
marko
.filter{it.get()['name'] == 'marko'}
.flatMap{it.get().out('knows')}
package com.tinkerpop.gremlin.process.graph.sideEffect;
import com.tinkerpop.gremlin.process.Traversal;
import com.tinkerpop.gremlin.process.graph.map.MapStep;
import java.util.NoSuchElementException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
public class TimeLimitStep<S> extends MapStep<S, S> {
private final AtomicLong startTime = new AtomicLong(-1);
public TimeLimitStep(final Traversal traversal, final long timeLimit) {
super(traversal);
super.setFunction(traverser -> {
if (this.startTime.get() == -1l)
this.startTime.set(System.currentTimeMillis());
if ((System.currentTimeMillis() - this.startTime.get()) >= timeLimit)
public DataOutputStream getDataOuputStream(final TaskAttemptContext job) throws IOException, InterruptedException {
final Configuration conf = job.getConfiguration();
boolean isCompressed = getCompressOutput(job);
CompressionCodec codec = null;
String extension = "";
if (isCompressed) {
final Class<? extends CompressionCodec> codecClass = getOutputCompressorClass(job, DefaultCodec.class);
codec = ReflectionUtils.newInstance(codecClass, conf);
extension = codec.getDefaultExtension();
}