-
-
Notifications
You must be signed in to change notification settings - Fork 102
Cypher : added 418 tests for Cypher Neo4J functions #3428
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
Closed
Closed
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
f363428
added neo4j functions tests
2376022
fixed factory
cdec6bb
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin 44d0c39
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin be84308
added elementid() (uses ID())
1ba12c7
Revert "added elementid() (uses ID())"
1d0342e
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin 6488c38
fixed some tests (expect 64bit, not 32)
e8375db
more 64bit fixes
a41ff64
fixed some errors
ca38e62
more errors fixes
703eba0
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin a8f9dcd
Update engine/src/test/java/com/arcadedb/query/opencypher/functions/O…
ExtReMLapin ddc6dbf
Update engine/src/test/java/com/arcadedb/query/opencypher/functions/O…
ExtReMLapin 99aa587
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin c454c1c
fixed compilation error
c826fe5
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin 16af5f2
fixed exception not being detected
00afff9
fixed missing exceptions
64e2abd
updated tests
8280281
updated tests
3b6fd79
Coll insert/remove force second arg
6a23fdf
point.distance cypher
9dff309
cypher point use map like cypher, not like sql
0762c40
geo utils support map xy or longitude latitude
91407e5
left support two args error and neg len error
2c5f0f0
two args and neg len
6275cb2
force 3 args for Replace function
69e265d
lTrim support two args
50ec604
rtrim two args
28f6a6e
substring better errors handling
87e67e6
sync
2f591d6
Round added precision and mode
3266b9b
added timezones
7e9e0c6
updated vectors
ce445f6
sync
f7b0fb0
SQLFunctionStandardDeviation now returns 0.0 instead of null
34c5150
Update engine/src/main/java/com/arcadedb/function/geo/CypherPointFunc…
ExtReMLapin ef55e43
updated old test
14fa415
Merge branch 'ArcadeData:main' into more_tests
ExtReMLapin 8e79172
sync
f8f942c
sync
cbc1491
fixed codacy being a crybaby
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
engine/src/main/java/com/arcadedb/function/geo/CypherPointDistanceFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Copyright © 2021-present Arcade Data Ltd ([email protected]) | ||
| * | ||
| * Licensed 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. | ||
| * | ||
| * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected]) | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package com.arcadedb.function.geo; | ||
|
|
||
| import com.arcadedb.exception.CommandExecutionException; | ||
| import com.arcadedb.function.StatelessFunction; | ||
| import com.arcadedb.query.sql.executor.CommandContext; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Cypher {@code point.distance(point1, point2)} function. | ||
| * | ||
| * <p>Computes the distance between two points. Uses Haversine formula for WGS-84 | ||
| * geographic points (result in meters), and Euclidean distance for Cartesian points.</p> | ||
| */ | ||
| public class CypherPointDistanceFunction implements StatelessFunction { | ||
| private static final double EARTH_RADIUS_M = 6371000.0; | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "point.distance"; | ||
| } | ||
|
|
||
| @Override | ||
| public Object execute(final Object[] args, final CommandContext context) { | ||
| if (args == null || args.length != 2) | ||
| throw new CommandExecutionException("point.distance() requires exactly 2 arguments"); | ||
| if (args[0] == null || args[1] == null) | ||
| return null; | ||
| if (!(args[0] instanceof Map) || !(args[1] instanceof Map)) | ||
| throw new CommandExecutionException("point.distance() arguments must be point values (maps)"); | ||
| final Map<?, ?> p1 = (Map<?, ?>) args[0]; | ||
| final Map<?, ?> p2 = (Map<?, ?>) args[1]; | ||
|
|
||
| // WGS-84: use Haversine formula | ||
| if (p1.containsKey("longitude") && p1.containsKey("latitude") && | ||
| p2.containsKey("longitude") && p2.containsKey("latitude")) | ||
| return haversineDistance( | ||
| ((Number) p1.get("latitude")).doubleValue(), ((Number) p1.get("longitude")).doubleValue(), | ||
| ((Number) p2.get("latitude")).doubleValue(), ((Number) p2.get("longitude")).doubleValue()); | ||
|
|
||
| // Cartesian: use Euclidean distance | ||
| final Number x1n = (Number) p1.get("x"); | ||
| final Number y1n = (Number) p1.get("y"); | ||
| final Number x2n = (Number) p2.get("x"); | ||
| final Number y2n = (Number) p2.get("y"); | ||
| if (x1n == null || y1n == null || x2n == null || y2n == null) | ||
| return null; | ||
| final double dx = x2n.doubleValue() - x1n.doubleValue(); | ||
| final double dy = y2n.doubleValue() - y1n.doubleValue(); | ||
| double sumSq = dx * dx + dy * dy; | ||
| final Number z1n = (Number) p1.get("z"); | ||
| final Number z2n = (Number) p2.get("z"); | ||
| if (z1n != null && z2n != null) { | ||
| final double dz = z2n.doubleValue() - z1n.doubleValue(); | ||
| sumSq += dz * dz; | ||
| } | ||
| return Math.sqrt(sumSq); | ||
| } | ||
|
|
||
| private double haversineDistance(final double lat1, final double lon1, final double lat2, final double lon2) { | ||
| final double dLat = Math.toRadians(lat2 - lat1); | ||
| final double dLon = Math.toRadians(lon2 - lon1); | ||
| final double a = Math.pow(Math.sin(dLat / 2), 2) | ||
| + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) | ||
| * Math.pow(Math.sin(dLon / 2), 2); | ||
| return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) * EARTH_RADIUS_M; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,7 +42,7 @@ public String getName() { | |||||||||
|
|
||||||||||
| @Override | ||||||||||
| public Object execute(final Object[] args, final CommandContext context) { | ||||||||||
| if (args.length < 1 || args.length > 2) | ||||||||||
| if (args.length < 1 || args.length > 3) | ||||||||||
| throw new CommandExecutionException("round() requires one or two arguments"); | ||||||||||
|
Comment on lines
+45
to
46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message
Suggested change
|
||||||||||
|
|
||||||||||
| if (args[0] == null) | ||||||||||
|
|
@@ -61,7 +61,7 @@ public Object execute(final Object[] args, final CommandContext context) { | |||||||||
| return (double) Math.round(value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // round(value, precision) | ||||||||||
| // round(value, precision) or round(value, precision, mode) | ||||||||||
| if (args[1] == null) | ||||||||||
| return null; | ||||||||||
|
|
||||||||||
|
|
@@ -70,7 +70,22 @@ public Object execute(final Object[] args, final CommandContext context) { | |||||||||
|
|
||||||||||
| final int precision = ((Number) args[1]).intValue(); | ||||||||||
|
|
||||||||||
| final BigDecimal bd = BigDecimal.valueOf(value).setScale(precision, RoundingMode.HALF_UP); | ||||||||||
| RoundingMode mode = RoundingMode.HALF_UP; | ||||||||||
| if (args.length == 3 && args[2] != null) { | ||||||||||
| final String modeStr = args[2].toString().toUpperCase().replace(" ", "_"); | ||||||||||
| mode = switch (modeStr) { | ||||||||||
| case "UP" -> RoundingMode.UP; | ||||||||||
| case "DOWN" -> RoundingMode.DOWN; | ||||||||||
| case "CEILING" -> RoundingMode.CEILING; | ||||||||||
| case "FLOOR" -> RoundingMode.FLOOR; | ||||||||||
| case "HALF_UP" -> RoundingMode.HALF_UP; | ||||||||||
| case "HALF_DOWN" -> RoundingMode.HALF_DOWN; | ||||||||||
| case "HALF_EVEN" -> RoundingMode.HALF_EVEN; | ||||||||||
| default -> throw new CommandExecutionException("round() unknown rounding mode: " + args[2]); | ||||||||||
| }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| final BigDecimal bd = BigDecimal.valueOf(value).setScale(precision, mode); | ||||||||||
| return bd.doubleValue(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.