Skip to content

Commit

Permalink
Merge pull request #73 from memgraph/print-enums
Browse files Browse the repository at this point in the history
Fix mgconsole print for enums.
  • Loading branch information
MarkoBarisic authored Jul 3, 2024
2 parents cc1c207 + d861e62 commit 4469f6a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 7 deletions.
43 changes: 36 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,47 @@ on:
push:
workflow_dispatch:

env:
OFFICIAL: false

jobs:
build_and_test_ubuntu:
strategy:
matrix:
platform: [ubuntu-22.04]
mg_version:
- "2.7.0"
- "2.18.0-rc1"
runs-on: ${{ matrix.platform }}
steps:
- name: Set up and check memgraph download link
run: |
mg_version=${{ matrix.mg_version }}
mg_version_short=${mg_version%%-*}
if [ "${{ env.OFFICIAL }}" = "true" ]; then
mg_url="https://download.memgraph.com/memgraph/v${mg_version}/${{ matrix.platform }}/memgraph_${mg_version_short}-1_amd64.deb"
else
mg_url="https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/memgraph/v${mg_version}/${{ matrix.platform }}/memgraph_${mg_version_short}-1_amd64.deb"
fi
echo "Checking Memgraph download link: $mg_url"
if curl --output /dev/null --silent --head --fail $mg_url; then
echo "Memgraph download link is valid"
echo "MEMGRAPH_DOWNLOAD_LINK=${mg_url}" >> $GITHUB_ENV
else
echo "Memgraph download link is not valid"
exit 1
fi
- name: Install dependencies (Ubuntu 22.04)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt install -y git cmake make gcc g++ libssl-dev # mgconsole deps
sudo apt install -y libpython3.10 python3-pip # memgraph deps
mkdir ~/memgraph
curl -L https://download.memgraph.com/memgraph/v${{ matrix.mg_version }}/ubuntu-22.04/memgraph_${{ matrix.mg_version }}-1_amd64.deb > ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb
curl -L ${{ env.MEMGRAPH_DOWNLOAD_LINK }} > ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb
sudo systemctl mask memgraph
sudo dpkg -i ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Install and test mgconsole
run: |
mkdir build
Expand All @@ -32,8 +53,15 @@ jobs:
make
sudo make install
ctest
- name: Save mgconsole test results
if: always()
uses: actions/upload-artifact@v4
with:
name: "mgconsole_ctest.log"
path: build/Testing/Temporary/LastTest.log

build_windows:
if: false
runs-on: windows-latest
steps:
- uses: msys2/setup-msys2@v2
Expand All @@ -46,16 +74,17 @@ jobs:
# First make sure python would resolve to the windows native python, not mingw one
echo "C:/msys64/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
echo "${{ env.pythonLocation }}" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Install mgconsole
run: |
$env:OPENSSL_ROOT_DIR = "C:/msys64/mingw64"
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make
make install
- name: Save mgconsole Windows build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: "mgconsole Windows build"
path: build/src/mgconsole.exe
Expand All @@ -69,7 +98,7 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- name: Set-up repository
uses: actions/checkout@v2
uses: actions/checkout@v4
# NOTE: CI can't execute end2end tests because there is no way to run
# Memgraph on CI MacOS machines.
- name: Install openssl
Expand All @@ -83,7 +112,7 @@ jobs:
cmake -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" -DCMAKE_BUILD_TYPE=Release ..
make
- name: Save mgconsole MacOS build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: "mgconsole MacOS build"
path: build/src/mgconsole
35 changes: 35 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ void PrintStringUnescaped(std::ostream &os, const mg_string *str) {
os.write(mg_string_data(str), mg_string_size(str));
}

std::string GetMemgraphSpecificType(const mg_value *mg_val) {
std::string type;
if (mg_val && mg_value_get_type(mg_val) == MG_VALUE_TYPE_STRING) {
auto *type_val_mg_str = mg_value_string(mg_val);
type = std::string(mg_string_data(type_val_mg_str), mg_string_size(type_val_mg_str));
}
return type;
}

bool PrintIfMemgraphSpecificType(std::ostream &os, const mg_map *map) {
// Current format is
// { "__type": "<type_name>", "__value": <actual value> }
static const char kTypeKey[] = "__type";
static const char kMgEnum[] = "mg_enum";
static const char kValue[] = "__value";

if (mg_map_size(map) != 2) {
return false;
}

auto memgraph_type = GetMemgraphSpecificType(mg_map_at(map, kTypeKey));
if (memgraph_type == kMgEnum) {
auto *enum_value = mg_map_at(map, kValue);
if (mg_value_get_type(enum_value) == MG_VALUE_TYPE_STRING) {
PrintStringUnescaped(os, mg_value_string(enum_value));
return true;
}
}
return false;
}

void PrintValue(std::ostream &os, const mg_string *str) {
os << utils::Escape(std::string(mg_string_data(str), mg_string_size(str)));
}
Expand All @@ -157,6 +188,10 @@ void PrintValue(std::ostream &os, const mg_list *list) {
}

void PrintValue(std::ostream &os, const mg_map *map) {
if (PrintIfMemgraphSpecificType(os, map)) {
return;
}

os << "{";
for (uint32_t i = 0; i < mg_map_size(map); ++i) {
if (i > 0) {
Expand Down
4 changes: 4 additions & 0 deletions tests/input_output/input/enum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SHOW ENUMS;
CREATE (n :l1 {s: Status::Good}) RETURN n;
CREATE (n :l2 {s: {__type: "test", __value: "test_value"}}) RETURN n;
MATCH (n) return n;
6 changes: 6 additions & 0 deletions tests/input_output/output_csv/enum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Enum Name","Enum Values"
"""Status""","[""Good"", ""Bad""]"
"n"
"(:l1 {s: Status::Good})"
"n"
"(:l2 {s: {__type: ""test"", __value: ""test_value""}})"
15 changes: 15 additions & 0 deletions tests/input_output/output_tabular/enum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
+-----------------+-----------------+
| Enum Name | Enum Values |
+-----------------+-----------------+
| "Status" | ["Good", "Bad"] |
+-----------------+-----------------+
+-------------------------+
| n |
+-------------------------+
| (:l1 {s: Status::Good}) |
+-------------------------+
+----------------------------------------------------+
| n |
+----------------------------------------------------+
| (:l2 {s: {__type: "test", __value: "test_value"}}) |
+----------------------------------------------------+
1 change: 1 addition & 0 deletions tests/input_output/prepare.cypher
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE ENUM Status VALUES { Good, Bad };
7 changes: 7 additions & 0 deletions tests/input_output/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ echo_success "Started memgraph"

## Tests

client_flags="--use-ssl=$use_ssl"

echo_info "Prepare database"
echo # Blank line

$client_binary $client_flags < ${DIR}/prepare.cypher > $tmpdir/prepare.log

echo_info "Running tests"
echo # Blank line

Expand Down

0 comments on commit 4469f6a

Please sign in to comment.