{"mock":"https://private-anon-2fc7c2b286-rat2.apiary-mock.com/","production":"http://127.0.0.1:5002/","proxy":"https://private-anon-2fc7c2b286-rat2.apiary-proxy.com/"}
FORMAT: 1A HOST: http://127.0.0.1:5002 # RAT2 RAT is an abbreviaton for Relational Algebra Translator. RAT2 is a newer version of RAT currently deployed to the [dbs.fit.cvut.cz](http://dbs.fit.cvut.cz) server. This document describes the RAT2 API. The main translation method accepts only JSON format requests. ## API test [/] ### Check if the API runs [GET] + Response 200 (application/json) "It works!" ## Version [/version] ### Retrieve the version of the application [GET] + Response 200 (application/json) "2.0.0" ## RA query translation [/translate] RAT2 expects the requests in the same format as original RAT did. RAT2 takes a JSON object containing a `query`, `type` and a nested JSON object `scheme` representing the database scheme. The key `query` should contain a plain UTF-8 string representing the RA query. For new lines delimitting use the `\n` character. **HTML tags are not allowed** as it would result in an error response containing information about the error which occurred within lexical analysis. Allowed values for the key `type` are: `oracle`, `postgresql` and `mariadb`. Other values will result in an error **404 BAD REQUEST** response. The key `scheme` must contain a non-empty database scheme stored as an another JSON object, which keys (strings) stand for table names. Each key (table name) must specify a non-empty list of it's column names (strings). For more details see the example below: ``` { 'LODNIK': ['lodnik_id', 'jmeno', 'prijmeni'], 'PLAVBA': ['plavba_id', 'odkud', 'kam', 'datum'] } ``` ### Translation requests and responses [PUT] + Request Improperly defined request, either error in the structure, values, type or in the RA query itself (application/json) { "query": "LODNIK", "type": "dummy", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 400 (application/json) { "status": "error", "sql": "", "messages": [ { "message": "Unsupported SQL dialect 'dummy'" } ], "evaluation_trees": [] } + Request Well defined request with lexical errors in the RA query (application/json) { "query": "LODNIK $ [ * lodnik_id jmeno]", "type": "oracle", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 400 (application/json) { "status": "error", "sql": "", "messages": [ { "line": 1, "column": 8, "message": "Illegal character '$' at line: 1, column: 8, expected: 'TABLE_NAME', '[', '(', '*', '<', '<*', '!<', '!<*', '*>', '![', '!*>', '*^L', '*^R', '*^F', '\\', '\u2229', '\u222a', '\u00d7', '\u00f7', '{', '}'" }, { "line": 1, "column": 12, "message": "Illegal character '*' at line: 1, column: 12, expected: 'COLUMN_NAME', '\u00ac', 'NOT', 'not', '('" }, { "line": 1, "column": 24, "message": "Illegal expression 'jmeno' at line: 1, column: 24, expected: '->', '\u2192', ',', ']'" } ], "evaluation_trees": [] } + Request A potential request which results in throwing and catching an unexpected exception (application/json) { "query": "<some buggy RA query>", "type": "oracle", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 400 (application/json) { "status": "error", "sql": "", "messages": [ { "message": "Ooops, it seems you found a bug! `:(", "request": "Please refer to our gitlab <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://gitlab.fit.cvut.cz/dbs/newDBS-bug/issues\">issue tracker</a>, create a new issue and please attach the debug information below. Thank you", "debug": { "query": "<some buggy RA query>", "type": "oracle", "scheme": "{'LODNIK': ['lodnik_id', 'jmeno', 'prijmeni']}" } } ], "evaluation_trees": [] } + Request A sample request, however RAT could not be instantiated, internal application error (application/json) { "query": "<some RA query>", "type": "oracle", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 500 (application/json) { "status": "error", "sql": "", "messages": [ { "message": "Jeez! Something went wrong, RAT could not handle your request x(" } ], "evaluation_trees": [] } + Request Well defined request, however the RA query contains minor issues (application/json) { "query": "LODNIK[x, y](z > 1)", "type": "postgresql", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 200 (application/json) { "status": "warning", "sql": "SELECT DISTINCT *\nFROM (\n SELECT DISTINCT x,\n y\n FROM LODNIK\n) R1\nWHERE z > 1;", "messages": [ { "message": "Projection over a non-existing attribute: 'x'" }, { "message": "Projection over a non-existing attribute: 'y'" }, { "message": "Selection over a non-existing attribute: 'z'" } ], "evaluation_trees": [ { "children": [ { "children": [ { "children": [], "columns": [ [ "LODNIK.lodnik_id", "lodnik_id" ], [ "LODNIK.jmeno", "jmeno" ], [ "LODNIK.prijmeni", "prijmeni" ] ], "value": "LODNIK" } ], "columns": [ [ "x" ], [ "y" ] ], "value": "[x, y]" } ], "columns": [ [ "x" ], [ "y" ] ], "value": "(z > 1)" } ] } + Request Absolutely correct request producing multiple RA evaluation trees (application/json) { "query": "x:= LODNIK\nx", "type": "oracle", "scheme": { "LODNIK": ["lodnik_id", "jmeno", "prijmeni"] } } + Response 200 (application/json) { "status": "success", "sql": "WITH X AS (\n SELECT DISTINCT *\n FROM LODNIK\n)\nSELECT DISTINCT *\nFROM X;", "messages": [], "evaluation_trees": [ { "children": [ { "children": [], "columns": [ [ "LODNIK.lodnik_id", "lodnik_id" ], [ "LODNIK.jmeno", "jmeno" ], [ "LODNIK.prijmeni", "prijmeni" ] ], "value": "LODNIK" } ], "columns": [ [ "X.lodnik_id", "lodnik_id" ], [ "X.jmeno", "jmeno" ], [ "X.prijmeni", "prijmeni" ] ], "value": "x" }, { "children": [], "columns": [ [ "X.lodnik_id", "lodnik_id" ], [ "X.jmeno", "jmeno" ], [ "X.prijmeni", "prijmeni" ] ], "value": "x" } ] }