|
50 | 50 | "service_url = os.environ['TIMESCALE_SERVICE_URL']"
|
51 | 51 | ]
|
52 | 52 | },
|
53 |
| - { |
54 |
| - "attachments": {}, |
55 |
| - "cell_type": "markdown", |
56 |
| - "metadata": {}, |
57 |
| - "source": [ |
58 |
| - "# Query Builder" |
59 |
| - ] |
60 |
| - }, |
61 | 53 | {
|
62 | 54 | "cell_type": "code",
|
63 | 55 | "execution_count": null,
|
|
85 | 77 | "outputs": [],
|
86 | 78 | "source": [
|
87 | 79 | "#| export\n",
|
88 |
| - "\n", |
89 |
| - "SEARCH_RESULT_ID_IDX = 0\n", |
90 |
| - "SEARCH_RESULT_METADATA_IDX = 1\n", |
91 |
| - "SEARCH_RESULT_CONTENTS_IDX = 2\n", |
92 |
| - "SEARCH_RESULT_EMBEDDING_IDX = 3\n", |
93 |
| - "SEARCH_RESULT_DISTANCE_IDX = 4" |
94 |
| - ] |
95 |
| - }, |
96 |
| - { |
97 |
| - "cell_type": "code", |
98 |
| - "execution_count": null, |
99 |
| - "metadata": {}, |
100 |
| - "outputs": [], |
101 |
| - "source": [ |
102 |
| - "#| export\n", |
103 |
| - "\n", |
104 | 80 | "#copied from Cassandra: https://docs.datastax.com/en/drivers/python/3.2/_modules/cassandra/util.html#uuid_from_time\n",
|
105 |
| - "def uuid_from_time(time_arg=None, node=None, clock_seq=None):\n", |
106 |
| - " if time_arg is None:\n", |
107 |
| - " return uuid.uuid1(node, clock_seq)\n", |
| 81 | + "def uuid_from_time(time_arg = None, node=None, clock_seq=None):\n", |
108 | 82 | " \"\"\"\n",
|
109 |
| - " Converts a datetime or timestamp to a type 1 :class:`uuid.UUID`.\n", |
110 |
| - "\n", |
111 |
| - " :param time_arg:\n", |
112 |
| - " The time to use for the timestamp portion of the UUID.\n", |
113 |
| - " This can either be a :class:`datetime` object or a timestamp\n", |
114 |
| - " in seconds (as returned from :meth:`time.time()`).\n", |
115 |
| - " :type datetime: :class:`datetime` or timestamp\n", |
116 |
| - "\n", |
117 |
| - " :param node:\n", |
118 |
| - " None integer for the UUID (up to 48 bits). If not specified, this\n", |
119 |
| - " field is randomized.\n", |
120 |
| - " :type node: long\n", |
121 |
| - "\n", |
122 |
| - " :param clock_seq:\n", |
123 |
| - " Clock sequence field for the UUID (up to 14 bits). If not specified,\n", |
124 |
| - " a random sequence is generated.\n", |
125 |
| - " :type clock_seq: int\n", |
126 |
| - "\n", |
127 |
| - " :rtype: :class:`uuid.UUID`\n", |
128 |
| - "\n", |
| 83 | + " Converts a datetime or timestamp to a type 1 `uuid.UUID`.\n", |
| 84 | + "\n", |
| 85 | + " Parameters\n", |
| 86 | + " ----------\n", |
| 87 | + " time_arg\n", |
| 88 | + " The time to use for the timestamp portion of the UUID.\n", |
| 89 | + " This can either be a `datetime` object or a timestamp in seconds\n", |
| 90 | + " (as returned from `time.time()`).\n", |
| 91 | + " node\n", |
| 92 | + " Bytes for the UUID (up to 48 bits). If not specified, this\n", |
| 93 | + " field is randomized.\n", |
| 94 | + " clock_seq\n", |
| 95 | + " Clock sequence field for the UUID (up to 14 bits). If not specified,\n", |
| 96 | + " a random sequence is generated.\n", |
| 97 | + "\n", |
| 98 | + " Returns\n", |
| 99 | + " -------\n", |
| 100 | + " uuid.UUID: For the given time, node, and clock sequence\n", |
129 | 101 | " \"\"\"\n",
|
| 102 | + " if time_arg is None:\n", |
| 103 | + " return uuid.uuid1(node, clock_seq)\n", |
130 | 104 | " if hasattr(time_arg, 'utctimetuple'):\n",
|
131 | 105 | " seconds = int(calendar.timegm(time_arg.utctimetuple()))\n",
|
132 | 106 | " microseconds = (seconds * 1e6) + time_arg.time().microsecond\n",
|
|
157 | 131 | " clock_seq_hi_variant, clock_seq_low, node), version=1)"
|
158 | 132 | ]
|
159 | 133 | },
|
| 134 | + { |
| 135 | + "attachments": {}, |
| 136 | + "cell_type": "markdown", |
| 137 | + "metadata": {}, |
| 138 | + "source": [ |
| 139 | + "# Query Builder" |
| 140 | + ] |
| 141 | + }, |
| 142 | + { |
| 143 | + "cell_type": "code", |
| 144 | + "execution_count": null, |
| 145 | + "metadata": {}, |
| 146 | + "outputs": [], |
| 147 | + "source": [ |
| 148 | + "#| export\n", |
| 149 | + "\n", |
| 150 | + "SEARCH_RESULT_ID_IDX = 0\n", |
| 151 | + "SEARCH_RESULT_METADATA_IDX = 1\n", |
| 152 | + "SEARCH_RESULT_CONTENTS_IDX = 2\n", |
| 153 | + "SEARCH_RESULT_EMBEDDING_IDX = 3\n", |
| 154 | + "SEARCH_RESULT_DISTANCE_IDX = 4" |
| 155 | + ] |
| 156 | + }, |
160 | 157 | {
|
161 | 158 | "cell_type": "code",
|
162 | 159 | "execution_count": null,
|
|
166 | 163 | "#| export\n",
|
167 | 164 | "class UUIDTimeRange:\n",
|
168 | 165 | " def __init__(self, start_date: Optional[datetime] = None, end_date: Optional[datetime] = None, start_inclusive=True, end_inclusive=False):\n",
|
| 166 | + " \"\"\"\n", |
| 167 | + " A UUIDTimeRange is a time range predicate on the UUID Version 1 timestamps.\n", |
| 168 | + " \"\"\"\n", |
169 | 169 | " if start_date is not None and end_date is not None:\n",
|
170 | 170 | " if start_date > end_date:\n",
|
171 | 171 | " raise Exception(\"start_date must be before end_date\")\n",
|
|
1278 | 1278 | " raised = True\n",
|
1279 | 1279 | "assert raised\n",
|
1280 | 1280 | "\n",
|
1281 |
| - "import datetime\n", |
1282 |
| - "specific_datetime = datetime.datetime(2018, 8, 10, 15, 30, 0)\n", |
| 1281 | + "specific_datetime = datetime(2018, 8, 10, 15, 30, 0)\n", |
1283 | 1282 | "await vec.upsert([\n",
|
1284 | 1283 | " # current time\n",
|
1285 | 1284 | " (uuid.uuid1(), {\"key\": \"val\"}, \"the brown fox\", [1.0, 1.2]),\n",
|
|
1969 | 1968 | " raised = True\n",
|
1970 | 1969 | "assert raised\n",
|
1971 | 1970 | "\n",
|
1972 |
| - "import datetime\n", |
1973 |
| - "specific_datetime = datetime.datetime(2018, 8, 10, 15, 30, 0)\n", |
| 1971 | + "specific_datetime = datetime(2018, 8, 10, 15, 30, 0)\n", |
1974 | 1972 | "vec.upsert([\n",
|
1975 | 1973 | " # current time\n",
|
1976 | 1974 | " (uuid.uuid1(), {\"key\": \"val\"}, \"the brown fox\", [1.0, 1.2]),\n",
|
|
0 commit comments