Skip to content

Commit

Permalink
[NOID] fixes #3349: Can not create custom procedure with void return …
Browse files Browse the repository at this point in the history
…type using apoc.custom.declareProcedure (#3356)
  • Loading branch information
conker84 authored and vga91 committed Jan 17, 2023
1 parent acebcdc commit 15f78a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apoc-core
Submodule apoc-core updated 79 files
+23 −0 .github/workflows/traceability.yml
+4 −4 build.gradle
+2 −0 common/build.gradle
+0 −30 common/src/main/antlr/apoc/custom/Signature.g4
+1 −9 common/src/main/java/apoc/ApocConfig.java
+1 −0 common/src/main/java/apoc/ApocExtensionFactory.java
+0 −16 common/src/main/java/apoc/Description.java
+1 −0 common/src/main/java/apoc/RegisterComponentFactory.java
+1 −7 common/src/main/java/apoc/SystemLabels.java
+0 −15 common/src/main/java/apoc/SystemPropertyKeys.java
+0 −4 common/src/main/java/apoc/export/cypher/FileManagerFactory.java
+0 −3 common/src/main/java/apoc/load/LoadJsonUtils.java
+0 −3 common/src/main/java/apoc/load/Mapping.java
+0 −66 common/src/main/java/apoc/load/util/JdbcUtil.java
+0 −130 common/src/main/java/apoc/load/util/LoadCsvConfig.java
+0 −85 common/src/main/java/apoc/load/util/LoadJdbcConfig.java
+4 −4 common/src/main/java/apoc/meta/MetaConfig.java
+1 −1 common/src/main/java/apoc/meta/Tables4LabelsProfile.java
+0 −15 common/src/main/java/apoc/result/BooleanResult.java
+0 −20 common/src/main/java/apoc/result/IdsResult.java
+0 −42 common/src/main/java/apoc/result/KernelInfoResult.java
+0 −15 common/src/main/java/apoc/result/KeyValueResult.java
+0 −27 common/src/main/java/apoc/result/NodeValueErrorMapResult.java
+0 −27 common/src/main/java/apoc/result/NodeWithMapResult.java
+0 −37 common/src/main/java/apoc/result/StoreInfoResult.java
+0 −15 common/src/main/java/apoc/result/StringResult.java
+0 −33 common/src/main/java/apoc/result/TransactionInfoResult.java
+1 −0 common/src/main/java/apoc/result/VirtualNode.java
+1 −1 common/src/main/java/apoc/result/VirtualPath.java
+1 −0 common/src/main/java/apoc/result/VirtualRelationship.java
+5 −58 common/src/main/java/apoc/util/FileUtils.java
+0 −4 common/src/main/java/apoc/util/JsonUtil.java
+0 −43 common/src/main/java/apoc/util/UrlResolver.java
+0 −46 common/src/main/java/apoc/util/Util.java
+0 −50 common/src/main/java/apoc/uuid/UuidConfig.java
+1 −1 core/src/main/java/apoc/coll/Coll.java
+2 −2 core/src/main/java/apoc/export/csv/ExportCSV.java
+111 −30 core/src/main/java/apoc/index/SchemaIndex.java
+2 −2 core/src/main/java/apoc/load/SkipWhitespaceInputStream.java
+12 −12 core/src/main/java/apoc/path/LabelMatcherGroup.java
+3 −3 core/src/main/java/apoc/path/LabelSequenceEvaluator.java
+14 −14 core/src/main/java/apoc/path/NodeEvaluators.java
+28 −20 core/src/main/java/apoc/path/PathExplorer.java
+2 −1 core/src/main/java/apoc/text/Strings.java
+50 −50 core/src/main/java/apoc/trigger/Trigger.java
+12 −10 core/src/main/java/apoc/trigger/TriggerHandler.java
+148 −0 core/src/main/java/apoc/trigger/TriggerHandlerNewProcedures.java
+89 −0 core/src/main/java/apoc/trigger/TriggerInfo.java
+0 −0 core/src/main/java/apoc/trigger/TriggerMetadata.java
+136 −0 core/src/main/java/apoc/trigger/TriggerNewProcedures.java
+2 −1 core/src/main/java/apoc/util/Utils.java
+305 −30 core/src/test/java/apoc/export/ExportCoreSecurityTest.java
+3 −2 core/src/test/java/apoc/export/csv/ExportCsvTest.java
+1 −1 core/src/test/java/apoc/export/graphml/ExportGraphMLTestUtil.java
+255 −25 core/src/test/java/apoc/index/SchemaIndexTest.java
+141 −11 core/src/test/java/apoc/path/ExpandPathTest.java
+1 −1 core/src/test/java/apoc/path/LabelSequenceTest.java
+103 −38 core/src/test/java/apoc/path/NodeFilterTest.java
+215 −0 core/src/test/java/apoc/path/SubgraphTest.java
+1 −1 core/src/test/java/apoc/refactor/CloneSubgraphTest.java
+121 −0 core/src/test/java/apoc/trigger/TriggerClusterRoutingTest.java
+192 −0 core/src/test/java/apoc/trigger/TriggerEnterpriseFeaturesTest.java
+592 −0 core/src/test/java/apoc/trigger/TriggerNewProceduresTest.java
+63 −15 core/src/test/java/apoc/trigger/TriggerRestartTest.java
+15 −4 core/src/test/java/apoc/trigger/TriggerTest.java
+0 −0 images/apoc.gif
+ images/apoc.png
+17,166 −0 log.txt
+9 −29 readme.adoc
+8 −2 test-startup/src/test/java/StartupTest.java
+9 −3 test-utils/build.gradle
+26 −0 test-utils/src/main/java/apoc/trigger/TriggerTestUtil.java
+0 −32 test-utils/src/main/java/apoc/util/GoogleCloudStorageContainerExtension.java
+0 −23 test-utils/src/main/java/apoc/util/MySQLContainerExtension.java
+2 −1 test-utils/src/main/java/apoc/util/Neo4jContainerExtension.java
+8 −13 test-utils/src/main/java/apoc/util/TestContainerUtil.java
+41 −17 test-utils/src/main/java/apoc/util/TestUtil.java
+13 −2 test-utils/src/main/java/apoc/util/TestcontainersCausalCluster.java
+16 −5 test-utils/src/main/java/org/neo4j/test/rule/DbmsRule.java
6 changes: 4 additions & 2 deletions extended/src/main/java/apoc/custom/CypherProcedures.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ private void validateProcedure(String statement, List<FieldSignature> input, Lis
private void checkMode(QueryExecutionType.QueryType queryType, Mode mode) {
Map<QueryExecutionType.QueryType, Mode> map = Map.of(QueryExecutionType.QueryType.WRITE, Mode.WRITE,
QueryExecutionType.QueryType.READ_ONLY, Mode.READ,
QueryExecutionType.QueryType.READ_WRITE, Mode.WRITE);
QueryExecutionType.QueryType.READ_WRITE, Mode.WRITE,
QueryExecutionType.QueryType.DBMS, Mode.DBMS,
QueryExecutionType.QueryType.SCHEMA_WRITE, Mode.SCHEMA);

if (!map.get(queryType).equals(mode)) {
throw new RuntimeException(String.format("The query execution type is %s, but you provided mode %s.\n" +
"Supported modes are %s",
queryType.name(),
mode.name(),
map.values().stream().sorted().collect(Collectors.toList()).toString()));
map.values().stream().sorted().collect(Collectors.toList())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private String serializeSignatures(List<FieldSignature> signatures) {

public static List<FieldSignature> deserializeSignatures(String s) {
List<Map<String, Object>> mapped = Util.fromJson(s, List.class);
if (mapped.isEmpty()) return ProcedureSignature.VOID;
return mapped.stream().map(map -> {
String typeString = (String) map.get("type");
if (typeString.endsWith("?")) {
Expand Down
35 changes: 34 additions & 1 deletion extended/src/test/java/apoc/custom/CypherProceduresTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.QueryExecutionException;
import org.neo4j.graphdb.Transaction;
import org.neo4j.procedure.builtin.BuiltInDbmsProcedures;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static apoc.custom.CypherProceduresHandler.FUNCTION;
import static apoc.custom.CypherProceduresHandler.PROCEDURE;
Expand All @@ -48,9 +50,10 @@ public class CypherProceduresTest {
@Rule
public ExpectedException thrown = ExpectedException.none();


@Before
public void setup() {
TestUtil.registerProcedure(db, CypherProcedures.class);
TestUtil.registerProcedure(db, CypherProcedures.class, BuiltInDbmsProcedures.class);
}

@AfterAll
Expand Down Expand Up @@ -584,6 +587,36 @@ public void testIssue2032() {
assertProcedureFails(String.format(SIGNATURE_SYNTAX_ERROR, procedureSignature),
"call apoc.custom.declareProcedure('" + procedureSignature + "','RETURN $first + $s AS answer')");
}

@Test
public void testIssue3349() {
String procedure = """
CALL apoc.custom.declareProcedure(
'retFunctionNames() :: (name :: STRING)',
'call dbms.listConfig() YIELD name RETURN name',
'DBMS'
);""";
db.executeTransactionally(procedure);
List<String> functions = db.executeTransactionally("CALL custom.retFunctionNames()", Map.of(), result -> result
.stream()
.map(m -> (String) m.get("name"))
.collect(Collectors.toList()));
assertFalse(functions.isEmpty());


String procedureVoid = "CALL apoc.custom.declareProcedure(\n" +
" 'setTxMetadata(meta :: MAP) :: VOID',\n" +
" '\n" +
" CALL tx.setMetaData($meta)" +
" ',\n" +
" 'DBMS'\n" +
");";
db.executeTransactionally(procedureVoid);
// This should run without exception
db.executeTransactionally("CALL custom.setTxMetadata($meta)", Map.of(
"meta", Map.of("foo", "bar")
));
}


private void assertProcedureFails(String expectedMessage, String query) {
Expand Down

0 comments on commit 15f78a6

Please sign in to comment.