def test_starting_with_specifier(): """ Compiling a Minerva query starting with a specifier should raise an exception. """ minerva_query = [{"type": "S", "value": "11030"}] relation_group_name = "test" compile_sql(minerva_query, relation_group_name)
def test_get_aggregate_shard(self): awacs_query = [{"type": "C", "value": ["dummy_type"]}] granularity = create_granularity("900") formula = "SUM(Drops)" shard_indexes = [15680] with closing(self.conn.cursor()) as cursor: entitytype_cell = name_to_entitytype(cursor, 'dummy_type') sql, args, entity_id_column = compile_sql(awacs_query, None) select_statement = "SELECT {} AS id {}".format(entity_id_column, sql) entities_query = cursor.mogrify(select_statement, args) get_shard = partial(get_aggregate_shard, self.conn, entities_query, entitytype_cell.id, granularity, formula) shards = map(get_shard, shard_indexes) for shard in shards: logging.debug("{} - {}".format(shard[0], shard[-1])) eq_(len(shards), len(shard_indexes))
def test_simple(): minerva_query = [{"type": "C", "value": ["Cell"]}] relation_group_name = "test" sql = compile_sql(minerva_query, relation_group_name) expected_sql = ( "FROM directory.entitytaglink tl_0_0 " "JOIN directory.tag t_0_0 ON t_0_0.id = tl_0_0.tag_id " "AND lower(t_0_0.name) = lower(%s)") expected_args = ["Cell"] expected_entity_id_column = "tl_0_0.entity_id" expected = (expected_sql, expected_args, expected_entity_id_column) eq_(sql, expected)