├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── docs ├── JSON in Database.md ├── JSON in Database.pptx ├── Logical Equality.md ├── Nomenclature.md ├── Perspective.md ├── Student Project 190124.md ├── The Future.md ├── gsoc.md ├── jx_expressions_leaves.md ├── nested1.png ├── nested2.png ├── perspectives.pptx ├── ref1.png ├── ref2.png ├── ref3.png ├── schema1.png ├── schema2.png ├── schema3.png ├── schema4.png ├── t1.png ├── t2.png ├── t3.png ├── t3b.png ├── t4.png └── t4b.png ├── jx_sqlite ├── README.md ├── __init__.py ├── base_table.py ├── container.py ├── edges_table.py ├── expressions.py ├── expressions │ ├── __init__.py │ ├── _utils.py │ ├── abs_op.py │ ├── add_op.py │ ├── and_op.py │ ├── basic_add_op.py │ ├── basic_eq_op.py │ ├── basic_index_of_op.py │ ├── basic_mul_op.py │ ├── basic_starts_with_op.py │ ├── basic_substring_op.py │ ├── between_op.py │ ├── boolean_op.py │ ├── case_op.py │ ├── coalesce_op.py │ ├── concat_op.py │ ├── count_op.py │ ├── date_op.py │ ├── div_op.py │ ├── eq_op.py │ ├── exists_op.py │ ├── exp_op.py │ ├── find_op.py │ ├── first_op.py │ ├── floor_op.py │ ├── from_unix_op.py │ ├── get_op.py │ ├── gt_op.py │ ├── gte_op.py │ ├── in_op.py │ ├── integer_op.py │ ├── last_op.py │ ├── leaves_op.py │ ├── left_op.py │ ├── length_op.py │ ├── literal.py │ ├── lt_op.py │ ├── lte_op.py │ ├── max_op.py │ ├── min_op.py │ ├── missing_op.py │ ├── mul_op.py │ ├── ne_op.py │ ├── not_left_op.py │ ├── not_op.py │ ├── not_right_op.py │ ├── number_op.py │ ├── offset_op.py │ ├── or_op.py │ ├── prefix_op.py │ ├── range_op.py │ ├── reg_exp_op.py │ ├── right_op.py │ ├── rows_op.py │ ├── script_op.py │ ├── select_op.py │ ├── sql_eq_op.py │ ├── sql_instr_op.py │ ├── sql_script.py │ ├── sql_substr_op.py │ ├── string_op.py │ ├── sub_op.py │ ├── suffix_op.py │ ├── tuple_op.py │ ├── unix_op.py │ ├── variable.py │ └── when_op.py ├── groupby_table.py ├── insert_table.py ├── meta_columns.py ├── namespace.py ├── query_table.py ├── schema.py ├── setop_table.py ├── snowflake.py ├── sqlite.py ├── table.py └── utils.py ├── requirements.txt ├── resources └── scripts │ └── run_tests.bat ├── setup.py ├── setuptools.json ├── tests ├── __init__.py ├── config │ └── sqlite.json └── test_jx │ ├── __init__.py │ ├── test_agg_ops.py │ ├── test_deep_ops.py │ ├── test_edge_1.py │ ├── test_edge_2.py │ ├── test_edge_time.py │ ├── test_expressions.py │ ├── test_expressions_w_set_ops.py │ ├── test_filters.py │ ├── test_groupby_1.py │ ├── test_groupby_2.py │ ├── test_metadata.py │ ├── test_query_normalization.py │ ├── test_schema_merging.py │ ├── test_set_ops.py │ ├── test_sort.py │ ├── test_time_domain.py │ ├── test_time_parser.py │ └── test_update.py └── vendor ├── jx_base ├── README.md ├── __init__.py ├── container.py ├── dimensions.py ├── domains.py ├── expressions │ ├── __init__.py │ ├── _utils.py │ ├── abs_op.py │ ├── add_op.py │ ├── and_op.py │ ├── base_binary_op.py │ ├── base_inequality_op.py │ ├── base_multi_op.py │ ├── basic_add_op.py │ ├── basic_eq_op.py │ ├── basic_index_of_op.py │ ├── basic_mul_op.py │ ├── basic_multi_op.py │ ├── basic_starts_with_op.py │ ├── basic_substring_op.py │ ├── between_op.py │ ├── boolean_op.py │ ├── case_op.py │ ├── coalesce_op.py │ ├── concat_op.py │ ├── count_op.py │ ├── date_op.py │ ├── div_op.py │ ├── eq_op.py │ ├── es_nested_op.py │ ├── es_script.py │ ├── exists_op.py │ ├── exp_op.py │ ├── expression.py │ ├── false_op.py │ ├── find_op.py │ ├── first_op.py │ ├── floor_op.py │ ├── from_unix_op.py │ ├── get_op.py │ ├── gt_op.py │ ├── gte_op.py │ ├── in_op.py │ ├── integer_op.py │ ├── is_boolean_op.py │ ├── is_integer_op.py │ ├── is_number_op.py │ ├── is_string_op.py │ ├── last_op.py │ ├── leaves_op.py │ ├── left_op.py │ ├── length_op.py │ ├── literal.py │ ├── lt_op.py │ ├── lte_op.py │ ├── max_op.py │ ├── min_op.py │ ├── missing_op.py │ ├── mod_op.py │ ├── mul_op.py │ ├── ne_op.py │ ├── not_left_op.py │ ├── not_op.py │ ├── not_right_op.py │ ├── null_op.py │ ├── number_op.py │ ├── offset_op.py │ ├── or_op.py │ ├── prefix_op.py │ ├── python_script.py │ ├── query_op.py │ ├── range_op.py │ ├── reg_exp_op.py │ ├── right_op.py │ ├── rows_op.py │ ├── script_op.py │ ├── select_op.py │ ├── split_op.py │ ├── sql_eq_op.py │ ├── sql_instr_op.py │ ├── sql_script.py │ ├── sql_substr_op.py │ ├── string_op.py │ ├── sub_op.py │ ├── suffix_op.py │ ├── true_op.py │ ├── tuple_op.py │ ├── union_op.py │ ├── unix_op.py │ ├── variable.py │ └── when_op.py ├── facts.py ├── language.py ├── meta_columns.py ├── namespace.py ├── queries.py ├── query.py ├── schema.py ├── snowflake.py ├── table.py └── utils.py ├── jx_python ├── __init__.py ├── containers │ ├── __init__.py │ ├── cube.py │ └── list_usingPythonList.py ├── cubes │ ├── __init__.py │ └── aggs.py ├── expression_compiler.py ├── expressions │ ├── __init__.py │ ├── _utils.py │ ├── add_op.py │ ├── and_op.py │ ├── basic_eq_op.py │ ├── basic_index_of_op.py │ ├── between_op.py │ ├── boolean_op.py │ ├── case_op.py │ ├── coalesce_op.py │ ├── concat_op.py │ ├── count_op.py │ ├── date_op.py │ ├── div_op.py │ ├── eq_op.py │ ├── exists_op.py │ ├── exp_op.py │ ├── false_op.py │ ├── find_op.py │ ├── first_op.py │ ├── floor_op.py │ ├── get_op.py │ ├── gt_op.py │ ├── gte_op.py │ ├── in_op.py │ ├── integer_op.py │ ├── last_op.py │ ├── leaves_op.py │ ├── length_op.py │ ├── literal.py │ ├── lt_op.py │ ├── lte_op.py │ ├── max_op.py │ ├── missing_op.py │ ├── mod_op.py │ ├── mul_op.py │ ├── ne_op.py │ ├── not_left_op.py │ ├── not_op.py │ ├── not_right_op.py │ ├── number_op.py │ ├── offset_op.py │ ├── or_op.py │ ├── prefix_op.py │ ├── python_script.py │ ├── range_op.py │ ├── reg_exp_op.py │ ├── right_op.py │ ├── rows_op.py │ ├── script_op.py │ ├── select_op.py │ ├── split_op.py │ ├── string_op.py │ ├── sub_op.py │ ├── suffix_op.py │ ├── true_op.py │ ├── tuple_op.py │ ├── variable.py │ └── when_op.py ├── flat_list.py ├── group_by.py ├── jx.py ├── lists │ ├── __init__.py │ └── aggs.py ├── namespace │ ├── __init__.py │ ├── normal.py │ └── rename.py ├── records.py ├── table.py └── windows.py ├── mo_collections ├── __init__.py ├── array.py ├── index.py ├── matrix.py ├── multiset.py ├── persistent_queue.py ├── queue.py ├── relation.py └── unique_index.py ├── mo_dots ├── __init__.py ├── datas.py ├── lists.py ├── nones.py ├── objects.py └── utils.py ├── mo_files ├── __init__.py ├── mimetype.py └── url.py ├── mo_future └── __init__.py ├── mo_json ├── __init__.py ├── decoder.py ├── encoder.py ├── stream.py └── typed_encoder.py ├── mo_json_config ├── __init__.py └── convert.py ├── mo_kwargs └── __init__.py ├── mo_logs ├── __init__.py ├── constants.py ├── convert.py ├── exceptions.py ├── log_usingElasticSearch.py ├── log_usingEmail.py ├── log_usingFile.py ├── log_usingHandler.py ├── log_usingLogger.py ├── log_usingMozLog.py ├── log_usingMulti.py ├── log_usingNothing.py ├── log_usingSES.py ├── log_usingStream.py ├── log_usingThread.py ├── log_usingThreadedStream.py ├── startup.py └── strings.py ├── mo_math ├── __init__.py ├── aes_crypto.py ├── crypto.py ├── hashes.py ├── randoms.py ├── rsa_crypto.py ├── stats.py └── vendor │ ├── __init__.py │ ├── aespython │ ├── README.md │ ├── __init__.py │ ├── aes_cipher.py │ ├── aes_tables.py │ ├── cbc_mode.py │ ├── cfb_mode.py │ ├── cipher_mode.py │ ├── key_expander.py │ ├── mode_test.py │ ├── ofb_mode.py │ └── test_keys.py │ └── strangman │ ├── README.md │ ├── __init__.py │ ├── pstat.py │ ├── stats.py │ └── statstest.py ├── mo_sql └── __init__.py ├── mo_testing ├── __init__.py └── fuzzytestcase.py ├── mo_threads ├── __init__.py ├── busy_lock.py ├── lock.py ├── multiprocess.py ├── profiles.py ├── python.py ├── python_worker.py ├── queues.py ├── signals.py ├── threads.py └── till.py ├── mo_times ├── __init__.py ├── dates.py ├── durations.py ├── timer.py └── vendor │ ├── __init__.py │ └── dateutil │ ├── __init__.py │ ├── easter.py │ ├── parser.py │ ├── relativedelta.py │ ├── rrule.py │ ├── tz.py │ ├── tzwin.py │ └── zoneinfo │ ├── __init__.py │ └── zoneinfo--latest.tar.gz └── pyLibrary ├── __init__.py ├── aws ├── __init__.py └── s3.py ├── convert.py ├── env ├── README.md ├── __init__.py ├── big_data.py ├── emailer.py ├── flask_wrappers.py ├── git.py ├── http.py └── pulse.py ├── meta.py ├── sql ├── __init__.py ├── redshift.py └── util.py ├── testing ├── __init__.py └── elasticsearch.py ├── utils.py └── vendor ├── __init__.py └── sqlite ├── README.md ├── compile.bat ├── extension-functions.c ├── libsqlitefunctions.so ├── sqlite3.def ├── sqlite3.h └── sqlite3ext.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.iml 3 | .git 4 | .svn 5 | .env 6 | /docs/perspectives.pptx 7 | /docs/query.md 8 | /*.sqlite 9 | /vendor/pyLibrary/vendor/sqlite/*.dll 10 | /vendor/pyLibrary/vendor/sqlite/sqlite3_32.def 11 | /vendor/pyLibrary/vendor/sqlite/sqlite3_64.def 12 | /*.sqlite-journal 13 | /.idea 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "3.6" 5 | 6 | install: 7 | - "pip install -r requirements.txt" 8 | 9 | env: 10 | - PYTHONPATH=.:vendor 11 | 12 | script: 13 | - python -m unittest discover tests 14 | -------------------------------------------------------------------------------- /docs/JSON in Database.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/JSON in Database.pptx -------------------------------------------------------------------------------- /docs/gsoc.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/gsoc.md -------------------------------------------------------------------------------- /docs/nested1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/nested1.png -------------------------------------------------------------------------------- /docs/nested2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/nested2.png -------------------------------------------------------------------------------- /docs/perspectives.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/perspectives.pptx -------------------------------------------------------------------------------- /docs/ref1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/ref1.png -------------------------------------------------------------------------------- /docs/ref2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/ref2.png -------------------------------------------------------------------------------- /docs/ref3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/ref3.png -------------------------------------------------------------------------------- /docs/schema1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/schema1.png -------------------------------------------------------------------------------- /docs/schema2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/schema2.png -------------------------------------------------------------------------------- /docs/schema3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/schema3.png -------------------------------------------------------------------------------- /docs/schema4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/schema4.png -------------------------------------------------------------------------------- /docs/t1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t1.png -------------------------------------------------------------------------------- /docs/t2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t2.png -------------------------------------------------------------------------------- /docs/t3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t3.png -------------------------------------------------------------------------------- /docs/t3b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t3b.png -------------------------------------------------------------------------------- /docs/t4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t4.png -------------------------------------------------------------------------------- /docs/t4b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/docs/t4b.png -------------------------------------------------------------------------------- /jx_sqlite/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Definitions 3 | 4 | To provide clarity between the relational model and the data warehouse model, we use the following terms 5 | 6 | * Table - A set of rows 7 | * Schema - Describes the columns for a table 8 | * Facts - A number of tables connected by relations (hierarchical database) 9 | * Snowflake - Describes all columns in a set of facts 10 | * Container - Contains many facts 11 | * Namespace - Describes the container, and contains all the snowflakes 12 | 13 | 14 | ## Directory structure 15 | 16 | This directory is a stack of classes which used to be one massive class 17 | We hope these clears up the separation enough to perform better refactorings 18 | 19 | * **QueryTable** - implement the Container interface 20 | * **AggsTable** - aggregates 21 | * **SetOpTable** - simple set operations 22 | * **InsertTable** - methods for inserting documents 23 | * **BaseTable** - Constructor 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /jx_sqlite/base_table.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | 12 | from __future__ import absolute_import, division, unicode_literals 13 | 14 | import jx_base 15 | from mo_kwargs import override 16 | 17 | 18 | class BaseTable(jx_base.Table): 19 | @override 20 | def __init__(self, name, container): 21 | """ 22 | :param name: NAME FOR THIS TABLE 23 | :param db: THE DB TO USE 24 | :param uid: THE UNIQUE INDEX FOR THIS TABLE 25 | :return: HANDLE FOR TABLE IN db 26 | """ 27 | self.name = name 28 | self.db = container.db 29 | self.container = container 30 | 31 | @property 32 | def snowflake(self): 33 | return self.schema.snowflake 34 | 35 | @property 36 | def namespace(self): 37 | return self.container.ns 38 | 39 | @property 40 | def schema(self): 41 | return self.container.ns.get_schema(self.name) 42 | 43 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/abs_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import AbsOp as AbsOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from jx_sqlite.expressions.sql_script import SQLScript 15 | from mo_json import NUMBER 16 | 17 | 18 | class AbsOp(AbsOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | expr = SQLang[self.term].partial_eval().to_sql(schema)[0].sql.n 22 | return SQLScript( 23 | expr="ABS(" + expr + ")", 24 | data_type=NUMBER, 25 | frum=self, 26 | miss=self.missing(), 27 | schema=schema, 28 | ) 29 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/add_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import AddOp as AddOp_ 13 | from jx_sqlite.expressions._utils import multiop_to_sql 14 | 15 | 16 | class AddOp(AddOp_): 17 | to_sql = multiop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/and_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import AndOp as AndOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | from mo_sql import SQL_AND, SQL_FALSE, SQL_TRUE, sql_iso 16 | 17 | 18 | class AndOp(AndOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | if not self.terms: 22 | return wrap([{"name": ".", "sql": {"b": SQL_TRUE}}]) 23 | elif all(self.terms): 24 | return wrap( 25 | [ 26 | { 27 | "name": ".", 28 | "sql": { 29 | "b": SQL_AND.join( 30 | [ 31 | sql_iso( 32 | SQLang[t].to_sql(schema, boolean=True)[0].sql.b 33 | ) 34 | for t in self.terms 35 | ] 36 | ) 37 | }, 38 | } 39 | ] 40 | ) 41 | else: 42 | return wrap([{"name": ".", "sql": {"b": SQL_FALSE}}]) 43 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/basic_add_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicAddOp as BasicAddOp_ 13 | from jx_sqlite.expressions._utils import basic_multiop_to_sql 14 | 15 | 16 | class BasicAddOp(BasicAddOp_): 17 | to_sql = basic_multiop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/basic_eq_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicEqOp as BasicEqOp_ 13 | from jx_sqlite.expressions._utils import check, SQLang 14 | from mo_sql import sql_iso, SQL_EQ 15 | 16 | 17 | class BasicEqOp(BasicEqOp_): 18 | @check 19 | def to_sql(self, schema, not_null=False, boolean=False, many=False): 20 | return sql_iso(SQLang[self.rhs].to_sql(schema)) + SQL_EQ + sql_iso(+ SQLang[self.lhs].to_sql(schema)) 21 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/basic_mul_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicMulOp as BasicMulOp_ 13 | from jx_sqlite.expressions._utils import basic_multiop_to_sql 14 | 15 | 16 | class BasicMulOp(BasicMulOp_): 17 | to_sql = basic_multiop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/basic_starts_with_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicStartsWithOp as BasicStartsWithOp_, is_literal 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from jx_sqlite.expressions.sql_eq_op import SqlEqOp 15 | from jx_sqlite.expressions.sql_instr_op import SqlInstrOp 16 | from jx_sqlite.sqlite import quote_value 17 | from mo_dots import wrap 18 | from mo_sql import SQL, ConcatSQL, SQL_LIKE, SQL_ESCAPE, SQL_ONE 19 | 20 | 21 | class BasicStartsWithOp(BasicStartsWithOp_): 22 | @check 23 | def to_sql(self, schema, not_null=False, boolean=False): 24 | prefix = SQLang[self.prefix].partial_eval() 25 | if is_literal(prefix): 26 | value = SQLang[self.value].partial_eval().to_sql(schema)[0].sql.s 27 | prefix = prefix.value 28 | if "%" in prefix or "_" in prefix: 29 | for r in "\\_%": 30 | prefix = prefix.replaceAll(r, "\\" + r) 31 | sql = ConcatSQL(value, SQL_LIKE, quote_value(prefix+"%"), SQL_ESCAPE, SQL("\\")) 32 | else: 33 | sql = ConcatSQL(value, SQL_LIKE, quote_value(prefix+"%")) 34 | return wrap([{"name": ".", "sql": {"b": sql}}]) 35 | else: 36 | return ( 37 | SqlEqOp([SqlInstrOp([self.value, prefix]), SQL_ONE]) 38 | .partial_eval() 39 | .to_sql() 40 | ) 41 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/basic_substring_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicSubstringOp as BasicSubstringOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from jx_sqlite.expressions.add_op import AddOp 15 | from jx_sqlite.expressions.literal import Literal 16 | from jx_sqlite.expressions.sub_op import SubOp 17 | from jx_sqlite.sqlite import sql_call 18 | from mo_dots import wrap 19 | 20 | 21 | class BasicSubstringOp(BasicSubstringOp_): 22 | @check 23 | def to_sql(self, schema, not_null=False, boolean=False): 24 | value = SQLang[self.value].to_sql(schema, not_null=True)[0].sql.s 25 | start = ( 26 | AddOp([self.start, Literal(1)]) 27 | .partial_eval() 28 | .to_sql(schema, not_null=True)[0] 29 | .sql.n 30 | ) 31 | length = ( 32 | SubOp([self.end, self.start]) 33 | .partial_eval() 34 | .to_sql(schema, not_null=True)[0] 35 | .sql.n 36 | ) 37 | sql = sql_call("SUBSTR", value, start, length) 38 | return wrap([{"name": ".", "sql": {"s": sql}}]) 39 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/between_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BetweenOp as BetweenOp_ 13 | from jx_sqlite.expressions._utils import check 14 | 15 | 16 | class BetweenOp(BetweenOp_): 17 | @check 18 | def to_sql(self, schema, not_null=False, boolean=False): 19 | return self.partial_eval().to_sql(schema) 20 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/boolean_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BooleanOp as BooleanOp_, FALSE, TRUE, is_literal 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | 15 | 16 | class BooleanOp(BooleanOp_): 17 | @check 18 | def to_sql(self, schema, not_null=False, boolean=False): 19 | term = SQLang[self.term].partial_eval() 20 | if term.type == "boolean": 21 | sql = term.to_sql(schema) 22 | return sql 23 | elif is_literal(term) and term.value in ("T", "F"): 24 | if term.value == "T": 25 | return TRUE.to_sql(schema) 26 | else: 27 | return FALSE.to_sql(schema) 28 | else: 29 | sql = term.exists().partial_eval().to_sql(schema) 30 | return sql 31 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/case_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import CaseOp as CaseOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import coalesce, wrap 15 | from mo_sql import ( 16 | SQL_CASE, 17 | SQL_ELSE, 18 | SQL_END, 19 | SQL_NULL, 20 | SQL_THEN, 21 | SQL_WHEN, 22 | ConcatSQL, 23 | ) 24 | 25 | 26 | class CaseOp(CaseOp_): 27 | @check 28 | def to_sql(self, schema, not_null=False, boolean=False): 29 | if len(self.whens) == 1: 30 | return SQLang[self.whens[-1]].to_sql(schema) 31 | 32 | output = {} 33 | for t in "bsn": # EXPENSIVE LOOP to_sql() RUN 3 TIMES 34 | els_ = coalesce(SQLang[self.whens[-1]].to_sql(schema)[0].sql[t], SQL_NULL) 35 | acc = SQL_ELSE + els_ + SQL_END 36 | for w in reversed(self.whens[0:-1]): 37 | acc = ConcatSQL( 38 | SQL_WHEN, 39 | SQLang[w.when].to_sql(schema, boolean=True)[0].sql.b, 40 | SQL_THEN, 41 | coalesce(SQLang[w.then].to_sql(schema)[0].sql[t], SQL_NULL), 42 | acc, 43 | ) 44 | output[t] = SQL_CASE + acc 45 | return wrap([{"name": ".", "sql": output}]) 46 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/coalesce_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import CoalesceOp as CoalesceOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | from mo_sql import sql_coalesce 16 | 17 | 18 | class CoalesceOp(CoalesceOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | acc = {"b": [], "s": [], "n": [], "0": []} 22 | 23 | for term in self.terms: 24 | for t, v in SQLang[term].to_sql(schema)[0].sql.items(): 25 | acc[t].append(v) 26 | 27 | output = {} 28 | for t, terms in acc.items(): 29 | if not terms: 30 | continue 31 | elif len(terms) == 1: 32 | output[t] = terms[0] 33 | else: 34 | output[t] = sql_coalesce(terms) 35 | return wrap([{"name": ".", "sql": output}]) 36 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/date_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import DateOp as DateOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.sqlite import quote_value 15 | from mo_dots import wrap 16 | 17 | 18 | class DateOp(DateOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | return wrap([{"name": ".", "sql": {"n": quote_value(self.value)}}]) 22 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/div_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import DivOp as DivOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import Null, wrap 15 | from mo_sql import sql_coalesce, sql_iso 16 | 17 | 18 | class DivOp(DivOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | lhs = SQLang[self.lhs].to_sql(schema)[0].sql.n 22 | rhs = SQLang[self.rhs].to_sql(schema)[0].sql.n 23 | d = SQLang[self.default].to_sql(schema)[0].sql.n 24 | 25 | if lhs and rhs: 26 | if d == None: 27 | return wrap( 28 | [{"name": ".", "sql": {"n": sql_iso(lhs) + " / " + sql_iso(rhs)}}] 29 | ) 30 | else: 31 | return wrap( 32 | [ 33 | { 34 | "name": ".", 35 | "sql": { 36 | "n": sql_coalesce( 37 | [sql_iso(lhs) + " / " + sql_iso(rhs), d] 38 | ) 39 | }, 40 | } 41 | ] 42 | ) 43 | else: 44 | return Null 45 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/exists_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ExistsOp as ExistsOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from mo_dots import wrap 15 | from mo_sql import SQL_FALSE, SQL_IS_NOT_NULL, SQL_OR, sql_iso 16 | 17 | 18 | class ExistsOp(ExistsOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | field = self.field.to_sql(schema)[0].sql 22 | acc = [] 23 | for t, v in field.items(): 24 | if t in "bns": 25 | acc.append(sql_iso(v + SQL_IS_NOT_NULL)) 26 | 27 | if not acc: 28 | return wrap([{"name": ".", "sql": {"b": SQL_FALSE}}]) 29 | else: 30 | return wrap([{"name": ".", "sql": {"b": SQL_OR.join(acc)}}]) 31 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/exp_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ExpOp as ExpOp_ 13 | from jx_sqlite.expressions._utils import _binaryop_to_sql 14 | 15 | 16 | class ExpOp(ExpOp_): 17 | to_sql = _binaryop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/first_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FirstOp as FirstOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_logs import Log 15 | 16 | 17 | class FirstOp(FirstOp_): 18 | @check 19 | def to_sql(self, schema, not_null=False, boolean=False): 20 | value = SQLang[self.term].to_sql(schema, not_null=True) 21 | for c in value: 22 | for t, v in c.sql.items(): 23 | if t == "j": 24 | Log.error("can not handle") 25 | return value 26 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/floor_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FloorOp as FloorOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | from mo_future import text 16 | from mo_sql import sql_iso 17 | 18 | 19 | class FloorOp(FloorOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | lhs = SQLang[self.lhs].to_sql(schema)[0].sql.n 23 | rhs = SQLang[self.rhs].to_sql(schema)[0].sql.n 24 | modifier = lhs + " < 0 " 25 | 26 | if text(rhs).strip() != "1": 27 | floor = "CAST" + sql_iso(lhs + "/" + rhs + " AS INTEGER") 28 | sql = sql_iso(sql_iso(floor) + "-" + sql_iso(modifier)) + "*" + rhs 29 | else: 30 | floor = "CAST" + sql_iso(lhs + " AS INTEGER") 31 | sql = sql_iso(floor) + "-" + sql_iso(modifier) 32 | 33 | return wrap([{"name": ".", "sql": {"n": sql}}]) 34 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/from_unix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FromUnixOp as FromUnixOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from mo_dots import wrap 15 | from mo_sql import sql_iso 16 | 17 | 18 | class FromUnixOp(FromUnixOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | v = self.value.to_sql(schema)[0].sql 22 | return wrap([{"name": ".", "sql": {"n": "FROM_UNIXTIME" + sql_iso(v.n)}}]) 23 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/get_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GetOp as GetOp_ 13 | 14 | 15 | class GetOp(GetOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/gt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GtOp as GtOp_ 13 | from jx_sqlite.expressions._utils import _inequality_to_sql 14 | 15 | 16 | class GtOp(GtOp_): 17 | to_sql = _inequality_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/gte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GteOp as GteOp_ 13 | from jx_sqlite.expressions._utils import _inequality_to_sql 14 | 15 | 16 | class GteOp(GteOp_): 17 | to_sql = _inequality_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/in_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_sqlite.sqlite import quote_list 13 | 14 | from jx_base.expressions import InOp as InOp_ 15 | from jx_base.language import is_op 16 | from jx_sqlite.expressions._utils import SQLang, check 17 | from jx_sqlite.expressions.literal import Literal 18 | from mo_dots import wrap 19 | from mo_json import json2value 20 | from mo_logs import Log 21 | from mo_sql import SQL_FALSE, SQL_OR, sql_iso, ConcatSQL, SQL_IN 22 | 23 | 24 | class InOp(InOp_): 25 | @check 26 | def to_sql(self, schema, not_null=False, boolean=False): 27 | if not is_op(self.superset, Literal): 28 | Log.error("Not supported") 29 | j_value = json2value(self.superset.json) 30 | if j_value: 31 | var = SQLang[self.value].to_sql(schema) 32 | sql = SQL_OR.join( 33 | sql_iso(v, SQL_IN, quote_list(j_value)) 34 | for t, v in var[0].sql.items() 35 | ) 36 | else: 37 | sql = SQL_FALSE 38 | return wrap([{"name": ".", "sql": {"b": sql}}]) 39 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/integer_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import IntegerOp as IntegerOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from mo_dots import wrap 15 | from mo_sql import sql_coalesce 16 | 17 | 18 | class IntegerOp(IntegerOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | value = self.term.to_sql(schema, not_null=True) 22 | acc = [] 23 | for c in value: 24 | for t, v in c.sql.items(): 25 | if t == "s": 26 | acc.append("CAST(" + v + " as INTEGER)") 27 | else: 28 | acc.append(v) 29 | 30 | if not acc: 31 | return wrap([]) 32 | elif len(acc) == 1: 33 | return wrap([{"name": ".", "sql": {"n": acc[0]}}]) 34 | else: 35 | return wrap([{"name": ".", "sql": {"n": sql_coalesce(acc)}}]) 36 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/last_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LastOp as LastOp_ 13 | 14 | 15 | class LastOp(LastOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/left_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LeftOp as LeftOp_, ONE 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.expressions.sql_substr_op import SqlSubstrOp 15 | 16 | 17 | class LeftOp(LeftOp_): 18 | @check 19 | def to_sql(self, schema, not_null=False, boolean=False): 20 | return SqlSubstrOp([self.value, ONE, self.length]).partial_eval().to_sql(schema) 21 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/length_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LengthOp as LengthOp_, is_literal 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from jx_sqlite.sqlite import quote_value 15 | from mo_dots import Null, wrap 16 | from mo_future import text 17 | from mo_json import value2json 18 | from mo_sql import SQL, sql_iso, ConcatSQL 19 | 20 | 21 | class LengthOp(LengthOp_): 22 | @check 23 | def to_sql(self, schema, not_null=False, boolean=False): 24 | term = SQLang[self.term].partial_eval() 25 | if is_literal(term): 26 | val = term.value 27 | if isinstance(val, text): 28 | sql = quote_value(len(val)) 29 | elif isinstance(val, (float, int)): 30 | sql = quote_value(len(value2json(val))) 31 | else: 32 | return Null 33 | else: 34 | value = term.to_sql(schema, not_null=not_null)[0].sql.s 35 | sql = ConcatSQL(SQL("LENGTH"), sql_iso(value)) 36 | return wrap([{"name": ".", "sql": {"n": sql}}]) 37 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/literal.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_sqlite.sqlite import quote_value 13 | 14 | from jx_base.expressions import Literal as Literal_ 15 | from jx_sqlite.expressions._utils import check 16 | from mo_dots import wrap 17 | from mo_future import text 18 | from mo_math import is_number 19 | 20 | 21 | class Literal(Literal_): 22 | @check 23 | def to_sql(self, schema, not_null=False, boolean=False): 24 | value = self.value 25 | if value == None: 26 | return wrap([{"name": "."}]) 27 | elif isinstance(value, text): 28 | return wrap([{"name": ".", "sql": {"s": quote_value(value)}}]) 29 | elif is_number(value): 30 | return wrap([{"name": ".", "sql": {"n": quote_value(value)}}]) 31 | elif value in [True, False]: 32 | return wrap([{"name": ".", "sql": {"b": quote_value(value)}}]) 33 | else: 34 | return wrap([{"name": ".", "sql": {"j": quote_value(self.json)}}]) 35 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/lt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LtOp as LtOp_ 13 | from jx_sqlite.expressions._utils import _inequality_to_sql 14 | 15 | 16 | class LtOp(LtOp_): 17 | to_sql = _inequality_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/lte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LteOp as LteOp_ 13 | from jx_sqlite.expressions._utils import _inequality_to_sql 14 | 15 | 16 | class LteOp(LteOp_): 17 | to_sql = _inequality_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/max_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MaxOp as MaxOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | from mo_sql import sql_iso, sql_list 16 | 17 | 18 | class MaxOp(MaxOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | terms = [SQLang[t].partial_eval().to_sql(schema)[0].sql.n for t in self.terms] 22 | return wrap([{"name": ".", "sql": {"n": "max" + sql_iso((sql_list(terms)))}}]) 23 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/min_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MinOp as MinOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | from mo_sql import sql_iso, sql_list 16 | 17 | 18 | class MinOp(MinOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | terms = [SQLang[t].partial_eval().to_sql(schema)[0].sql.n for t in self.terms] 22 | return wrap([{"name": ".", "sql": {"n": "min" + sql_iso((sql_list(terms)))}}]) 23 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/missing_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MissingOp as MissingOp_ 13 | from jx_base.language import is_op 14 | from jx_sqlite.expressions._utils import SQLang, check 15 | from mo_dots import wrap 16 | from mo_sql import ( 17 | SQL_AND, 18 | SQL_EMPTY_STRING, 19 | SQL_FALSE, 20 | SQL_IS_NULL, 21 | SQL_OR, 22 | SQL_TRUE, 23 | sql_iso, 24 | SQL_EQ, ConcatSQL) 25 | 26 | 27 | class MissingOp(MissingOp_): 28 | @check 29 | def to_sql(self, schema, not_null=False, boolean=False): 30 | value = SQLang[self.expr].partial_eval() 31 | missing_value = value.missing().partial_eval() 32 | 33 | if not is_op(missing_value, MissingOp): 34 | return missing_value.to_sql(schema) 35 | 36 | value_sql = value.to_sql(schema) 37 | 38 | if len(value_sql) > 1: 39 | return wrap([{"name": ".", "sql": {"b": SQL_FALSE}}]) 40 | 41 | acc = [] 42 | for c in value_sql: 43 | for t, v in c.sql.items(): 44 | if t in "bn": 45 | acc.append(ConcatSQL(sql_iso(v), SQL_IS_NULL)) 46 | if t == "s": 47 | acc.append(ConcatSQL( 48 | sql_iso(sql_iso(v), SQL_IS_NULL), 49 | SQL_OR, 50 | sql_iso(sql_iso(v), SQL_EQ, SQL_EMPTY_STRING) 51 | )) 52 | 53 | if not acc: 54 | return wrap([{"name": ".", "sql": {"b": SQL_TRUE}}]) 55 | else: 56 | return wrap([{"name": ".", "sql": {"b": SQL_AND.join(acc)}}]) 57 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/mul_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MulOp as MulOp_ 13 | from jx_sqlite.expressions._utils import multiop_to_sql 14 | 15 | 16 | class MulOp(MulOp_): 17 | to_sql = multiop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/ne_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NeOp as NeOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.expressions.eq_op import EqOp 15 | from jx_sqlite.expressions.not_op import NotOp 16 | 17 | 18 | class NeOp(NeOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | return ( 22 | NotOp("not", EqOp([self.lhs, self.rhs]).partial_eval()) 23 | .partial_eval() 24 | .to_sql(schema) 25 | ) 26 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/not_left_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotLeftOp as NotLeftOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from mo_dots import wrap 15 | 16 | 17 | class NotLeftOp(NotLeftOp_): 18 | @check 19 | def to_sql(self, schema, not_null=False, boolean=False): 20 | # test_v = self.value.missing().to_sql(boolean=True)[0].sql.b 21 | # test_l = self.length.missing().to_sql(boolean=True)[0].sql.b 22 | v = self.value.to_sql(schema, not_null=True)[0].sql.s 23 | l = "max(0, " + self.length.to_sql(schema, not_null=True)[0].sql.n + ")" 24 | 25 | expr = "substr(" + v + ", " + l + "+1)" 26 | return wrap([{"name": ".", "sql": {"s": expr}}]) 27 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/not_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotOp as NotOp_ 13 | from jx_base.language import is_op 14 | from jx_sqlite.expressions._utils import check 15 | from jx_sqlite.expressions.boolean_op import BooleanOp 16 | from mo_dots import wrap 17 | from mo_sql import sql_iso 18 | 19 | 20 | class NotOp(NotOp_): 21 | @check 22 | def to_sql(self, schema, not_null=False, boolean=False): 23 | not_expr = NotOp(BooleanOp(self.term)).partial_eval() 24 | if is_op(not_expr, NotOp): 25 | return wrap( 26 | [ 27 | { 28 | "name": ".", 29 | "sql": { 30 | "b": "NOT " + sql_iso(not_expr.term.to_sql(schema)[0].sql.b) 31 | }, 32 | } 33 | ] 34 | ) 35 | else: 36 | return not_expr.to_sql(schema) 37 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/not_right_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotRightOp as NotRightOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.sqlite import sql_call 15 | from mo_dots import wrap 16 | from mo_sql import SQL_ONE, SQL_ZERO, SQL 17 | 18 | 19 | class NotRightOp(NotRightOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | v = self.value.to_sql(schema, not_null=True)[0].sql.s 23 | r = self.length.to_sql(schema, not_null=True)[0].sql.n 24 | l = sql_call("MAX", SQL_ZERO, sql_call("length", v) + SQL(" - ") + sql_call("MAX", SQL_ZERO, r)) 25 | sql = sql_call("SUBSTR", v, SQL_ONE, l) 26 | return wrap([{"name": ".", "sql": {"s": sql}}]) 27 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/number_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NumberOp as NumberOp_ 13 | from jx_sqlite.expressions import _utils 14 | from jx_sqlite.expressions._utils import SQLang, check 15 | from mo_dots import wrap 16 | from mo_sql import sql_coalesce 17 | 18 | 19 | class NumberOp(NumberOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | value = SQLang[self.term].to_sql(schema, not_null=True) 23 | acc = [] 24 | for c in value: 25 | for t, v in c.sql.items(): 26 | if t == "s": 27 | acc.append("CAST(" + v + " as FLOAT)") 28 | else: 29 | acc.append(v) 30 | 31 | if not acc: 32 | return wrap([]) 33 | elif len(acc) == 1: 34 | return wrap([{"name": ".", "sql": {"n": acc[0]}}]) 35 | else: 36 | return wrap([{"name": ".", "sql": {"n": sql_coalesce(acc)}}]) 37 | 38 | 39 | _utils.NumberOp = NumberOp -------------------------------------------------------------------------------- /jx_sqlite/expressions/offset_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import OffsetOp as OffsetOp_ 13 | 14 | 15 | class OffsetOp(OffsetOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/or_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import OrOp as OrOp_ 13 | from jx_sqlite.expressions import _utils 14 | from jx_sqlite.expressions._utils import SQLang, check 15 | from mo_dots import wrap 16 | from mo_sql import SQL_OR, sql_iso, JoinSQL 17 | 18 | 19 | class OrOp(OrOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | return wrap( 23 | [ 24 | { 25 | "name": ".", 26 | "sql": { 27 | "b": JoinSQL( 28 | SQL_OR, 29 | [ 30 | sql_iso(SQLang[t].to_sql(schema, boolean=True)[0].sql.b) 31 | for t in self.terms 32 | ], 33 | ) 34 | }, 35 | } 36 | ] 37 | ) 38 | 39 | 40 | _utils.OrOp = OrOp 41 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/prefix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import PrefixOp as PrefixOp_ 13 | from jx_sqlite.expressions._utils import check, SQLang 14 | from jx_sqlite.sqlite import sql_call 15 | from mo_dots import wrap 16 | from mo_sql import SQL_TRUE, ConcatSQL, SQL_EQ, SQL_ONE 17 | 18 | 19 | class PrefixOp(PrefixOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | if not self.expr: 23 | return wrap([{"name": ".", "sql": {"b": SQL_TRUE}}]) 24 | else: 25 | sql = ConcatSQL( 26 | sql_call( 27 | "INSTR", 28 | SQLang[self.expr].to_sql(schema)[0].sql.s, 29 | SQLang[self.prefix].to_sql(schema)[0].sql.s, 30 | ), 31 | SQL_EQ, 32 | SQL_ONE, 33 | ) 34 | return wrap([{"name": ".", "sql": {"b": sql}}]) 35 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/reg_exp_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import RegExpOp as RegExpOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.sqlite import quote_value 15 | from mo_dots import wrap 16 | from mo_json import json2value 17 | 18 | 19 | class RegExpOp(RegExpOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | pattern = quote_value(json2value(self.pattern.json)) 23 | value = self.var.to_sql(schema)[0].sql.s 24 | return wrap([{"name": ".", "sql": {"b": value + " REGEXP " + pattern}}]) 25 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/right_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import RightOp as RightOp_, ZERO, simplified 13 | from jx_sqlite.expressions.basic_substring_op import BasicSubstringOp 14 | from jx_sqlite.expressions.length_op import LengthOp 15 | from jx_sqlite.expressions.max_op import MaxOp 16 | from jx_sqlite.expressions.min_op import MinOp 17 | from jx_sqlite.expressions.sub_op import SubOp 18 | 19 | 20 | class RightOp(RightOp_): 21 | @simplified 22 | def partial_eval(self): 23 | value = self.value.partial_eval() 24 | length = self.length.partial_eval() 25 | max_length = LengthOp(value) 26 | 27 | return BasicSubstringOp( 28 | [ 29 | value, 30 | MaxOp([ZERO, MinOp([max_length, SubOp([max_length, length])])]), 31 | max_length, 32 | ] 33 | ) 34 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/rows_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import RowsOp as RowsOp_ 13 | 14 | 15 | class RowsOp(RowsOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/script_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ScriptOp as ScriptOp_ 13 | 14 | 15 | class ScriptOp(ScriptOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/select_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import SelectOp as SelectOp_ 13 | 14 | 15 | class SelectOp(SelectOp_): 16 | pass 17 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/sql_instr_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import SqlInstrOp as SqlInstrOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.sqlite import sql_call 15 | from mo_dots import wrap 16 | 17 | 18 | class SqlInstrOp(SqlInstrOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | value = self.value.to_sql(schema, not_null=True)[0].sql.s 22 | find = self.find.to_sql(schema, not_null=True)[0].sql.s 23 | 24 | return wrap( 25 | [{"name": ".", "sql": {"n": sql_call("INSTR", value, find)}}] 26 | ) 27 | 28 | def partial_eval(self): 29 | value = self.value.partial_eval() 30 | find = self.find.partial_eval() 31 | return SqlInstrOp([value, find]) 32 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/sql_substr_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NULL, SqlSubstrOp as SqlSubstrOp_ 13 | from jx_sqlite.expressions._utils import check, SQLang 14 | from jx_sqlite.expressions.literal import Literal 15 | from jx_sqlite.sqlite import sql_call 16 | from mo_dots import wrap 17 | 18 | 19 | class SqlSubstrOp(SqlSubstrOp_): 20 | @check 21 | def to_sql(self, schema, not_null=False, boolean=False): 22 | value = SQLang[self.value].to_sql(schema, not_null=True)[0].sql.s 23 | start = SQLang[self.start].to_sql(schema, not_null=True)[0].sql.n 24 | if self.length is NULL: 25 | sql = sql_call("SUBSTR", value, start) 26 | else: 27 | length = SQLang[self.length].to_sql(schema, not_null=True)[0].sql.n 28 | sql = sql_call("SUBSTR", value, start, length) 29 | return wrap([{"name": ".", "sql": {"s": sql}}]) 30 | 31 | def partial_eval(self): 32 | value = SQLang[self.value].partial_eval() 33 | start = SQLang[self.start].partial_eval() 34 | length = SQLang[self.length].partial_eval() 35 | if isinstance(start, Literal) and start.value == 1: 36 | if length is NULL: 37 | return value 38 | return SqlSubstrOp([value, start, length]) 39 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/sub_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import SubOp as SubOp_ 13 | from jx_sqlite.expressions._utils import _binaryop_to_sql 14 | 15 | 16 | class SubOp(SubOp_): 17 | to_sql = _binaryop_to_sql 18 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/suffix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import SuffixOp as SuffixOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from jx_sqlite.expressions.eq_op import EqOp 15 | from jx_sqlite.expressions.length_op import LengthOp 16 | from jx_sqlite.expressions.literal import Literal 17 | from jx_sqlite.expressions.right_op import RightOp 18 | from mo_dots import wrap 19 | from mo_sql import SQL_FALSE, SQL_TRUE 20 | 21 | 22 | class SuffixOp(SuffixOp_): 23 | @check 24 | def to_sql(self, schema, not_null=False, boolean=False): 25 | if not self.expr: 26 | return wrap([{"name": ".", "sql": {"b": SQL_FALSE}}]) 27 | elif isinstance(self.suffix, Literal) and not self.suffix.value: 28 | return wrap([{"name": ".", "sql": {"b": SQL_TRUE}}]) 29 | else: 30 | return ( 31 | EqOp([RightOp([self.expr, LengthOp(self.suffix)]), self.suffix]) 32 | .partial_eval() 33 | .to_sql(schema) 34 | ) 35 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/tuple_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import TupleOp as TupleOp_ 13 | from jx_sqlite.expressions._utils import SQLang, check 14 | from mo_dots import wrap 15 | 16 | 17 | class TupleOp(TupleOp_): 18 | @check 19 | def to_sql(self, schema, not_null=False, boolean=False): 20 | return wrap( 21 | [{"name": ".", "sql": SQLang[t].to_sql(schema)[0].sql} for t in self.terms] 22 | ) 23 | -------------------------------------------------------------------------------- /jx_sqlite/expressions/unix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import UnixOp as UnixOp_ 13 | from jx_sqlite.expressions._utils import check 14 | from mo_dots import wrap 15 | from mo_sql import sql_iso 16 | 17 | 18 | class UnixOp(UnixOp_): 19 | @check 20 | def to_sql(self, schema, not_null=False, boolean=False): 21 | v = self.value.to_sql(schema)[0].sql 22 | return wrap([{"name": ".", "sql": {"n": "UNIX_TIMESTAMP" + sql_iso(v.n)}}]) 23 | -------------------------------------------------------------------------------- /jx_sqlite/namespace.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | 9 | from __future__ import absolute_import, division, unicode_literals 10 | 11 | from copy import copy 12 | 13 | import jx_base 14 | from jx_base import Facts 15 | from jx_sqlite.meta_columns import ColumnList 16 | from jx_sqlite.schema import Schema 17 | from jx_sqlite.snowflake import Snowflake 18 | 19 | 20 | class Namespace(jx_base.Namespace): 21 | """ 22 | MANAGE SQLITE DATABASE 23 | """ 24 | def __init__(self, db): 25 | self.db = db 26 | self.columns = ColumnList(db) 27 | 28 | def __copy__(self): 29 | output = object.__new__(Namespace) 30 | output.db = None 31 | output.columns = copy(self.columns) 32 | return output 33 | 34 | def get_facts(self, fact_name): 35 | snowflake = Snowflake(fact_name, self) 36 | return Facts(self, snowflake) 37 | 38 | def get_schema(self, fact_name): 39 | return Schema(".", Snowflake(fact_name, self)) 40 | 41 | def get_snowflake(self, fact_name): 42 | return Snowflake(fact_name, self) 43 | 44 | def add_column_to_schema(self, column): 45 | self.columns.add(column) 46 | 47 | -------------------------------------------------------------------------------- /jx_sqlite/table.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | 9 | from __future__ import absolute_import, division, unicode_literals 10 | 11 | import jx_base 12 | from jx_sqlite.schema import Schema 13 | from mo_logs import Log 14 | 15 | 16 | class Table(jx_base.Table): 17 | 18 | def __init__(self, nested_path, snowflake): 19 | if not isinstance(nested_path, list): 20 | Log.error("Expecting list of paths") 21 | self.nested_path = nested_path 22 | self.schema = Schema(nested_path, snowflake) 23 | # self.columns = [] # PLAIN DATABASE COLUMNS 24 | 25 | @property 26 | def name(self): 27 | """ 28 | :return: THE TABLE NAME RELATIVE TO THE FACT TABLE 29 | """ 30 | return self.nested_path[0] 31 | 32 | def map(self, mapping): 33 | return self 34 | 35 | -------------------------------------------------------------------------------- /jx_sqlite/utils.py: -------------------------------------------------------------------------------- 1 | from jx_base import Snowflake 2 | from mo_json.typed_encoder import untype_path 3 | class BasicSnowflake(Snowflake): 4 | def __init__(self, query_paths, columns): 5 | self._query_paths = query_paths 6 | self._columns = columns 7 | 8 | @property 9 | def query_paths(self): 10 | return self._query_paths 11 | 12 | @property 13 | def columns(self): 14 | return self._columns 15 | 16 | @property 17 | def column(self): 18 | return ColumnLocator(self._columns) 19 | 20 | 21 | class ColumnLocator(object): 22 | def __init__(self, columns): 23 | self.columns = columns 24 | 25 | def __getitem__(self, column_name): 26 | return [ 27 | c 28 | for c in self.columns 29 | if untype_path(c.name) == column_name 30 | ] 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | mo-future>=1.1 2 | mo-dots>=1.5.17188 3 | mo-logs 4 | mo-files>=1.2 5 | mo-threads 6 | mo-kwargs 7 | mo-math 8 | mo-times 9 | mo-collections>=1.2.17235 10 | mo-testing>=1.0.17168 11 | mo-json>=2.1.17319 12 | mo-json-config 13 | mo-sql -------------------------------------------------------------------------------- /resources/scripts/run_tests.bat: -------------------------------------------------------------------------------- 1 | set PYTHONPATH=. 2 | python -m unittest discover -v -s tests 3 | -------------------------------------------------------------------------------- /tests/config/sqlite.json: -------------------------------------------------------------------------------- 1 | { 2 | "use": "sqlite", 3 | "db":{ 4 | "name": "testing", 5 | // "filename":"test.sqlite", 6 | "upgrade": true, 7 | "load_functions": true 8 | }, 9 | "constants": { 10 | "jx_sqlitel.sqlite.DEBUG": true 11 | }, 12 | "debug": { 13 | "trace":true 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/test_jx/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Author: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | from __future__ import absolute_import, division, unicode_literals 12 | 13 | from mo_logs import Log 14 | from mo_testing.fuzzytestcase import FuzzyTestCase 15 | 16 | TEST_TABLE = "testdata" 17 | 18 | global_settings = None 19 | utils = None 20 | 21 | 22 | class BaseTestCase(FuzzyTestCase): 23 | 24 | def __init__(self, *args, **kwargs): 25 | FuzzyTestCase.__init__(self, *args, **kwargs) 26 | if not utils: 27 | try: 28 | import tests 29 | except Exception as e: 30 | Log.error("Expecting ./tests/__init__.py with instructions to setup testing", cause=e) 31 | if utils is None: 32 | Log.error("Expecting ./tests/__init__.py to set `global_settings` and `utils` so tests can be run") 33 | self.utils = utils 34 | 35 | @classmethod 36 | def setUpClass(cls): 37 | utils.setUpClass() 38 | 39 | @classmethod 40 | def tearDownClass(cls): 41 | utils.tearDownClass() 42 | 43 | def setUp(self): 44 | utils.setUp() 45 | 46 | def tearDown(self): 47 | utils.tearDown() 48 | -------------------------------------------------------------------------------- /tests/test_jx/test_query_normalization.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Author: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | from __future__ import absolute_import, division, unicode_literals 12 | 13 | from jx_base.query import _normalize_edges, _normalize_select 14 | from mo_dots import Null 15 | from mo_json import json2value, value2json 16 | from mo_testing.fuzzytestcase import FuzzyTestCase 17 | 18 | 19 | class TestQueryNormalization(FuzzyTestCase): 20 | def test_complex_edge_with_no_name(self): 21 | edge = {"value": ["a", "c"]} 22 | self.assertRaises(Exception, _normalize_edges, edge) 23 | 24 | def test_complex_edge_value(self): 25 | edge = {"name": "n", "value": ["a", "c"]} 26 | 27 | result = json2value(value2json(_normalize_edges(edge, Null)[0])) 28 | expected = { 29 | "name": "n", 30 | "value": {"tuple": ["a", "c"]}, 31 | "domain": {"dimension": {"fields": ["a", "c"]}} 32 | } 33 | self.assertEqual(result, expected) 34 | 35 | def test_naming_select(self): 36 | select = {"value": "result.duration", "aggregate": "avg"} 37 | result = _normalize_select(select, None) 38 | #DEEP NAMES ARE ALLOWED, AND NEEDED TO BUILD STRUCTURE FROM A QUERY 39 | expected = [{"name": "result.duration", "value": "result.duration", "aggregate": "average"}] 40 | self.assertEqual(result, expected) 41 | -------------------------------------------------------------------------------- /tests/test_jx/test_update.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Author: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NULL 13 | from tests.test_jx import BaseTestCase, TEST_TABLE 14 | 15 | 16 | class TestUpdate(BaseTestCase): 17 | 18 | def test_new_field(self): 19 | settings = self.utils.fill_container( 20 | { 21 | "query": {"from": TEST_TABLE}, 22 | "data": [ 23 | {"a": 1, "b": 5}, 24 | {"a": 3, "b": 4}, 25 | {"a": 4, "b": 3}, 26 | {"a": 6, "b": 2}, 27 | {"a": 2} 28 | ] 29 | }, 30 | typed=False 31 | ) 32 | import jx_elasticsearch 33 | container = jx_elasticsearch.new_instance(read_only=False, kwargs=self.utils._es_test_settings) 34 | container.update({ 35 | "update": settings.alias, 36 | "set": {"c": {"add": ["a", "b"]}} 37 | }) 38 | 39 | self.utils.send_queries({ 40 | "query": { 41 | "from": settings.alias, 42 | "select": ["c", "a"] 43 | }, 44 | "expecting_table": { 45 | "header": ["a", "c"], 46 | "data": [[1, 6], [3, 7], [4, 7], [6, 8], [2, NULL]] 47 | } 48 | }) 49 | -------------------------------------------------------------------------------- /vendor/jx_base/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Some help for the programmer 3 | 4 | Some nomenclature is required to help follow the logic of these modules 5 | 6 | ### Table 7 | 8 | Same as with database terminology; it is a single, unordered, set of rows; 9 | 10 | ### Schema 11 | 12 | A set of columns that describe all the (possibly optional) properties available on all rows of a table. 13 | 14 | ### Facts 15 | 16 | Represents the multiple tables in the hierarchical database 17 | 18 | ### Snowflake 19 | 20 | JSON Query Expressions are used the query hierarchical databases. The relations in a hierarchical database are limited to a tree; the path between any two tables is unique; in a query, no matter which table is "origin", any column in the hierarchical database can be accessed using a unique combination of joins with the origin. 21 | 22 | With this in mind, a Snowflake is a list of all columns, for all the tables, in the hierarchical database. 23 | 24 | ### Container 25 | 26 | Datastore that has multiple facts 27 | 28 | ### Namespace 29 | 30 | Metadata for a container: Information on multiple snowflakes. 31 | 32 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/abs_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.language import is_op 25 | from mo_json import NUMBER 26 | 27 | 28 | class AbsOp(Expression): 29 | data_type = NUMBER 30 | 31 | def __init__(self, term): 32 | Expression.__init__(self, term) 33 | self.term = term 34 | 35 | def __data__(self): 36 | return {"abs": self.term.__data__()} 37 | 38 | def __eq__(self, other): 39 | if not is_op(other, AbsOp): 40 | return False 41 | return self.term == other.term 42 | 43 | def vars(self): 44 | return self.term.vars() 45 | 46 | def map(self, map_): 47 | return self.lang[AbsOp(self.term.map(map_))] 48 | 49 | def missing(self): 50 | return self.term.missing() 51 | 52 | @simplified 53 | def partial_eval(self): 54 | return AbsOp(self.term.partial_eval()) 55 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/add_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_multi_op import BaseMultiOp 23 | 24 | 25 | class AddOp(BaseMultiOp): 26 | op = "add" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/basic_add_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.basic_multi_op import BasicMultiOp 23 | 24 | 25 | class BasicAddOp(BasicMultiOp): 26 | op = "basic.add" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/basic_eq_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from jx_base.language import is_op 25 | from mo_json import BOOLEAN 26 | 27 | 28 | class BasicEqOp(Expression): 29 | """ 30 | PLACEHOLDER FOR BASIC `==` OPERATOR (CAN NOT DEAL WITH NULLS) 31 | """ 32 | 33 | data_type = BOOLEAN 34 | 35 | def __init__(self, terms): 36 | Expression.__init__(self, terms) 37 | self.lhs, self.rhs = terms 38 | 39 | def __data__(self): 40 | return {"basic.eq": [self.lhs.__data__(), self.rhs.__data__()]} 41 | 42 | def missing(self): 43 | return FALSE 44 | 45 | def __eq__(self, other): 46 | if not is_op(other, BasicEqOp): 47 | return False 48 | return self.lhs == other.lhs and self.rhs == other.rhs 49 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/basic_mul_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.basic_multi_op import BasicMultiOp 23 | 24 | 25 | class BasicMulOp(BasicMultiOp): 26 | op = "basic.mul" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/basic_substring_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import STRING 25 | 26 | 27 | class BasicSubstringOp(Expression): 28 | """ 29 | PLACEHOLDER FOR BASIC value.substring(start, end) (CAN NOT DEAL WITH NULLS) 30 | """ 31 | 32 | data_type = STRING 33 | 34 | def __init__(self, terms): 35 | Expression.__init__(self, terms) 36 | self.value, self.start, self.end = terms 37 | 38 | def __data__(self): 39 | return { 40 | "basic.substring": [ 41 | self.value.__data__(), 42 | self.start.__data__(), 43 | self.end.__data__(), 44 | ] 45 | } 46 | 47 | def missing(self): 48 | return FALSE 49 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/count_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.false_op import FALSE 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.expressions.true_op import TrueOp 25 | from jx_base.expressions.tuple_op import TupleOp 26 | from mo_dots import is_many 27 | from mo_json import INTEGER 28 | 29 | 30 | class CountOp(Expression): 31 | has_simple_form = False 32 | data_type = INTEGER 33 | 34 | def __init__(self, terms, **clauses): 35 | Expression.__init__(self, terms) 36 | if is_many(terms): 37 | # SHORTCUT: ASSUME AN ARRAY OF IS A TUPLE 38 | self.terms = self.lang[TupleOp(terms)] 39 | else: 40 | self.terms = terms 41 | 42 | def __data__(self): 43 | return {"count": self.terms.__data__()} 44 | 45 | def vars(self): 46 | return self.terms.vars() 47 | 48 | def map(self, map_): 49 | return self.lang[CountOp(self.terms.map(map_))] 50 | 51 | def missing(self): 52 | return FALSE 53 | 54 | def exists(self): 55 | return TrueOp 56 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/date_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions import literal 23 | from jx_base.expressions.literal import Literal 24 | from mo_dots import coalesce 25 | from mo_future import is_text 26 | from mo_json import NUMBER 27 | from mo_times.dates import unicode2Date, Date 28 | 29 | 30 | class DateOp(Literal): 31 | date_type = NUMBER 32 | 33 | def __init__(self, term): 34 | if hasattr(self, "date"): 35 | return 36 | if is_text(term): 37 | self.date = term 38 | else: 39 | self.date = coalesce(term.get("literal"), term) 40 | v = unicode2Date(self.date) 41 | if isinstance(v, Date): 42 | Literal.__init__(self, v.unix) 43 | else: 44 | Literal.__init__(self, v.seconds) 45 | 46 | @classmethod 47 | def define(cls, expr): 48 | return cls.lang[DateOp(expr.get("date"))] 49 | 50 | def __data__(self): 51 | return {"date": self.date} 52 | 53 | def __call__(self, row=None, rownum=None, rows=None): 54 | return Date(self.date) 55 | 56 | 57 | literal.DateOp=DateOp -------------------------------------------------------------------------------- /vendor/jx_base/expressions/div_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified, builtin_ops 23 | from jx_base.expressions.and_op import AndOp 24 | from jx_base.expressions.base_binary_op import BaseBinaryOp 25 | from jx_base.expressions.eq_op import EqOp 26 | from jx_base.expressions.literal import Literal, ZERO, is_literal 27 | from jx_base.expressions.or_op import OrOp 28 | 29 | 30 | class DivOp(BaseBinaryOp): 31 | op = "div" 32 | 33 | def missing(self): 34 | return self.lang[ 35 | AndOp( 36 | [ 37 | self.default.missing(), 38 | OrOp( 39 | [self.lhs.missing(), self.rhs.missing(), EqOp([self.rhs, ZERO])] 40 | ), 41 | ] 42 | ) 43 | ].partial_eval() 44 | 45 | @simplified 46 | def partial_eval(self): 47 | default = self.default.partial_eval() 48 | rhs = self.rhs.partial_eval() 49 | if rhs is ZERO: 50 | return default 51 | lhs = self.lhs.partial_eval() 52 | if is_literal(lhs) and is_literal(rhs): 53 | return Literal(builtin_ops[self.op](lhs.value, rhs.value)) 54 | return self.__class__([lhs, rhs], default=default) 55 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/es_nested_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.language import is_op 25 | from mo_json import BOOLEAN 26 | 27 | 28 | class EsNestedOp(Expression): 29 | data_type = BOOLEAN 30 | has_simple_form = False 31 | 32 | def __init__(self, terms): 33 | Expression.__init__(self, terms) 34 | self.path, self.query = terms 35 | 36 | @simplified 37 | def partial_eval(self): 38 | if self.path.var == ".": 39 | return self.query.partial_eval() 40 | return self.lang[ 41 | EsNestedOp("es.nested", [self.path, self.query.partial_eval()]) 42 | ] 43 | 44 | def __data__(self): 45 | return {"es.nested": {self.path.var: self.query.__data__()}} 46 | 47 | def __eq__(self, other): 48 | if is_op(other, EsNestedOp): 49 | return self.path.var == other.path.var and self.query == other.query 50 | return False 51 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/es_script.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | 24 | 25 | class EsScript(Expression): 26 | """ 27 | REPRESENT A Painless SCRIPT 28 | """ 29 | 30 | pass 31 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/exists_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.expressions.false_op import FALSE 25 | from mo_json import BOOLEAN 26 | 27 | NotOp = None 28 | 29 | 30 | class ExistsOp(Expression): 31 | data_type = BOOLEAN 32 | 33 | def __init__(self, term): 34 | Expression.__init__(self, [term]) 35 | self.field = term 36 | 37 | def __data__(self): 38 | return {"exists": self.field.__data__()} 39 | 40 | def vars(self): 41 | return self.field.vars() 42 | 43 | def map(self, map_): 44 | return self.lang[ExistsOp(self.field.map(map_))] 45 | 46 | def missing(self): 47 | return FALSE 48 | 49 | def exists(self): 50 | return TRUE 51 | 52 | @simplified 53 | def partial_eval(self): 54 | return self.lang[NotOp(self.field.missing())].partial_eval() 55 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/exp_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_binary_op import BaseBinaryOp 23 | 24 | 25 | class ExpOp(BaseBinaryOp): 26 | op = "exp" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/from_unix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from mo_json import NUMBER 24 | 25 | 26 | class FromUnixOp(Expression): 27 | """ 28 | FOR USING ON DATABASES WHICH HAVE A DATE COLUMNS: CONVERT TO UNIX 29 | """ 30 | 31 | data_type = NUMBER 32 | 33 | def __init__(self, term): 34 | Expression.__init__(self, term) 35 | self.value = term 36 | 37 | def vars(self): 38 | return self.value.vars() 39 | 40 | def map(self, map_): 41 | return self.lang[FromUnixOp(self.value.map(map_))] 42 | 43 | def missing(self): 44 | return self.value.missing() 45 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/get_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.literal import is_literal 24 | 25 | 26 | class GetOp(Expression): 27 | has_simple_form = True 28 | 29 | def __init__(self, term): 30 | Expression.__init__(self, term) 31 | self.var = term[0] 32 | self.offsets = term[1:] 33 | 34 | def __data__(self): 35 | if is_literal(self.var) and len(self.offsets) == 1 and is_literal(self.offset): 36 | return {"get": {self.var.json, self.offsets[0].value}} 37 | else: 38 | return {"get": [self.var.__data__()] + [o.__data__() for o in self.offsets]} 39 | 40 | def vars(self): 41 | output = self.var.vars() 42 | for o in self.offsets: 43 | output |= o.vars() 44 | return output 45 | 46 | def map(self, map_): 47 | return self.lang[ 48 | GetOp([self.var.map(map_)] + [o.map(map_) for o in self.offsets]) 49 | ] 50 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/gt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_inequality_op import BaseInequalityOp 23 | 24 | 25 | class GtOp(BaseInequalityOp): 26 | op = "gt" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/gte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_inequality_op import BaseInequalityOp 23 | 24 | 25 | class GteOp(BaseInequalityOp): 26 | op = "gte" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/integer_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified 23 | from jx_base.expressions.coalesce_op import CoalesceOp 24 | from jx_base.expressions.expression import Expression 25 | from jx_base.expressions.first_op import FirstOp 26 | from jx_base.language import is_op 27 | from mo_json import INTEGER 28 | 29 | 30 | class IntegerOp(Expression): 31 | data_type = INTEGER 32 | 33 | def __init__(self, term): 34 | Expression.__init__(self, [term]) 35 | self.term = term 36 | 37 | def __data__(self): 38 | return {"integer": self.term.__data__()} 39 | 40 | def vars(self): 41 | return self.term.vars() 42 | 43 | def map(self, map_): 44 | return self.lang[IntegerOp(self.term.map(map_))] 45 | 46 | def missing(self): 47 | return self.term.missing() 48 | 49 | @simplified 50 | def partial_eval(self): 51 | term = self.lang[FirstOp(self.term)].partial_eval() 52 | if is_op(term, CoalesceOp): 53 | return self.lang[CoalesceOp([IntegerOp(t) for t in term.terms])] 54 | if term.type == INTEGER: 55 | return term 56 | return self.lang[IntegerOp(term)] 57 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/is_boolean_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import BOOLEAN 25 | 26 | 27 | class IsBooleanOp(Expression): 28 | data_type = BOOLEAN 29 | 30 | def __init__(self, term): 31 | Expression.__init__(self, [term]) 32 | self.term = term 33 | 34 | def __data__(self): 35 | return {"is_boolean": self.term.__data__()} 36 | 37 | def vars(self): 38 | return self.term.vars() 39 | 40 | def map(self, map_): 41 | return self.lang[IsBooleanOp(self.term.map(map_))] 42 | 43 | def missing(self): 44 | return FALSE 45 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/is_integer_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import BOOLEAN 25 | 26 | 27 | class IsIntegerOp(Expression): 28 | data_type = BOOLEAN 29 | 30 | def __init__(self, term): 31 | Expression.__init__(self, [term]) 32 | self.term = term 33 | 34 | def __data__(self): 35 | return {"is_integer": self.term.__data__()} 36 | 37 | def vars(self): 38 | return self.term.vars() 39 | 40 | def map(self, map_): 41 | return self.lang[IsIntegerOp(self.term.map(map_))] 42 | 43 | def missing(self): 44 | return FALSE 45 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/is_number_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import simplified 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.expressions.false_op import FALSE 25 | from jx_base.expressions.null_op import NULL 26 | from jx_base.expressions.true_op import TRUE 27 | from mo_json import BOOLEAN, INTEGER, NUMBER, OBJECT 28 | 29 | 30 | class IsNumberOp(Expression): 31 | data_type = BOOLEAN 32 | 33 | def __init__(self, term): 34 | Expression.__init__(self, [term]) 35 | self.term = term 36 | 37 | def __data__(self): 38 | return {"is_number": self.term.__data__()} 39 | 40 | def vars(self): 41 | return self.term.vars() 42 | 43 | def map(self, map_): 44 | return self.lang[IsNumberOp(self.term.map(map_))] 45 | 46 | def missing(self): 47 | return FALSE 48 | 49 | @simplified 50 | def partial_eval(self): 51 | term = self.term.partial_eval() 52 | 53 | if term is NULL: 54 | return FALSE 55 | elif term.type in (INTEGER, NUMBER): 56 | return TRUE 57 | elif term.type == OBJECT: 58 | return self 59 | else: 60 | return FALSE 61 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/is_string_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import BOOLEAN 25 | 26 | 27 | class IsStringOp(Expression): 28 | data_type = BOOLEAN 29 | 30 | def __init__(self, term): 31 | Expression.__init__(self, [term]) 32 | self.term = term 33 | 34 | def __data__(self): 35 | return {"is_string": self.term.__data__()} 36 | 37 | def vars(self): 38 | return self.term.vars() 39 | 40 | def map(self, map_): 41 | return self.lang[IsStringOp(self.term.map(map_))] 42 | 43 | def missing(self): 44 | return FALSE 45 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/leaves_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import OBJECT 25 | 26 | 27 | class LeavesOp(Expression): 28 | date_type = OBJECT 29 | 30 | def __init__(self, term, prefix=None): 31 | Expression.__init__(self, term) 32 | self.term = term 33 | self.prefix = prefix 34 | 35 | def __data__(self): 36 | if self.prefix: 37 | return {"leaves": self.term.__data__(), "prefix": self.prefix} 38 | else: 39 | return {"leaves": self.term.__data__()} 40 | 41 | def vars(self): 42 | return self.term.vars() 43 | 44 | def map(self, map_): 45 | return self.lang[LeavesOp(self.term.map(map_))] 46 | 47 | def missing(self): 48 | return FALSE 49 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/lt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_inequality_op import BaseInequalityOp 23 | 24 | 25 | class LtOp(BaseInequalityOp): 26 | op = "lt" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/lte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_inequality_op import BaseInequalityOp 23 | 24 | 25 | class LteOp(BaseInequalityOp): 26 | op = "lte" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/mod_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_binary_op import BaseBinaryOp 23 | 24 | 25 | class ModOp(BaseBinaryOp): 26 | op = "mod" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/mul_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_multi_op import BaseMultiOp 23 | 24 | 25 | class MulOp(BaseMultiOp): 26 | op = "mul" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/offset_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from mo_future import text 24 | from mo_logs import Log 25 | from mo_math import is_integer 26 | 27 | 28 | class OffsetOp(Expression): 29 | """ 30 | OFFSET INDEX INTO A TUPLE 31 | """ 32 | 33 | def __init__(self, var): 34 | Expression.__init__(self, None) 35 | if not is_integer(var): 36 | Log.error("Expecting an integer") 37 | self.var = var 38 | 39 | def __call__(self, row, rownum=None, rows=None): 40 | try: 41 | return row[self.var] 42 | except Exception: 43 | return None 44 | 45 | def __data__(self): 46 | return {"offset": self.var} 47 | 48 | def vars(self): 49 | return {} 50 | 51 | def __hash__(self): 52 | return self.var.__hash__() 53 | 54 | def __eq__(self, other): 55 | return self.var == other 56 | 57 | def __unicode__(self): 58 | return text(self.var) 59 | 60 | def __str__(self): 61 | return str(self.var) 62 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/python_script.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | 24 | 25 | class PythonScript(Expression): 26 | """ 27 | REPRESENT A Python SCRIPT 28 | """ 29 | 30 | pass 31 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/query_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | 24 | 25 | class QueryOp(Expression): 26 | pass 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/range_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions._utils import operators 23 | from jx_base.expressions.and_op import AndOp 24 | from jx_base.expressions.expression import Expression 25 | from jx_base.expressions.literal import Literal 26 | from mo_json import BOOLEAN 27 | from mo_logs import Log 28 | 29 | 30 | class RangeOp(Expression): 31 | has_simple_form = True 32 | data_type = BOOLEAN 33 | 34 | def __new__(cls, term, *args): 35 | Expression.__new__(cls, *args) 36 | field, comparisons = term # comparisons IS A Literal() 37 | return cls.lang[ 38 | AndOp( 39 | [ 40 | getattr(cls.lang, operators[op])([field, Literal(value)]) 41 | for op, value in comparisons.value.items() 42 | ] 43 | ) 44 | ] 45 | 46 | def __init__(self, term): 47 | Log.error("Should never happen!") 48 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/reg_exp_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from jx_base.expressions.true_op import TRUE 25 | from mo_json import BOOLEAN 26 | 27 | 28 | class RegExpOp(Expression): 29 | has_simple_form = True 30 | data_type = BOOLEAN 31 | 32 | def __init__(self, terms): 33 | Expression.__init__(self, terms) 34 | self.var, self.pattern = terms 35 | 36 | def __data__(self): 37 | return {"regexp": {self.var.var: self.pattern}} 38 | 39 | def vars(self): 40 | return {self.var} 41 | 42 | def map(self, map_): 43 | return self.lang[RegExpOp([self.var.map(map_), self.pattern])] 44 | 45 | def missing(self): 46 | return FALSE 47 | 48 | def exists(self): 49 | return TRUE 50 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/sql_eq_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.eq_op import EqOp 23 | from jx_base.expressions.expression import Expression 24 | from jx_base.expressions.false_op import FALSE 25 | from jx_base.language import is_op 26 | from mo_json import BOOLEAN 27 | 28 | 29 | class SqlEqOp(Expression): 30 | data_type = BOOLEAN 31 | 32 | def __init__(self, terms): 33 | Expression.__init__(self, terms) 34 | self.lhs, self.rhs = terms 35 | 36 | def __data__(self): 37 | return {"sql.eq": [self.lhs.__data__(), self.rhs.__data__()]} 38 | 39 | def missing(self): 40 | return FALSE 41 | 42 | def __eq__(self, other): 43 | if not is_op(other, EqOp): 44 | return False 45 | return self.lhs == other.lhs and self.rhs == other.rhs 46 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/sql_instr_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import INTEGER 25 | 26 | 27 | class SqlInstrOp(Expression): 28 | data_type = INTEGER 29 | 30 | def __init__(self, params): 31 | Expression.__init__(self, params) 32 | self.value, self.find = params 33 | 34 | def __data__(self): 35 | return {"sql.instr": [self.value.__data__(), self.find.__data__()]} 36 | 37 | def vars(self): 38 | return self.value.vars() | self.find.vars() 39 | 40 | def missing(self): 41 | return FALSE 42 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/sql_script.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | 24 | 25 | class SQLScript(Expression): 26 | """ 27 | REPRESENT A SQL SCRIPT 28 | """ 29 | 30 | pass 31 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/sql_substr_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from jx_base.expressions.false_op import FALSE 24 | from mo_json import INTEGER 25 | 26 | 27 | class SqlSubstrOp(Expression): 28 | data_type = INTEGER 29 | 30 | def __init__(self, params): 31 | Expression.__init__(self, params) 32 | self.value, self.start, self.length = params 33 | 34 | def __data__(self): 35 | return { 36 | "sql.substr": [ 37 | self.value.__data__(), 38 | self.start.__data__(), 39 | self.length.__data__(), 40 | ] 41 | } 42 | 43 | def vars(self): 44 | return self.value.vars() | self.start.vars() | self.length.vars() 45 | 46 | def missing(self): 47 | return FALSE 48 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/sub_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.base_binary_op import BaseBinaryOp 23 | 24 | 25 | class SubOp(BaseBinaryOp): 26 | op = "sub" 27 | -------------------------------------------------------------------------------- /vendor/jx_base/expressions/unix_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | """ 12 | # NOTE: 13 | 14 | THE self.lang[operator] PATTERN IS CASTING NEW OPERATORS TO OWN LANGUAGE; 15 | KEEPING Python AS# Python, ES FILTERS AS ES FILTERS, AND Painless AS 16 | Painless. WE COULD COPY partial_eval(), AND OTHERS, TO THIER RESPECTIVE 17 | LANGUAGE, BUT WE KEEP CODE HERE SO THERE IS LESS OF IT 18 | 19 | """ 20 | from __future__ import absolute_import, division, unicode_literals 21 | 22 | from jx_base.expressions.expression import Expression 23 | from mo_json import NUMBER 24 | 25 | 26 | class UnixOp(Expression): 27 | """ 28 | FOR USING ON DATABASES WHICH HAVE A DATE COLUMNS: CONVERT TO UNIX 29 | """ 30 | 31 | has_simple_form = True 32 | data_type = NUMBER 33 | 34 | def __init__(self, term): 35 | Expression.__init__(self, term) 36 | self.value = term 37 | 38 | def vars(self): 39 | return self.value.vars() 40 | 41 | def map(self, map_): 42 | return self.lang[UnixOp(self.value.map(map_))] 43 | 44 | def missing(self): 45 | return self.value.missing() 46 | -------------------------------------------------------------------------------- /vendor/jx_base/facts.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from mo_future import is_text 13 | from mo_logs import Log 14 | 15 | 16 | class Facts(object): 17 | """ 18 | REPRESENT A HIERARCHICAL DATASTORE: MULTIPLE TABLES IN A DATABASE ALONG 19 | WITH THE RELATIONS THAT CONNECT THEM ALL, BUT LIMITED TO A TREE 20 | """ 21 | 22 | def __init__(self, name, container): 23 | if not is_text(name): 24 | Log.error("parameter is wrong") 25 | self.container = container 26 | self.name = name 27 | 28 | @property 29 | def namespace(self): 30 | return self.container.namespace 31 | 32 | @property 33 | def snowflake(self): 34 | return self.schema.snowflake 35 | 36 | @property 37 | def schema(self): 38 | return self.container.ns.get_schema(self.name) 39 | 40 | -------------------------------------------------------------------------------- /vendor/jx_base/namespace.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.query import QueryOp 13 | from mo_dots import is_data 14 | 15 | 16 | class Namespace(object): 17 | """ 18 | A CONGLOMERATION OF Snowflake METADATA 19 | A Namespace HOLDS METADATA FOR A Collection 20 | """ 21 | 22 | def get_snowflake(self, fact_table): 23 | raise NotImplementedError() 24 | 25 | def get_schema(self, name): 26 | raise NotImplementedError() 27 | 28 | def convert(self, expr): 29 | raise NotImplementedError() 30 | 31 | def _convert_query(self, query): 32 | output = QueryOp(None) 33 | output.select = self._convert_clause(query.select) 34 | output.where = self.convert(query.where) 35 | output["from"] = self._convert_from(query["from"]) 36 | output.edges = self._convert_clause(query.edges) 37 | output.window = convert_list(self._convert_window, query.window) 38 | output.sort = self._convert_clause(query.sort) 39 | output.format = query.format 40 | 41 | return output 42 | 43 | def _convert_from(self, frum): 44 | raise NotImplementedError() 45 | 46 | def _convert_clause(self, clause): 47 | raise NotImplementedError() 48 | 49 | def _convert_window(self, clause): 50 | raise NotImplementedError() 51 | 52 | 53 | def convert_list(operator, operand): 54 | if operand==None: 55 | return None 56 | elif is_data(operand): 57 | return operator(operand) 58 | else: 59 | return map(operator, operand) 60 | 61 | 62 | -------------------------------------------------------------------------------- /vendor/jx_base/queries.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | from __future__ import absolute_import, division, unicode_literals 9 | 10 | import re 11 | 12 | from mo_future import is_text 13 | from mo_logs import Log 14 | 15 | keyword_pattern = re.compile(r"(\w|[\\.,$-])+(?:\.(\w|[\\.,$-])+)*") 16 | 17 | 18 | def is_variable_name(value): 19 | if value.__class__.__name__ == "Variable": 20 | Log.warning("not expected") 21 | return True 22 | 23 | if not value or not is_text(value): 24 | return False # _a._b 25 | value = value.lstrip(".") 26 | if not value: 27 | return True 28 | match = keyword_pattern.match(value) 29 | if not match: 30 | return False 31 | return match.group(0) == value 32 | 33 | def dequote(s): 34 | """ 35 | If a string has single or double quotes around it, remove them. 36 | Make sure the pair of quotes match. 37 | If a matching pair of quotes is not found, return the string unchanged. 38 | """ 39 | if (s[0] == s[-1]) and s.startswith(("'", '"')): 40 | return s[1:-1] 41 | return s 42 | 43 | def is_column_name(col): 44 | if re.match(r"(\$|\w|\\\.)+(?:\.(\$|\w|\\\.)+)*\.\$\w{6}$", col): 45 | return True 46 | else: 47 | return False 48 | 49 | 50 | def get_property_name(s): 51 | if s==".": 52 | return s 53 | else: 54 | return s.lstrip(".") 55 | -------------------------------------------------------------------------------- /vendor/jx_base/snowflake.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | 13 | class Snowflake(object): 14 | """ 15 | REPRESENT ONE ALIAS, AND ITS NESTED ARRAYS 16 | """ 17 | 18 | def get_schema(self, query_path): 19 | raise NotImplemented() 20 | 21 | @property 22 | def query_paths(self): 23 | raise NotImplemented() 24 | 25 | @property 26 | def columns(self): 27 | raise NotImplemented() 28 | 29 | -------------------------------------------------------------------------------- /vendor/jx_base/table.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | 13 | class Table(object): 14 | 15 | def __init__(self, full_name): 16 | self.name = full_name 17 | 18 | def map(self, mapping): 19 | return self 20 | 21 | -------------------------------------------------------------------------------- /vendor/jx_base/utils.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | from __future__ import absolute_import, division, unicode_literals 9 | 10 | import re 11 | 12 | from mo_future import is_text 13 | from mo_logs import Log 14 | 15 | keyword_pattern = re.compile(r"(\w|[\\.])(\w|[\\.$-])*(?:\.(\w|[\\.$-])+)*") 16 | 17 | 18 | def is_variable_name(value): 19 | if value.__class__.__name__ == "Variable": 20 | Log.warning("not expected") 21 | return True 22 | 23 | if not value or not is_text(value): 24 | return False # _a._b 25 | value = value.lstrip(".") 26 | if not value: 27 | return True 28 | match = keyword_pattern.match(value) 29 | if not match: 30 | return False 31 | return match.group(0) == value 32 | 33 | 34 | def dequote(s): 35 | """ 36 | If a string has single or double quotes around it, remove them. 37 | Make sure the pair of quotes match. 38 | If a matching pair of quotes is not found, return the string unchanged. 39 | """ 40 | if (s[0] == s[-1]) and s.startswith(("'", '"')): 41 | return s[1:-1] 42 | return s 43 | 44 | 45 | def is_column_name(col): 46 | if re.match(r"(\$|\w|\\\.)+(?:\.(\$|\w|\\\.)+)*\.\$\w{6}$", col): 47 | return True 48 | else: 49 | return False 50 | 51 | 52 | def get_property_name(s): 53 | if s == ".": 54 | return s 55 | else: 56 | return s.lstrip(".") 57 | -------------------------------------------------------------------------------- /vendor/jx_python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/jx_python/__init__.py -------------------------------------------------------------------------------- /vendor/jx_python/containers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/jx_python/containers/__init__.py -------------------------------------------------------------------------------- /vendor/jx_python/cubes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/jx_python/cubes/__init__.py -------------------------------------------------------------------------------- /vendor/jx_python/expression_compiler.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division 11 | 12 | import re 13 | 14 | from mo_future import first 15 | from mo_dots import Data, coalesce, is_data, listwrap, wrap_leaves 16 | from mo_logs import Log, strings 17 | from mo_times.dates import Date 18 | 19 | GLOBALS = { 20 | "true": True, 21 | "false": False, 22 | "null": None, 23 | "EMPTY_DICT": {}, 24 | "coalesce": coalesce, 25 | "listwrap": listwrap, 26 | "Date": Date, 27 | "Log": Log, 28 | "Data": Data, 29 | "re": re, 30 | "wrap_leaves": wrap_leaves, 31 | "is_data": is_data, 32 | "first": first 33 | } 34 | 35 | 36 | def compile_expression(source, function_name="output"): 37 | """ 38 | THIS FUNCTION IS ON ITS OWN FOR MINIMAL GLOBAL NAMESPACE 39 | 40 | :param source: PYTHON SOURCE CODE 41 | :param function_name: OPTIONAL NAME TO GIVE TO OUTPUT FUNCTION 42 | :return: PYTHON FUNCTION 43 | """ 44 | 45 | fake_locals = {} 46 | try: 47 | exec( 48 | ( 49 | "def " + function_name + "(row, rownum=None, rows=None):\n" + 50 | " _source = " + strings.quote(source) + "\n" + 51 | " try:\n" + 52 | " return " + source + "\n" + 53 | " except Exception as e:\n" + 54 | " Log.error(u'Problem with dynamic function {{func|quote}}', func=_source, cause=e)\n" 55 | ), 56 | GLOBALS, 57 | fake_locals, 58 | ) 59 | except Exception as e: 60 | Log.error(u"Bad source: {{source}}", source=source, cause=e) 61 | return fake_locals["output"] 62 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/add_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import AddOp as AddOp_ 13 | from jx_python.expressions._utils import multiop_to_python 14 | 15 | 16 | class AddOp(AddOp_): 17 | to_python = multiop_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/and_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import AndOp as AndOp_ 13 | from jx_python.expressions._utils import Python 14 | from jx_python.expressions.boolean_op import BooleanOp 15 | 16 | 17 | class AndOp(AndOp_): 18 | def to_python(self, not_null=False, boolean=False, many=False): 19 | if not self.terms: 20 | return "True" 21 | else: 22 | return " and ".join( 23 | "(" + BooleanOp(Python[t]).to_python() + ")" for t in self.terms 24 | ) 25 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/basic_eq_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicEqOp as BasicEqOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class BasicEqOp(BasicEqOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "(" 20 | + Python[self.rhs].to_python() 21 | + ") == (" 22 | + Python[self.lhs].to_python() 23 | + ")" 24 | ) 25 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/basic_index_of_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BasicIndexOfOp as BasicIndexOfOp_ 13 | from jx_python.expressions._utils import with_var, Python 14 | 15 | 16 | class BasicIndexOfOp(BasicIndexOfOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return with_var( 19 | "f", 20 | "(" 21 | + Python[self.value].to_python() 22 | + ").find" 23 | + "(" 24 | + Python[self.find].to_python() 25 | + ")", 26 | "None if f==-1 else f", 27 | ) 28 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/between_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BetweenOp as BetweenOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class BetweenOp(BetweenOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | Python[self.value].to_python() 20 | + " in " 21 | + Python[self.superset].to_python(many=True) 22 | ) 23 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/boolean_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import BooleanOp as BooleanOp_ 13 | from jx_python.expressions._utils import with_var, Python 14 | 15 | 16 | class BooleanOp(BooleanOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return with_var( 19 | "f", 20 | Python[self.term].to_python(), 21 | "bool(f)", 22 | ) 23 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/case_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import CaseOp as CaseOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class CaseOp(CaseOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | acc = Python[self.whens[-1]].to_python() 19 | for w in reversed(self.whens[0:-1]): 20 | acc = ( 21 | "(" 22 | + Python[w.then].to_python() 23 | + ") if (" 24 | + Python[w.when].to_python(boolean=True) 25 | + ") else (" 26 | + acc 27 | + ")" 28 | ) 29 | return acc 30 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/coalesce_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import CoalesceOp as CoalesceOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class CoalesceOp(CoalesceOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "coalesce(" + (", ".join(Python[t].to_python() for t in self.terms)) + ")" 20 | ) 21 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/concat_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ConcatOp as ConcatOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class ConcatOp(ConcatOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | v = Python[self.value].to_python() 19 | l = Python[self.length].to_python() 20 | return ( 21 | "None if " 22 | + v 23 | + " == None or " 24 | + l 25 | + " == None else " 26 | + v 27 | + "[0:max(0, " 28 | + l 29 | + ")]" 30 | ) 31 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/count_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import CountOp as CountOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class CountOp(CountOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "sum(((0 if v==None else 1) for v in " 20 | + Python[self.terms].to_python(not_null=False, boolean=False, many=True) 21 | + "), 0)" 22 | ) 23 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/date_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import DateOp as DateOp_ 13 | from mo_future import text 14 | from mo_times.dates import Date 15 | 16 | 17 | class DateOp(DateOp_): 18 | def to_python(self, not_null=False, boolean=False, many=False): 19 | return text(Date(self.value).unix) 20 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/div_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import DivOp as DivOp_ 13 | from jx_python.expressions._utils import _binaryop_to_python 14 | 15 | 16 | class DivOp(DivOp_): 17 | to_python = _binaryop_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/eq_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import EqOp as EqOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class EqOp(EqOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "(" 20 | + Python[self.rhs].to_python() 21 | + ") in listwrap(" 22 | + Python[self.lhs].to_python() 23 | + ")" 24 | ) 25 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/exists_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ExistsOp as ExistsOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class ExistsOp(ExistsOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return Python[self.field].to_python() + " != None" 19 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/exp_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ExpOp as ExpOp_ 13 | from jx_python.expressions._utils import _binaryop_to_python 14 | 15 | 16 | class ExpOp(ExpOp_): 17 | to_python = _binaryop_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/false_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FalseOp as FalseOp_ 13 | 14 | 15 | class FalseOp(FalseOp_): 16 | def to_python(self, not_null=False, boolean=False, many=False): 17 | return "False" 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/first_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FirstOp as FirstOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class FirstOp(FirstOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | value = Python[self.term].to_python() 19 | return "listwrap(" + value + ")[0]" 20 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/floor_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import FloorOp as FloorOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class FloorOp(FloorOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "mo_math.floor(" 20 | + Python[self.lhs].to_python() 21 | + ", " 22 | + Python[self.rhs].to_python() 23 | + ")" 24 | ) 25 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/get_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GetOp as GetOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class GetOp(GetOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | output = ["(" + Python[self.var].to_python() + ")"] 19 | for o in self.offsets: 20 | output.append("[" + Python[o].to_python() + "]") 21 | return "".join(output) 22 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/gt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GtOp as GtOp_ 13 | from jx_python.expressions._utils import _inequality_to_python 14 | 15 | 16 | class GtOp(GtOp_): 17 | to_python = _inequality_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/gte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import GteOp as GteOp_ 13 | from jx_python.expressions._utils import _inequality_to_python 14 | 15 | 16 | class GteOp(GteOp_): 17 | to_python = _inequality_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/in_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import InOp as InOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class InOp(InOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | Python[self.value].to_python() 20 | + " in " 21 | + Python[self.superset].to_python(many=True) 22 | ) 23 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/integer_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import IntegerOp as IntegerOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class IntegerOp(IntegerOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return "int(" + Python[self.term].to_python() + ")" 19 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/last_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LastOp as LastOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class LastOp(LastOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | term = Python[self.term].to_python() 19 | return "last(" + term + ")" 20 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/leaves_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LeavesOp as LeavesOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class LeavesOp(LeavesOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return "Data(" + Python[self.term].to_python() + ").leaves()" 19 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/length_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LengthOp as LengthOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class LengthOp(LengthOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | value = Python[self.term].to_python() 19 | return "len(" + value + ") if (" + value + ") != None else None" 20 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/literal.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import Literal as Literal_ 13 | from mo_dots import unwrap 14 | from mo_future import text 15 | from mo_json import json2value 16 | 17 | 18 | class Literal(Literal_): 19 | def to_python(self, not_null=False, boolean=False, many=False): 20 | return text(repr(unwrap(json2value(self.json)))) 21 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/lt_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LtOp as LtOp_ 13 | from jx_python.expressions._utils import _inequality_to_python 14 | 15 | 16 | class LtOp(LtOp_): 17 | to_python = _inequality_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/lte_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import LteOp as LteOp_ 13 | from jx_python.expressions._utils import _inequality_to_python 14 | 15 | 16 | class LteOp(LteOp_): 17 | to_python = _inequality_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/max_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MaxOp as MaxOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class MaxOp(MaxOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return "max([" + (",".join(Python[t].to_python() for t in self.terms)) + "])" 19 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/missing_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MissingOp as MissingOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class MissingOp(MissingOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return Python[self.expr].to_python() + " == None" 19 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/mod_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import ModOp as ModOp_ 13 | from jx_python.expressions._utils import _binaryop_to_python 14 | 15 | 16 | class ModOp(ModOp_): 17 | to_python = _binaryop_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/mul_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import MulOp as MulOp_ 13 | from jx_python.expressions._utils import multiop_to_python 14 | 15 | 16 | class MulOp(MulOp_): 17 | to_python = multiop_to_python 18 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/ne_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NeOp as NeOp_ 13 | from jx_python.expressions._utils import Python, with_var 14 | 15 | 16 | class NeOp(NeOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | lhs = Python[self.lhs].to_python() 19 | rhs = Python[self.rhs].to_python() 20 | 21 | return with_var("r, l", "("+lhs+","+rhs+")", "l!=None and r!=None and l!=r") 22 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/not_left_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotLeftOp as NotLeftOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class NotLeftOp(NotLeftOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | v = Python[self.value].to_python() 19 | l = Python[self.length].to_python() 20 | return ( 21 | "None if " 22 | + v 23 | + " == None or " 24 | + l 25 | + " == None else " 26 | + v 27 | + "[max(0, " 28 | + l 29 | + "):]" 30 | ) 31 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/not_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotOp as NotOp_ 13 | from jx_python.expressions._utils import Python 14 | from jx_python.expressions.boolean_op import BooleanOp 15 | 16 | 17 | class NotOp(NotOp_): 18 | def to_python(self, not_null=False, boolean=False, many=False): 19 | return "not (" + BooleanOp(Python[self.term]).to_python(boolean=True) + ")" 20 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/not_right_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import NotRightOp as NotRightOp_ 13 | from jx_python.expressions._utils import Python 14 | 15 | 16 | class NotRightOp(NotRightOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | v = Python[self.value].to_python() 19 | l = Python[self.length].to_python() 20 | return ( 21 | "None if " 22 | + v 23 | + " == None or " 24 | + l 25 | + " == None else " 26 | + v 27 | + "[0:max(0, len(" 28 | + v 29 | + ")-(" 30 | + l 31 | + "))]" 32 | ) 33 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/number_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions.number_op import NumberOp as NumberOp_ 13 | from jx_base.expressions.true_op import TRUE 14 | from jx_python.expressions import _utils 15 | from jx_python.expressions._utils import Python 16 | from mo_json import INTEGER, NUMBER 17 | 18 | 19 | class NumberOp(NumberOp_): 20 | def to_python(self, not_null=False, boolean=False, many=False): 21 | term = Python[self.term] 22 | if not_null: 23 | if term.type in [NUMBER, INTEGER]: 24 | return term.to_python(not_null=True) 25 | else: 26 | return "float(" + Python[self.term].to_python(not_null=True) + ")" 27 | else: 28 | exists = self.term.exists() 29 | value = Python[self.term].to_python(not_null=True) 30 | 31 | if exists is TRUE: 32 | return "float(" + value + ")" 33 | else: 34 | return ( 35 | "float(" 36 | + value 37 | + ") if (" 38 | + Python[exists].to_python() 39 | + ") else None" 40 | ) 41 | 42 | 43 | _utils.NumberOp = NumberOp 44 | -------------------------------------------------------------------------------- /vendor/jx_python/expressions/offset_op.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http:# mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | from __future__ import absolute_import, division, unicode_literals 11 | 12 | from jx_base.expressions import OffsetOp as OffsetOp_ 13 | from mo_future import text 14 | 15 | 16 | class OffsetOp(OffsetOp_): 17 | def to_python(self, not_null=False, boolean=False, many=False): 18 | return ( 19 | "row[" 20 | + text(self.var) 21 | + "] if 0<=" 22 | + text(self.var) 23 | + " 4 | 5 | This module offers extensions to the standard Python 6 | datetime module. 7 | """ 8 | __author__ = "Tomi Pieviläinen " 9 | __license__ = "Simplified BSD" 10 | __version__ = "2.1" 11 | -------------------------------------------------------------------------------- /vendor/mo_times/vendor/dateutil/parser.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/mo_times/vendor/dateutil/parser.py -------------------------------------------------------------------------------- /vendor/mo_times/vendor/dateutil/zoneinfo/zoneinfo--latest.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/mo_times/vendor/dateutil/zoneinfo/zoneinfo--latest.tar.gz -------------------------------------------------------------------------------- /vendor/pyLibrary/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/pyLibrary/__init__.py -------------------------------------------------------------------------------- /vendor/pyLibrary/env/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Environment 3 | 4 | This directory is for connecting to other systems. Generally, these 5 | classes are facades that assume content is UTF-8 encoded JSON. 6 | 7 | 8 | 9 | ## emailer 10 | 11 | A simple emailer, the primary purpose is to accept a [Data](https://github.com/klahnakoski/mo-dots/blob/dev/docs/README.md) 12 | of settings. 13 | 14 | 15 | ## pulse 16 | 17 | For connecting clients to [Mozilla's Pulse](https://pulse.mozilla.org/). 18 | 19 | 20 | -------------------------------------------------------------------------------- /vendor/pyLibrary/env/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/pyLibrary/env/__init__.py -------------------------------------------------------------------------------- /vendor/pyLibrary/env/git.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | # Contact: Kyle Lahnakoski (kyle@lahnakoski.com) 9 | # 10 | 11 | from __future__ import absolute_import, division, unicode_literals 12 | 13 | from mo_logs.exceptions import suppress_exception 14 | from mo_threads import Process, THREAD_STOP 15 | from pyLibrary.meta import cache 16 | 17 | 18 | @cache 19 | def get_revision(): 20 | """ 21 | GET THE CURRENT GIT REVISION 22 | """ 23 | proc = Process("git log", ["git", "log", "-1"]) 24 | 25 | try: 26 | for line in proc.stdout: 27 | if line.startswith("commit "): 28 | return line[7:] 29 | finally: 30 | with suppress_exception: 31 | proc.join() 32 | 33 | 34 | @cache 35 | def get_remote_revision(url, branch): 36 | """ 37 | GET REVISION OF A REMOTE BRANCH 38 | """ 39 | proc = Process("git remote revision", ["git", "ls-remote", url, "refs/heads/" + branch]) 40 | 41 | try: 42 | for line in proc.stdout: 43 | line = line.strip() 44 | if not line: 45 | continue 46 | return line.split("\t")[0] 47 | finally: 48 | try: 49 | proc.join() 50 | except Exception: 51 | pass 52 | 53 | 54 | @cache 55 | def get_branch(): 56 | """ 57 | GET THE CURRENT GIT BRANCH 58 | """ 59 | proc = Process("git status", ["git", "status"]) 60 | 61 | try: 62 | for line in proc.stdout: 63 | if line.startswith("On branch "): 64 | return line[10:] 65 | finally: 66 | try: 67 | proc.join() 68 | except Exception: 69 | pass 70 | -------------------------------------------------------------------------------- /vendor/pyLibrary/sql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/pyLibrary/sql/__init__.py -------------------------------------------------------------------------------- /vendor/pyLibrary/testing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/pyLibrary/testing/__init__.py -------------------------------------------------------------------------------- /vendor/pyLibrary/vendor/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'klahnakoski' 2 | -------------------------------------------------------------------------------- /vendor/pyLibrary/vendor/sqlite/README.md: -------------------------------------------------------------------------------- 1 | Sqlite 2 | ====== 3 | 4 | A copy of version 3.13.0 binaries and header file as per [Sqlite public domain licence](https://www.sqlite.org/copyright.html) -------------------------------------------------------------------------------- /vendor/pyLibrary/vendor/sqlite/compile.bat: -------------------------------------------------------------------------------- 1 | gcc -shared -I "C:\Users\kyle\code\ActiveData\pyLibrary\vendor\sqlite\sqlite.h" -o libsqlitefunctions.so extension-functions.c 2 | -------------------------------------------------------------------------------- /vendor/pyLibrary/vendor/sqlite/libsqlitefunctions.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/jx-sqlite/a379d80eaf4f0debbd47fc8d6cb0da55603e13dc/vendor/pyLibrary/vendor/sqlite/libsqlitefunctions.so --------------------------------------------------------------------------------