{ "info": { "author": "Dmitry Ignatovich", "author_email": "mechatroner@yandex.ru", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3" ], "description": "RBQL is both a library and a command line tool which provides SQL-like language with Python expressions\n\n[Official Site](https://rbql.org/)\n\n\n### Using RBQL as Python library\n\nIf you want to use rbql module as a python library for your own app - read the API and integration [Documentation](https://github.com/mechatroner/rbql-py/blob/master/LIBRARY.md) \n\n\n### Using RBQL as CLI App\n\n#### Installation:\n```\n$ pip install rbql\n```\n\n#### Usage example (non-interactive mode):\n```\n$ rbql-py --query \"select a1, a2 order by a1\" --delim , < input.csv\n```\n\n#### Usage example (interactive mode):\nIn interactive mode rbql-py will show input table preview so it is easier to type SQL-like query. \n```\n$ rbql-py --input input.csv --output result.csv\n```\n\n### Main Features\n\n* Use Python expressions inside _SELECT_, _UPDATE_, _WHERE_ and _ORDER BY_ statements\n* Result set of any query immediately becomes a first-class table on it's own\n* Supports input tables with inconsistent number of fields per record\n* Output records appear in the same order as in input unless _ORDER BY_ is provided\n* Each record has a unique NR (line number) identifier\n* Supports all main SQL keywords\n* Supports aggregate functions and GROUP BY queries\n* Provides some new useful query modes which traditional SQL engines do not have\n* Supports both _TOP_ and _LIMIT_ keywords\n* Supports user-defined functions (UDF)\n* Works out of the box, no external dependencies\n\n#### Limitations:\n\n* RBQL doesn't support nested queries, but they can be emulated with consecutive queries\n* Number of tables in all JOIN queries is always 2 (input table and join table), use consecutive queries to join 3 or more tables\n\n### Supported SQL Keywords (Keywords are case insensitive)\n\n* SELECT\n* UPDATE\n* WHERE\n* ORDER BY ... [ DESC | ASC ]\n* [ LEFT | INNER ] JOIN\n* DISTINCT\n* GROUP BY\n* TOP _N_\n* LIMIT _N_\n\nAll keywords have the same meaning as in SQL queries. You can check them [online](https://www.w3schools.com/sql/default.asp) \n\n\n### Special variables\n\n| Variable Name | Variable Type | Variable Description |\n|--------------------------|---------------|--------------------------------------|\n| _a1_, _a2_,..., _a{N}_ |string | Value of i-th column |\n| _b1_, _b2_,..., _b{N}_ |string | Value of i-th column in join table B |\n| _NR_ |integer | Line number (1-based) |\n| _NF_ |integer | Number of fields in line |\n\n\n### UPDATE statement\n\n_UPDATE_ query produces a new table where original values are replaced according to the UPDATE expression, so it can also be considered a special type of SELECT query. This prevents accidental data loss from poorly written queries. \n_UPDATE SET_ is synonym to _UPDATE_, because in RBQL there is no need to specify the source table. \n\n\n### Aggregate functions and queries\n\nRBQL supports the following aggregate functions, which can also be used with _GROUP BY_ keyword: \n_COUNT()_, _ARRAY_AGG()_, _MIN()_, _MAX()_, _SUM()_, _AVG()_, _VARIANCE()_, _MEDIAN()_\n\n#### Limitations\nAggregate functions inside Python (or JS) expressions are not supported. Although you can use expressions inside aggregate functions.\nE.g. `MAX(float(a1) / 1000)` - valid; `MAX(a1) / 1000` - invalid\n\n\n### JOIN statements\n\nJoin table B can be referenced either by it's file path or by it's name - an arbitary string which user should provide before executing the JOIN query. \nRBQL supports _STRICT LEFT JOIN_ which is like _LEFT JOIN_, but generates an error if any key in left table \"A\" doesn't have exactly one matching key in the right table \"B\". \n\n#### Limitations\n\n* _JOIN_ statements must have the following form: _ (/path/to/table.tsv | table_name ) ON ai == bj_ \n\n\n### SELECT EXCEPT statement\n\nSELECT EXCEPT can be used to select everything except specific columns. E.g. to select everything but columns 2 and 4, run: `SELECT * EXCEPT a2, a4` \nTraditional SQL engines do not support this query mode.\n\n\n### SELECT DISTINCT COUNT statement\n\nRBQL supports _DISTINCT COUNT_ keyword which is like _DISTINCT_, but adds a new column to the \"distinct\" result set: number of occurrences of the entry, similar to _uniq -c_ unix command. \n`SELECT DISTINCT COUNT a1` is equivalent to `SELECT a1, COUNT(a1) GROUP BY a1` \n\n\n### UNNEST() operator\nUNNEST(list) takes a list/array as an argument and repeats the output record multiple times - one time for each value from the list argument. \nExample: `SELECT a1, UNNEST(a2.split(';'))` \n\n\n### User Defined Functions (UDF)\n\nRBQL supports User Defined Functions \nYou can define custom functions and/or import libraries in a special file: `~/.rbql_init_source.py`\n\n\n## Examples of RBQL queries\n\n* `select top 100 a1, int(a2) * 10, len(a4) where a1 == \"Buy\" order by int(a2)`\n* `select * order by random.random()` - random sort, this is an equivalent of bash command _sort -R_\n* `select top 20 len(a1) / 10, a2 where a2 in [\"car\", \"plane\", \"boat\"]` - use Python's \"in\" to emulate SQL's \"in\"\n* `select len(a1) / 10, a2 where a2 in [\"car\", \"plane\", \"boat\"] limit 20`\n* `update set a3 = 'US' where a3.find('of America') != -1`\n* `select * where NR <= 10` - this is an equivalent of bash command \"head -n 10\", NR is 1-based')\n* `select a1, a4` - this is an equivalent of bash command \"cut -f 1,4\"\n* `select * order by int(a2) desc` - this is an equivalent of bash command \"sort -k2,2 -r -n\"\n* `select NR, *` - enumerate lines, NR is 1-based\n* `select * where re.match(\".*ab.*\", a1) is not None` - select entries where first column has \"ab\" pattern\n* `select a1, b1, b2 inner join ./countries.txt on a2 == b1 order by a1, a3` - an example of join query\n* `select distinct count len(a1) where a2 != 'US'`\n* `select MAX(a1), MIN(a1) where a2 != 'US' group by a2, a3`\n\n\n### FAQ\n\n#### How does RBQL work?\n\nRBQL parses SQL-like user query, creates a new python worker module, then imports and executes it.\n\nExplanation of simplified Python version of RBQL algorithm by example.\n1. User enters the following query, which is stored as a string _Q_:\n```\n SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL'\n```\n2. RBQL replaces all `a{i}` substrings in the query string _Q_ with `a[{i - 1}]` substrings. The result is the following string:\n```\n Q = \"SELECT a[2], int(a[3]) + 100, len(a[1]) WHERE a[0] != 'SELL'\"\n```\n\n3. RBQL searches for \"SELECT\" and \"WHERE\" keywords in the query string _Q_, throws the keywords away, and puts everything after these keywords into two variables _S_ - select part and _W_ - where part, so we will get:\n```\n S = \"a[2], int(a[3]) + 100, len(a[1])\"\n W = \"a[0] != 'SELL'\"\n```\n\n4. RBQL has static template script which looks like this:\n```\n for line in sys.stdin:\n a = line.rstrip('\\n').split('\\t')\n if %%%W_Expression%%%:\n out_fields = [%%%S_Expression%%%]\n print '\\t'.join([str(v) for v in out_fields])\n```\n\n5. RBQL replaces `%%%W_Expression%%%` with _W_ and `%%%S_Expression%%%` with _S_ so we get the following script:\n```\n for line in sys.stdin:\n a = line.rstrip('\\n').split('\\t')\n if a[0] != 'SELL':\n out_fields = [a[2], int(a[3]) + 100, len(a[1])]\n print '\\t'.join([str(v) for v in out_fields])\n```\n\n6. RBQL runs the patched script against user's data file: \n```\n ./tmp_script.py < data.tsv > result.tsv\n```\nResult set of the original query (`SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL'`) is in the \"result.tsv\" file.\nIt is clear that this simplified version can only work with tab-separated files.\n\n\n#### Is this technology reliable?\n\nIt should be: RBQL scripts have only 1000 - 2000 lines combined (depending on how you count them) and there are no external dependencies.\nThere is no complex logic, even query parsing functions are very simple. If something goes wrong RBQL will show an error instead of producing incorrect output, also there are currently 5 different warning types.\n\n\n### References\n\n* rbql-js library and CLI App for Node.js - [npm](https://www.npmjs.com/package/rbql) \n* rbql-py library and CLI App in [python](https://pypi.org/project/rbql/) \n* Rainbow CSV extension with integrated RBQL in [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv) \n* Rainbow CSV extension with integrated RBQL in [Vim](https://github.com/mechatroner/rainbow_csv) \n* Rainbow CSV extension with integrated RBQL in [Sublime Text 3](https://packagecontrol.io/packages/rainbow_csv) \n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mechatroner/RBQL", "keywords": "SQL SQL-like transpiler RBQL library CLI command-line CSV TSV", "license": "", "maintainer": "", "maintainer_email": "", "name": "rbql", "package_url": "https://pypi.org/project/rbql/", "platform": "", "project_url": "https://pypi.org/project/rbql/", "project_urls": { "Homepage": "https://github.com/mechatroner/RBQL" }, "release_url": "https://pypi.org/project/rbql/0.9.1/", "requires_dist": null, "requires_python": "", "summary": "Rainbow Query Language", "version": "0.9.1" }, "last_serial": 5726051, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "2e0d774736cf701c9f1979673a25c6c0", "sha256": "ece32ffa7df268bca28566225206f14654520562bc2a09a6de4ea92dea5afc7f" }, "downloads": -1, "filename": "rbql-0.2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "2e0d774736cf701c9f1979673a25c6c0", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 17415, "upload_time": "2018-09-25T05:52:47", "url": "https://files.pythonhosted.org/packages/31/47/455442a89da0e6785398881a57229f318d52936fa931cfd41fd7392607f0/rbql-0.2.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "485e8ac9214665797158f0f6ee09f484", "sha256": "95a336187a9465afaaa2d4bd1269c512c41efe604a855295429543243d01a9ff" }, "downloads": -1, "filename": "rbql-0.2.0.tar.gz", "has_sig": false, "md5_digest": "485e8ac9214665797158f0f6ee09f484", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18767, "upload_time": "2018-09-25T05:52:49", "url": "https://files.pythonhosted.org/packages/90/a8/8777b35725aa6b8677c755e9d08378e83c94eaed07daa7927ec443845f85/rbql-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "06919d99fcf770d858c0632c2af07cce", "sha256": "5ae3ba25e563f67e8c344c1b972810882c9bff742bac40b0004055ba1047ef3d" }, "downloads": -1, "filename": "rbql-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "06919d99fcf770d858c0632c2af07cce", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18614, "upload_time": "2018-11-07T04:33:42", "url": "https://files.pythonhosted.org/packages/5b/d0/1adc568de501749e28dada5e71b503873d1311801709319ab3dfae84ba07/rbql-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "47deccbcc3c625890916d7dbeea2026f", "sha256": "e9b2ff7966d4819e2cb82cfd66d1dd4fe4b5b10ac469cffd3e8e7892d9c95603" }, "downloads": -1, "filename": "rbql-0.3.0.tar.gz", "has_sig": false, "md5_digest": "47deccbcc3c625890916d7dbeea2026f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19508, "upload_time": "2018-11-07T04:33:44", "url": "https://files.pythonhosted.org/packages/44/4c/dc22ee2cfbed0b6f6c9ced96b745d7b9d9d617916978c2e402c4b3138df1/rbql-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "e1059245cda30ff7b3f891735617dcd3", "sha256": "4240150ce460acfdc3aa4fd8edef59da7753b54e980353e6e11bacb37df44ce3" }, "downloads": -1, "filename": "rbql-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e1059245cda30ff7b3f891735617dcd3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 22486, "upload_time": "2018-12-28T04:54:41", "url": "https://files.pythonhosted.org/packages/bd/51/3e771ae1421f9cf3f8f621328891d35822a694e44a8b653bc924a2425d19/rbql-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0c57b6fe934d188ce11a95fb8d01abac", "sha256": "0070ff82100d405ad6b18f86c396fbf9df307c1f371e79e933c6f32b4e24d00f" }, "downloads": -1, "filename": "rbql-0.4.0.tar.gz", "has_sig": false, "md5_digest": "0c57b6fe934d188ce11a95fb8d01abac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23954, "upload_time": "2018-12-28T04:54:43", "url": "https://files.pythonhosted.org/packages/5c/97/f6996d4fa392865716c52533c0379cb6bc09e1a772a464680403f6f4def2/rbql-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "43c92f33d2d1da8ad6a70c147ad82ea5", "sha256": "33c3bdde69141995a559f08c38a12506766a668c70be09ea97168a77340aa1b6" }, "downloads": -1, "filename": "rbql-0.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "43c92f33d2d1da8ad6a70c147ad82ea5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 24454, "upload_time": "2019-07-04T02:57:10", "url": "https://files.pythonhosted.org/packages/30/1d/8d07155d42ecabb2434631bcefb514b1a859d5968bc360ad9b44a92636c3/rbql-0.5.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cc5243c3973d5cbce0f59249b33e77a3", "sha256": "0cb8a101dade60d5eda298aec2a0d7db03d85ce066f95a209f4b46c50b5337ff" }, "downloads": -1, "filename": "rbql-0.5.0.tar.gz", "has_sig": false, "md5_digest": "cc5243c3973d5cbce0f59249b33e77a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24902, "upload_time": "2019-07-04T02:57:12", "url": "https://files.pythonhosted.org/packages/38/aa/82f50af43b92e96f7d97476063928f2da3ee9cf9f70c730a01432d579313/rbql-0.5.0.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "5b7178b627ce8209b54c5d84bd61b858", "sha256": "c7dec382461aa4f28168564e6801bafcd5ffac552a3aa4ee8600cd75ab6875c0" }, "downloads": -1, "filename": "rbql-0.7.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5b7178b627ce8209b54c5d84bd61b858", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 24507, "upload_time": "2019-07-13T22:41:31", "url": "https://files.pythonhosted.org/packages/27/58/050b87c3057ffe2191c0420ac0d53fa199d4cd0134654a771c8c2b2f12dc/rbql-0.7.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39fd6a635b8bbc870171624e51601756", "sha256": "61688d666f85878f8bb1defa43b398ca47affb2e88fbe7a7c0eb25fd9a1c9f01" }, "downloads": -1, "filename": "rbql-0.7.0.tar.gz", "has_sig": false, "md5_digest": "39fd6a635b8bbc870171624e51601756", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25111, "upload_time": "2019-07-13T22:41:32", "url": "https://files.pythonhosted.org/packages/8d/bc/824db4eac6f008401541d93f7e21f88de5c9049c5913056a6b5a340099b1/rbql-0.7.0.tar.gz" } ], "0.8.0": [ { "comment_text": "", "digests": { "md5": "bc700672a2049c00b2b98b458fa50732", "sha256": "047b7d9589c572aa77a8da8eb4e08c7cdaa5c24d0251ebe1228617036309281b" }, "downloads": -1, "filename": "rbql-0.8.0-py3-none-any.whl", "has_sig": false, "md5_digest": "bc700672a2049c00b2b98b458fa50732", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 25567, "upload_time": "2019-08-03T02:52:06", "url": "https://files.pythonhosted.org/packages/04/06/c77a062e3f491edce981c84540edcefab11168db5b181081ff3383b06e40/rbql-0.8.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "863eb3bb76d24a2f9e3f59fd223474a1", "sha256": "19eafa57036932761ef5cc77d0822be358a55f703411be79d3bf1bdb3a22c879" }, "downloads": -1, "filename": "rbql-0.8.0.tar.gz", "has_sig": false, "md5_digest": "863eb3bb76d24a2f9e3f59fd223474a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26036, "upload_time": "2019-08-03T02:52:08", "url": "https://files.pythonhosted.org/packages/db/3b/1c582b31c723138b3e99c89977f04ee39bd3aa36ca1d1faaf460efa1c11b/rbql-0.8.0.tar.gz" } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "4f90dd09cbd2659d2f010d1bd3fcbca7", "sha256": "42a9e2f13d016887ed2ff7878ac76360c3fde60ecb81e254f73c38a8cb3ea3cd" }, "downloads": -1, "filename": "rbql-0.9.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4f90dd09cbd2659d2f010d1bd3fcbca7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 26740, "upload_time": "2019-08-25T04:56:11", "url": "https://files.pythonhosted.org/packages/de/e0/46fc500a8e2cf99e5c2abbef9a1600137f99e69474cde730ddddd572f821/rbql-0.9.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e5f8262fe9f1efa90394d7642023827", "sha256": "e0b8519f046a73d9ea4a1ab2ce6fd21d9c876dfba4ffcd7cf2b169c50ed368cb" }, "downloads": -1, "filename": "rbql-0.9.0.tar.gz", "has_sig": false, "md5_digest": "7e5f8262fe9f1efa90394d7642023827", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27238, "upload_time": "2019-08-25T04:56:13", "url": "https://files.pythonhosted.org/packages/0e/8b/82223d22a8b46fb0845a0c9cfc8451735b6de129e168d1cad613a0c0199f/rbql-0.9.0.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "aa77debb251e1671e49961abc42359b3", "sha256": "f097622128563d48dbac9fc0ba6377cdc74d890cf83a671305eb8494284af17a" }, "downloads": -1, "filename": "rbql-0.9.1-py3-none-any.whl", "has_sig": false, "md5_digest": "aa77debb251e1671e49961abc42359b3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 26509, "upload_time": "2019-08-25T05:01:25", "url": "https://files.pythonhosted.org/packages/ac/28/e8ab2ebaca50c8d679915504ff4a76bb050309a010fa7693e3090e02eb67/rbql-0.9.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eddfec38554998cebdc8c271216134e3", "sha256": "06dbc0a6129c7f1f5062b87cfc2c84ac0c661d4ff0e20059d961981d1e0c8bc8" }, "downloads": -1, "filename": "rbql-0.9.1.tar.gz", "has_sig": false, "md5_digest": "eddfec38554998cebdc8c271216134e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26782, "upload_time": "2019-08-25T05:01:26", "url": "https://files.pythonhosted.org/packages/7a/4e/c537b0df2c9648b14cd3abc3a9d7aa6581b7c68210ee25dcae148488bc1f/rbql-0.9.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aa77debb251e1671e49961abc42359b3", "sha256": "f097622128563d48dbac9fc0ba6377cdc74d890cf83a671305eb8494284af17a" }, "downloads": -1, "filename": "rbql-0.9.1-py3-none-any.whl", "has_sig": false, "md5_digest": "aa77debb251e1671e49961abc42359b3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 26509, "upload_time": "2019-08-25T05:01:25", "url": "https://files.pythonhosted.org/packages/ac/28/e8ab2ebaca50c8d679915504ff4a76bb050309a010fa7693e3090e02eb67/rbql-0.9.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eddfec38554998cebdc8c271216134e3", "sha256": "06dbc0a6129c7f1f5062b87cfc2c84ac0c661d4ff0e20059d961981d1e0c8bc8" }, "downloads": -1, "filename": "rbql-0.9.1.tar.gz", "has_sig": false, "md5_digest": "eddfec38554998cebdc8c271216134e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26782, "upload_time": "2019-08-25T05:01:26", "url": "https://files.pythonhosted.org/packages/7a/4e/c537b0df2c9648b14cd3abc3a9d7aa6581b7c68210ee25dcae148488bc1f/rbql-0.9.1.tar.gz" } ] }