Skip to content

Commit

Permalink
Add Point2&3D spatial formatting (#77)
Browse files Browse the repository at this point in the history
NOTE: Changed --storage-recover-on-startup to --data-recovery-on-startup
  • Loading branch information
gitbuda authored Aug 10, 2024
1 parent 4469f6a commit 36baafe
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
platform: [ubuntu-22.04]
mg_version:
- "2.18.0-rc1"
- "2.19.0-rc2"
runs-on: ${{ matrix.platform }}
steps:
- name: Set up and check memgraph download link
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
cmake ..
make
sudo make install
ctest
ctest --verbose
- name: Save mgconsole test results
if: always()
uses: actions/upload-artifact@v4
Expand Down
20 changes: 20 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cstdint>
#include <ios>
#include <iostream>
#include <ostream>
#include <string>
#include <string_view>
#include <type_traits>
Expand Down Expand Up @@ -336,6 +337,19 @@ void PrintValue(std::ostream &os, const mg_duration *duration) {
os << "S";
}

void PrintValue(std::ostream &os, const mg_point_2d *value) {
os << "POINT({ x:" << mg_point_2d_x(value) << ","
<< " y:" << mg_point_2d_y(value) << ","
<< " srid:" << mg_point_2d_srid(value) << " })";
}

void PrintValue(std::ostream &os, const mg_point_3d *value) {
os << "POINT({ x:" << mg_point_3d_x(value) << ","
<< " y:" << mg_point_3d_y(value) << ","
<< " z:" << mg_point_3d_z(value) << ","
<< " srid:" << mg_point_3d_srid(value) << " })";
}

void PrintValue(std::ostream &os, const mg_value *value) {
switch (mg_value_get_type(value)) {
case MG_VALUE_TYPE_NULL:
Expand Down Expand Up @@ -383,6 +397,12 @@ void PrintValue(std::ostream &os, const mg_value *value) {
case MG_VALUE_TYPE_DURATION:
PrintValue(os, mg_value_duration(value));
return;
case MG_VALUE_TYPE_POINT_2D:
PrintValue(os, mg_value_point_2d(value));
return;
case MG_VALUE_TYPE_POINT_3D:
PrintValue(os, mg_value_point_3d(value));
return;
default:
os << "{unknown value}";
break;
Expand Down
4 changes: 4 additions & 0 deletions tests/input_output/input/spatial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RETURN point({x:0, y:1}) AS point;
RETURN point({latitude:0, longitude:1}) AS point;
RETURN point({x:0, y:1, z:2}) AS point;
RETURN point({latitude:0, longitude:1, height:2}) AS point;
8 changes: 8 additions & 0 deletions tests/input_output/output_csv/spatial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"point"
"POINT({ x:0, y:1, srid:7203 })"
"point"
"POINT({ x:1, y:0, srid:4326 })"
"point"
"POINT({ x:0, y:1, z:2, srid:9757 })"
"point"
"POINT({ x:1, y:0, z:2, srid:4979 })"
20 changes: 20 additions & 0 deletions tests/input_output/output_tabular/spatial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
+--------------------------------+
| point |
+--------------------------------+
| POINT({ x:0, y:1, srid:7203 }) |
+--------------------------------+
+--------------------------------+
| point |
+--------------------------------+
| POINT({ x:1, y:0, srid:4326 }) |
+--------------------------------+
+-------------------------------------+
| point |
+-------------------------------------+
| POINT({ x:0, y:1, z:2, srid:9757 }) |
+-------------------------------------+
+-------------------------------------+
| point |
+-------------------------------------+
| POINT({ x:1, y:0, z:2, srid:4979 }) |
+-------------------------------------+
2 changes: 1 addition & 1 deletion tests/input_output/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $memgraph_binary --bolt-port 7687 \
--storage-properties-on-edges=true \
--storage-snapshot-interval-sec=0 \
--storage-wal-enabled=false \
--storage-recover-on-startup=false \
--data-recovery-on-startup=false \
--storage-snapshot-on-exit=false \
--telemetry-enabled=false \
--log-file='' &
Expand Down

0 comments on commit 36baafe

Please sign in to comment.