|
| 1 | +.. _rm-compare-converted-queries: |
| 2 | + |
| 3 | +========================= |
| 4 | +Compare Converted Queries |
| 5 | +========================= |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +You can use the :guilabel:`Test Queries` pane to compare source |
| 14 | +and destination queries, views, and stored procedure results |
| 15 | +in Relational Migrator. The :guilabel:`Test Queries` can |
| 16 | +help you verify the accuracy of converted code and |
| 17 | +show the source and destination data after you run a sync job. |
| 18 | + |
| 19 | +About this Task |
| 20 | +--------------- |
| 21 | + |
| 22 | +The :guilabel:`Test Queries` pane is split into three separate |
| 23 | +user interfaces: ``Console``, ``Results``, and ``Messages``. |
| 24 | +Click the pill buttons next to :guilabel:`Test Queries` to |
| 25 | +change the user interface. The following table summarizes |
| 26 | +each user interface: |
| 27 | + |
| 28 | +.. list-table:: |
| 29 | + :header-rows: 1 |
| 30 | + :widths: 20 80 |
| 31 | + |
| 32 | + * - User Interface |
| 33 | + - Description |
| 34 | + * - Console |
| 35 | + - This is the default user interface of the |
| 36 | + :guilabel:`Test Queries` pane. You can click |
| 37 | + the :guilabel:`Run Source Query` button to |
| 38 | + run all converted queries. You can also specify |
| 39 | + parameters for stored procedures in the |
| 40 | + :guilabel:`Source Script` text field. |
| 41 | + * - Results |
| 42 | + - This user interface is used to view the query results |
| 43 | + from the source and destination queries. You must run |
| 44 | + a source or destination query to view the ``Results`` |
| 45 | + user interface. |
| 46 | + * - Messages |
| 47 | + - This user interface is used to show messages from each |
| 48 | + database connection. You can see error messages, |
| 49 | + execution stats, and any print statements. |
| 50 | + |
| 51 | +Before you Begin |
| 52 | +---------------- |
| 53 | + |
| 54 | +- You must sign in to your Atlas account in Relational Migrator. |
| 55 | + For details, see :ref:`rm-atlas-log-in`. |
| 56 | + |
| 57 | +- For details on how to turn on Query Converter, see |
| 58 | + :ref:`rm-enable-query-converter`. |
| 59 | + |
| 60 | +- To use the :guilabel:`Test Queries` pane, Relational |
| 61 | + Migrator must have access to the Query Runner. For details |
| 62 | + on how to setup Query Runner, see :ref:`rm-install-query-runner`. |
| 63 | + |
| 64 | +Steps |
| 65 | +----- |
| 66 | + |
| 67 | +.. procedure:: |
| 68 | + :style: normal |
| 69 | + |
| 70 | + .. step:: Select a query on the :guilabel:`Query Converter` pane |
| 71 | + |
| 72 | + a. From the :guilabel:`Code Generation` tab, click the |
| 73 | + :guilabel:`Query Converter` pane. |
| 74 | + |
| 75 | + .. note:: |
| 76 | + |
| 77 | + If you are not already logged into your Atlas account or have |
| 78 | + an expired session, you must login to proceed. |
| 79 | + |
| 80 | + #. On the left-hand :guilabel:`Queries` pane, select a query, view, |
| 81 | + or stored procedure. |
| 82 | + |
| 83 | + #. If your query has not been converted, select a |
| 84 | + :guilabel:`Target Language` and click :guilabel:`Convert` |
| 85 | + :icon-lg:`Sparkle`. |
| 86 | + |
| 87 | + .. step:: Open the :guilabel:`Test Queries` pane |
| 88 | + |
| 89 | + a. From the :guilabel:`Code Generation` tab, click the |
| 90 | + :guilabel:`Query Converter` pane. |
| 91 | + |
| 92 | + #. On the bottom-right of the screen, click the :icon-lg:`ChevronUp` |
| 93 | + button. |
| 94 | + |
| 95 | + .. step:: *(Optional)* Specify parameters |
| 96 | + |
| 97 | + If you're converting a stored procedure with parameters, specify the |
| 98 | + stored procedure's parameters in the :guilabel:`Source Script` text field. |
| 99 | + |
| 100 | + For example, for the following PostGreSQL stored procedure: |
| 101 | + |
| 102 | + .. code-block:: sql |
| 103 | + :copyable: false |
| 104 | + |
| 105 | + CREATE OR REPLACE PROCEDURE PUBLIC.CANCEL_CUSTOMER_ORDERS(IN CUST_ID INTEGER) |
| 106 | + LANGUAGE PLPQSQL |
| 107 | + |
| 108 | + AS $PROCEDURE$ |
| 109 | + BEGIN |
| 110 | + UPDATE ORDERS SET STATUS = 'CANCELLED' WHERE CUSTOMER_ID = CUST_ID; |
| 111 | + END;$PROCEDURE$ |
| 112 | + |
| 113 | + Specify the ``CUST_ID`` in the :guilabel:`Source Script` text field |
| 114 | + by replacing ``<value>`` with the customer ID: |
| 115 | + |
| 116 | + .. code-block:: sql |
| 117 | + :copyable: false |
| 118 | + :emphasize-lines: 7 |
| 119 | + |
| 120 | + DO |
| 121 | + $$ |
| 122 | + DECLARE |
| 123 | + CUST_ID INTEGER; |
| 124 | + BEGIN |
| 125 | + --TODO: Set parameter values here |
| 126 | + CUST_ID := <value> |
| 127 | + |
| 128 | + CALL public.cancel_customer_orders(cust_id); |
| 129 | + END; |
| 130 | + $$ |
| 131 | + |
| 132 | + .. step:: Run the source query |
| 133 | + |
| 134 | + a. On the :guilabel:`Test Queries` |
| 135 | + pane, click the :guilabel:`Run Source Query` |
| 136 | + button. |
| 137 | + |
| 138 | + #. Enter the connection details to your source database. |
| 139 | + |
| 140 | + #. On the :guilabel:`Connection Details` form, click :guilabel:`Run`. |
| 141 | + |
| 142 | + The data from the source database populates in the |
| 143 | + :guilabel:`Results` user interface. You can click |
| 144 | + the :guilabel:`Messages` pill to see execution |
| 145 | + statistics such as ``Execution Time``, ``Row Count``, |
| 146 | + error messages, and print statements. |
| 147 | + |
| 148 | + .. step:: Run the converted query |
| 149 | + |
| 150 | + a. On the :guilabel:`Test Queries` |
| 151 | + pane, click :guilabel:`Run Converted Query` |
| 152 | + button. |
| 153 | + |
| 154 | + #. Enter the connection details to your database. |
| 155 | + |
| 156 | + #. On the :guilabel:`Connection Details` form, click :guilabel:`Run`. |
| 157 | + |
| 158 | + |
| 159 | + The data from the destination database populates |
| 160 | + on the right-side of the :guilabel:`Results` user |
| 161 | + interface. |
| 162 | + |
| 163 | + #. You can use the :guilabel:`Results` pane to compare the |
| 164 | + source and destination data and types. |
| 165 | + |
| 166 | + .. note:: |
| 167 | + |
| 168 | + You can click the :icon-lg:`Menu` and |
| 169 | + :icon-lg:`Apps` buttons to switch between |
| 170 | + the document and row view for the data. |
| 171 | + |
| 172 | + .. step:: *(Optional)* Edit the converted query |
| 173 | + |
| 174 | + If the destination query needs to be changed, you can make |
| 175 | + code changes in the :guilabel:`Converted MongoDB Query` |
| 176 | + pane and run the updated query. |
| 177 | + |
| 178 | + a. On the :guilabel:`Converted MongoDB Query` pane, |
| 179 | + click the :icon-lg:`Edit` button. |
| 180 | + |
| 181 | + #. Edit the code and click :guilabel:`Save`. |
| 182 | + |
| 183 | + #. Click :guilabel:`Run Converted Query`. |
| 184 | + |
| 185 | +Learn More |
| 186 | +---------- |
| 187 | + |
| 188 | +- :ref:`rm-convert-queries` |
| 189 | +- :ref:`rm-convert-views` |
| 190 | +- :ref:`rm-convert-stored-procedures` |
0 commit comments