From eb7f8e537817c40c14f18c2e1cbd07fdf0096577 Mon Sep 17 00:00:00 2001 From: Aidar Samerkhanov Date: Thu, 6 Jun 2024 18:22:19 +0300 Subject: [PATCH 01/11] Fix mgconsole print for enums. --- src/utils/utils.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 11fa81c2..1d2f2e74 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -130,6 +130,34 @@ std::string Escape(const std::string &src) { return ret; } +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": "", "__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) { + PrintValue(os, mg_map_at(map, kValue)); + return true; + } + return false; +} + template ::value, T> = true> void PrintIfNotZero(std::ostream &os, T value, std::string_view suffix = "") { if (value) { @@ -157,6 +185,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) { From c3402f66e3bf9899cafd880b474465abab711fec Mon Sep 17 00:00:00 2001 From: Aidar Samerkhanov Date: Fri, 7 Jun 2024 17:50:25 +0300 Subject: [PATCH 02/11] Add tests for enum print. --- tests/input_output/input/enum.txt | 5 +++++ tests/input_output/output_csv/enum.txt | 8 ++++++++ tests/input_output/output_tabular/enum.txt | 20 ++++++++++++++++++++ tests/input_output/prepare.cypher | 1 + tests/input_output/run-tests.sh | 7 +++++++ 5 files changed, 41 insertions(+) create mode 100644 tests/input_output/input/enum.txt create mode 100644 tests/input_output/output_csv/enum.txt create mode 100644 tests/input_output/output_tabular/enum.txt create mode 100644 tests/input_output/prepare.cypher diff --git a/tests/input_output/input/enum.txt b/tests/input_output/input/enum.txt new file mode 100644 index 00000000..88acfb2c --- /dev/null +++ b/tests/input_output/input/enum.txt @@ -0,0 +1,5 @@ +SHOW ENUMS; +CREATE (n :l1 {s: Status::Good}) RETURN n; +CREATE (n :l2 {s: {__type: "test", __value: "test_value"}}) RETURN n; +CREATE (n :l3 {s: {__type: "mg_enum", __value: "some_value"}}) RETURN n; +MATCH (n) return n; \ No newline at end of file diff --git a/tests/input_output/output_csv/enum.txt b/tests/input_output/output_csv/enum.txt new file mode 100644 index 00000000..17062dec --- /dev/null +++ b/tests/input_output/output_csv/enum.txt @@ -0,0 +1,8 @@ +"Enum Name","Enum Values" +"""Status""","[""Good"", ""Bad""]" +"n" +"(:l1 {s: ""Status::Good""})" +"n" +"(:l2 {s: {__type: ""test"", __value: ""test_value""}})" +"n" +"(:l3 {s: ""some_value""})" \ No newline at end of file diff --git a/tests/input_output/output_tabular/enum.txt b/tests/input_output/output_tabular/enum.txt new file mode 100644 index 00000000..9c95953e --- /dev/null +++ b/tests/input_output/output_tabular/enum.txt @@ -0,0 +1,20 @@ ++-----------------+-----------------+ +| Enum Name | Enum Values | ++-----------------+-----------------+ +| "Status" | ["Good", "Bad"] | ++-----------------+-----------------+ ++---------------------------+ +| n | ++---------------------------+ +| (:l1 {s: "Status::Good"}) | ++---------------------------+ ++----------------------------------------------------+ +| n | ++----------------------------------------------------+ +| (:l2 {s: {__type: "test", __value: "test_value"}}) | ++----------------------------------------------------+ ++-------------------------+ +| n | ++-------------------------+ +| (:l3 {s: "some_value"}) | ++-------------------------+ \ No newline at end of file diff --git a/tests/input_output/prepare.cypher b/tests/input_output/prepare.cypher new file mode 100644 index 00000000..b38f3fd2 --- /dev/null +++ b/tests/input_output/prepare.cypher @@ -0,0 +1 @@ +CREATE ENUM Status VALUES { Good, Bad }; diff --git a/tests/input_output/run-tests.sh b/tests/input_output/run-tests.sh index 951f90ef..1b44df9a 100755 --- a/tests/input_output/run-tests.sh +++ b/tests/input_output/run-tests.sh @@ -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 From deeb6800bae8a712e80f027b8d6d31a36c8a80ae Mon Sep 17 00:00:00 2001 From: Aidar Samerkhanov Date: Fri, 7 Jun 2024 18:12:17 +0300 Subject: [PATCH 03/11] Print enum as a literal, not string --- src/utils/utils.cpp | 29 ++++++++++++---------- tests/input_output/input/enum.txt | 1 - tests/input_output/output_csv/enum.txt | 6 ++--- tests/input_output/output_tabular/enum.txt | 17 +++++-------- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 1d2f2e74..ae6511d1 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -130,6 +130,17 @@ std::string Escape(const std::string &src) { return ret; } +template ::value, T> = true> +void PrintIfNotZero(std::ostream &os, T value, std::string_view suffix = "") { + if (value) { + os << value << suffix; + } +} + +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) { @@ -152,23 +163,15 @@ bool PrintIfMemgraphSpecificType(std::ostream &os, const mg_map *map) { auto memgraph_type = GetMemgraphSpecificType(mg_map_at(map, kTypeKey)); if (memgraph_type == kMgEnum) { - PrintValue(os, mg_map_at(map, kValue)); - return true; + 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; } -template ::value, T> = true> -void PrintIfNotZero(std::ostream &os, T value, std::string_view suffix = "") { - if (value) { - os << value << suffix; - } -} - -void PrintStringUnescaped(std::ostream &os, const mg_string *str) { - os.write(mg_string_data(str), mg_string_size(str)); -} - void PrintValue(std::ostream &os, const mg_string *str) { os << utils::Escape(std::string(mg_string_data(str), mg_string_size(str))); } diff --git a/tests/input_output/input/enum.txt b/tests/input_output/input/enum.txt index 88acfb2c..745493e6 100644 --- a/tests/input_output/input/enum.txt +++ b/tests/input_output/input/enum.txt @@ -1,5 +1,4 @@ SHOW ENUMS; CREATE (n :l1 {s: Status::Good}) RETURN n; CREATE (n :l2 {s: {__type: "test", __value: "test_value"}}) RETURN n; -CREATE (n :l3 {s: {__type: "mg_enum", __value: "some_value"}}) RETURN n; MATCH (n) return n; \ No newline at end of file diff --git a/tests/input_output/output_csv/enum.txt b/tests/input_output/output_csv/enum.txt index 17062dec..1fd0632f 100644 --- a/tests/input_output/output_csv/enum.txt +++ b/tests/input_output/output_csv/enum.txt @@ -1,8 +1,6 @@ "Enum Name","Enum Values" """Status""","[""Good"", ""Bad""]" "n" -"(:l1 {s: ""Status::Good""})" +"(:l1 {s: Status::Good})" "n" -"(:l2 {s: {__type: ""test"", __value: ""test_value""}})" -"n" -"(:l3 {s: ""some_value""})" \ No newline at end of file +"(:l2 {s: {__type: ""test"", __value: ""test_value""}})" \ No newline at end of file diff --git a/tests/input_output/output_tabular/enum.txt b/tests/input_output/output_tabular/enum.txt index 9c95953e..ea7bfd66 100644 --- a/tests/input_output/output_tabular/enum.txt +++ b/tests/input_output/output_tabular/enum.txt @@ -3,18 +3,13 @@ +-----------------+-----------------+ | "Status" | ["Good", "Bad"] | +-----------------+-----------------+ -+---------------------------+ -| n | -+---------------------------+ -| (:l1 {s: "Status::Good"}) | -+---------------------------+ ++-------------------------+ +| n | ++-------------------------+ +| (:l1 {s: Status::Good}) | ++-------------------------+ +----------------------------------------------------+ | n | +----------------------------------------------------+ | (:l2 {s: {__type: "test", __value: "test_value"}}) | -+----------------------------------------------------+ -+-------------------------+ -| n | -+-------------------------+ -| (:l3 {s: "some_value"}) | -+-------------------------+ \ No newline at end of file ++----------------------------------------------------+ \ No newline at end of file From 33ef521ad0b286e1a17871cda38096586c980f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Tue, 18 Jun 2024 15:49:29 +0200 Subject: [PATCH 04/11] Add step to save test logs for ubuntu 22.04 build --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3cd69df..56814501 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,12 @@ jobs: make sudo make install ctest + - name: Save mgconsole test results + if: always() + uses: actions/upload-artifact@v2 + with: + name: "mgconsole_ctest.log" + path: build/Testing/Temporary/LastTest.log build_windows: runs-on: windows-latest From d0eb6a2fe60bb6398297078ce83fd8f4d49776a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Tue, 18 Jun 2024 16:05:57 +0200 Subject: [PATCH 05/11] Update github actions versions --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56814501..597cb352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: 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 @@ -34,7 +34,7 @@ jobs: ctest - name: Save mgconsole test results if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: "mgconsole_ctest.log" path: build/Testing/Temporary/LastTest.log @@ -52,7 +52,7 @@ 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: | mkdir build @@ -61,7 +61,7 @@ jobs: 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 @@ -75,7 +75,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 @@ -89,7 +89,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 From 53e9bc91f1fd3efa3982d3c38d0c782bb12df5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Tue, 18 Jun 2024 16:07:01 +0200 Subject: [PATCH 06/11] Add openssl root dir to fix windows build --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 597cb352..1cef1462 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,7 @@ jobs: - 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 .. From fbae58f49e15486c9a1f2fb9df0ae8a79fe483df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Wed, 26 Jun 2024 21:11:58 +0200 Subject: [PATCH 07/11] Add functionality to download unofficial memgraph binaries --- .github/workflows/ci.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cef1462..e5eb939a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,22 +4,41 @@ 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: | + if [ "${{ env.OFFICIAL }}" = "true" ]; then + mg_url="https://download.memgraph.com/memgraph/v${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-1_amd64.deb" + else + mg_url="https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/memgraph/v${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-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 From ab8489e718b88ba7fe39330dcdab496bdf68c57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Wed, 26 Jun 2024 21:13:08 +0200 Subject: [PATCH 08/11] Fix syntax error --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5eb939a..c52cf9a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,14 +23,14 @@ jobs: else mg_url="https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/memgraph/v${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-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 + 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' From 61196ee6124547b27f7f564d20d30eaadaf535e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Wed, 26 Jun 2024 21:13:56 +0200 Subject: [PATCH 09/11] Fix syntax error --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c52cf9a9..0f89724b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: mg_url="https://download.memgraph.com/memgraph/v${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-1_amd64.deb" else mg_url="https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/memgraph/v${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-1_amd64.deb" - fi + 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" From 7af1660c2db5085b3c261d143fd9310cdba19dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Wed, 26 Jun 2024 21:17:26 +0200 Subject: [PATCH 10/11] Fix version in link --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f89724b..0eead0df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,12 @@ jobs: 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${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-1_amd64.deb" + 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${{ matrix.mg_version }}/${{ matrix.platform }}/memgraph_${{ matrix.mg_version }}-1_amd64.deb" + 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 From d861e62b0570a24591b0f303e71cbb15b34e359b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bari=C5=A1i=C4=87?= Date: Wed, 3 Jul 2024 14:27:51 +0200 Subject: [PATCH 11/11] Skip windows build in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eead0df..af6594e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,7 @@ jobs: path: build/Testing/Temporary/LastTest.log build_windows: + if: false runs-on: windows-latest steps: - uses: msys2/setup-msys2@v2