File size: 5,909 Bytes
3932407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import requests

from .assertions import assert_http_ok
from .fixtures import create_collection
from .utils import every_test, start_cluster

COLL_NAME = "test_collection"


def test_order_by_from_remote_shard(tmp_path, every_test):
    peer_api_uris, peer_dirs, bootstrap_uri = start_cluster(tmp_path, num_peers=2, port_seed=10000)

    uri = peer_api_uris[0]

    create_collection(uri, collection=COLL_NAME, shard_number=2, replication_factor=1)

    requests.put(
        f"{uri}/collections/{COLL_NAME}/index",
        json={"field_name": "index", "field_schema": "integer"},
    ).raise_for_status()

    res = requests.put(
        f"{uri}/collections/{COLL_NAME}/points",
        params={
            "wait": "true",
        },
        json={
            "points": [
                {
                    "id": 0,
                    "payload": {
                        "index": 0,
                        "timestamp": "2024-04-12T08:40:06.189301",
                        "text": "Italy: tomatoes, olive oil, pasta.",
                        "title": "food",
                    },
                    "vector": {},
                }
            ]
        },
    )
    assert_http_ok(res)

    requests.put(
        f"{uri}/collections/{COLL_NAME}/points",
        params={
            "wait": "true",
        },
        json={
            "batch": {
                "ids": [11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                "payloads": [
                    {
                        "timestamp": "2024-04-12T08:40:20.015587",
                        "text": "Japan: Polite, punctual, public transport reliance",
                        "index": 11,
                        "title": "travel",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:20.290047",
                        "text": "Italy: Relaxed, historical tours, slow-paced",
                        "index": 12,
                        "title": "travel",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:20.562687",
                        "text": "USA: Road trips, diverse landscapes.",
                        "index": 13,
                        "title": "travel",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:09.482208",
                        "text": "Japan: seafood-centric with artistic presentation.",
                        "index": 1,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:09.744967",
                        "text": "Mexico: beans, chili peppers, and meat.",
                        "index": 2,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:10.020073",
                        "text": "India: diverse vegetarian and meat dishes.",
                        "index": 3,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:10.285342",
                        "text": "France: Gourmet dining, focuses on cheese, wine",
                        "index": 4,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:10.883714",
                        "text": "China: diverse cuisines, emphasizes balance, uses rice",
                        "index": 5,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:13.166867",
                        "text": "Thailand: five flavors, spicy, sweet, salty, sour.",
                        "index": 6,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:15.436143",
                        "text": "USA: Melting pot, diverse, large portions, fast food.",
                        "index": 7,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:15.697163",
                        "text": "Brazil: barbecue heavy",
                        "index": 8,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:15.963504",
                        "text": "Greece: Olive oil, feta, yogurt, seafood",
                        "index": 9,
                        "title": "food",
                    },
                    {
                        "timestamp": "2024-04-12T08:40:16.738832",
                        "text": "Ethiopia: bread with spicy stews and vegetables",
                        "index": 10,
                        "title": "food",
                    },
                ],
                "vectors": {},
            }
        },
    ).raise_for_status()

    res = requests.post(
        f"{uri}/collections/{COLL_NAME}/points/scroll", json={"limit": 10, "order_by": "index"}
    )

    assert_http_ok(res)

    for point in res.json()["result"]["points"]:
        assert point.get("payload") is not None

    values = [point["payload"]["index"] for point in res.json()["result"]["points"]]

    assert values == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    # It should also work when with_payload is False
    res = requests.post(
        f"{uri}/collections/{COLL_NAME}/points/scroll",
        json={"limit": 10, "order_by": "index", "with_payload": False},
    )

    assert_http_ok(res)

    ids = [point["id"] for point in res.json()["result"]["points"]]

    assert ids == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    for point in res.json()["result"]["points"]:
        assert point.get("payload") is None