|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": { |
6 | 6 | "application/vnd.databricks.v1+cell": { |
7 | | - "cellMetadata": {}, |
| 7 | + "cellMetadata": { |
| 8 | + "byteLimit": 2048000, |
| 9 | + "rowLimit": 10000 |
| 10 | + }, |
8 | 11 | "inputWidgets": {}, |
9 | 12 | "nuid": "7d1791bd-9552-4116-90b2-daa678bbffb8", |
10 | 13 | "showTitle": false, |
|
21 | 24 | "execution_count": 0, |
22 | 25 | "metadata": { |
23 | 26 | "application/vnd.databricks.v1+cell": { |
24 | | - "cellMetadata": {}, |
| 27 | + "cellMetadata": { |
| 28 | + "byteLimit": 2048000, |
| 29 | + "rowLimit": 10000 |
| 30 | + }, |
25 | 31 | "inputWidgets": {}, |
26 | 32 | "nuid": "2901fbc9-49db-4285-8b94-c460f34d4c4f", |
27 | 33 | "showTitle": false, |
|
40 | 46 | "cell_type": "markdown", |
41 | 47 | "metadata": { |
42 | 48 | "application/vnd.databricks.v1+cell": { |
43 | | - "cellMetadata": {}, |
| 49 | + "cellMetadata": { |
| 50 | + "byteLimit": 2048000, |
| 51 | + "rowLimit": 10000 |
| 52 | + }, |
44 | 53 | "inputWidgets": {}, |
45 | 54 | "nuid": "655120e7-6b25-417c-a08a-c6925feaa425", |
46 | 55 | "showTitle": false, |
|
108 | 117 | "execution_count": 0, |
109 | 118 | "metadata": { |
110 | 119 | "application/vnd.databricks.v1+cell": { |
111 | | - "cellMetadata": {}, |
| 120 | + "cellMetadata": { |
| 121 | + "byteLimit": 2048000, |
| 122 | + "rowLimit": 10000 |
| 123 | + }, |
112 | 124 | "inputWidgets": {}, |
113 | 125 | "nuid": "a2368434-0191-416c-aa1d-12cd44cf48e6", |
114 | 126 | "showTitle": false, |
115 | 127 | "tableResultSettingsMap": {}, |
116 | 128 | "title": "" |
117 | 129 | } |
118 | 130 | }, |
119 | | - "outputs": [], |
| 131 | + "outputs": [ |
| 132 | + { |
| 133 | + "output_type": "stream", |
| 134 | + "name": "stdout", |
| 135 | + "output_type": "stream", |
| 136 | + "text": [ |
| 137 | + "+-------+-------------------+-------------------+----------+------------+\n|user_id| session_start| session_end|session_id|session_type|\n+-------+-------------------+-------------------+----------+------------+\n| 101|2023-11-01 08:00:00|2023-11-01 09:00:00| 1| Viewer|\n| 101|2023-11-01 10:00:00|2023-11-01 11:00:00| 2| Streamer|\n| 102|2023-11-01 13:00:00|2023-11-01 14:00:00| 3| Viewer|\n| 102|2023-11-01 15:00:00|2023-11-01 16:00:00| 4| Viewer|\n| 101|2023-11-02 09:00:00|2023-11-02 10:00:00| 5| Viewer|\n| 102|2023-11-02 12:00:00|2023-11-02 13:00:00| 6| Streamer|\n| 101|2023-11-02 13:00:00|2023-11-02 14:00:00| 7| Streamer|\n| 102|2023-11-02 16:00:00|2023-11-02 17:00:00| 8| Viewer|\n| 103|2023-11-01 08:00:00|2023-11-01 09:00:00| 9| Viewer|\n| 103|2023-11-02 20:00:00|2023-11-02 23:00:00| 10| Viewer|\n| 103|2023-11-03 09:00:00|2023-11-03 10:00:00| 11| Viewer|\n+-------+-------------------+-------------------+----------+------------+\n\n" |
| 138 | + ] |
| 139 | + } |
| 140 | + ], |
120 | 141 | "source": [ |
121 | 142 | "sessions_data_3060 = [\n", |
122 | 143 | " (101, \"2023-11-01 08:00:00\", \"2023-11-01 09:00:00\", 1, \"Viewer\"),\n", |
|
136 | 157 | "sessions_df_3060 = spark.createDataFrame(sessions_data_3060, sessions_columns_3060)\n", |
137 | 158 | "sessions_df_3060.show()" |
138 | 159 | ] |
| 160 | + }, |
| 161 | + { |
| 162 | + "cell_type": "code", |
| 163 | + "execution_count": 0, |
| 164 | + "metadata": { |
| 165 | + "application/vnd.databricks.v1+cell": { |
| 166 | + "cellMetadata": { |
| 167 | + "byteLimit": 2048000, |
| 168 | + "rowLimit": 10000 |
| 169 | + }, |
| 170 | + "inputWidgets": {}, |
| 171 | + "nuid": "cbed387c-a844-4d77-a6ba-e898b49508ca", |
| 172 | + "showTitle": false, |
| 173 | + "tableResultSettingsMap": {}, |
| 174 | + "title": "" |
| 175 | + } |
| 176 | + }, |
| 177 | + "outputs": [], |
| 178 | + "source": [ |
| 179 | + "sessions_df_3060 = sessions_df_3060\\\n", |
| 180 | + " .withColumn(\"session_start\", col(\"session_start\").cast(\"timestamp\")) \\\n", |
| 181 | + " .withColumn(\"session_end\", col(\"session_end\").cast(\"timestamp\"))" |
| 182 | + ] |
| 183 | + }, |
| 184 | + { |
| 185 | + "cell_type": "code", |
| 186 | + "execution_count": 0, |
| 187 | + "metadata": { |
| 188 | + "application/vnd.databricks.v1+cell": { |
| 189 | + "cellMetadata": { |
| 190 | + "byteLimit": 2048000, |
| 191 | + "rowLimit": 10000 |
| 192 | + }, |
| 193 | + "inputWidgets": {}, |
| 194 | + "nuid": "726ca09a-f2a4-4df3-83ba-bcadd8c9c44e", |
| 195 | + "showTitle": false, |
| 196 | + "tableResultSettingsMap": {}, |
| 197 | + "title": "" |
| 198 | + } |
| 199 | + }, |
| 200 | + "outputs": [], |
| 201 | + "source": [ |
| 202 | + "windowSpec = Window.partitionBy(\"user_id\").orderBy(\"session_start\")" |
| 203 | + ] |
| 204 | + }, |
| 205 | + { |
| 206 | + "cell_type": "code", |
| 207 | + "execution_count": 0, |
| 208 | + "metadata": { |
| 209 | + "application/vnd.databricks.v1+cell": { |
| 210 | + "cellMetadata": { |
| 211 | + "byteLimit": 2048000, |
| 212 | + "rowLimit": 10000 |
| 213 | + }, |
| 214 | + "inputWidgets": {}, |
| 215 | + "nuid": "547345a8-db64-495a-8175-f47e5e284574", |
| 216 | + "showTitle": false, |
| 217 | + "tableResultSettingsMap": {}, |
| 218 | + "title": "" |
| 219 | + } |
| 220 | + }, |
| 221 | + "outputs": [], |
| 222 | + "source": [ |
| 223 | + "sessions_df_3060 = sessions_df_3060\\\n", |
| 224 | + " .withColumn(\"prev_end\", lag(\"session_end\").over(windowSpec)) \\\n", |
| 225 | + " .withColumn(\"prev_type\", lag(\"session_type\").over(windowSpec))" |
| 226 | + ] |
| 227 | + }, |
| 228 | + { |
| 229 | + "cell_type": "code", |
| 230 | + "execution_count": 0, |
| 231 | + "metadata": { |
| 232 | + "application/vnd.databricks.v1+cell": { |
| 233 | + "cellMetadata": { |
| 234 | + "byteLimit": 2048000, |
| 235 | + "rowLimit": 10000 |
| 236 | + }, |
| 237 | + "inputWidgets": {}, |
| 238 | + "nuid": "b3af788b-33db-4006-8e79-9f62c465133f", |
| 239 | + "showTitle": false, |
| 240 | + "tableResultSettingsMap": {}, |
| 241 | + "title": "" |
| 242 | + } |
| 243 | + }, |
| 244 | + "outputs": [], |
| 245 | + "source": [ |
| 246 | + "sessions_df_3060 = sessions_df_3060\\\n", |
| 247 | + " .withColumn(\"gap_hours\", (unix_timestamp(col(\"session_start\")) - unix_timestamp(col(\"prev_end\"))) / 3600)" |
| 248 | + ] |
| 249 | + }, |
| 250 | + { |
| 251 | + "cell_type": "code", |
| 252 | + "execution_count": 0, |
| 253 | + "metadata": { |
| 254 | + "application/vnd.databricks.v1+cell": { |
| 255 | + "cellMetadata": { |
| 256 | + "byteLimit": 2048000, |
| 257 | + "rowLimit": 10000 |
| 258 | + }, |
| 259 | + "inputWidgets": {}, |
| 260 | + "nuid": "28314437-b74b-427a-957d-695e11a8da4e", |
| 261 | + "showTitle": false, |
| 262 | + "tableResultSettingsMap": {}, |
| 263 | + "title": "" |
| 264 | + } |
| 265 | + }, |
| 266 | + "outputs": [ |
| 267 | + { |
| 268 | + "output_type": "display_data", |
| 269 | + "data": { |
| 270 | + "text/html": [ |
| 271 | + "<style scoped>\n", |
| 272 | + " .table-result-container {\n", |
| 273 | + " max-height: 300px;\n", |
| 274 | + " overflow: auto;\n", |
| 275 | + " }\n", |
| 276 | + " table, th, td {\n", |
| 277 | + " border: 1px solid black;\n", |
| 278 | + " border-collapse: collapse;\n", |
| 279 | + " }\n", |
| 280 | + " th, td {\n", |
| 281 | + " padding: 5px;\n", |
| 282 | + " }\n", |
| 283 | + " th {\n", |
| 284 | + " text-align: left;\n", |
| 285 | + " }\n", |
| 286 | + "</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>user_id</th></tr></thead><tbody><tr><td>102</td></tr><tr><td>103</td></tr></tbody></table></div>" |
| 287 | + ] |
| 288 | + }, |
| 289 | + "metadata": { |
| 290 | + "application/vnd.databricks.v1+output": { |
| 291 | + "addedWidgets": {}, |
| 292 | + "aggData": [], |
| 293 | + "aggError": "", |
| 294 | + "aggOverflow": false, |
| 295 | + "aggSchema": [], |
| 296 | + "aggSeriesLimitReached": false, |
| 297 | + "aggType": "", |
| 298 | + "arguments": {}, |
| 299 | + "columnCustomDisplayInfos": {}, |
| 300 | + "data": [ |
| 301 | + [ |
| 302 | + 102 |
| 303 | + ], |
| 304 | + [ |
| 305 | + 103 |
| 306 | + ] |
| 307 | + ], |
| 308 | + "datasetInfos": [], |
| 309 | + "dbfsResultPath": null, |
| 310 | + "isJsonSchema": true, |
| 311 | + "metadata": {}, |
| 312 | + "overflow": false, |
| 313 | + "plotOptions": { |
| 314 | + "customPlotOptions": {}, |
| 315 | + "displayType": "table", |
| 316 | + "pivotAggregation": null, |
| 317 | + "pivotColumns": null, |
| 318 | + "xColumns": null, |
| 319 | + "yColumns": null |
| 320 | + }, |
| 321 | + "removedWidgets": [], |
| 322 | + "schema": [ |
| 323 | + { |
| 324 | + "metadata": "{}", |
| 325 | + "name": "user_id", |
| 326 | + "type": "\"long\"" |
| 327 | + } |
| 328 | + ], |
| 329 | + "type": "table" |
| 330 | + } |
| 331 | + }, |
| 332 | + "output_type": "display_data" |
| 333 | + } |
| 334 | + ], |
| 335 | + "source": [ |
| 336 | + "sessions_df_3060\\\n", |
| 337 | + " .filter((col(\"session_type\") == col(\"prev_type\")) & (col(\"gap_hours\") <= 12)) \\\n", |
| 338 | + " .select(\"user_id\").distinct() \\\n", |
| 339 | + " .orderBy(\"user_id\").display()" |
| 340 | + ] |
139 | 341 | } |
140 | 342 | ], |
141 | 343 | "metadata": { |
142 | 344 | "application/vnd.databricks.v1+notebook": { |
143 | | - "computePreferences": null, |
| 345 | + "computePreferences": { |
| 346 | + "hardware": { |
| 347 | + "accelerator": null, |
| 348 | + "gpuPoolId": null, |
| 349 | + "memory": null |
| 350 | + } |
| 351 | + }, |
144 | 352 | "dashboards": [], |
145 | 353 | "environmentMetadata": { |
146 | 354 | "base_environment": "", |
147 | | - "environment_version": "1" |
| 355 | + "environment_version": "2" |
148 | 356 | }, |
149 | 357 | "inputWidgetPreferences": null, |
150 | 358 | "language": "python", |
|
0 commit comments