Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate yaml deps into main jar #4098

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ apoc.convert.fromYaml(value :: STRING, config = {} :: MAP) :: ANY
== Config parameters
include::partial$usage/config/apoc.convert.fromYaml.adoc[]

[[yaml-dependencies]]
=== Install dependencies
Note that to use this function, you have to install additional dependencies
which can be downloaded https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/{apoc-release}/apoc-yaml-dependencies-{apoc-release}-all.jar[from this link].


[[usage-apoc.convert.fromYaml]]
== Usage Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ apoc.convert.toYaml(value :: ANY, config = {} :: MAP) :: STRING
== Config parameters
include::partial$usage/config/apoc.convert.toYaml.adoc[]

[[yaml-dependencies]]
=== Install dependencies
Note that to use this function, you have to install additional dependencies
which can be downloaded https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/{apoc-release}/apoc-yaml-dependencies-{apoc-release}-all.jar[from this link].


[[usage-apoc.convert.toYaml]]
== Usage Examples
include::partial$usage/apoc.convert.toYaml.adoc[]
Expand Down
4 changes: 2 additions & 2 deletions extended/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {
}

def withoutJacksons = {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
Expand All @@ -83,6 +84,7 @@ dependencies {
exclude group: 'org.apache.commons', module: 'commons-lang3'
}
implementation group: 'us.fatehi', name: 'schemacrawler', version: '16.20.8'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.17.0', withoutJacksons

// These will be dependencies not packaged with the .jar
// They need to be provided either through the database or in an extra .jar
Expand Down Expand Up @@ -113,11 +115,9 @@ dependencies {
// testImplementation analogous is not needed since is bundled via `test-utils` submodule
compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.3.6', withoutServers

compileOnly group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1'
compileOnly group: 'org.apache.arrow', name: 'arrow-vector', version: '13.0.0'
compileOnly group: 'org.apache.arrow', name: 'arrow-memory-netty', version: '13.0.0'

testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1'
testImplementation group: 'org.apache.arrow', name: 'arrow-vector', version: '13.0.0'
testImplementation group: 'org.apache.arrow', name: 'arrow-memory-netty', version: '13.0.0'

Expand Down
25 changes: 7 additions & 18 deletions extended/src/main/java/apoc/convert/ConvertExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@

@Extended
public class ConvertExtended {
private static final String YAML_MISSING_DEPS_ERROR = """
Cannot find the Yaml client jar.
Please put the apoc-yaml-dependencies-5.x.x-all.jar into plugin folder.
See the documentation: https://neo4j.com/labs/apoc/5/overview/apoc.convert/apoc.convert.toYaml/#yaml-dependencies""";


@UserFunction("apoc.convert.toYaml")
@Description("apoc.convert.toYaml(value, $config) - Serializes the given value to a YAML string")
public String toYaml(@Name("value") Object value, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) {
Object result = writeYamlResult(value);
try {
return getYamlFactory(result, config);
} catch (NoClassDefFoundError e) {
throw new MissingDependencyException(YAML_MISSING_DEPS_ERROR);
} catch (IOException e) {
throw new RuntimeException("Can't convert " + "value" + " to yaml", e);
}
Expand All @@ -47,13 +40,9 @@ public String toYaml(@Name("value") Object value, @Name(value = "config", defaul
@UserFunction("apoc.convert.fromYaml")
@Description("apoc.convert.fromYaml(value, $config) - Deserializes the YAML string to Neo4j value")
public Object fromYaml(@Name("value") String value, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws Exception {
try {
Object parse = parse(value, config);
var mappingConf = (Map<String, Object>) config.getOrDefault(MAPPING_KEY, Map.of());
return toValidYamlValue(parse, null, mappingConf, true);
} catch (NoClassDefFoundError e) {
throw new MissingDependencyException(YAML_MISSING_DEPS_ERROR);
}
Object parse = parse(value, config);
var mappingConf = (Map<String, Object>) config.getOrDefault(MAPPING_KEY, Map.of());
return toValidYamlValue(parse, null, mappingConf, true);
}

/**
Expand All @@ -65,15 +54,15 @@ private Object writeYamlResult(Object value) {
return switch (type) {
case NODE -> nodeToMap((Node) value);
case RELATIONSHIP -> relToMap((Relationship) value);

case PATH -> writeYamlResult(Iterables.stream((Path) value)
.map(i -> i instanceof Node ? nodeToMap((Node) i) : relToMap((Relationship) i))
.collect(Collectors.toList()));

case LIST -> ConvertUtils.convertToList(value).stream()
.map(this::writeYamlResult)
.collect(Collectors.toList());

case MAP -> ((Map<String, Object>) value)
.entrySet()
.stream()
Expand All @@ -82,7 +71,7 @@ private Object writeYamlResult(Object value) {
(mapAccumulator, entry) ->
mapAccumulator.put(entry.getKey(), writeYamlResult(entry.getValue())),
HashMap::putAll);

default -> value;
};
}
Expand Down
1 change: 0 additions & 1 deletion extra-dependencies/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ include('selenium')
include('hadoop')
include('gcs')
include('aws')
include('yaml')
25 changes: 0 additions & 25 deletions extra-dependencies/yaml/build.gradle

This file was deleted.

Binary file not shown.

This file was deleted.

183 changes: 0 additions & 183 deletions extra-dependencies/yaml/gradlew

This file was deleted.

Loading
Loading