You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by dkuppitz <gi...@git.apache.org> on 2016/05/31 12:53:31 UTC
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
GitHub user dkuppitz opened a pull request:
https://github.com/apache/incubator-tinkerpop/pull/323
TINKERPOP-1298 Save OLAP results to file
https://issues.apache.org/jira/browse/TINKERPOP-1298
Implemented `BulkExportVertexProgram` which allows to export tabular result sets in CSV format (or rather any clear-text format).
Docs and integration test were added.
VOTE: +1
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/apache/incubator-tinkerpop TINKERPOP-1298
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-tinkerpop/pull/323.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #323
----
commit df6cfd603468e05a80070b2ba547059c5f4fec12
Author: Daniel Kuppitz <da...@hotmail.com>
Date: 2016-05-22T07:37:41Z
added BulkExportVertexProgram
commit f4cccc0942f5e98bf3fbacf65bac09c11aeb7269
Author: Daniel Kuppitz <da...@hotmail.com>
Date: 2016-05-23T16:24:22Z
Added script and configuration file that can be used for OLAP CSV exports.
commit d3292fb8940fb29d07dbf619032b3b6321a59896
Author: Daniel Kuppitz <da...@hotmail.com>
Date: 2016-05-27T18:32:27Z
Don't let users mess with halted traversers. Instead simply provide all preformatted values.
commit 741ca40269203ee4bf7f53f960575415f4b8a121
Author: Daniel Kuppitz <da...@hotmail.com>
Date: 2016-05-31T12:46:01Z
Documented `BulkExportVertexProgram` and added an integration test.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65183975
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgram.java ---
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationUtils;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.Memory;
+import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
+import org.apache.tinkerpop.gremlin.process.computer.Messenger;
+import org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey;
+import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.util.AbstractVertexProgramBuilder;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.javatuples.Tuple;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgram implements VertexProgram<Tuple> {
+
+ public static final String BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX = "gremlin.bulkExportVertexProgram";
+ public static final String BULK_EXPORT_PROPERTIES = String.join(".", BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX, "properties");
+
+ private Configuration configuration;
+ private Map<String, String> properties;
+ private List<String> sortedProperties;
+ private Set<VertexComputeKey> vertexComputeKeys;
+
+ private BulkExportVertexProgram() {
+ }
+
+ @Override
+ public void loadState(final Graph graph, final Configuration config) {
+ configuration = new BaseConfiguration();
+ if (config != null) {
+ ConfigurationUtils.copy(config, configuration);
+ }
+ properties = new HashMap<>();
+ sortedProperties = new ArrayList<>();
+ for (final String tuple : configuration.getString(BULK_EXPORT_PROPERTIES, "").split("\1")) {
+ final String[] parts = tuple.split("\2", -1);
+ properties.put(parts[0], parts[1]);
+ sortedProperties.add(parts[0]);
+ }
+ vertexComputeKeys = Collections.singleton(VertexComputeKey.of(BULK_EXPORT_PROPERTIES, false));
+ }
+
+ @Override
+ public void storeState(final Configuration config) {
+ VertexProgram.super.storeState(config);
+ if (configuration != null) {
+ ConfigurationUtils.copy(configuration, config);
+ }
+ }
+
+ @Override
+ public void setup(final Memory memory) {
+ }
+
+ @Override
+ public void execute(final Vertex sourceVertex, final Messenger<Tuple> messenger, final Memory memory) {
--- End diff --
You never even send a message that is `Tuple`? Why do you specify `Tuple` as the message type?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65182884
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java ---
@@ -295,6 +296,7 @@ private void validate() {
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(UUID.class, kryo -> new UUIDSerializer(), 17));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(URI.class, kryo -> new URISerializer(), 72));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(VertexTerminator.class, null, 13));
+ add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(AbstractMap.SimpleEntry.class, kryo -> new EntrySerializer(), 120)); // ***LAST ID***
--- End diff --
We already have:
https://github.com/apache/incubator-tinkerpop/blob/741ca40269203ee4bf7f53f960575415f4b8a121/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java#L282
Can you simply use that?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by dkuppitz <gi...@git.apache.org>.
Github user dkuppitz commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65209307
--- Diff: gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgramTest.java ---
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.io.script.ScriptResourceAccess;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.structure.Column.keys;
+import static org.apache.tinkerpop.gremlin.structure.Column.values;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgramTest extends AbstractGremlinProcessTest {
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void shouldExportCsvFile() throws Exception {
+ if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) {
+ g.V().hasLabel("person").match(
+ __.as("person").values("name").as("name"),
+ __.as("person").values("age").as("age"),
+ __.as("person").outE("created").count().as("projects")
+ ).select("person").
+ coalesce(__.out("created"), __.identity()).
+ coalesce(__.in("created"), __.identity()).
+ groupCount("m").by(__.select("person", "name", "age", "projects")).cap("m").unfold().as("kv").
+ select(keys).select("person").as("person").
+ select("kv").select(keys).select("name").as("name").
+ select("kv").select(keys).select("age").as("age").
+ select("kv").select(keys).select("projects").as("projects").
+ select("kv").select(values).map(__.union(__.identity(), __.constant(-1)).sum()).as("coworkers").
+ select("person", "name", "age", "projects", "coworkers").
+ program(BulkDumperVertexProgram.build().create(graph)).iterate();
+
+ final Configuration config = graph.configuration();
+ final String outputLocation = config.getString("gremlin.hadoop.outputLocation");
+ final String scriptFileName =
+ TestHelper.generateTempFileFromResource(ScriptResourceAccess.class, "script-csv-export.groovy", "").
+ getAbsolutePath().replace('\\', '/');
+
+ config.setProperty("gremlin.hadoop.inputLocation", outputLocation + "/~g");
--- End diff --
Mainly working around [TINKERPOP-1304](https://issues.apache.org/jira/browse/TINKERPOP-1304). But even if 1304 would be solved, I would have to set the `graphWriter` to `ScriptOutputFormat`. I will add some appropriate methods to `HadoopGraphProvider`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65183485
--- Diff: gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgramTest.java ---
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.io.script.ScriptResourceAccess;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.structure.Column.keys;
+import static org.apache.tinkerpop.gremlin.structure.Column.values;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgramTest extends AbstractGremlinProcessTest {
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void shouldExportCsvFile() throws Exception {
+ if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) {
+ g.V().hasLabel("person").match(
+ __.as("person").values("name").as("name"),
+ __.as("person").values("age").as("age"),
+ __.as("person").outE("created").count().as("projects")
+ ).select("person").
+ coalesce(__.out("created"), __.identity()).
+ coalesce(__.in("created"), __.identity()).
+ groupCount("m").by(__.select("person", "name", "age", "projects")).cap("m").unfold().as("kv").
+ select(keys).select("person").as("person").
+ select("kv").select(keys).select("name").as("name").
+ select("kv").select(keys).select("age").as("age").
+ select("kv").select(keys).select("projects").as("projects").
+ select("kv").select(values).map(__.union(__.identity(), __.constant(-1)).sum()).as("coworkers").
+ select("person", "name", "age", "projects", "coworkers").
+ program(BulkDumperVertexProgram.build().create(graph)).iterate();
+
+ final Configuration config = graph.configuration();
+ final String outputLocation = config.getString("gremlin.hadoop.outputLocation");
+ final String scriptFileName =
+ TestHelper.generateTempFileFromResource(ScriptResourceAccess.class, "script-csv-export.groovy", "").
+ getAbsolutePath().replace('\\', '/');
+
+ config.setProperty("gremlin.hadoop.inputLocation", outputLocation + "/~g");
+ config.setProperty("gremlin.hadoop.outputLocation", outputLocation + "-csv");
+ config.setProperty("gremlin.hadoop.graphReader", "org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoInputFormat");
+ config.setProperty("gremlin.hadoop.graphWriter", "org.apache.tinkerpop.gremlin.hadoop.structure.io.script.ScriptOutputFormat");
+ config.setProperty("gremlin.hadoop.scriptOutputFormat.script", scriptFileName);
+
+ graph.compute().program(BulkExportVertexProgram.build().keys("name", "age", "projects", "coworkers").create(graph)).submit().get();
+
+ final Set<String> lines = new HashSet<>();
+ lines.add("josh,32,2,3");
+ lines.add("marko,29,1,2");
+ lines.add("peter,35,1,2");
+ lines.add("vadas,27,0,0");
+
+ final File output = new File(outputLocation + "-csv/~g");
+ for (final File f : output.listFiles()) {
+ if (f.getName().startsWith("part-")) {
--- End diff --
Again, more Hadoop stuff that should not be here. Also, this is file handling, please look into `Storage`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65209732
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java ---
@@ -295,6 +296,7 @@ private void validate() {
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(UUID.class, kryo -> new UUIDSerializer(), 17));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(URI.class, kryo -> new URISerializer(), 72));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(VertexTerminator.class, null, 13));
+ add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(AbstractMap.SimpleEntry.class, kryo -> new EntrySerializer(), 120)); // ***LAST ID***
--- End diff --
I suspect its because you are serializing something in the `Configuration` that needs it. You should figure out how to NOT store your configuration data like that.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by dkuppitz <gi...@git.apache.org>.
Github user dkuppitz commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65209483
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgram.java ---
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationUtils;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.Memory;
+import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
+import org.apache.tinkerpop.gremlin.process.computer.Messenger;
+import org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey;
+import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.util.AbstractVertexProgramBuilder;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.javatuples.Tuple;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgram implements VertexProgram<Tuple> {
+
+ public static final String BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX = "gremlin.bulkExportVertexProgram";
+ public static final String BULK_EXPORT_PROPERTIES = String.join(".", BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX, "properties");
+
+ private Configuration configuration;
+ private Map<String, String> properties;
+ private List<String> sortedProperties;
+ private Set<VertexComputeKey> vertexComputeKeys;
+
+ private BulkExportVertexProgram() {
+ }
+
+ @Override
+ public void loadState(final Graph graph, final Configuration config) {
+ configuration = new BaseConfiguration();
+ if (config != null) {
+ ConfigurationUtils.copy(config, configuration);
+ }
+ properties = new HashMap<>();
+ sortedProperties = new ArrayList<>();
+ for (final String tuple : configuration.getString(BULK_EXPORT_PROPERTIES, "").split("\1")) {
+ final String[] parts = tuple.split("\2", -1);
+ properties.put(parts[0], parts[1]);
+ sortedProperties.add(parts[0]);
+ }
+ vertexComputeKeys = Collections.singleton(VertexComputeKey.of(BULK_EXPORT_PROPERTIES, false));
+ }
+
+ @Override
+ public void storeState(final Configuration config) {
+ VertexProgram.super.storeState(config);
+ if (configuration != null) {
+ ConfigurationUtils.copy(configuration, config);
+ }
+ }
+
+ @Override
+ public void setup(final Memory memory) {
+ }
+
+ @Override
+ public void execute(final Vertex sourceVertex, final Messenger<Tuple> messenger, final Memory memory) {
--- End diff --
Copy & paste. I've already changed it to `Object`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65182601
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgram.java ---
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationUtils;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.Memory;
+import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
+import org.apache.tinkerpop.gremlin.process.computer.Messenger;
+import org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey;
+import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.util.AbstractVertexProgramBuilder;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.javatuples.Tuple;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgram implements VertexProgram<Tuple> {
+
+ public static final String BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX = "gremlin.bulkExportVertexProgram";
+ public static final String BULK_EXPORT_PROPERTIES = String.join(".", BULK_EXPORT_VERTEX_PROGRAM_CFG_PREFIX, "properties");
+
+ private Configuration configuration;
+ private Map<String, String> properties;
+ private List<String> sortedProperties;
+ private Set<VertexComputeKey> vertexComputeKeys;
+
+ private BulkExportVertexProgram() {
+ }
+
+ @Override
+ public void loadState(final Graph graph, final Configuration config) {
+ configuration = new BaseConfiguration();
+ if (config != null) {
+ ConfigurationUtils.copy(config, configuration);
+ }
+ properties = new HashMap<>();
+ sortedProperties = new ArrayList<>();
+ for (final String tuple : configuration.getString(BULK_EXPORT_PROPERTIES, "").split("\1")) {
+ final String[] parts = tuple.split("\2", -1);
+ properties.put(parts[0], parts[1]);
+ sortedProperties.add(parts[0]);
+ }
+ vertexComputeKeys = Collections.singleton(VertexComputeKey.of(BULK_EXPORT_PROPERTIES, false));
+ }
+
+ @Override
+ public void storeState(final Configuration config) {
+ VertexProgram.super.storeState(config);
+ if (configuration != null) {
+ ConfigurationUtils.copy(configuration, config);
+ }
+ }
+
+ @Override
+ public void setup(final Memory memory) {
+ }
+
+ @Override
+ public void execute(final Vertex sourceVertex, final Messenger<Tuple> messenger, final Memory memory) {
+ final VertexProperty<TraverserSet> haltedTraversers = sourceVertex.property(TraversalVertexProgram.HALTED_TRAVERSERS);
+ haltedTraversers.ifPresent(traverserSet -> {
+ final List<List<String>> rows = new ArrayList<>();
+ for (final Traverser t : (Iterable<Traverser>) traverserSet) {
+ final List<String> columns = new ArrayList<>();
+ final Path path = t.path();
+ final Iterable<String> keys = properties.isEmpty()
+ ? t.path().labels().stream().flatMap(Collection::stream).sorted().collect(Collectors.toSet())
+ : sortedProperties;
+ for (final String key : keys) {
+ final String format = properties.getOrDefault(key, "");
+ final Object value = path.get(key);
+ columns.add("".equals(format) ? value.toString() : String.format(format, value));
+ }
+ rows.add(columns);
+ }
+ sourceVertex.property(BULK_EXPORT_PROPERTIES, rows);
+ });
+ }
+
+ @Override
+ public boolean terminate(final Memory memory) {
+ return properties == null || properties.isEmpty() || !memory.isInitialIteration();
+ }
+
+ @Override
+ public Set<MessageScope> getMessageScopes(final Memory memory) {
+ return Collections.emptySet();
+ }
+
+ @SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException", "CloneDoesntCallSuperClone"})
+ @Override
+ public VertexProgram<Tuple> clone() {
--- End diff --
Extend `StaticVertexProgram<Tuple>` instead of implementing `VertexProgram<Tuple>` and you can get rid of this `clone()` method (and others I believe?).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by dkuppitz <gi...@git.apache.org>.
Github user dkuppitz commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65208387
--- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java ---
@@ -295,6 +296,7 @@ private void validate() {
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(UUID.class, kryo -> new UUIDSerializer(), 17));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(URI.class, kryo -> new URISerializer(), 72));
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(VertexTerminator.class, null, 13));
+ add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(AbstractMap.SimpleEntry.class, kryo -> new EntrySerializer(), 120)); // ***LAST ID***
--- End diff --
I know it's weird, but the sample job throw serialization exceptions if `AbstractMap.SimpleEntry` is not explicitly registered.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-tinkerpop pull request: TINKERPOP-1298 Save OLAP results to file
Posted by okram <gi...@git.apache.org>.
Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/323#discussion_r65183282
--- Diff: gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkdumping/BulkExportVertexProgramTest.java ---
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.computer.bulkdumping;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.io.script.ScriptResourceAccess;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.structure.Column.keys;
+import static org.apache.tinkerpop.gremlin.structure.Column.values;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class BulkExportVertexProgramTest extends AbstractGremlinProcessTest {
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void shouldExportCsvFile() throws Exception {
+ if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) {
+ g.V().hasLabel("person").match(
+ __.as("person").values("name").as("name"),
+ __.as("person").values("age").as("age"),
+ __.as("person").outE("created").count().as("projects")
+ ).select("person").
+ coalesce(__.out("created"), __.identity()).
+ coalesce(__.in("created"), __.identity()).
+ groupCount("m").by(__.select("person", "name", "age", "projects")).cap("m").unfold().as("kv").
+ select(keys).select("person").as("person").
+ select("kv").select(keys).select("name").as("name").
+ select("kv").select(keys).select("age").as("age").
+ select("kv").select(keys).select("projects").as("projects").
+ select("kv").select(values).map(__.union(__.identity(), __.constant(-1)).sum()).as("coworkers").
+ select("person", "name", "age", "projects", "coworkers").
+ program(BulkDumperVertexProgram.build().create(graph)).iterate();
+
+ final Configuration config = graph.configuration();
+ final String outputLocation = config.getString("gremlin.hadoop.outputLocation");
+ final String scriptFileName =
+ TestHelper.generateTempFileFromResource(ScriptResourceAccess.class, "script-csv-export.groovy", "").
+ getAbsolutePath().replace('\\', '/');
+
+ config.setProperty("gremlin.hadoop.inputLocation", outputLocation + "/~g");
--- End diff --
Why is Hadoop stuff here? This sort of information should all be in `HadoopGraphProvider` (and thus, extended to `SparkGraphProvider` and `GiraphGraphProvider`).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---