def find_container(frum, after): """ :param frum: :return: """ global namespace if not namespace: if not container.config.default.settings: Log.error( "expecting jx_base.container.config.default.settings to contain default elasticsearch connection info" ) namespace = ElasticsearchMetadata(container.config.default.settings) if not frum: Log.error("expecting json query expression with from clause") # FORCE A RELOAD namespace.get_columns(frum, after=after) if is_text(frum): if frum in container_cache: return container_cache[frum] path = split_field(frum) if path[0] == "meta": if path[1] == "columns": return namespace.meta.columns.denormalized() elif path[1] == "tables": return namespace.meta.tables else: fact_table_name = join_field(path[:2]) else: fact_table_name = path[0] type_ = container.config.default.type settings = set_default( { "alias": fact_table_name, "name": frum, "exists": True }, container.config.default.settings, ) settings.type = None output = container.type2container[type_](settings) container_cache[frum] = output return output elif is_data(frum) and frum.type and container.type2container[frum.type]: # TODO: Ensure the frum.name is set, so we capture the deep queries if not frum.type: Log.error("Expecting from clause to have a 'type' property") return container.type2container[frum.type](frum.settings) elif is_data(frum) and (frum["from"] or is_container(frum["from"])): from jx_base.query import QueryOp return QueryOp.wrap(frum) elif is_container(frum): return ListContainer("test_list", frum) else: return frum
def fill_container(self, subtest, typed=True): """ RETURN SETTINGS THAT CAN BE USED TO POINT TO THE INDEX THAT'S FILLED """ subtest = wrap(subtest) _settings = self._es_test_settings # ALREADY COPIED AT setUp() try: url = "file://resources/schema/basic_schema.json.template?{{.|url}}" url = expand_template(url, { "type": _settings.type, "metadata": subtest.metadata }) _settings.schema = mo_json_config.get(url) # MAKE CONTAINER container = self._es_cluster.get_or_create_index( typed=typed, schema=subtest.schema or _settings.schema, kwargs=_settings ) container.add_alias(_settings.index) _settings.alias = container.settings.alias _settings.index = container.settings.index ESUtils.indexes.append(_settings.index) # INSERT DATA if '"null"' in value2json(subtest.data): Log.error("not expected") container.extend([{"value": d} for d in subtest.data]) container.flush() now = Date.now() namespace = ElasticsearchMetadata(self._es_cluster.settings) namespace.get_columns(_settings.alias, after=now) # FORCE A RELOAD # ENSURE query POINTS TO CONTAINER frum = subtest.query["from"] if frum == None: subtest.query["from"] = _settings.alias elif is_text(frum): subtest.query["from"] = frum.replace(test_jx.TEST_TABLE, _settings.alias) else: Log.error("Do not know how to handle") except Exception as e: Log.error("can not load {{data}} into container", data=subtest.data, cause=e) return _settings